opencode-self-improvement 0.15.18 → 0.15.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +4 -0
  2. package/package.json +4 -2
  3. package/src/capture/candidates.ts +17 -6
  4. package/src/capture/lag.ts +6 -2
  5. package/src/capture/prompt.ts +1 -1
  6. package/src/capture/runtime.ts +85 -21
  7. package/src/capture/session-model.ts +2 -1
  8. package/src/capture/transcript.ts +10 -4
  9. package/src/capture/triggers.ts +48 -14
  10. package/src/command/ensure.ts +6 -1
  11. package/src/consolidate/propose.ts +47 -17
  12. package/src/consolidate/render.ts +3 -1
  13. package/src/core/cmp-ts.ts +2 -2
  14. package/src/core/config/budgets.ts +0 -1
  15. package/src/core/config/paths.ts +2 -3
  16. package/src/core/hooks.ts +8 -3
  17. package/src/core/host.ts +8 -3
  18. package/src/core/logfmt/format.ts +20 -5
  19. package/src/core/logfmt/publish.ts +21 -4
  20. package/src/core/lru.ts +20 -20
  21. package/src/core/permissions.ts +21 -5
  22. package/src/core/runtime.ts +7 -3
  23. package/src/core/state.ts +12 -2
  24. package/src/core/time.ts +0 -1
  25. package/src/core/tokenize.ts +16 -5
  26. package/src/core/types.ts +8 -1
  27. package/src/events.ts +74 -18
  28. package/src/evidence/record.ts +29 -9
  29. package/src/gate/gate.ts +244 -94
  30. package/src/gate/resolver.ts +105 -20
  31. package/src/hits/ledger.ts +35 -10
  32. package/src/identity/host-events.ts +35 -11
  33. package/src/identity/repokey.ts +27 -9
  34. package/src/identity/session-context.ts +39 -8
  35. package/src/index.ts +108 -42
  36. package/src/init/detect.ts +62 -12
  37. package/src/init/run.ts +50 -11
  38. package/src/inject/anchor.ts +11 -5
  39. package/src/inject/attribution.ts +29 -6
  40. package/src/inject/budget.ts +9 -2
  41. package/src/inject/digest.ts +16 -8
  42. package/src/inject/epochs.ts +43 -15
  43. package/src/inject/pull.ts +11 -5
  44. package/src/inject/version.ts +10 -5
  45. package/src/portable/decay.ts +20 -9
  46. package/src/portable/export.ts +30 -10
  47. package/src/portable/import.ts +43 -12
  48. package/src/recall/relevant.ts +11 -5
  49. package/src/recall/score.ts +5 -3
  50. package/src/status/format.ts +8 -2
  51. package/src/status/metrics.ts +22 -6
  52. package/src/status/payload.ts +7 -2
  53. package/src/status/report.ts +63 -18
  54. package/src/status/write.ts +21 -7
  55. package/src/store/blocklist.ts +16 -4
  56. package/src/store/containment.ts +27 -8
  57. package/src/store/files/append.ts +57 -37
  58. package/src/store/files/deletions.ts +5 -2
  59. package/src/store/files/load.ts +37 -11
  60. package/src/store/files/prune.ts +18 -5
  61. package/src/store/files/snapshots.ts +6 -2
  62. package/src/store/files/supersede.ts +32 -12
  63. package/src/store/files/target.ts +4 -1
  64. package/src/store/lock.ts +10 -2
  65. package/src/store/model/visibility.ts +26 -6
  66. package/src/store/prune.ts +1 -1
  67. package/src/store/quarantine/quarantine.ts +36 -9
  68. package/src/store/quarantine/release.ts +9 -3
  69. package/src/store/secrets.ts +4 -2
  70. package/src/store/tombstones/rejection.ts +21 -5
  71. package/src/store/tombstones/tombstone.ts +48 -11
  72. package/src/store/undo.ts +43 -18
  73. package/src/tools/consolidate.ts +18 -8
  74. package/src/tools/decay.ts +37 -9
  75. package/src/tools/deps.ts +10 -2
  76. package/src/tools/evidence.ts +7 -4
  77. package/src/tools/export.ts +10 -4
  78. package/src/tools/forget.ts +15 -5
  79. package/src/tools/import.ts +16 -5
  80. package/src/tools/init.ts +13 -4
  81. package/src/tools/list.ts +12 -6
  82. package/src/tools/merge-review.ts +52 -20
  83. package/src/tools/recall.ts +17 -9
  84. package/src/tools/registry.ts +4 -1
  85. package/src/tools/remember.ts +21 -7
  86. package/src/tools/schema.ts +55 -18
  87. package/src/tools/status-tool.ts +29 -11
  88. package/src/tools/undo.ts +23 -8
  89. package/src/tools/update.ts +116 -40
  90. package/src/tui/panel.tsx +119 -30
  91. package/src/viewer/mutate.ts +57 -20
  92. package/src/viewer/rejections.ts +1 -1
  93. package/src/viewer/server.ts +88 -28
