@0xmaxma/claude-gateway 1.6.9 → 1.7.0
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.
- package/README.md +149 -20
- package/config.template.json +59 -1
- package/dist/agent/dreaming/accept.d.ts +43 -0
- package/dist/agent/dreaming/accept.d.ts.map +1 -0
- package/dist/agent/dreaming/accept.js +230 -0
- package/dist/agent/dreaming/accept.js.map +1 -0
- package/dist/agent/dreaming/applier.d.ts +77 -0
- package/dist/agent/dreaming/applier.d.ts.map +1 -0
- package/dist/agent/dreaming/applier.js +406 -0
- package/dist/agent/dreaming/applier.js.map +1 -0
- package/dist/agent/dreaming/audit.d.ts +27 -0
- package/dist/agent/dreaming/audit.d.ts.map +1 -0
- package/dist/agent/dreaming/audit.js +100 -0
- package/dist/agent/dreaming/audit.js.map +1 -0
- package/dist/agent/dreaming/compactor.d.ts +66 -0
- package/dist/agent/dreaming/compactor.d.ts.map +1 -0
- package/dist/agent/dreaming/compactor.js +306 -0
- package/dist/agent/dreaming/compactor.js.map +1 -0
- package/dist/agent/dreaming/config.d.ts +19 -0
- package/dist/agent/dreaming/config.d.ts.map +1 -0
- package/dist/agent/dreaming/config.js +107 -0
- package/dist/agent/dreaming/config.js.map +1 -0
- package/dist/agent/dreaming/episodic.d.ts +42 -0
- package/dist/agent/dreaming/episodic.d.ts.map +1 -0
- package/dist/agent/dreaming/episodic.js +116 -0
- package/dist/agent/dreaming/episodic.js.map +1 -0
- package/dist/agent/dreaming/gather.d.ts +31 -0
- package/dist/agent/dreaming/gather.d.ts.map +1 -0
- package/dist/agent/dreaming/gather.js +55 -0
- package/dist/agent/dreaming/gather.js.map +1 -0
- package/dist/agent/dreaming/index.d.ts +87 -0
- package/dist/agent/dreaming/index.d.ts.map +1 -0
- package/dist/agent/dreaming/index.js +377 -0
- package/dist/agent/dreaming/index.js.map +1 -0
- package/dist/agent/dreaming/migrate-cli.d.ts +17 -0
- package/dist/agent/dreaming/migrate-cli.d.ts.map +1 -0
- package/dist/agent/dreaming/migrate-cli.js +42 -0
- package/dist/agent/dreaming/migrate-cli.js.map +1 -0
- package/dist/agent/dreaming/migrate.d.ts +72 -0
- package/dist/agent/dreaming/migrate.d.ts.map +1 -0
- package/dist/agent/dreaming/migrate.js +374 -0
- package/dist/agent/dreaming/migrate.js.map +1 -0
- package/dist/agent/dreaming/report.d.ts +39 -0
- package/dist/agent/dreaming/report.d.ts.map +1 -0
- package/dist/agent/dreaming/report.js +121 -0
- package/dist/agent/dreaming/report.js.map +1 -0
- package/dist/agent/dreaming/reviewer.d.ts +43 -0
- package/dist/agent/dreaming/reviewer.d.ts.map +1 -0
- package/dist/agent/dreaming/reviewer.js +249 -0
- package/dist/agent/dreaming/reviewer.js.map +1 -0
- package/dist/agent/dreaming/staleness.d.ts +68 -0
- package/dist/agent/dreaming/staleness.d.ts.map +1 -0
- package/dist/agent/dreaming/staleness.js +281 -0
- package/dist/agent/dreaming/staleness.js.map +1 -0
- package/dist/agent/dreaming/types.d.ts +130 -0
- package/dist/agent/dreaming/types.d.ts.map +1 -0
- package/dist/agent/dreaming/types.js +10 -0
- package/dist/agent/dreaming/types.js.map +1 -0
- package/dist/agent/knowledge/archive-db.d.ts +114 -0
- package/dist/agent/knowledge/archive-db.d.ts.map +1 -0
- package/dist/agent/knowledge/archive-db.js +474 -0
- package/dist/agent/knowledge/archive-db.js.map +1 -0
- package/dist/agent/knowledge/chunk.d.ts +21 -0
- package/dist/agent/knowledge/chunk.d.ts.map +1 -0
- package/dist/agent/knowledge/chunk.js +67 -0
- package/dist/agent/knowledge/chunk.js.map +1 -0
- package/dist/agent/knowledge/config.d.ts +20 -0
- package/dist/agent/knowledge/config.d.ts.map +1 -0
- package/dist/agent/knowledge/config.js +143 -0
- package/dist/agent/knowledge/config.js.map +1 -0
- package/dist/agent/knowledge/graph-demo.d.ts +25 -0
- package/dist/agent/knowledge/graph-demo.d.ts.map +1 -0
- package/dist/agent/knowledge/graph-demo.js +132 -0
- package/dist/agent/knowledge/graph-demo.js.map +1 -0
- package/dist/agent/knowledge/index.d.ts +24 -0
- package/dist/agent/knowledge/index.d.ts.map +1 -0
- package/dist/agent/knowledge/index.js +50 -0
- package/dist/agent/knowledge/index.js.map +1 -0
- package/dist/agent/knowledge/indexer.d.ts +34 -0
- package/dist/agent/knowledge/indexer.d.ts.map +1 -0
- package/dist/agent/knowledge/indexer.js +271 -0
- package/dist/agent/knowledge/indexer.js.map +1 -0
- package/dist/agent/knowledge/lifecycle.d.ts +91 -0
- package/dist/agent/knowledge/lifecycle.d.ts.map +1 -0
- package/dist/agent/knowledge/lifecycle.js +205 -0
- package/dist/agent/knowledge/lifecycle.js.map +1 -0
- package/dist/agent/knowledge/provenance.d.ts +15 -0
- package/dist/agent/knowledge/provenance.d.ts.map +1 -0
- package/dist/agent/knowledge/provenance.js +37 -0
- package/dist/agent/knowledge/provenance.js.map +1 -0
- package/dist/agent/knowledge/reindex-cli.d.ts +13 -0
- package/dist/agent/knowledge/reindex-cli.d.ts.map +1 -0
- package/dist/agent/knowledge/reindex-cli.js +53 -0
- package/dist/agent/knowledge/reindex-cli.js.map +1 -0
- package/dist/agent/knowledge/reindex-spawn.d.ts +30 -0
- package/dist/agent/knowledge/reindex-spawn.d.ts.map +1 -0
- package/dist/agent/knowledge/reindex-spawn.js +97 -0
- package/dist/agent/knowledge/reindex-spawn.js.map +1 -0
- package/dist/agent/knowledge/shared-promote.d.ts +18 -0
- package/dist/agent/knowledge/shared-promote.d.ts.map +1 -0
- package/dist/agent/knowledge/shared-promote.js +29 -0
- package/dist/agent/knowledge/shared-promote.js.map +1 -0
- package/dist/agent/knowledge/shared-writer.d.ts +24 -0
- package/dist/agent/knowledge/shared-writer.d.ts.map +1 -0
- package/dist/agent/knowledge/shared-writer.js +97 -0
- package/dist/agent/knowledge/shared-writer.js.map +1 -0
- package/dist/agent/knowledge/types.d.ts +83 -0
- package/dist/agent/knowledge/types.d.ts.map +1 -0
- package/dist/agent/knowledge/types.js +12 -0
- package/dist/agent/knowledge/types.js.map +1 -0
- package/dist/agent/knowledge/wiki.d.ts +107 -0
- package/dist/agent/knowledge/wiki.d.ts.map +1 -0
- package/dist/agent/knowledge/wiki.js +415 -0
- package/dist/agent/knowledge/wiki.js.map +1 -0
- package/dist/agent/memory-metrics.d.ts +48 -0
- package/dist/agent/memory-metrics.d.ts.map +1 -0
- package/dist/agent/memory-metrics.js +156 -0
- package/dist/agent/memory-metrics.js.map +1 -0
- package/dist/agent/runner.d.ts +24 -1
- package/dist/agent/runner.d.ts.map +1 -1
- package/dist/agent/runner.js +82 -6
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/skill-learning/config.d.ts +18 -0
- package/dist/agent/skill-learning/config.d.ts.map +1 -0
- package/dist/agent/skill-learning/config.js +71 -0
- package/dist/agent/skill-learning/config.js.map +1 -0
- package/dist/agent/skill-learning/curator.d.ts +45 -0
- package/dist/agent/skill-learning/curator.d.ts.map +1 -0
- package/dist/agent/skill-learning/curator.js +171 -0
- package/dist/agent/skill-learning/curator.js.map +1 -0
- package/dist/agent/skill-learning/index.d.ts +79 -0
- package/dist/agent/skill-learning/index.d.ts.map +1 -0
- package/dist/agent/skill-learning/index.js +308 -0
- package/dist/agent/skill-learning/index.js.map +1 -0
- package/dist/agent/skill-learning/metrics.d.ts +13 -0
- package/dist/agent/skill-learning/metrics.d.ts.map +1 -0
- package/dist/agent/skill-learning/metrics.js +109 -0
- package/dist/agent/skill-learning/metrics.js.map +1 -0
- package/dist/agent/skill-learning/notifier.d.ts +111 -0
- package/dist/agent/skill-learning/notifier.d.ts.map +1 -0
- package/dist/agent/skill-learning/notifier.js +398 -0
- package/dist/agent/skill-learning/notifier.js.map +1 -0
- package/dist/agent/skill-learning/reviewer.d.ts +61 -0
- package/dist/agent/skill-learning/reviewer.d.ts.map +1 -0
- package/dist/agent/skill-learning/reviewer.js +271 -0
- package/dist/agent/skill-learning/reviewer.js.map +1 -0
- package/dist/agent/skill-learning/telemetry.d.ts +22 -0
- package/dist/agent/skill-learning/telemetry.d.ts.map +1 -0
- package/dist/agent/skill-learning/telemetry.js +90 -0
- package/dist/agent/skill-learning/telemetry.js.map +1 -0
- package/dist/agent/skill-learning/trigger.d.ts +23 -0
- package/dist/agent/skill-learning/trigger.d.ts.map +1 -0
- package/dist/agent/skill-learning/trigger.js +44 -0
- package/dist/agent/skill-learning/trigger.js.map +1 -0
- package/dist/agent/skill-learning/types.d.ts +165 -0
- package/dist/agent/skill-learning/types.d.ts.map +1 -0
- package/dist/agent/skill-learning/types.js +11 -0
- package/dist/agent/skill-learning/types.js.map +1 -0
- package/dist/agent/skill-learning/writer.d.ts +37 -0
- package/dist/agent/skill-learning/writer.d.ts.map +1 -0
- package/dist/agent/skill-learning/writer.js +223 -0
- package/dist/agent/skill-learning/writer.js.map +1 -0
- package/dist/agent/workspace-loader.d.ts +83 -6
- package/dist/agent/workspace-loader.d.ts.map +1 -1
- package/dist/agent/workspace-loader.js +207 -14
- package/dist/agent/workspace-loader.js.map +1 -1
- package/dist/api/gateway-router.d.ts +2 -0
- package/dist/api/gateway-router.d.ts.map +1 -1
- package/dist/api/gateway-router.js +293 -6
- package/dist/api/gateway-router.js.map +1 -1
- package/dist/api/skills-router.d.ts +2 -2
- package/dist/api/skills-router.d.ts.map +1 -1
- package/dist/api/skills-router.js +61 -1
- package/dist/api/skills-router.js.map +1 -1
- package/dist/apps/agent-manager.d.ts +7 -0
- package/dist/apps/agent-manager.d.ts.map +1 -1
- package/dist/apps/agent-manager.js +13 -1
- package/dist/apps/agent-manager.js.map +1 -1
- package/dist/config/migrator.d.ts +2 -0
- package/dist/config/migrator.d.ts.map +1 -1
- package/dist/config/migrator.js +72 -1
- package/dist/config/migrator.js.map +1 -1
- package/dist/history/cleanup.d.ts +7 -0
- package/dist/history/cleanup.d.ts.map +1 -1
- package/dist/history/cleanup.js +27 -0
- package/dist/history/cleanup.js.map +1 -1
- package/dist/history/db.d.ts +65 -0
- package/dist/history/db.d.ts.map +1 -1
- package/dist/history/db.js +261 -0
- package/dist/history/db.js.map +1 -1
- package/dist/index.js +122 -20
- package/dist/index.js.map +1 -1
- package/dist/session/process.d.ts +10 -0
- package/dist/session/process.d.ts.map +1 -1
- package/dist/session/process.js +86 -1
- package/dist/session/process.js.map +1 -1
- package/dist/skills/loader.d.ts +8 -0
- package/dist/skills/loader.d.ts.map +1 -1
- package/dist/skills/loader.js +29 -1
- package/dist/skills/loader.js.map +1 -1
- package/dist/types.d.ts +116 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/web-ui.d.ts.map +1 -1
- package/dist/ui/web-ui.js +1126 -3
- package/dist/ui/web-ui.js.map +1 -1
- package/mcp/package.json +2 -1
- package/mcp/server.ts +2 -0
- package/mcp/tools/memory/archive-reader.test.ts +212 -0
- package/mcp/tools/memory/archive-reader.ts +253 -0
- package/mcp/tools/memory/module.ts +152 -0
- package/mcp/tools/memory/retrieval-recorder.ts +66 -0
- package/mcp/tools/skills/module.ts +28 -0
- package/package.json +1 -1
- package/resource/claude_gateway.svg +1038 -112
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dreaming applier (planning-64 K4) — the ONLY path that mutates durable memory.
|
|
3
|
+
*
|
|
4
|
+
* Applies a reviewer's proposed ops to MEMORY.md / USER.md in `auto` mode, with
|
|
5
|
+
* the safety properties from openclaw dreaming-consolidation + the planning-63 P3
|
|
6
|
+
* findings:
|
|
7
|
+
* - **Backup first**: a rollback pre-image is written before any mutation.
|
|
8
|
+
* - **Ordered apply + unambiguous anchors**: ops are applied in order against
|
|
9
|
+
* the CURRENT (already-mutated) content; a `replace`/`remove` whose anchor is
|
|
10
|
+
* gone OR occurs more than once is skipped, never misapplied to the wrong
|
|
11
|
+
* occurrence. Anchor splicing is index-based (not `String.replace`) so `$`
|
|
12
|
+
* sequences in the new content are inserted literally.
|
|
13
|
+
* - **Bounded loss (gross)**: the guard measures GROSS original content deleted,
|
|
14
|
+
* not net length, so an `add` cannot mask a destructive `remove`/`replace`.
|
|
15
|
+
* Replaces are gated at `maxPriorLossFraction`; when over budget, removes (the
|
|
16
|
+
* shrink lever) may prune deeply but never near-total. If the guard trips, only
|
|
17
|
+
* the `add`s are appended (append-only fallback) — a dream can never silently
|
|
18
|
+
* gut memory.
|
|
19
|
+
* - **Net-negative when over budget**: if the file is already over budget, an
|
|
20
|
+
* `add` (or a `replace` that grows the file) is skipped — a dream never
|
|
21
|
+
* enlarges an over-budget file (the core P3 fix).
|
|
22
|
+
* - **Concurrency-safe (CAS)**: the on-disk content is re-checked against the
|
|
23
|
+
* snapshot immediately before the atomic rename; if a live agent edited the
|
|
24
|
+
* file meanwhile, the dream aborts rather than clobber that write.
|
|
25
|
+
* - **Atomic write + validation**: the result is written temp-then-rename and
|
|
26
|
+
* never leaves a previously-non-empty file empty (else rollback).
|
|
27
|
+
*
|
|
28
|
+
* Writing the file is enough to be restart-safe: a MEMORY.md/USER.md change is
|
|
29
|
+
* classified memory-only (planning-63 Part A) → no session is restarted.
|
|
30
|
+
*/
|
|
31
|
+
import type { DreamProposal, DreamFile } from './types';
|
|
32
|
+
import { type EpisodicWriteResult } from './episodic';
|
|
33
|
+
export interface ApplyOptions {
|
|
34
|
+
/** Soft budget for MEMORY.md; USER.md uses userBudgetChars. 0 ⇒ no budget gate. */
|
|
35
|
+
memoryBudgetChars: number;
|
|
36
|
+
userBudgetChars: number;
|
|
37
|
+
maxPriorLossFraction?: number;
|
|
38
|
+
/**
|
|
39
|
+
* planning-65: when set, `tier:"episodic"` `add` ops are appended to
|
|
40
|
+
* `memory/<topic>.md` under this dir (relative to the workspace). Omitted ⇒
|
|
41
|
+
* episodic ops are ignored (durable-only behavior, back-compat).
|
|
42
|
+
*/
|
|
43
|
+
episodicArchiveDir?: string;
|
|
44
|
+
/**
|
|
45
|
+
* planning-67: when true (write routing on), a net-shrink `remove` of a MEMORY.md
|
|
46
|
+
* block is relocated to `memory/archive/pruned.md` (searchable) BEFORE it is cut,
|
|
47
|
+
* and a `remove` of a pinned block is skipped entirely. Off ⇒ prior behavior
|
|
48
|
+
* (remove deletes without archiving).
|
|
49
|
+
*/
|
|
50
|
+
archivePrunedRemovals?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface ApplyFileResult {
|
|
53
|
+
file: DreamFile;
|
|
54
|
+
applied: number;
|
|
55
|
+
skipped: number;
|
|
56
|
+
mode: 'rewrite' | 'append-fallback' | 'none';
|
|
57
|
+
backupPath: string | null;
|
|
58
|
+
bytesBefore: number;
|
|
59
|
+
bytesAfter: number;
|
|
60
|
+
/** The proposals actually applied to this file (used for shared promotion). */
|
|
61
|
+
appliedProposals: DreamProposal[];
|
|
62
|
+
}
|
|
63
|
+
export interface ApplyResult {
|
|
64
|
+
files: ApplyFileResult[];
|
|
65
|
+
totalApplied: number;
|
|
66
|
+
/** All proposals actually applied across files — the ONLY ones safe to promote. */
|
|
67
|
+
appliedProposals: DreamProposal[];
|
|
68
|
+
/** Episodic notes appended to `memory/<topic>.md` (planning-65). Empty when routing off. */
|
|
69
|
+
episodic: EpisodicWriteResult[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Apply reviewer proposals to the agent's memory files (auto mode). Never throws;
|
|
73
|
+
* on any per-file error that file is left untouched. Backups are kept under
|
|
74
|
+
* `<workspace>/.dreaming/backups/`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function applyDreamProposals(workspaceDir: string, proposals: DreamProposal[], opts: ApplyOptions, now?: number): ApplyResult;
|
|
77
|
+
//# sourceMappingURL=applier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applier.d.ts","sourceRoot":"","sources":["../../../src/agent/dreaming/applier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAA4C,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAchG,MAAM,WAAW,YAAY;IAC3B,mFAAmF;IACnF,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,SAAS,GAAG,iBAAiB,GAAG,MAAM,CAAC;IAC7C,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,+EAA+E;IAC/E,gBAAgB,EAAE,aAAa,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,mFAAmF;IACnF,gBAAgB,EAAE,aAAa,EAAE,CAAC;IAClC,4FAA4F;IAC5F,QAAQ,EAAE,mBAAmB,EAAE,CAAC;CACjC;AA4RD;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,aAAa,EAAE,EAC1B,IAAI,EAAE,YAAY,EAClB,GAAG,GAAE,MAAmB,GACvB,WAAW,CAwDb"}
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Dreaming applier (planning-64 K4) — the ONLY path that mutates durable memory.
|
|
4
|
+
*
|
|
5
|
+
* Applies a reviewer's proposed ops to MEMORY.md / USER.md in `auto` mode, with
|
|
6
|
+
* the safety properties from openclaw dreaming-consolidation + the planning-63 P3
|
|
7
|
+
* findings:
|
|
8
|
+
* - **Backup first**: a rollback pre-image is written before any mutation.
|
|
9
|
+
* - **Ordered apply + unambiguous anchors**: ops are applied in order against
|
|
10
|
+
* the CURRENT (already-mutated) content; a `replace`/`remove` whose anchor is
|
|
11
|
+
* gone OR occurs more than once is skipped, never misapplied to the wrong
|
|
12
|
+
* occurrence. Anchor splicing is index-based (not `String.replace`) so `$`
|
|
13
|
+
* sequences in the new content are inserted literally.
|
|
14
|
+
* - **Bounded loss (gross)**: the guard measures GROSS original content deleted,
|
|
15
|
+
* not net length, so an `add` cannot mask a destructive `remove`/`replace`.
|
|
16
|
+
* Replaces are gated at `maxPriorLossFraction`; when over budget, removes (the
|
|
17
|
+
* shrink lever) may prune deeply but never near-total. If the guard trips, only
|
|
18
|
+
* the `add`s are appended (append-only fallback) — a dream can never silently
|
|
19
|
+
* gut memory.
|
|
20
|
+
* - **Net-negative when over budget**: if the file is already over budget, an
|
|
21
|
+
* `add` (or a `replace` that grows the file) is skipped — a dream never
|
|
22
|
+
* enlarges an over-budget file (the core P3 fix).
|
|
23
|
+
* - **Concurrency-safe (CAS)**: the on-disk content is re-checked against the
|
|
24
|
+
* snapshot immediately before the atomic rename; if a live agent edited the
|
|
25
|
+
* file meanwhile, the dream aborts rather than clobber that write.
|
|
26
|
+
* - **Atomic write + validation**: the result is written temp-then-rename and
|
|
27
|
+
* never leaves a previously-non-empty file empty (else rollback).
|
|
28
|
+
*
|
|
29
|
+
* Writing the file is enough to be restart-safe: a MEMORY.md/USER.md change is
|
|
30
|
+
* classified memory-only (planning-63 Part A) → no session is restarted.
|
|
31
|
+
*/
|
|
32
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
33
|
+
if (k2 === undefined) k2 = k;
|
|
34
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
35
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
36
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
37
|
+
}
|
|
38
|
+
Object.defineProperty(o, k2, desc);
|
|
39
|
+
}) : (function(o, m, k, k2) {
|
|
40
|
+
if (k2 === undefined) k2 = k;
|
|
41
|
+
o[k2] = m[k];
|
|
42
|
+
}));
|
|
43
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
44
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
45
|
+
}) : function(o, v) {
|
|
46
|
+
o["default"] = v;
|
|
47
|
+
});
|
|
48
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
49
|
+
var ownKeys = function(o) {
|
|
50
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
51
|
+
var ar = [];
|
|
52
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
53
|
+
return ar;
|
|
54
|
+
};
|
|
55
|
+
return ownKeys(o);
|
|
56
|
+
};
|
|
57
|
+
return function (mod) {
|
|
58
|
+
if (mod && mod.__esModule) return mod;
|
|
59
|
+
var result = {};
|
|
60
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
61
|
+
__setModuleDefault(result, mod);
|
|
62
|
+
return result;
|
|
63
|
+
};
|
|
64
|
+
})();
|
|
65
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
|
+
exports.applyDreamProposals = applyDreamProposals;
|
|
67
|
+
const fs = __importStar(require("fs"));
|
|
68
|
+
const path = __importStar(require("path"));
|
|
69
|
+
const episodic_1 = require("./episodic");
|
|
70
|
+
const migrate_1 = require("./migrate");
|
|
71
|
+
const DEFAULT_MAX_PRIOR_LOSS_FRACTION = 0.25; // openclaw default (replaces, and removes under budget)
|
|
72
|
+
// When the file is ALREADY over budget, removals are the intended shrink lever, so
|
|
73
|
+
// allow deep pruning — but never a near-total wipe (a runaway reviewer that removes
|
|
74
|
+
// almost everything is still rejected).
|
|
75
|
+
const OVER_BUDGET_MAX_REMOVE_FRACTION = 0.9;
|
|
76
|
+
const MAX_BACKUPS = 20; // retained rollback pre-images per file (prevents disk creep)
|
|
77
|
+
const MEMORY_FILES = ['MEMORY.md', 'USER.md'];
|
|
78
|
+
// planning-67: where net-shrink `remove`d blocks are relocated (archive-first) so
|
|
79
|
+
// no dream op ever deletes recall. Distinct from completed.md (terminal) / stale.md (GC).
|
|
80
|
+
const PRUNED_ARCHIVE_REL = 'memory/archive/pruned.md';
|
|
81
|
+
/** Backups dir for rollback pre-images. */
|
|
82
|
+
function backupsDir(workspaceDir) {
|
|
83
|
+
return path.join(workspaceDir, '.dreaming', 'backups');
|
|
84
|
+
}
|
|
85
|
+
/** Read the current on-disk content of a file, '' when absent/unreadable. */
|
|
86
|
+
function readOnDisk(filePath) {
|
|
87
|
+
try {
|
|
88
|
+
return fs.readFileSync(filePath, 'utf8');
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Write `content` to `file` atomically (temp in same dir + rename). */
|
|
95
|
+
function atomicWrite(filePath, content) {
|
|
96
|
+
const dir = path.dirname(filePath);
|
|
97
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
98
|
+
const tmp = path.join(dir, `.tmp-dream-${process.pid}-${process.hrtime.bigint().toString(36)}`);
|
|
99
|
+
try {
|
|
100
|
+
fs.writeFileSync(tmp, content, 'utf8');
|
|
101
|
+
fs.renameSync(tmp, filePath);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
// Don't leave a half-written temp behind on ENOSPC/EIO etc.
|
|
105
|
+
try {
|
|
106
|
+
fs.rmSync(tmp, { force: true });
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
/* best-effort cleanup */
|
|
110
|
+
}
|
|
111
|
+
throw err;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* planning-67: append `remove`d MEMORY.md blocks to the searchable pruned archive
|
|
116
|
+
* BEFORE they are cut, so a net-shrink prune never loses recall. Archive-first
|
|
117
|
+
* mirrors the compactor: on a crash between this and the MEMORY.md rewrite the text
|
|
118
|
+
* lives in both files (harmless duplicate), never nowhere. Best-effort.
|
|
119
|
+
*/
|
|
120
|
+
function archivePrunedBlocks(workspaceDir, blocks, now) {
|
|
121
|
+
if (blocks.length === 0)
|
|
122
|
+
return;
|
|
123
|
+
const archivePath = path.join(workspaceDir, PRUNED_ARCHIVE_REL);
|
|
124
|
+
const existing = readOnDisk(archivePath);
|
|
125
|
+
const header = existing
|
|
126
|
+
? existing.replace(/\s*$/, '') + '\n\n'
|
|
127
|
+
: '# Pruned memory entries\n\nRemoved from MEMORY.md by nightly net-shrink (planning-67). Still searchable via `memory_search`.\n\n';
|
|
128
|
+
const stamp = new Date(now).toISOString().slice(0, 10);
|
|
129
|
+
const body = blocks.map((b) => `<!-- pruned ${stamp} -->\n${b.trim()}`).join('\n\n');
|
|
130
|
+
atomicWrite(archivePath, header + body + '\n');
|
|
131
|
+
}
|
|
132
|
+
/** Keep only the newest `keep` `<file>.<ts>.bak` pre-images; delete the rest. */
|
|
133
|
+
function pruneBackups(dir, file, keep) {
|
|
134
|
+
try {
|
|
135
|
+
const prefix = `${file}.`;
|
|
136
|
+
// The name embeds `.${now}.bak` with a fixed-width ms timestamp, so a
|
|
137
|
+
// lexicographic sort is chronological (oldest first) for the foreseeable future.
|
|
138
|
+
const entries = fs
|
|
139
|
+
.readdirSync(dir)
|
|
140
|
+
.filter((n) => n.startsWith(prefix) && n.endsWith('.bak'))
|
|
141
|
+
.sort();
|
|
142
|
+
for (let i = 0; i < entries.length - keep; i++) {
|
|
143
|
+
try {
|
|
144
|
+
fs.rmSync(path.join(dir, entries[i]), { force: true });
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
/* best-effort */
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
/* best-effort */
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Write the rollback pre-image LAZILY — only once a mutation is actually about to
|
|
157
|
+
* be committed (a no-op run leaves no backup) — then prune old pre-images.
|
|
158
|
+
*/
|
|
159
|
+
function writeBackup(workspaceDir, file, original, now) {
|
|
160
|
+
const dir = backupsDir(workspaceDir);
|
|
161
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
162
|
+
const backupPath = path.join(dir, `${file}.${now}.bak`);
|
|
163
|
+
atomicWrite(backupPath, original);
|
|
164
|
+
pruneBackups(dir, file, MAX_BACKUPS);
|
|
165
|
+
return backupPath;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Apply a single op to the current content, re-resolving its anchor against that
|
|
169
|
+
* content. Returns the new content + deleted-char count, or null when the op could
|
|
170
|
+
* not be applied (anchor gone OR ambiguous) so the caller can count it as skipped.
|
|
171
|
+
*/
|
|
172
|
+
function applyOp(content, p) {
|
|
173
|
+
if (p.op === 'add') {
|
|
174
|
+
const addition = (p.content ?? '').trim();
|
|
175
|
+
if (!addition)
|
|
176
|
+
return null;
|
|
177
|
+
if (p.target) {
|
|
178
|
+
// Insert after the anchor line if the anchor is present.
|
|
179
|
+
const idx = content.indexOf(p.target);
|
|
180
|
+
if (idx === -1) {
|
|
181
|
+
// Anchor gone → append instead of failing (add is additive by nature).
|
|
182
|
+
return { next: `${content.replace(/\s*$/, '')}\n\n${addition}\n`, deleted: 0 };
|
|
183
|
+
}
|
|
184
|
+
const insertAt = idx + p.target.length;
|
|
185
|
+
return { next: `${content.slice(0, insertAt)}\n${addition}${content.slice(insertAt)}`, deleted: 0 };
|
|
186
|
+
}
|
|
187
|
+
return { next: `${content.replace(/\s*$/, '')}\n\n${addition}\n`, deleted: 0 };
|
|
188
|
+
}
|
|
189
|
+
if (p.op === 'replace' || p.op === 'remove') {
|
|
190
|
+
const target = p.target ?? '';
|
|
191
|
+
if (!target)
|
|
192
|
+
return null;
|
|
193
|
+
const first = content.indexOf(target);
|
|
194
|
+
if (first === -1)
|
|
195
|
+
return null; // anchor gone → skip
|
|
196
|
+
// Ambiguous anchor: if the target occurs more than once we cannot know which
|
|
197
|
+
// region the reviewer meant, so refuse rather than silently mutate the FIRST
|
|
198
|
+
// occurrence (which may be the wrong one, or a copy just inserted by an `add`).
|
|
199
|
+
if (content.indexOf(target, first + target.length) !== -1)
|
|
200
|
+
return null;
|
|
201
|
+
const replacement = p.op === 'replace' ? (p.content ?? '').trim() : '';
|
|
202
|
+
// Splice by index — NOT String.replace — so `$`, `$&`, `` $` `` etc. in the
|
|
203
|
+
// replacement are inserted literally, never interpreted as replacement patterns
|
|
204
|
+
// ($-sequences are common in memory: `kill $$`, prices, shell snippets).
|
|
205
|
+
const next = content.slice(0, first) + replacement + content.slice(first + target.length);
|
|
206
|
+
return { next, deleted: target.length };
|
|
207
|
+
}
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
function applyToFile(workspaceDir, file, proposals, budgetChars, maxLossFraction, now, archivePruned) {
|
|
211
|
+
const filePath = path.join(workspaceDir, file);
|
|
212
|
+
const original = readOnDisk(filePath);
|
|
213
|
+
const before = original.length;
|
|
214
|
+
const overBudget = budgetChars > 0 && before > budgetChars;
|
|
215
|
+
// planning-67: relocate `remove`d blocks to a searchable archive (and never prune
|
|
216
|
+
// a pinned block) — only for MEMORY.md when write routing is on.
|
|
217
|
+
const pruneActive = archivePruned && file === 'MEMORY.md';
|
|
218
|
+
const prunedBlocks = [];
|
|
219
|
+
const base = {
|
|
220
|
+
file,
|
|
221
|
+
applied: 0,
|
|
222
|
+
skipped: 0,
|
|
223
|
+
mode: 'none',
|
|
224
|
+
backupPath: null,
|
|
225
|
+
bytesBefore: before,
|
|
226
|
+
bytesAfter: before,
|
|
227
|
+
appliedProposals: [],
|
|
228
|
+
};
|
|
229
|
+
if (proposals.length === 0)
|
|
230
|
+
return base;
|
|
231
|
+
// Apply ops in order, re-resolving anchors against the mutated content. Track how
|
|
232
|
+
// much ORIGINAL content is destroyed (GROSS) — measured against `original`, so an
|
|
233
|
+
// `add` that refills length can't mask a big deletion, AND a chained edit that
|
|
234
|
+
// targets content a PRIOR op introduced (e.g. AAA→BBB→CCC) is not double-counted
|
|
235
|
+
// as original loss. A `remove` of original text loses its whole span; a `replace`
|
|
236
|
+
// of original text loses only the net shrink (equal/longer replacements = intended
|
|
237
|
+
// edit, ~0 loss).
|
|
238
|
+
let content = original;
|
|
239
|
+
let applied = 0;
|
|
240
|
+
let skipped = 0;
|
|
241
|
+
let deletedOriginal = 0;
|
|
242
|
+
const appliedProposals = [];
|
|
243
|
+
for (const p of proposals) {
|
|
244
|
+
// Net-negative gate: when over budget, an `add` that grows the file is skipped.
|
|
245
|
+
if (overBudget && p.op === 'add') {
|
|
246
|
+
skipped++;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
// Over budget, a `replace` whose new content is LONGER than its target grows the
|
|
250
|
+
// file — that works against the shrink purpose, so skip it too.
|
|
251
|
+
if (overBudget && p.op === 'replace') {
|
|
252
|
+
const repl = (p.content ?? '').trim();
|
|
253
|
+
if (repl.length > (p.target ?? '').length) {
|
|
254
|
+
skipped++;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// planning-67: never prune a pinned block (durable prefs/identity) out of the
|
|
259
|
+
// injected core — skip the remove entirely rather than relocate it.
|
|
260
|
+
if (pruneActive && p.op === 'remove' && (0, migrate_1.isTargetPinned)(original, p.target ?? '')) {
|
|
261
|
+
skipped++;
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
const r = applyOp(content, p);
|
|
265
|
+
if (r === null) {
|
|
266
|
+
skipped++;
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
content = r.next;
|
|
270
|
+
const t = p.target ?? '';
|
|
271
|
+
if (p.op === 'remove') {
|
|
272
|
+
if (t && original.includes(t))
|
|
273
|
+
deletedOriginal += t.length;
|
|
274
|
+
// planning-67: stage the removed block for the searchable pruned archive.
|
|
275
|
+
if (pruneActive && t)
|
|
276
|
+
prunedBlocks.push(t);
|
|
277
|
+
}
|
|
278
|
+
else if (p.op === 'replace') {
|
|
279
|
+
const repl = (p.content ?? '').trim();
|
|
280
|
+
if (t && original.includes(t))
|
|
281
|
+
deletedOriginal += Math.max(0, t.length - repl.length);
|
|
282
|
+
}
|
|
283
|
+
applied++;
|
|
284
|
+
appliedProposals.push(p);
|
|
285
|
+
}
|
|
286
|
+
// Bounded-loss gate — GROSS original content destroyed, NOT net length. Under
|
|
287
|
+
// budget it is capped at maxPriorLossFraction; when the file is already over
|
|
288
|
+
// budget, deletions are the intended shrink lever, so the cap is raised (deep
|
|
289
|
+
// pruning allowed) but never to a near-total wipe.
|
|
290
|
+
const lossCap = overBudget ? OVER_BUDGET_MAX_REMOVE_FRACTION : maxLossFraction;
|
|
291
|
+
const lossFraction = before > 0 ? deletedOriginal / before : 0;
|
|
292
|
+
const rewriteRejected = applied > 0 && lossFraction > lossCap;
|
|
293
|
+
// Validation: never turn a previously-non-empty file into an empty one.
|
|
294
|
+
const wouldEmpty = before > 0 && content.trim().length === 0;
|
|
295
|
+
if (rewriteRejected || wouldEmpty) {
|
|
296
|
+
let appended = original;
|
|
297
|
+
let appendCount = 0;
|
|
298
|
+
const appendedProposals = [];
|
|
299
|
+
for (const p of proposals) {
|
|
300
|
+
if (p.op !== 'add' || overBudget)
|
|
301
|
+
continue; // append adds only; respect net-negative
|
|
302
|
+
const r = applyOp(appended, { ...p, target: undefined }); // pure append
|
|
303
|
+
if (r !== null) {
|
|
304
|
+
appended = r.next;
|
|
305
|
+
appendCount++;
|
|
306
|
+
appendedProposals.push(p);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (appendCount > 0 && appended !== original) {
|
|
310
|
+
// CAS: abort if a live agent edited the file since our snapshot (avoid
|
|
311
|
+
// clobbering its write — our backup is the stale pre-image).
|
|
312
|
+
if (readOnDisk(filePath) !== original) {
|
|
313
|
+
return { ...base, applied: 0, skipped: proposals.length, mode: 'none', backupPath: null };
|
|
314
|
+
}
|
|
315
|
+
const backupPath = writeBackup(workspaceDir, file, original, now);
|
|
316
|
+
atomicWrite(filePath, appended);
|
|
317
|
+
return {
|
|
318
|
+
...base,
|
|
319
|
+
applied: appendCount,
|
|
320
|
+
skipped: proposals.length - appendCount,
|
|
321
|
+
mode: 'append-fallback',
|
|
322
|
+
backupPath,
|
|
323
|
+
bytesAfter: appended.length,
|
|
324
|
+
appliedProposals: appendedProposals,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
// Nothing safe to do → leave the file untouched (no backup written).
|
|
328
|
+
return { ...base, applied: 0, skipped: proposals.length, mode: 'none', backupPath: null };
|
|
329
|
+
}
|
|
330
|
+
if (applied === 0 || content === original) {
|
|
331
|
+
return { ...base, applied: 0, skipped, mode: 'none', backupPath: null };
|
|
332
|
+
}
|
|
333
|
+
// CAS: abort if the file changed underneath us since the snapshot.
|
|
334
|
+
if (readOnDisk(filePath) !== original) {
|
|
335
|
+
return { ...base, applied: 0, skipped: proposals.length, mode: 'none', backupPath: null };
|
|
336
|
+
}
|
|
337
|
+
// planning-67: archive-first — relocate the removed blocks to the searchable
|
|
338
|
+
// pruned archive BEFORE cutting them from MEMORY.md (recall never lost). Best-
|
|
339
|
+
// effort; a failed archive must not abort the shrink.
|
|
340
|
+
if (pruneActive && prunedBlocks.length > 0) {
|
|
341
|
+
try {
|
|
342
|
+
archivePrunedBlocks(workspaceDir, prunedBlocks, now);
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
/* best-effort — never blocks the rewrite */
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const backupPath = writeBackup(workspaceDir, file, original, now);
|
|
349
|
+
atomicWrite(filePath, content);
|
|
350
|
+
return { ...base, applied, skipped, mode: 'rewrite', backupPath, bytesAfter: content.length, appliedProposals };
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Apply reviewer proposals to the agent's memory files (auto mode). Never throws;
|
|
354
|
+
* on any per-file error that file is left untouched. Backups are kept under
|
|
355
|
+
* `<workspace>/.dreaming/backups/`.
|
|
356
|
+
*/
|
|
357
|
+
function applyDreamProposals(workspaceDir, proposals, opts, now = Date.now()) {
|
|
358
|
+
const maxLoss = opts.maxPriorLossFraction ?? DEFAULT_MAX_PRIOR_LOSS_FRACTION;
|
|
359
|
+
const files = [];
|
|
360
|
+
let totalApplied = 0;
|
|
361
|
+
const appliedProposals = [];
|
|
362
|
+
for (const file of MEMORY_FILES) {
|
|
363
|
+
// Durable ops only: episodic ops (tier:'episodic') route to memory/<topic>.md
|
|
364
|
+
// below, never into an evergreen file.
|
|
365
|
+
const forFile = proposals.filter((p) => (p.tier ?? 'durable') !== 'episodic' && p.file === file);
|
|
366
|
+
const budget = file === 'MEMORY.md' ? opts.memoryBudgetChars : opts.userBudgetChars;
|
|
367
|
+
try {
|
|
368
|
+
const res = applyToFile(workspaceDir, file, forFile, budget, maxLoss, now, opts.archivePrunedRemovals === true);
|
|
369
|
+
files.push(res);
|
|
370
|
+
totalApplied += res.applied;
|
|
371
|
+
appliedProposals.push(...res.appliedProposals);
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
files.push({
|
|
375
|
+
file,
|
|
376
|
+
applied: 0,
|
|
377
|
+
skipped: forFile.length,
|
|
378
|
+
mode: 'none',
|
|
379
|
+
backupPath: null,
|
|
380
|
+
bytesBefore: 0,
|
|
381
|
+
bytesAfter: 0,
|
|
382
|
+
appliedProposals: [],
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
// planning-65 — episodic tier: append task-log notes to memory/<topic>.md. Only
|
|
387
|
+
// when an episodic dir is configured (routing on); each append is validated +
|
|
388
|
+
// realpath-confined in `appendEpisodicNote`. A note that writes OK counts toward
|
|
389
|
+
// totalApplied and joins appliedProposals (so audit/shared-promote see it).
|
|
390
|
+
const episodic = [];
|
|
391
|
+
if (opts.episodicArchiveDir !== undefined) {
|
|
392
|
+
const dir = opts.episodicArchiveDir || episodic_1.DEFAULT_EPISODIC_DIR;
|
|
393
|
+
for (const p of proposals) {
|
|
394
|
+
if (p.tier !== 'episodic' || p.op !== 'add' || !p.topic || !p.content)
|
|
395
|
+
continue;
|
|
396
|
+
const res = (0, episodic_1.appendEpisodicNote)(workspaceDir, dir, p.topic, p.content, now);
|
|
397
|
+
episodic.push(res);
|
|
398
|
+
if (res.ok) {
|
|
399
|
+
totalApplied++;
|
|
400
|
+
appliedProposals.push(p);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return { files, totalApplied, appliedProposals, episodic };
|
|
405
|
+
}
|
|
406
|
+
//# sourceMappingURL=applier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applier.js","sourceRoot":"","sources":["../../../src/agent/dreaming/applier.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2VH,kDA6DC;AAtZD,uCAAyB;AACzB,2CAA6B;AAE7B,yCAAgG;AAChG,uCAA2C;AAE3C,MAAM,+BAA+B,GAAG,IAAI,CAAC,CAAC,wDAAwD;AACtG,mFAAmF;AACnF,oFAAoF;AACpF,wCAAwC;AACxC,MAAM,+BAA+B,GAAG,GAAG,CAAC;AAC5C,MAAM,WAAW,GAAG,EAAE,CAAC,CAAC,8DAA8D;AACtF,MAAM,YAAY,GAAgB,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AAC3D,kFAAkF;AAClF,0FAA0F;AAC1F,MAAM,kBAAkB,GAAG,0BAA0B,CAAC;AA2CtD,2CAA2C;AAC3C,SAAS,UAAU,CAAC,YAAoB;IACtC,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC;AAED,6EAA6E;AAC7E,SAAS,UAAU,CAA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I,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO;gBAAE,SAAS;YAChF,MAAM,GAAG,GAAG,IAAA,6BAAkB,EAAC,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAC3E,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACnB,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC;gBACX,YAAY,EAAE,CAAC;gBACf,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dream audit trail: a human-readable DREAMS.md diary + a structured
|
|
3
|
+
* promotions.jsonl, both under `<workspace>/.dreaming/`. Best-effort — an audit
|
|
4
|
+
* write must never throw into the scheduler. In propose mode this is the ONLY
|
|
5
|
+
* output; no memory file is touched.
|
|
6
|
+
*/
|
|
7
|
+
import type { DreamMode, DreamOutcome, DreamProposal } from './types';
|
|
8
|
+
export declare const DREAMING_DIR = ".dreaming";
|
|
9
|
+
export interface DreamAuditEntry {
|
|
10
|
+
ts: number;
|
|
11
|
+
outcome: DreamOutcome;
|
|
12
|
+
mode: DreamMode;
|
|
13
|
+
summary: string;
|
|
14
|
+
proposals: DreamProposal[];
|
|
15
|
+
tokensSpent: number;
|
|
16
|
+
sessionCount: number;
|
|
17
|
+
/** Ops the K4 applier actually wrote to memory (auto mode). Undefined ⇒ propose. */
|
|
18
|
+
appliedCount?: number;
|
|
19
|
+
/** Terminal-state entries the deterministic compactor archived this run (#337). */
|
|
20
|
+
compactedCount?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Append one dream run to the diary + (when there are proposals) the JSONL
|
|
24
|
+
* audit. Returns the diary path on success, null on any I/O failure.
|
|
25
|
+
*/
|
|
26
|
+
export declare function writeDreamAudit(workspaceDir: string, entry: DreamAuditEntry): string | null;
|
|
27
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../../src/agent/dreaming/audit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEtE,eAAO,MAAM,YAAY,cAAc,CAAC;AAExC,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,oFAAoF;IACpF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAMD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,CAoD3F"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Dream audit trail: a human-readable DREAMS.md diary + a structured
|
|
4
|
+
* promotions.jsonl, both under `<workspace>/.dreaming/`. Best-effort — an audit
|
|
5
|
+
* write must never throw into the scheduler. In propose mode this is the ONLY
|
|
6
|
+
* output; no memory file is touched.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.DREAMING_DIR = void 0;
|
|
43
|
+
exports.writeDreamAudit = writeDreamAudit;
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
exports.DREAMING_DIR = '.dreaming';
|
|
47
|
+
function truncate(s, n) {
|
|
48
|
+
return s.length > n ? s.slice(0, n) + '…' : s;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Append one dream run to the diary + (when there are proposals) the JSONL
|
|
52
|
+
* audit. Returns the diary path on success, null on any I/O failure.
|
|
53
|
+
*/
|
|
54
|
+
function writeDreamAudit(workspaceDir, entry) {
|
|
55
|
+
try {
|
|
56
|
+
const dir = path.join(workspaceDir, exports.DREAMING_DIR);
|
|
57
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
58
|
+
const iso = new Date(entry.ts).toISOString();
|
|
59
|
+
const lines = [`## ${iso} — ${entry.outcome} (${entry.mode})`];
|
|
60
|
+
if (entry.summary)
|
|
61
|
+
lines.push('', entry.summary);
|
|
62
|
+
if (entry.proposals.length) {
|
|
63
|
+
lines.push('');
|
|
64
|
+
for (const p of entry.proposals) {
|
|
65
|
+
const anchor = p.target ? ` [${truncate(p.target, 40)}]` : '';
|
|
66
|
+
const dest = p.tier === 'episodic' ? `memory/${p.topic}.md` : (p.file ?? '?');
|
|
67
|
+
lines.push(`- **${p.op}** \`${dest}\`${anchor} — ${p.reason} ` +
|
|
68
|
+
`_(score ${p.score.toFixed(2)}, recall ${p.recallCount})_`);
|
|
69
|
+
}
|
|
70
|
+
lines.push('', entry.mode === 'auto'
|
|
71
|
+
? `_auto mode: applied ${entry.appliedCount ?? 0} op(s) to memory — rollback pre-image kept in .dreaming/backups/._`
|
|
72
|
+
: '_propose mode: proposals logged only — memory not modified._');
|
|
73
|
+
}
|
|
74
|
+
else if (entry.outcome === 'no-changes') {
|
|
75
|
+
lines.push('', '_No changes proposed._');
|
|
76
|
+
}
|
|
77
|
+
else if (entry.outcome === 'skipped-empty') {
|
|
78
|
+
lines.push('', '_No sessions in the lookback window._');
|
|
79
|
+
}
|
|
80
|
+
else if (entry.outcome === 'error') {
|
|
81
|
+
lines.push('', '_Reviewer produced no usable output (timeout or malformed) — no-op._');
|
|
82
|
+
}
|
|
83
|
+
if (entry.compactedCount && entry.compactedCount > 0) {
|
|
84
|
+
lines.push('', `_compaction: archived ${entry.compactedCount} completed entr${entry.compactedCount === 1 ? 'y' : 'ies'} to memory/archive/ (still searchable)._`);
|
|
85
|
+
}
|
|
86
|
+
lines.push('', `_tokens: ${entry.tokensSpent}, sessions: ${entry.sessionCount}_`, '', '---', '');
|
|
87
|
+
fs.appendFileSync(path.join(dir, 'DREAMS.md'), lines.join('\n') + '\n', 'utf8');
|
|
88
|
+
if (entry.proposals.length) {
|
|
89
|
+
const jsonl = entry.proposals
|
|
90
|
+
.map((p) => JSON.stringify({ ts: entry.ts, mode: entry.mode, ...p }))
|
|
91
|
+
.join('\n') + '\n';
|
|
92
|
+
fs.appendFileSync(path.join(dir, 'promotions.jsonl'), jsonl, 'utf8');
|
|
93
|
+
}
|
|
94
|
+
return path.join(dir, 'DREAMS.md');
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../../../src/agent/dreaming/audit.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BH,0CAoDC;AAjFD,uCAAyB;AACzB,2CAA6B;AAIhB,QAAA,YAAY,GAAG,WAAW,CAAC;AAgBxC,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS;IACpC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAAC,YAAoB,EAAE,KAAsB;IAC1E,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,oBAAY,CAAC,CAAC;QA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