mirror of
https://github.com/lukaszraczylo/claude-adam.git
synced 2026-06-10 23:29:03 +00:00
6d8ff37cb2
Bug fixes (HIGH):
- adam-observe.mjs: errorFingerprint no longer false-positives when
toolResponse.is_error === false; ERROR_RE only used as fallback when
is_error is undefined.
- adam-observe.mjs: resetSessionLocal now clears tool_window so retry_loop
cannot fire on the first tool of a new session by matching prior session.
- adam-archive.mjs: ts dedup uses Map<ts, count> instead of Set<ts>; two
journal entries sharing a millisecond are no longer both archived when
only one is referenced in source_entries.
- adam-nudge.mjs: only counts proposal filenames matching
/^\d{4}-\d{2}-\d{3}-/ pattern; README/notes in proposals/ no longer bump.
- skills/adam-self-improvement/SKILL.md: contradiction_flag veto now applied
at apply time (carry-over from earlier review).
Test isolation:
- adam/tests/run-tests.sh: ALWAYS runs against an isolated $HOME under
mktemp -d. Previously truncated live ~/.claude/adam/journal.jsonl on
every run — destructive on production state.
Conciseness:
- agents/adam.md: -19 LOC (cuts: vestigial cursor sentence, duplicate
not-do bullets, blast-radius bullet collapse, Inputs paths delegate to
SKILL.md, win-cluster-vs-struggle-cluster commentary already enforced
by cluster-key separation, # Overlap section spec compressed).
- skills/adam-self-improvement/SKILL.md: -4 LOC (framing paragraph, dead
catch-all bullet for non-eligible types).
Auto-prune script DELETED:
- The cumulative-count primitive cannot distinguish "never used" from
"used before tracking began"; mtime gate is meaningless for installed
files. Auto-prune deferred to v0.4 with a per-key lastSeen schema.
Cross-platform:
- macOS (BSD coreutils) and Linux (Alpine, glibc + musl) verified.
- All scripts use portable forms (stat -f || stat -c, mktemp -d -t).
- README documents platform support explicitly.
DX overhaul:
- install.sh: hardened — supports `curl | bash` via auto-clone,
--version=vX.Y.Z pinning, --yes / --dry-run flags, jq-based
settings.json merge with diff prompt and backup, conservative file
copy that detects local mtime drift and writes <file>.adam-new
instead of clobbering, idempotent across re-runs.
- adam-uninstall.sh: NEW. Soft-archives ~/.claude/adam/ to .bak.<ts>/
by default; --purge to delete; --yes for non-interactive; jq-based
settings.json cleanup with diff prompt.
- README.md: curl one-liner install + version-pinned variant at top,
What's New section through v0.3.1, upgrade-safe data files callout,
uninstaller documentation, platform support note, expanded rubric
showing skill_edit gate.
Test count: 27 passed, 0 failed (was 27 — no regression).
123 lines
3.7 KiB
JavaScript
Executable File
123 lines
3.7 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
// Usage: adam-archive.mjs <proposal-path>
|
|
// Reads `source_entries` from proposal frontmatter, moves matching journal
|
|
// entries from journal.jsonl to journal/actioned-<id>.jsonl. Used by the
|
|
// adam-self-improvement skill after each apply/reject so subsequent /reflect
|
|
// runs do not re-cluster already-actioned signals.
|
|
|
|
import { readFileSync, writeFileSync, appendFileSync, mkdirSync, existsSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { homedir } from "node:os";
|
|
|
|
const ROOT = join(homedir(), ".claude", "adam");
|
|
const JOURNAL = join(ROOT, "journal.jsonl");
|
|
const JOURNAL_DIR = join(ROOT, "journal");
|
|
|
|
function parseFrontmatter(content) {
|
|
const m = content.match(/^---\n([\s\S]*?)\n---/);
|
|
if (!m) return {};
|
|
const fm = {};
|
|
const lines = m[1].split("\n");
|
|
let i = 0;
|
|
while (i < lines.length) {
|
|
const line = lines[i];
|
|
const idx = line.indexOf(":");
|
|
if (idx === -1) { i++; continue; }
|
|
const key = line.slice(0, idx).trim();
|
|
const value = line.slice(idx + 1).trim();
|
|
if (key === "source_entries") {
|
|
const arr = [];
|
|
if (value.startsWith("[") && value.endsWith("]")) {
|
|
const inner = value.slice(1, -1)
|
|
.split(",")
|
|
.map(s => s.trim().replace(/^['"]|['"]$/g, ""));
|
|
arr.push(...inner.filter(Boolean));
|
|
fm[key] = arr;
|
|
i++;
|
|
continue;
|
|
}
|
|
i++;
|
|
while (i < lines.length && /^\s*-\s+/.test(lines[i])) {
|
|
const item = lines[i].replace(/^\s*-\s+/, "").trim().replace(/^['"]|['"]$/g, "");
|
|
if (item) arr.push(item);
|
|
i++;
|
|
}
|
|
fm[key] = arr;
|
|
continue;
|
|
}
|
|
fm[key] = value;
|
|
i++;
|
|
}
|
|
return fm;
|
|
}
|
|
|
|
function main() {
|
|
const proposalPath = process.argv[2];
|
|
if (!proposalPath) {
|
|
console.error("usage: adam-archive.mjs <proposal-path>");
|
|
process.exit(2);
|
|
}
|
|
|
|
let proposal;
|
|
try {
|
|
proposal = readFileSync(proposalPath, "utf8");
|
|
} catch (e) {
|
|
console.error(`cannot read ${proposalPath}: ${e.message}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const fm = parseFrontmatter(proposal);
|
|
const id = fm.id || "unknown";
|
|
const sourceEntries = Array.isArray(fm.source_entries) ? fm.source_entries : [];
|
|
|
|
if (sourceEntries.length === 0) {
|
|
console.log(`${id}: no source_entries in frontmatter — nothing to archive`);
|
|
return;
|
|
}
|
|
|
|
if (!existsSync(JOURNAL)) {
|
|
console.log(`${id}: journal does not exist at ${JOURNAL}`);
|
|
return;
|
|
}
|
|
|
|
const lines = readFileSync(JOURNAL, "utf8").split("\n").filter(Boolean);
|
|
// tsCounts: how many entries with this ts the proposal claims as its own.
|
|
// Same-millisecond duplicates: only consume up to the recorded count.
|
|
const tsCounts = new Map();
|
|
for (const ts of sourceEntries) tsCounts.set(ts, (tsCounts.get(ts) || 0) + 1);
|
|
const matched = [];
|
|
const remaining = [];
|
|
|
|
for (const line of lines) {
|
|
try {
|
|
const e = JSON.parse(line);
|
|
const remainingCount = e.ts ? (tsCounts.get(e.ts) || 0) : 0;
|
|
if (remainingCount > 0) {
|
|
matched.push(line);
|
|
tsCounts.set(e.ts, remainingCount - 1);
|
|
} else {
|
|
remaining.push(line);
|
|
}
|
|
} catch {
|
|
remaining.push(line);
|
|
}
|
|
}
|
|
|
|
if (matched.length === 0) {
|
|
console.log(`${id}: no matching entries in journal (already archived?)`);
|
|
return;
|
|
}
|
|
|
|
mkdirSync(JOURNAL_DIR, { recursive: true });
|
|
const archivePath = join(JOURNAL_DIR, `actioned-${id}.jsonl`);
|
|
appendFileSync(archivePath, matched.join("\n") + "\n");
|
|
writeFileSync(JOURNAL, remaining.length ? remaining.join("\n") + "\n" : "");
|
|
|
|
console.log(`${id}: archived ${matched.length}/${lines.length} entries → ${archivePath}`);
|
|
}
|
|
|
|
try { main(); } catch (e) {
|
|
console.error(`error: ${e.message}`);
|
|
process.exit(1);
|
|
}
|