@@ -2,18 +2,19 @@
2
2
  // and handler are byte-identical to the pre-split source; closure access arrives
3
3
  // through ToolDeps.
4
4
  import type { ToolRegister } from "./deps.ts";
5
- import { proposeConsolidations } from "../consolidate/propose.ts"
5
+ import { proposeConsolidations } from "../consolidate/propose.ts";
6
6
  import { renderProposals } from "../consolidate/render.ts";
7
7
  import { record } from "../evidence/record.ts";
8
8
  import { readLedger, readReads } from "../hits/ledger.ts";
9
- import { loadAll } from "../store/files/load.ts"
10
- import { isInjectable } from "../store/model/predicates.ts"
9
+ import { loadAll } from "../store/files/load.ts";
10
+ import { isInjectable } from "../store/model/predicates.ts";
11
11
  import { isVisibleTo, readerFromSid } from "../store/model/visibility.ts";
12
12
  import { ConsolidateArgs, validated } from "./schema.ts";
13
13
 
14
14
  export const register: ToolRegister = (editor, deps) => {
15
15
  const { toolIds, direct } = deps;
16
- editor.add(validated(ConsolidateArgs, {
16
+ editor.add(
17
+ validated(ConsolidateArgs, {
17
18
  name: "memory_consolidate",
18
19
  description:
19
20
  "Propose consolidations of near-duplicate settled rows — read-only, nothing is written. Clusters same-scope same-type rows by jaccard, picks the most recently used member as canonical (#42's rule: the row retrieval keeps landing on), and proposes it ONLY when replaying the cluster's own logged reads proves the merged row catches at least as many reads as the best single member did. A cluster with no recorded reads is reported as unmeasured, never merged on resemblance. Resolve a proposal with memory_merge_review; absorbed rows stay recoverable. The merge is deterministic — the canonical row is the survivor's prose plus the absorbed rows' aliases — because this plugin ships no model and a rewritten row cannot be diffed or audited.",
@@ -21,8 +22,12 @@ export const register: ToolRegister = (editor, deps) => {
21
22
  async execute(args, context): Promise<{ content: string }> {
22
23
  const { sid } = toolIds(context);
23
24
  const reader = readerFromSid(sid);
24
- const all = (await loadAll()).filter(isInjectable).filter((m) => isVisibleTo(m, reader));
25
- const rows = args.scope ? all.filter((m) => m.scope === args.scope) : all;
25
+ const all = (await loadAll())
26
+ .filter(isInjectable)
27
+ .filter((m) => isVisibleTo(m, reader));
28
+ const rows = args.scope
29
+ ? all.filter((m) => m.scope === args.scope)
30
+ : all;
26
31
  const ledger = await readLedger();
27
32
  const use = ledger.byRow;
28
33
  const reads = await readReads();
@@ -33,10 +38,15 @@ export const register: ToolRegister = (editor, deps) => {
33
38
  const out = renderProposals({ ...report, plans: shown });
34
39
  await record(
35
40
  "consolidate_propose",
36
- { clusters: shown.length, rows: report.rowsBefore, would_drop: report.rowsBefore - report.rowsAfter },
41
+ {
42
+ clusters: shown.length,
43
+ rows: report.rowsBefore,
44
+ would_drop: report.rowsBefore - report.rowsAfter,
45
+ },
37
46
  false,
38
47
  );
39
48
  return { content: out };
40
49
  },
41
- }));
50
+ }),
51
+ );
42
52
  };
@@ -3,7 +3,7 @@
3
3
  // through ToolDeps.
4
4
  import type { ToolRegister } from "./deps.ts";
5
5
  import { record } from "../evidence/record.ts";
6
- import { snapshotFiles } from "../store/files/snapshots.ts"
6
+ import { snapshotFiles } from "../store/files/snapshots.ts";
7
7
  import { markManySuperseded } from "../store/files/supersede.ts";
8
8
  import { findStaleOpen } from "../portable/decay.ts";
9
9
  import { flattenMemoryText } from "../store/sanitize.ts";
@@ -11,14 +11,16 @@ import { DecayArgs, validated } from "./schema.ts";
11
11
 
12
12
  export const register: ToolRegister = (editor, deps) => {
13
13
  const { toolIds, direct } = deps;
14
- editor.add(validated(DecayArgs, {
14
+ editor.add(
15
+ validated(DecayArgs, {
15
16
  name: "memory_decay",
16
17
  description:
17
18
  "Retire stale open threads (status=open older than olderThanDays) by superseding them — never deleting; rows stay recoverable via memory_undo. DRY RUN BY DEFAULT: without an explicit dryRun=false this only LISTS what would retire and mutates nothing (fail-closed). A real run snapshots every affected file before the first mutation.",
18
19
  options: direct,
19
20
  async execute(args, context): Promise<{ content: string }> {
20
21
  const { sid } = toolIds(context);
21
- const days = Number(args.olderThanDays) > 0 ? Number(args.olderThanDays) : 14;
22
+ const days =
23
+ Number(args.olderThanDays) > 0 ? Number(args.olderThanDays) : 14;
22
24
  const dryRun = args.dryRun !== false; // only an explicit false mutates
23
25
  const stale = await findStaleOpen(days, sid);
24
26
  if (!stale.length) {
@@ -33,7 +35,11 @@ export const register: ToolRegister = (editor, deps) => {
33
35
  if (dryRun) {
34
36
  await record(
35
37
  "decay_dry_run",
36
- { days, stale: stale.length, mem: stale.map((m) => m.ts).join(",") },
38
+ {
39
+ days,
40
+ stale: stale.length,
41
+ mem: stale.map((m) => m.ts).join(","),
42
+ },
37
43
  false,
38
44
  );
39
45
  return {
@@ -46,7 +52,9 @@ export const register: ToolRegister = (editor, deps) => {
46
52
  // one whole-file copy per affected file, taken before the first
47
53
  // mutation. The batch pass snapshots again per file it touches; this
48
54
  // pass guarantees a pre-decay copy exists even if a later file fails.
49
- const snapshot = await snapshotFiles([...new Set(stale.map((m) => m.file))]);
55
+ const snapshot = await snapshotFiles([
56
+ ...new Set(stale.map((m) => m.file)),
57
+ ]);
50
58
  // One lock/read/snapshot/publish per file for the whole decay run (#61):
51
59
  // N retired rows are one undo point, not N. Idempotent (a no-op on rows
52
60
  // already superseded, out-of-band ones skipped under the lock).
@@ -54,13 +62,32 @@ export const register: ToolRegister = (editor, deps) => {
54
62
  let retired: number;
55
63
  try {
56
64
  retired = await markManySuperseded(
57
- stale.map((m) => ({ ts: m.ts, fields: { superseded_by: "decay", reason: "decay" } })), durable,
65
+ stale.map((m) => ({
66
+ ts: m.ts,
67
+ fields: { superseded_by: "decay", reason: "decay" },
68
+ })),
69
+ durable,
58
70
  );
59
71
  } catch (err) {
60
72
  if (durable.length === 0) throw err;
61
73
  let why = err instanceof Error ? err.message : String(err);
62
- await record("decay_applied", { days, retired: durable.length, mem: durable.join(","), snapshot: snapshot.join(","), partial: true, error: why }, false).catch((audit) => { why += `; audit failed: ${String(audit)}`; });
63
- return { content: `memory_decay PARTIAL: retired row(s) ${durable.join(", ")}; stopped: ${why}. Recover with memory_undo; inspect memory_evidence before retrying.` };
74
+ await record(
75
+ "decay_applied",
76
+ {
77
+ days,
78
+ retired: durable.length,
79
+ mem: durable.join(","),
80
+ snapshot: snapshot.join(","),
81
+ partial: true,
82
+ error: why,
83
+ },
84
+ false,
85
+ ).catch((audit) => {
86
+ why += `; audit failed: ${String(audit)}`;
87
+ });
88
+ return {
89
+ content: `memory_decay PARTIAL: retired row(s) ${durable.join(", ")}; stopped: ${why}. Recover with memory_undo; inspect memory_evidence before retrying.`,
90
+ };
64
91
  }
65
92
  await record(
66
93
  "decay_applied",
@@ -79,5 +106,6 @@ export const register: ToolRegister = (editor, deps) => {
79
106
  "Recover with memory_undo.",
80
107
  };
81
108
  },
82
- }));
109
+ }),
110
+ );
83
111
  };
package/src/tools/deps.ts CHANGED
@@ -10,10 +10,18 @@ export interface ToolDeps {
10
10
  toolIds: (context?: unknown) => { sid: string; call: string };
11
11
  bindSessionIdentity: (sid: string | undefined) => Promise<void>;
12
12
  ownerlessWriter: (sid: string | undefined) => string | null;
13
- refuseOwnerlessWrite: (sid: string, op: string) => Promise<{ content: string }>;
13
+ refuseOwnerlessWrite: (
14
+ sid: string,
15
+ op: string,
16
+ ) => Promise<{ content: string }>;
14
17
  gateContext: (sid?: string) => GateContext;
15
18
  sessions: ReturnType<typeof createInjectionEpochs>;
16
- noteHits: (src: HitSource, sid: string, rows: Memory[], query: string) => Promise<void>;
19
+ noteHits: (
20
+ src: HitSource,
21
+ sid: string,
22
+ rows: Memory[],
23
+ query: string,
24
+ ) => Promise<void>;
17
25
  direct: { readonly codemode: false };
18
26
  }
19
27
 
@@ -3,16 +3,18 @@
3
3
  // through ToolDeps.
4
4
  import type { ToolRegister } from "./deps.ts";
5
5
  import { evidenceFileFor } from "../evidence/record.ts";
6
- import { parseLine } from "../core/logfmt/format.ts"
6
+ import { parseLine } from "../core/logfmt/format.ts";
7
7
  import { readLines } from "../core/logfmt/read.ts";
8
8
  import { evidenceVisibleTo, readerFromSid } from "../store/model/visibility.ts";
9
9
  import { EvidenceArgs, validated } from "./schema.ts";
10
10
 
11
11
  export const register: ToolRegister = (editor, deps) => {
12
12
  const { toolIds, direct } = deps;
13
- editor.add(validated(EvidenceArgs, {
13
+ editor.add(
14
+ validated(EvidenceArgs, {
14
15
  name: "memory_evidence",
15
- description: "Read captured evidence (data only) for a date, optionally filtered by event.",
16
+ description:
17
+ "Read captured evidence (data only) for a date, optionally filtered by event.",
16
18
  options: direct,
17
19
  async execute(args, context): Promise<{ content: string }> {
18
20
  const { sid } = toolIds(context);
@@ -44,5 +46,6 @@ export const register: ToolRegister = (editor, deps) => {
44
46
  const limit = args.limit || 50;
45
47
  return { content: lines.slice(-limit).join("\n") };
46
48
  },
47
- }));
49
+ }),
50
+ );
48
51
  };
@@ -7,15 +7,20 @@ import { ExportArgs, validated } from "./schema.ts";
7
7
 
8
8
  export const register: ToolRegister = (editor, deps) => {
9
9
  const { toolIds, direct } = deps;
10
- editor.add(validated(ExportArgs, {
10
+ editor.add(
11
+ validated(ExportArgs, {
11
12
  name: "memory_export",
12
13
  description:
13
- "Export active memories as a JSONL file for backup or transfer to another machine — scoped to what this session can read: its own repository plus global rows (full-store breadth belongs to a session-less call made outside the plugin, the library route; the viewer has no export route). The first line is a metadata header ({_export,version,exportedAt,count}); each later line is one JSON object {ts,type,scope,content,status,tags,issue}. The header is what lets memory_import keep repo-scoped status:\"open\" frontier rows — a hand-written file without it imports such rows as settled, as does an imported open row claiming repo:\"global\". Defaults to a unique <memory-root>/exports/<timestamp>-<unique>.jsonl (each default export gets its own file; two exports in the same second never share a path); `file` must name a path inside <memory-root>/exports (a relative path resolves against it), `scope` exports one scope. Superseded rows are not exported (history stays in the store).",
14
+ 'Export active memories as a JSONL file for backup or transfer to another machine — scoped to what this session can read: its own repository plus global rows (full-store breadth belongs to a session-less call made outside the plugin, the library route; the viewer has no export route). The first line is a metadata header ({_export,version,exportedAt,count}); each later line is one JSON object {ts,type,scope,content,status,tags,issue}. The header is what lets memory_import keep repo-scoped status:"open" frontier rows — a hand-written file without it imports such rows as settled, as does an imported open row claiming repo:"global". Defaults to a unique <memory-root>/exports/<timestamp>-<unique>.jsonl (each default export gets its own file; two exports in the same second never share a path); `file` must name a path inside <memory-root>/exports (a relative path resolves against it), `scope` exports one scope. Superseded rows are not exported (history stays in the store).',
14
15
  options: direct,
15
16
  async execute(args, context): Promise<{ content: string }> {
16
17
  try {
17
18
  const { sid } = toolIds(context);
18
- const res = await exportMemories({ scope: args.scope, file: args.file, sessionID: sid });
19
+ const res = await exportMemories({
20
+ scope: args.scope,
21
+ file: args.file,
22
+ sessionID: sid,
23
+ });
19
24
  return { content: `Exported ${res.count} memories -> ${res.path}` };
20
25
  } catch (err) {
21
26
  return {
@@ -23,5 +28,6 @@ export const register: ToolRegister = (editor, deps) => {
23
28
  };
24
29
  }
25
30
  },
26
- }));
31
+ }),
32
+ );
27
33
  };
@@ -7,7 +7,8 @@ import { ForgetArgs, validated } from "./schema.ts";
7
7
 
8
8
  export const register: ToolRegister = (editor, deps) => {
9
9
  const { toolIds, bindSessionIdentity, direct } = deps;
10
- editor.add(validated(ForgetArgs, {
10
+ editor.add(
11
+ validated(ForgetArgs, {
11
12
  name: "memory_forget",
12
13
  description:
13
14
  "Delete memories by scope and type. Snapshots first, logs the reason for audit, never touches a repo.",
@@ -20,9 +21,18 @@ export const register: ToolRegister = (editor, deps) => {
20
21
  // by its own repository, not the instance's provisional binding.
21
22
  await bindSessionIdentity(sid);
22
23
  const res = await pruneMemory(args.scope, args.type, args.reason, sid);
23
- if (res.error) return { content: `memory_forget PARTIAL: deleted row(s) ${res.deleted.map((d) => d.memory.ts).join(", ")}; stopped: ${res.error}. Rejection tombstones or audit lines may be incomplete. Inspect memory_evidence / memory_undo before retrying.` };
24
- if (!res.deleted.length) return { content: `No memories found for ${args.type} in ${args.scope}` };
25
- return { content: `Deleted ${res.deleted.length} ${args.type} memory(s) from ${args.scope}. Audit: ${res.audit}` };
24
+ if (res.error)
25
+ return {
26
+ content: `memory_forget PARTIAL: deleted row(s) ${res.deleted.map((d) => d.memory.ts).join(", ")}; stopped: ${res.error}. Rejection tombstones or audit lines may be incomplete. Inspect memory_evidence / memory_undo before retrying.`,
27
+ };
28
+ if (!res.deleted.length)
29
+ return {
30
+ content: `No memories found for ${args.type} in ${args.scope}`,
31
+ };
32
+ return {
33
+ content: `Deleted ${res.deleted.length} ${args.type} memory(s) from ${args.scope}. Audit: ${res.audit}`,
34
+ };
26
35
  },
27
- }));
36
+ }),
37
+ );
28
38
  };
@@ -7,11 +7,19 @@ import { importMemories } from "../portable/import.ts";
7
7
  import { ImportArgs, validated } from "./schema.ts";
8
8
 
9
9
  export const register: ToolRegister = (editor, deps) => {
10
- const { toolIds, bindSessionIdentity, ownerlessWriter, refuseOwnerlessWrite, gateContext, direct } = deps;
11
- editor.add(validated(ImportArgs, {
10
+ const {
11
+ toolIds,
12
+ bindSessionIdentity,
13
+ ownerlessWriter,
14
+ refuseOwnerlessWrite,
15
+ gateContext,
16
+ direct,
17
+ } = deps;
18
+ editor.add(
19
+ validated(ImportArgs, {
12
20
  name: "memory_import",
13
21
  description:
14
- "Import memories from a JSONL export (see memory_export). Every row goes through the same 4-gate write pipeline as memory_remember (tagged `import`, original tags preserved), so duplicates collapse and ungrounded rows are blocked exactly as usual — those are normal tallied outcomes, not errors. Malformed lines are skipped and counted. `file` must be inside the memory root — copy the export there first. Frontier policy: status:\"open\" exempts a row from ref grounding, so it requires a memory_export header and cannot claim global scope; imported repo stamps are kept only when they match the importing session's repo, otherwise the importing repo is stamped. A stamped open row is downgraded when there is no current repo scope to verify it. Imported content is unverified by construction: injected rows surface a `[via import]` provenance marker.",
22
+ 'Import memories from a JSONL export (see memory_export). Every row goes through the same 4-gate write pipeline as memory_remember (tagged `import`, original tags preserved), so duplicates collapse and ungrounded rows are blocked exactly as usual — those are normal tallied outcomes, not errors. Malformed lines are skipped and counted. `file` must be inside the memory root — copy the export there first. Frontier policy: status:"open" exempts a row from ref grounding, so it requires a memory_export header and cannot claim global scope; imported repo stamps are kept only when they match the importing session\'s repo, otherwise the importing repo is stamped. A stamped open row is downgraded when there is no current repo scope to verify it. Imported content is unverified by construction: injected rows surface a `[via import]` provenance marker.',
15
23
  options: direct,
16
24
  async execute(args, context): Promise<{ content: string }> {
17
25
  const { sid } = toolIds(context);
@@ -36,7 +44,9 @@ export const register: ToolRegister = (editor, deps) => {
36
44
  content:
37
45
  `Imported ${args.file}: ${t.promoted} promoted, ${t.collapsed} duplicates collapsed, ` +
38
46
  `${t.blocked} blocked by the gate, ${t.skipped} malformed lines skipped.` +
39
- (t.quarantined ? ` ${t.quarantined} promoted ${t.quarantined === 1 ? "row" : "rows"} quarantined: withheld from recall/injection until human release in the viewer.` : "") +
47
+ (t.quarantined
48
+ ? ` ${t.quarantined} promoted ${t.quarantined === 1 ? "row" : "rows"} quarantined: withheld from recall/injection until human release in the viewer.`
49
+ : "") +
40
50
  (t.downgraded
41
51
  ? ` ${t.downgraded} open rows downgraded to settled (missing eligible memory_export header or verifiable repo scope).`
42
52
  : "") +
@@ -53,5 +63,6 @@ export const register: ToolRegister = (editor, deps) => {
53
63
  };
54
64
  }
55
65
  },
56
- }));
66
+ }),
67
+ );
57
68
  };
package/src/tools/init.ts CHANGED
@@ -2,13 +2,21 @@
2
2
  // and handler are byte-identical to the pre-split source; closure access arrives
3
3
  // through ToolDeps.
4
4
  import type { ToolRegister } from "./deps.ts";
5
- import { formatInit } from "../init/format.ts"
5
+ import { formatInit } from "../init/format.ts";
6
6
  import { runInit } from "../init/run.ts";
7
7
  import { InitArgs, validated } from "./schema.ts";
8
8
 
9
9
  export const register: ToolRegister = (editor, deps) => {
10
- const { toolIds, bindSessionIdentity, ownerlessWriter, refuseOwnerlessWrite, gateContext, direct } = deps;
11
- editor.add(validated(InitArgs, {
10
+ const {
11
+ toolIds,
12
+ bindSessionIdentity,
13
+ ownerlessWriter,
14
+ refuseOwnerlessWrite,
15
+ gateContext,
16
+ direct,
17
+ } = deps;
18
+ editor.add(
19
+ validated(InitArgs, {
12
20
  name: "memory_init",
13
21
  description:
14
22
  "Initialize repository memory and knowledge graph. Ensures the codebase-memory graph for this repo is indexed (one-shot `cli` spawn; no session MCP needed) and re-derives build/lint/test/typecheck command memories through the write gate, then stores an init stamp keyed on git HEAD. Idempotent: a no-op when the stamp matches HEAD, unless force=true (refresh after a refactor).",
@@ -26,5 +34,6 @@ export const register: ToolRegister = (editor, deps) => {
26
34
  });
27
35
  return { content: formatInit(summary) };
28
36
  },
29
- }));
37
+ }),
38
+ );
30
39
  };
package/src/tools/list.ts CHANGED
@@ -2,22 +2,25 @@
2
2
  // and handler are byte-identical to the pre-split source; closure access arrives
3
3
  // through ToolDeps.
4
4
  import type { ToolRegister } from "./deps.ts";
5
- import { loadAll } from "../store/files/load.ts"
6
- import { isInjectable } from "../store/model/predicates.ts"
5
+ import { loadAll } from "../store/files/load.ts";
6
+ import { isInjectable } from "../store/model/predicates.ts";
7
7
  import { isVisibleTo, readerFromSid } from "../store/model/visibility.ts";
8
8
  import { flattenMemoryText } from "../store/sanitize.ts";
9
9
  import { EmptyArgs, validated } from "./schema.ts";
10
10
 
11
11
  export const register: ToolRegister = (editor, deps) => {
12
12
  const { toolIds, direct } = deps;
13
- editor.add(validated(EmptyArgs, {
13
+ editor.add(
14
+ validated(EmptyArgs, {
14
15
  name: "memory_list",
15
16
  description: "List memory scopes and types for discovery.",
16
17
  options: direct,
17
18
  async execute(_args, context): Promise<{ content: string }> {
18
19
  const { sid } = toolIds(context);
19
20
  const reader = readerFromSid(sid);
20
- const mems = (await loadAll()).filter(isInjectable).filter((m) => isVisibleTo(m, reader));
21
+ const mems = (await loadAll())
22
+ .filter(isInjectable)
23
+ .filter((m) => isVisibleTo(m, reader));
21
24
  if (!mems.length) return { content: "No memories found" };
22
25
  const scopes = new Map<string, number>();
23
26
  const types = new Map<string, number>();
@@ -30,7 +33,10 @@ export const register: ToolRegister = (editor, deps) => {
30
33
  .sort((a, b) => b[1] - a[1])
31
34
  .map(([k, c]) => ` ${flattenMemoryText(k)}: ${c}`)
32
35
  .join("\n");
33
- return { content: `Total: ${mems.length}\n\nScopes:\n${fmt(scopes)}\n\nTypes:\n${fmt(types)}` };
36
+ return {
37
+ content: `Total: ${mems.length}\n\nScopes:\n${fmt(scopes)}\n\nTypes:\n${fmt(types)}`,
38
+ };
34
39
  },
35
- }));
40
+ }),
41
+ );
36
42
  };
@@ -4,15 +4,16 @@ import type { ToolRegister } from "./deps.ts";
4
4
  import { memoryRoot } from "../core/config/paths.ts";
5
5
  import { record } from "../evidence/record.ts";
6
6
  import { withStoreLock } from "../store/lock.ts";
7
- import { loadAll } from "../store/files/load.ts"
8
- import { clearSuperseded, markSuperseded } from "../store/files/supersede.ts"
7
+ import { loadAll } from "../store/files/load.ts";
8
+ import { clearSuperseded, markSuperseded } from "../store/files/supersede.ts";
9
9
  import { isVisibleTo, readerFromSid } from "../store/model/visibility.ts";
10
10
  import { MergeReviewArgs, validated } from "./schema.ts";
11
11
  import { join } from "node:path";
12
12
 
13
13
  export const register: ToolRegister = (editor, deps) => {
14
14
  const { toolIds, bindSessionIdentity, direct } = deps;
15
- editor.add(validated(MergeReviewArgs, {
15
+ editor.add(
16
+ validated(MergeReviewArgs, {
16
17
  name: "memory_merge_review",
17
18
  description:
18
19
  "Resolve an open merge/review gate non-destructively: mark the loser as superseded_by the survivor, and clear any supersession the survivor itself carries so the canonical row stays recallable. Both rows stay active data (the loser is recoverable via memory_undo); nothing is deleted. A session may merge exactly the rows it may read: global rows are mergeable from anywhere, but a row belonging to another repository is refused in either seat. Refuses before writing when the reason or the survivor id is missing, either id names a missing or blocklisted row, the loser is already superseded or is the survivor itself, or either seat names a foreign repository's row. Later lock or I/O failures can leave partial changes; the reply names the completed retirement and failure.",
@@ -26,12 +27,18 @@ export const register: ToolRegister = (editor, deps) => {
26
27
  // before the Reader below partitions the seats.
27
28
  await bindSessionIdentity(sid);
28
29
  if (!args.loser || !args.survivor || !args.reason) {
29
- return { content: "merge_review blocked: loser, survivor, and reason are all required (fail-closed)." };
30
+ return {
31
+ content:
32
+ "merge_review blocked: loser, survivor, and reason are all required (fail-closed).",
33
+ };
30
34
  }
31
35
  if (args.loser === args.survivor) {
32
36
  // (Same-row input would mark and then revive the same row: a
33
37
  // silent no-op that reports full success.)
34
- return { content: "merge_review blocked: loser and survivor are the same row — nothing to resolve. No evidence written." };
38
+ return {
39
+ content:
40
+ "merge_review blocked: loser and survivor are the same row — nothing to resolve. No evidence written.",
41
+ };
35
42
  }
36
43
  // A row id is a pointer, not authority (#131): resolving and
37
44
  // authorizing BOTH seats happens against the caller's Reader —
@@ -59,14 +66,19 @@ export const register: ToolRegister = (editor, deps) => {
59
66
  // Validate BEFORE touching the loser — a resolution must never
60
67
  // retire real data for a phantom.
61
68
  if (!survivorRow) {
62
- return { content: `merge_review blocked: survivor ${args.survivor} does not exist in the store — nothing to resolve. No evidence written.` };
69
+ return {
70
+ content: `merge_review blocked: survivor ${args.survivor} does not exist in the store — nothing to resolve. No evidence written.`,
71
+ };
63
72
  }
64
73
  const loserRow = all.find((m) => m.ts === args.loser);
65
74
  // loadAll omits blocklisted rows. An unresolved id therefore
66
75
  // proves neither existence nor ownership; raw mutation helpers
67
76
  // must not use it to bypass this read boundary (#204).
68
77
  if (!loserRow) {
69
- return { content: "merge_review blocked: loser is missing or unavailable — nothing to resolve. No evidence written." };
78
+ return {
79
+ content:
80
+ "merge_review blocked: loser is missing or unavailable — nothing to resolve. No evidence written.",
81
+ };
70
82
  }
71
83
  // Visibility is the authorization contract (#131): a session
72
84
  // may merge exactly the rows it may read. Global and legacy
@@ -76,20 +88,33 @@ export const register: ToolRegister = (editor, deps) => {
76
88
  // seat — including an attempt to revive another repository's
77
89
  // superseded survivor — is refused before any mutation.
78
90
  if (!isVisibleTo(loserRow, reader)) {
79
- return { content: "merge_review blocked: the loser belongs to another repository — this session may not retire it. Nothing was done. No evidence written." };
91
+ return {
92
+ content:
93
+ "merge_review blocked: the loser belongs to another repository — this session may not retire it. Nothing was done. No evidence written.",
94
+ };
80
95
  }
81
96
  if (!isVisibleTo(survivorRow, reader)) {
82
- return { content: "merge_review blocked: the survivor belongs to another repository — this session may not promote or revive it. Nothing was done. No evidence written." };
97
+ return {
98
+ content:
99
+ "merge_review blocked: the survivor belongs to another repository — this session may not promote or revive it. Nothing was done. No evidence written.",
100
+ };
83
101
  }
84
- const ok = await markSuperseded(args.loser, {
85
- superseded_by: args.survivor,
86
- reason: args.reason,
87
- symbol: args.loser,
88
- from: args.loser,
89
- to: args.survivor,
90
- }, mergeDurable);
102
+ const ok = await markSuperseded(
103
+ args.loser,
104
+ {
105
+ superseded_by: args.survivor,
106
+ reason: args.reason,
107
+ symbol: args.loser,
108
+ from: args.loser,
109
+ to: args.survivor,
110
+ },
111
+ mergeDurable,
112
+ );
91
113
  if (!ok) {
92
- return { content: "merge_review: loser not found or already superseded — nothing to resolve. No evidence written." };
114
+ return {
115
+ content:
116
+ "merge_review: loser not found or already superseded — nothing to resolve. No evidence written.",
117
+ };
93
118
  }
94
119
  // The survivor may itself have been superseded earlier (e.g. by
95
120
  // a row this very call just made the loser). Declaring it
@@ -115,14 +140,20 @@ export const register: ToolRegister = (editor, deps) => {
115
140
  return {
116
141
  content:
117
142
  `Resolved merge: ${args.survivor} is canonical; ${args.loser} superseded (recoverable via memory_undo). ` +
118
- (revived ? `Survivor's own supersession cleared, it is active again. ` : "") +
143
+ (revived
144
+ ? `Survivor's own supersession cleared, it is active again. `
145
+ : "") +
119
146
  `Evidence recorded for reason='${args.reason}'.`,
120
147
  };
121
148
  },
122
149
  {
123
150
  onTimeout: "fail",
124
151
  onEvent: (event, waitedMs) => {
125
- void record("store_lock", { event, waited_ms: waitedMs, op: "merge" });
152
+ void record("store_lock", {
153
+ event,
154
+ waited_ms: waitedMs,
155
+ op: "merge",
156
+ });
126
157
  },
127
158
  },
128
159
  );
@@ -145,5 +176,6 @@ export const register: ToolRegister = (editor, deps) => {
145
176
  };
146
177
  }
147
178
  },
148
- }));
179
+ }),
180
+ );
149
181
  };
@@ -4,8 +4,8 @@
4
4
  import type { ToolRegister } from "./deps.ts";
5
5
  import { record } from "../evidence/record.ts";
6
6
  import { formatMemory } from "../inject/format.ts";
7
- import { loadAll } from "../store/files/load.ts"
8
- import { isInjectable } from "../store/model/predicates.ts"
7
+ import { loadAll } from "../store/files/load.ts";
8
+ import { isInjectable } from "../store/model/predicates.ts";
9
9
  import { isVisibleTo, readerFromSid } from "../store/model/visibility.ts";
10
10
  import type { Memory } from "../store/model/memory.ts";
11
11
  import { RecallArgs, validated } from "./schema.ts";
@@ -25,10 +25,10 @@ function scoreMemory(m: Memory, q: string): number {
25
25
  return score;
26
26
  }
27
27
 
28
-
29
28
  export const register: ToolRegister = (editor, deps) => {
30
29
  const { toolIds, noteHits, direct } = deps;
31
- editor.add(validated(RecallArgs, {
30
+ editor.add(
31
+ validated(RecallArgs, {
32
32
  name: "memory_recall",
33
33
  description:
34
34
  "Look up durable project knowledge — build/test/lint commands, decisions, patterns, preferences, blockers — BEFORE searching the repo or reading files. Use for 'how do I run X', conventions, and past decisions. By scope, type, or free-text query; with no filters it returns the most recent memories.",
@@ -36,10 +36,13 @@ export const register: ToolRegister = (editor, deps) => {
36
36
  async execute(args, context): Promise<{ content: string }> {
37
37
  const { sid, call } = toolIds(context);
38
38
  const reader = readerFromSid(sid);
39
- let results = (await loadAll()).filter(isInjectable).filter((m) => isVisibleTo(m, reader));
39
+ let results = (await loadAll())
40
+ .filter(isInjectable)
41
+ .filter((m) => isVisibleTo(m, reader));
40
42
  if (!results.length) return { content: "No memories found" };
41
43
  const total = results.length;
42
- if (args.scope) results = results.filter((m) => m.scope.includes(args.scope!));
44
+ if (args.scope)
45
+ results = results.filter((m) => m.scope.includes(args.scope!));
43
46
  if (args.type) results = results.filter((m) => m.type === args.type);
44
47
  if (args.query) {
45
48
  results = results
@@ -49,7 +52,9 @@ export const register: ToolRegister = (editor, deps) => {
49
52
  .map((x) => x.m);
50
53
  }
51
54
  const limit = args.limit || 20;
52
- const limited = args.query ? results.slice(0, limit) : results.slice(-limit);
55
+ const limited = args.query
56
+ ? results.slice(0, limit)
57
+ : results.slice(-limit);
53
58
  if (!limited.length) return { content: "No matching memories" };
54
59
  const openIn = limited.filter((m) => m.status === "open").length;
55
60
  if (openIn > 0) {
@@ -66,7 +71,10 @@ export const register: ToolRegister = (editor, deps) => {
66
71
  );
67
72
  }
68
73
  if (args.query) await noteHits("recall", sid, limited, args.query);
69
- return { content: `Found ${results.length} (${total} total)\n\n${limited.map(formatMemory).join("\n")}` };
74
+ return {
75
+ content: `Found ${results.length} (${total} total)\n\n${limited.map(formatMemory).join("\n")}`,
76
+ };
70
77
  },
71
- }));
78
+ }),
79
+ );
72
80
  };
@@ -18,7 +18,10 @@ import { register as registerDecay } from "./decay.ts";
18
18
  import { register as registerStatus } from "./status-tool.ts";
19
19
  import type { ToolDeps, ToolEditorLike } from "./deps.ts";
20
20
 
21
- export function registerMemoryTools(editor: ToolEditorLike, deps: ToolDeps): void {
21
+ export function registerMemoryTools(
22
+ editor: ToolEditorLike,
23
+ deps: ToolDeps,
24
+ ): void {
22
25
  for (const register of [
23
26
  registerRemember,
24
27
  registerConsolidate,