@0xmaxma/claude-gateway 1.6.8 → 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/share-router.d.ts.map +1 -1
- package/dist/api/share-router.js +27 -1
- package/dist/api/share-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/share/share-store.d.ts +11 -0
- package/dist/share/share-store.d.ts.map +1 -1
- package/dist/share/share-store.js +3 -1
- package/dist/share/share-store.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/image/module.ts +114 -9
- 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/shared/share-client.ts +20 -1
- package/mcp/tools/skills/module.ts +28 -0
- package/package.json +1 -1
- package/resource/claude_gateway.svg +1038 -112
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic memory compactor (issue #337, approach #3) — the non-LLM shrink
|
|
3
|
+
* lever for append-only PR/issue logs in MEMORY.md.
|
|
4
|
+
*
|
|
5
|
+
* The problem: agents accumulate a `## Active PR` / `## Issues` style log where
|
|
6
|
+
* every entry is a full changelog line (description, review score, commit hash).
|
|
7
|
+
* Entries marked `MERGED` / `CLOSED` are terminal — the work is done — yet they
|
|
8
|
+
* are never removed, so the file grows unbounded (meguri: ~78 KB vs an 8 KB
|
|
9
|
+
* budget, ~50% of it these two log sections). The LLM reviewer can't see them
|
|
10
|
+
* (it is anchored to the recent transcript), so nothing ever prunes them.
|
|
11
|
+
*
|
|
12
|
+
* The fix, deterministically and WITHOUT losing recall: move each terminal-state
|
|
13
|
+
* entry's FULL text into a `memory/archive/*.md` file — which the knowledge
|
|
14
|
+
* indexer already walks (`indexer.ts` → `walkMarkdown('memory')`), so the
|
|
15
|
+
* archived record stays searchable via `memory_search` — and leave a compact
|
|
16
|
+
* one-line pointer in MEMORY.md. The agent still "remembers" everything; it just
|
|
17
|
+
* recalls the completed items on demand instead of carrying them in-prompt.
|
|
18
|
+
*
|
|
19
|
+
* Design constraints (this mutates real agent memory, so it is conservative):
|
|
20
|
+
* - Terminal markers are the UPPERCASE status words `MERGED` / `CLOSED` only.
|
|
21
|
+
* Prose like "Closes #1857" or "merged into develop" is NOT matched, so an
|
|
22
|
+
* open/active entry is never archived by accident.
|
|
23
|
+
* - Only top-level list bullets (`- ` / `* ` at column 0) plus their contiguous
|
|
24
|
+
* continuation lines form an archivable block. Headers and other structure
|
|
25
|
+
* are left untouched.
|
|
26
|
+
* - Idempotent: a pointer this pass emits (which links to the archive file) is
|
|
27
|
+
* never re-archived on the next run.
|
|
28
|
+
* - Nothing is ever dropped: an archived block is appended to the archive file
|
|
29
|
+
* BEFORE MEMORY.md is rewritten, and every removed block leaves a pointer.
|
|
30
|
+
*/
|
|
31
|
+
/** Where archived completed-log entries are stored (indexed + searchable). */
|
|
32
|
+
export declare const ARCHIVE_REL_PATH = "memory/archive/completed.md";
|
|
33
|
+
/** Result of the pure planning step — no I/O. */
|
|
34
|
+
export interface CompactionPlan {
|
|
35
|
+
/** New MEMORY.md content (terminal blocks replaced by pointers). */
|
|
36
|
+
nextMemory: string;
|
|
37
|
+
/** Text to append to the archive file ('' when nothing is archived). */
|
|
38
|
+
archiveAppend: string;
|
|
39
|
+
/** How many blocks were archived. */
|
|
40
|
+
archivedCount: number;
|
|
41
|
+
/** Net chars removed from MEMORY.md (before − after). */
|
|
42
|
+
charsRemoved: number;
|
|
43
|
+
}
|
|
44
|
+
/** Applied result — includes the archive path actually written. */
|
|
45
|
+
export interface CompactionResult {
|
|
46
|
+
archivedCount: number;
|
|
47
|
+
charsRemoved: number;
|
|
48
|
+
archivePath: string | null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Plan a compaction over `memory`. Pure (no I/O) so it is exhaustively testable.
|
|
52
|
+
* Terminal-state blocks (bullets or h3+ entry headers) are replaced with a
|
|
53
|
+
* one-line pointer; their full original text is collected into `archiveAppend`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function planCompaction(memory: string, now: number): CompactionPlan;
|
|
56
|
+
/**
|
|
57
|
+
* Run the deterministic compaction against an agent's MEMORY.md. Never throws;
|
|
58
|
+
* on any error the memory file is left untouched.
|
|
59
|
+
*
|
|
60
|
+
* Ordering is crash-safe: the archive file is appended FIRST, then MEMORY.md is
|
|
61
|
+
* rewritten. A crash between the two leaves the entries in BOTH files (a harmless
|
|
62
|
+
* duplicate), never lost. A CAS re-read guards against clobbering a concurrent
|
|
63
|
+
* agent edit.
|
|
64
|
+
*/
|
|
65
|
+
export declare function compactCompletedEntries(workspaceDir: string, now?: number): CompactionResult;
|
|
66
|
+
//# sourceMappingURL=compactor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compactor.d.ts","sourceRoot":"","sources":["../../../src/agent/dreaming/compactor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAKH,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,gCAAgC,CAAC;AAgC9D,iDAAiD;AACjD,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,aAAa,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,mEAAmE;AACnE,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAmGD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,cAAc,CA0C1E;AAuCD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,EACpB,GAAG,GAAE,MAAmB,GACvB,gBAAgB,CAsClB"}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Deterministic memory compactor (issue #337, approach #3) — the non-LLM shrink
|
|
4
|
+
* lever for append-only PR/issue logs in MEMORY.md.
|
|
5
|
+
*
|
|
6
|
+
* The problem: agents accumulate a `## Active PR` / `## Issues` style log where
|
|
7
|
+
* every entry is a full changelog line (description, review score, commit hash).
|
|
8
|
+
* Entries marked `MERGED` / `CLOSED` are terminal — the work is done — yet they
|
|
9
|
+
* are never removed, so the file grows unbounded (meguri: ~78 KB vs an 8 KB
|
|
10
|
+
* budget, ~50% of it these two log sections). The LLM reviewer can't see them
|
|
11
|
+
* (it is anchored to the recent transcript), so nothing ever prunes them.
|
|
12
|
+
*
|
|
13
|
+
* The fix, deterministically and WITHOUT losing recall: move each terminal-state
|
|
14
|
+
* entry's FULL text into a `memory/archive/*.md` file — which the knowledge
|
|
15
|
+
* indexer already walks (`indexer.ts` → `walkMarkdown('memory')`), so the
|
|
16
|
+
* archived record stays searchable via `memory_search` — and leave a compact
|
|
17
|
+
* one-line pointer in MEMORY.md. The agent still "remembers" everything; it just
|
|
18
|
+
* recalls the completed items on demand instead of carrying them in-prompt.
|
|
19
|
+
*
|
|
20
|
+
* Design constraints (this mutates real agent memory, so it is conservative):
|
|
21
|
+
* - Terminal markers are the UPPERCASE status words `MERGED` / `CLOSED` only.
|
|
22
|
+
* Prose like "Closes #1857" or "merged into develop" is NOT matched, so an
|
|
23
|
+
* open/active entry is never archived by accident.
|
|
24
|
+
* - Only top-level list bullets (`- ` / `* ` at column 0) plus their contiguous
|
|
25
|
+
* continuation lines form an archivable block. Headers and other structure
|
|
26
|
+
* are left untouched.
|
|
27
|
+
* - Idempotent: a pointer this pass emits (which links to the archive file) is
|
|
28
|
+
* never re-archived on the next run.
|
|
29
|
+
* - Nothing is ever dropped: an archived block is appended to the archive file
|
|
30
|
+
* BEFORE MEMORY.md is rewritten, and every removed block leaves a pointer.
|
|
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.ARCHIVE_REL_PATH = void 0;
|
|
67
|
+
exports.planCompaction = planCompaction;
|
|
68
|
+
exports.compactCompletedEntries = compactCompletedEntries;
|
|
69
|
+
const fs = __importStar(require("fs"));
|
|
70
|
+
const path = __importStar(require("path"));
|
|
71
|
+
/** Where archived completed-log entries are stored (indexed + searchable). */
|
|
72
|
+
exports.ARCHIVE_REL_PATH = 'memory/archive/completed.md';
|
|
73
|
+
const STATUS_WORDS = 'MERGED|CLOSED|DONE|COMPLETED|FINISHED|RESOLVED|CANCELLED|CANCELED|ARCHIVED|SUPERSEDED|OBSOLETE|DEPRECATED|EXPIRED|SHIPPED';
|
|
74
|
+
/**
|
|
75
|
+
* A "done / terminal" marker, domain-agnostic (not just dev): an UPPERCASE status
|
|
76
|
+
* word (case-sensitive, so prose like "Closes #12" or lowercase "closed early"
|
|
77
|
+
* never matches), a checked task box `[x]`/`[X]`, a ✅ check mark, or a
|
|
78
|
+
* ~~strikethrough~~. Covers any topic the agent marks done while keeping false
|
|
79
|
+
* positives low.
|
|
80
|
+
*/
|
|
81
|
+
const TERMINAL_RE = new RegExp(`(?:\\b(?:${STATUS_WORDS})\\b|✅|\\[[xX]\\]|~~[^~]+~~)`);
|
|
82
|
+
/** Leading done-marker to strip from a pointer label (checkbox / check / strike open). */
|
|
83
|
+
const LEAD_MARKER_RE = /^(?:✅|\[[xX]\]|~~)\s*/;
|
|
84
|
+
const TOP_BULLET_RE = /^[-*] /;
|
|
85
|
+
const HEADER_RE = /^#{1,6} /;
|
|
86
|
+
/** h1/h2 are structural sections; h3–h6 can be a completed *entry* header. */
|
|
87
|
+
const SECTION_RE = /^#{1,2} /;
|
|
88
|
+
const ENTRY_HEADER_RE = /^#{3,6} /;
|
|
89
|
+
const BLANK_RE = /^\s*$/;
|
|
90
|
+
/** True when this bullet line marks a terminal (done) entry we should archive. */
|
|
91
|
+
function isTerminalHead(head) {
|
|
92
|
+
// Never re-archive a pointer we already emitted (it links to the archive file).
|
|
93
|
+
if (head.includes(exports.ARCHIVE_REL_PATH))
|
|
94
|
+
return false;
|
|
95
|
+
return TERMINAL_RE.test(head);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Extract a compact identity label for the pointer line, from a lead line whose
|
|
99
|
+
* bullet/header prefix has already been stripped (`body`). Preference order:
|
|
100
|
+
* 1. An existing markdown link `[text](url)` — kept verbatim so the entry's own
|
|
101
|
+
* per-record memory/*.md link (if any) survives.
|
|
102
|
+
* 2. The identity text BEFORE the terminal marker, so status/detail stays in the
|
|
103
|
+
* archive and only the name lands in the pointer.
|
|
104
|
+
* 3. The first ~70 chars, markdown stripped.
|
|
105
|
+
*/
|
|
106
|
+
function extractLabel(body) {
|
|
107
|
+
const trimmed = body.replace(LEAD_MARKER_RE, '').trim();
|
|
108
|
+
const link = trimmed.match(/\[[^\]]+\]\([^)]+\)/);
|
|
109
|
+
if (link)
|
|
110
|
+
return link[0];
|
|
111
|
+
// Everything from the terminal marker onward is detail bound for the archive.
|
|
112
|
+
const cut = trimmed.search(TERMINAL_RE);
|
|
113
|
+
let ident = (cut > 0 ? trimmed.slice(0, cut) : trimmed).trim();
|
|
114
|
+
ident = ident
|
|
115
|
+
.replace(/[\s—–\-:,(~]+$/, '') // trailing separators / open strike left by the cut
|
|
116
|
+
.replace(/[*_`~]/g, '') // markdown emphasis / strike marks
|
|
117
|
+
.replace(/\s+/g, ' ')
|
|
118
|
+
.trim();
|
|
119
|
+
if (!ident)
|
|
120
|
+
ident = trimmed.replace(/[*_`~]/g, '').replace(/\s+/g, ' ').trim();
|
|
121
|
+
return ident.length > 70 ? ident.slice(0, 70).replace(/\s+\S*$/, '') + '…' : ident;
|
|
122
|
+
}
|
|
123
|
+
/** Which terminal marker matched (for the pointer suffix); non-word markers ⇒ DONE. */
|
|
124
|
+
function statusOf(head) {
|
|
125
|
+
const m = head.match(TERMINAL_RE);
|
|
126
|
+
if (!m)
|
|
127
|
+
return 'DONE';
|
|
128
|
+
return /^[A-Z]+$/.test(m[0]) ? m[0] : 'DONE';
|
|
129
|
+
}
|
|
130
|
+
function parseItems(memory) {
|
|
131
|
+
const lines = memory.split('\n');
|
|
132
|
+
const items = [];
|
|
133
|
+
let section = '';
|
|
134
|
+
for (let i = 0; i < lines.length; i++) {
|
|
135
|
+
const line = lines[i];
|
|
136
|
+
// h1/h2 = structural section title (updates provenance, never a block).
|
|
137
|
+
if (SECTION_RE.test(line)) {
|
|
138
|
+
section = line.replace(/^#{1,6}\s+/, '').trim();
|
|
139
|
+
items.push({ kind: 'raw', line });
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
// h3–h6 = a completed-entry header candidate; absorb its body until the next
|
|
143
|
+
// header (any level) or a blank line.
|
|
144
|
+
if (ENTRY_HEADER_RE.test(line)) {
|
|
145
|
+
const blockLines = [line];
|
|
146
|
+
let j = i + 1;
|
|
147
|
+
while (j < lines.length && !BLANK_RE.test(lines[j]) && !HEADER_RE.test(lines[j])) {
|
|
148
|
+
blockLines.push(lines[j]);
|
|
149
|
+
j++;
|
|
150
|
+
}
|
|
151
|
+
const headerPrefix = (line.match(/^#{3,6}\s+/) ?? ['### '])[0];
|
|
152
|
+
items.push({ kind: 'block', block: { lines: blockLines, section, lead: 'header', headerPrefix } });
|
|
153
|
+
i = j - 1;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (TOP_BULLET_RE.test(line)) {
|
|
157
|
+
const blockLines = [line];
|
|
158
|
+
// Absorb continuation lines: non-blank lines that are neither a header nor
|
|
159
|
+
// the next top-level bullet.
|
|
160
|
+
let j = i + 1;
|
|
161
|
+
while (j < lines.length &&
|
|
162
|
+
!BLANK_RE.test(lines[j]) &&
|
|
163
|
+
!HEADER_RE.test(lines[j]) &&
|
|
164
|
+
!TOP_BULLET_RE.test(lines[j])) {
|
|
165
|
+
blockLines.push(lines[j]);
|
|
166
|
+
j++;
|
|
167
|
+
}
|
|
168
|
+
items.push({ kind: 'block', block: { lines: blockLines, section, lead: 'bullet', headerPrefix: '' } });
|
|
169
|
+
i = j - 1;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
items.push({ kind: 'raw', line });
|
|
173
|
+
}
|
|
174
|
+
return items;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Plan a compaction over `memory`. Pure (no I/O) so it is exhaustively testable.
|
|
178
|
+
* Terminal-state blocks (bullets or h3+ entry headers) are replaced with a
|
|
179
|
+
* one-line pointer; their full original text is collected into `archiveAppend`.
|
|
180
|
+
*/
|
|
181
|
+
function planCompaction(memory, now) {
|
|
182
|
+
const items = parseItems(memory);
|
|
183
|
+
const date = new Date(now).toISOString().slice(0, 10);
|
|
184
|
+
const outLines = [];
|
|
185
|
+
const archiveChunks = [];
|
|
186
|
+
let archivedCount = 0;
|
|
187
|
+
for (const item of items) {
|
|
188
|
+
if (item.kind === 'raw') {
|
|
189
|
+
outLines.push(item.line);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const block = item.block;
|
|
193
|
+
const head = block.lines[0];
|
|
194
|
+
if (!isTerminalHead(head)) {
|
|
195
|
+
outLines.push(...block.lines);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
// Archive the full original block; leave a compact pointer behind. The pointer
|
|
199
|
+
// keeps the block's lead form (a bullet, or the same `### ` header level).
|
|
200
|
+
const original = block.lines.join('\n');
|
|
201
|
+
const prefix = block.lead === 'header' ? block.headerPrefix : '- ';
|
|
202
|
+
const body = head.replace(block.lead === 'header' ? ENTRY_HEADER_RE : TOP_BULLET_RE, '').trim();
|
|
203
|
+
const label = extractLabel(body);
|
|
204
|
+
const status = statusOf(head);
|
|
205
|
+
outLines.push(`${prefix}${label} — ${status}, archived ${date} → ${exports.ARCHIVE_REL_PATH}`);
|
|
206
|
+
archiveChunks.push(`<!-- archived ${date} from MEMORY.md · ## ${block.section} -->\n${original.trim()}\n`);
|
|
207
|
+
archivedCount++;
|
|
208
|
+
}
|
|
209
|
+
if (archivedCount === 0) {
|
|
210
|
+
return { nextMemory: memory, archiveAppend: '', archivedCount: 0, charsRemoved: 0 };
|
|
211
|
+
}
|
|
212
|
+
const nextMemory = outLines.join('\n');
|
|
213
|
+
return {
|
|
214
|
+
nextMemory,
|
|
215
|
+
archiveAppend: archiveChunks.join('\n'),
|
|
216
|
+
archivedCount,
|
|
217
|
+
charsRemoved: Math.max(0, memory.length - nextMemory.length),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/** Write `content` to `filePath` atomically (temp in same dir + rename). */
|
|
221
|
+
function atomicWrite(filePath, content) {
|
|
222
|
+
const dir = path.dirname(filePath);
|
|
223
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
224
|
+
const tmp = path.join(dir, `.tmp-compact-${process.pid}-${process.hrtime.bigint().toString(36)}`);
|
|
225
|
+
try {
|
|
226
|
+
fs.writeFileSync(tmp, content, 'utf8');
|
|
227
|
+
fs.renameSync(tmp, filePath);
|
|
228
|
+
}
|
|
229
|
+
catch (err) {
|
|
230
|
+
try {
|
|
231
|
+
fs.rmSync(tmp, { force: true });
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
/* best-effort cleanup */
|
|
235
|
+
}
|
|
236
|
+
throw err;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function readOnDisk(filePath) {
|
|
240
|
+
try {
|
|
241
|
+
return fs.readFileSync(filePath, 'utf8');
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
return '';
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/** Write a rollback pre-image of MEMORY.md before the compaction rewrite. */
|
|
248
|
+
function writeBackup(workspaceDir, original, now) {
|
|
249
|
+
try {
|
|
250
|
+
const dir = path.join(workspaceDir, '.dreaming', 'backups');
|
|
251
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
252
|
+
atomicWrite(path.join(dir, `MEMORY.md.${now}.compact.bak`), original);
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
/* best-effort — a failed backup must not block the (archive-first) compaction */
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Run the deterministic compaction against an agent's MEMORY.md. Never throws;
|
|
260
|
+
* on any error the memory file is left untouched.
|
|
261
|
+
*
|
|
262
|
+
* Ordering is crash-safe: the archive file is appended FIRST, then MEMORY.md is
|
|
263
|
+
* rewritten. A crash between the two leaves the entries in BOTH files (a harmless
|
|
264
|
+
* duplicate), never lost. A CAS re-read guards against clobbering a concurrent
|
|
265
|
+
* agent edit.
|
|
266
|
+
*/
|
|
267
|
+
function compactCompletedEntries(workspaceDir, now = Date.now()) {
|
|
268
|
+
const none = { archivedCount: 0, charsRemoved: 0, archivePath: null };
|
|
269
|
+
try {
|
|
270
|
+
const memPath = path.join(workspaceDir, 'MEMORY.md');
|
|
271
|
+
const original = readOnDisk(memPath);
|
|
272
|
+
if (!original.trim())
|
|
273
|
+
return none;
|
|
274
|
+
const plan = planCompaction(original, now);
|
|
275
|
+
if (plan.archivedCount === 0)
|
|
276
|
+
return none;
|
|
277
|
+
// Early CAS: if a live agent edited MEMORY.md since we read it, abort BEFORE
|
|
278
|
+
// touching the archive — otherwise we would append entries that then can't be
|
|
279
|
+
// removed from MEMORY.md (the late CAS below would block the rewrite), and the
|
|
280
|
+
// next run would archive them again. Concurrent edits are rare (dreams run in a
|
|
281
|
+
// quiet window) but this keeps the common case duplicate-free.
|
|
282
|
+
const memPathNow = readOnDisk(memPath);
|
|
283
|
+
if (memPathNow !== original)
|
|
284
|
+
return none;
|
|
285
|
+
// 1) Archive first (append to the searchable archive file). If a crash happens
|
|
286
|
+
// between this and the rewrite below, entries live in BOTH files (a harmless
|
|
287
|
+
// duplicate), never lost.
|
|
288
|
+
const archivePath = path.join(workspaceDir, exports.ARCHIVE_REL_PATH);
|
|
289
|
+
const existingArchive = readOnDisk(archivePath);
|
|
290
|
+
const header = existingArchive
|
|
291
|
+
? existingArchive.replace(/\s*$/, '') + '\n\n'
|
|
292
|
+
: '# Archived completed log entries\n\nMoved out of MEMORY.md by nightly compaction (#337). Still searchable via `memory_search`.\n\n';
|
|
293
|
+
atomicWrite(archivePath, header + plan.archiveAppend);
|
|
294
|
+
// 2) Late CAS: re-check immediately before the rewrite (guards the tiny window
|
|
295
|
+
// between the early check and here).
|
|
296
|
+
if (readOnDisk(memPath) !== original)
|
|
297
|
+
return { ...none, archivePath };
|
|
298
|
+
writeBackup(workspaceDir, original, now);
|
|
299
|
+
atomicWrite(memPath, plan.nextMemory);
|
|
300
|
+
return { archivedCount: plan.archivedCount, charsRemoved: plan.charsRemoved, archivePath };
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
return none;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=compactor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compactor.js","sourceRoot":"","sources":["../../../src/agent/dreaming/compactor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+JH,wCA0CC;AAgDD,0DAyCC;AAhSD,uCAAyB;AACzB,2CAA6B;AAE7B,8EAA8E;AACjE,QAAA,gBAAgB,GAAG,6BAA6B,CAAC;AAE9D,MAAM,YAAY,GAChB,2HAA2H,CAAC;AAC9H;;;;;;GAMG;AACH,MAAM,WAAW,GAAG,IAAI,MAAM,CAAC,YAAY,YAAY,8BAA8B,CAAC,CAAC;AACvF,0FAA0F;A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C,MAAM,EAAE,EAAE,CAAC,GAAG,MAAM;YAC9C,CAAC,CAAC,oIAAoI,CAAC;QACzI,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;QAEtD,+EAA+E;QAC/E,qCAAqC;QACrC,IAAI,UAAU,CAAC,OAAO,CAAC,KAAK,QAAQ;YAAE,OAAO,EAAE,GAAG,IAAI,EAAE,WAAW,EAAE,CAAC;QACtE,WAAW,CAAC,YAAY,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;QACzC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAEtC,OAAO,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,CAAC;IAC7F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the effective dreaming config for one agent.
|
|
3
|
+
*
|
|
4
|
+
* Precedence mirrors `resolveSkillLearningConfig`: a per-agent override wins over
|
|
5
|
+
* the global gateway default, which wins over the built-in default. The timezone
|
|
6
|
+
* is normalized once here (invalid → UTC, lesson #310) so the scheduler never
|
|
7
|
+
* re-guards.
|
|
8
|
+
*/
|
|
9
|
+
import type { DreamingConfig, ResolvedDreamingCfg, ResolvedStalenessCfg, StalenessConfig } from './types';
|
|
10
|
+
/** Built-in staleness-GC defaults (planning-66). */
|
|
11
|
+
export declare const STALENESS_DEFAULTS: ResolvedStalenessCfg;
|
|
12
|
+
export declare const DREAMING_DEFAULTS: ResolvedDreamingCfg;
|
|
13
|
+
/**
|
|
14
|
+
* Resolve the staleness-GC sub-config (planning-66). Booleans fall back to the
|
|
15
|
+
* default when absent/non-boolean; numerics are sanitized like the parent config.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveStalenessConfig(agentCfg?: StalenessConfig, globalCfg?: StalenessConfig): ResolvedStalenessCfg;
|
|
18
|
+
export declare function resolveDreamingConfig(agentCfg?: DreamingConfig, globalCfg?: DreamingConfig): ResolvedDreamingCfg;
|
|
19
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/agent/dreaming/config.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1G,oDAAoD;AACpD,eAAO,MAAM,kBAAkB,EAAE,oBAOhC,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,mBAe/B,CAAC;AAsBF;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,CAAC,EAAE,eAAe,EAC1B,SAAS,CAAC,EAAE,eAAe,GAC1B,oBAAoB,CActB;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,CAAC,EAAE,cAAc,EACzB,SAAS,CAAC,EAAE,cAAc,GACzB,mBAAmB,CA+BrB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the effective dreaming config for one agent.
|
|
4
|
+
*
|
|
5
|
+
* Precedence mirrors `resolveSkillLearningConfig`: a per-agent override wins over
|
|
6
|
+
* the global gateway default, which wins over the built-in default. The timezone
|
|
7
|
+
* is normalized once here (invalid → UTC, lesson #310) so the scheduler never
|
|
8
|
+
* re-guards.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.DREAMING_DEFAULTS = exports.STALENESS_DEFAULTS = void 0;
|
|
12
|
+
exports.resolveStalenessConfig = resolveStalenessConfig;
|
|
13
|
+
exports.resolveDreamingConfig = resolveDreamingConfig;
|
|
14
|
+
const config_1 = require("../skill-learning/config");
|
|
15
|
+
/** Built-in staleness-GC defaults (planning-66). */
|
|
16
|
+
exports.STALENESS_DEFAULTS = {
|
|
17
|
+
enabled: true,
|
|
18
|
+
staleTtlDays: 90,
|
|
19
|
+
keepImportance: 7,
|
|
20
|
+
minRetrievalKeep: 1,
|
|
21
|
+
supersession: true,
|
|
22
|
+
recordRetrievals: true,
|
|
23
|
+
};
|
|
24
|
+
exports.DREAMING_DEFAULTS = {
|
|
25
|
+
enabled: true,
|
|
26
|
+
mode: 'auto', // apply consolidation to memory; gated by the K4 applier (#330). Set 'propose' for dry-run.
|
|
27
|
+
dreamHour: 3,
|
|
28
|
+
dreamMinute: 0,
|
|
29
|
+
dreamTimezone: 'UTC',
|
|
30
|
+
quietMinutes: 30,
|
|
31
|
+
lookbackDays: 3,
|
|
32
|
+
maxChangesPerRun: 3,
|
|
33
|
+
reviewModel: 'claude-haiku-4-5-20251001',
|
|
34
|
+
promotionThreshold: 0.6,
|
|
35
|
+
minRecallCount: 2,
|
|
36
|
+
autoRouteOut: true,
|
|
37
|
+
staggerWindowMinutes: 30,
|
|
38
|
+
staleness: exports.STALENESS_DEFAULTS,
|
|
39
|
+
};
|
|
40
|
+
/** Pick the first defined value in precedence order, else the default. */
|
|
41
|
+
function pick(agent, global, fallback) {
|
|
42
|
+
if (agent !== undefined)
|
|
43
|
+
return agent;
|
|
44
|
+
if (global !== undefined)
|
|
45
|
+
return global;
|
|
46
|
+
return fallback;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sanitize a resolved numeric config value: fall back to the default on
|
|
50
|
+
* anything non-finite (string/null/NaN/Infinity from untyped JSON config) or
|
|
51
|
+
* out of [min, max]. Critical for `dreamHour`, which feeds the scheduler delay —
|
|
52
|
+
* a NaN there would make `setTimeout` fire immediately and the async reviewer
|
|
53
|
+
* fan out in a tight reschedule loop.
|
|
54
|
+
*/
|
|
55
|
+
function numOr(value, fallback, min, max) {
|
|
56
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
57
|
+
return fallback;
|
|
58
|
+
if (value < min || value > max)
|
|
59
|
+
return fallback;
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Resolve the staleness-GC sub-config (planning-66). Booleans fall back to the
|
|
64
|
+
* default when absent/non-boolean; numerics are sanitized like the parent config.
|
|
65
|
+
*/
|
|
66
|
+
function resolveStalenessConfig(agentCfg, globalCfg) {
|
|
67
|
+
const d = exports.STALENESS_DEFAULTS;
|
|
68
|
+
const bool = (a, g, fb = false) => {
|
|
69
|
+
const v = pick(a, g, fb);
|
|
70
|
+
return typeof v === 'boolean' ? v : fb;
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
enabled: bool(agentCfg?.enabled, globalCfg?.enabled, d.enabled),
|
|
74
|
+
staleTtlDays: numOr(pick(agentCfg?.staleTtlDays, globalCfg?.staleTtlDays, d.staleTtlDays), d.staleTtlDays, 0, Infinity),
|
|
75
|
+
keepImportance: numOr(pick(agentCfg?.keepImportance, globalCfg?.keepImportance, d.keepImportance), d.keepImportance, 0, 10),
|
|
76
|
+
minRetrievalKeep: numOr(pick(agentCfg?.minRetrievalKeep, globalCfg?.minRetrievalKeep, d.minRetrievalKeep), d.minRetrievalKeep, 0, Infinity),
|
|
77
|
+
supersession: bool(agentCfg?.supersession, globalCfg?.supersession, d.supersession),
|
|
78
|
+
recordRetrievals: bool(agentCfg?.recordRetrievals, globalCfg?.recordRetrievals, d.recordRetrievals),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function resolveDreamingConfig(agentCfg, globalCfg) {
|
|
82
|
+
const d = exports.DREAMING_DEFAULTS;
|
|
83
|
+
const rawTz = pick(agentCfg?.dreamTimezone, globalCfg?.dreamTimezone, d.dreamTimezone);
|
|
84
|
+
const mode = pick(agentCfg?.mode, globalCfg?.mode, d.mode);
|
|
85
|
+
return {
|
|
86
|
+
enabled: pick(agentCfg?.enabled, globalCfg?.enabled, d.enabled),
|
|
87
|
+
mode: mode === 'auto' ? 'auto' : 'propose', // anything but 'auto' is 'propose'
|
|
88
|
+
// dreamHour feeds the scheduler delay — must be a finite hour 0..23.
|
|
89
|
+
dreamHour: numOr(pick(agentCfg?.dreamHour, globalCfg?.dreamHour, d.dreamHour), d.dreamHour, 0, 23),
|
|
90
|
+
// dreamMinute pairs with dreamHour for minute-level scheduling — clamp 0..59.
|
|
91
|
+
dreamMinute: numOr(pick(agentCfg?.dreamMinute, globalCfg?.dreamMinute, d.dreamMinute), d.dreamMinute, 0, 59),
|
|
92
|
+
dreamTimezone: (0, config_1.isValidTimezone)(rawTz) ? rawTz : 'UTC',
|
|
93
|
+
quietMinutes: numOr(pick(agentCfg?.quietMinutes, globalCfg?.quietMinutes, d.quietMinutes), d.quietMinutes, 0, Infinity),
|
|
94
|
+
lookbackDays: numOr(pick(agentCfg?.lookbackDays, globalCfg?.lookbackDays, d.lookbackDays), d.lookbackDays, 0, Infinity),
|
|
95
|
+
maxChangesPerRun: numOr(pick(agentCfg?.maxChangesPerRun, globalCfg?.maxChangesPerRun, d.maxChangesPerRun), d.maxChangesPerRun, 0, Infinity),
|
|
96
|
+
reviewModel: pick(agentCfg?.reviewModel, globalCfg?.reviewModel, d.reviewModel),
|
|
97
|
+
promotionThreshold: numOr(pick(agentCfg?.promotionThreshold, globalCfg?.promotionThreshold, d.promotionThreshold), d.promotionThreshold, 0, 1),
|
|
98
|
+
minRecallCount: numOr(pick(agentCfg?.minRecallCount, globalCfg?.minRecallCount, d.minRecallCount), d.minRecallCount, 0, Infinity),
|
|
99
|
+
// planning-67: boolean-safe (ignore non-boolean JSON), default true.
|
|
100
|
+
autoRouteOut: [agentCfg?.autoRouteOut, globalCfg?.autoRouteOut].find((v) => typeof v === 'boolean') ??
|
|
101
|
+
d.autoRouteOut,
|
|
102
|
+
// planning-68: clamp to [0,55] so the jitter never crosses into the next hour.
|
|
103
|
+
staggerWindowMinutes: numOr(pick(agentCfg?.staggerWindowMinutes, globalCfg?.staggerWindowMinutes, d.staggerWindowMinutes), d.staggerWindowMinutes, 0, 55),
|
|
104
|
+
staleness: resolveStalenessConfig(agentCfg?.staleness, globalCfg?.staleness),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/agent/dreaming/config.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAwDH,wDAiBC;AAED,sDAkCC;AA3GD,qDAA2D;AAG3D,oDAAoD;AACvC,QAAA,kBAAkB,GAAyB;IACtD,OAAO,EAAE,IAAI;IACb,YAAY,EAAE,EAAE;IAChB,cAAc,EAAE,CAAC;IACjB,gBAAgB,EAAE,CAAC;IACnB,YAAY,EAAE,IAAI;IAClB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AAEW,QAAA,iBAAiB,GAAwB;IACpD,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,MAAM,EAAE,4FAA4F;IAC1G,SAAS,EAAE,CAAC;IACZ,WAAW,EAAE,CAAC;IACd,aAAa,EAAE,KAAK;IACpB,YAAY,EAAE,EAAE;IAChB,YAAY,EAAE,CAAC;IACf,gBAAgB,EAAE,CAAC;IACnB,WAAW,EAAE,2BAA2B;IACxC,kBAAkB,EAAE,GAAG;IACvB,cAAc,EAAE,CAAC;IACjB,YAAY,EAAE,IAAI;IAClB,oBAAoB,EAAE,EAAE;IACxB,SAAS,EAAE,0BAAkB;CAC9B,CAAC;AAEF,0EAA0E;AAC1E,SAAS,IAAI,CAAI,KAAoB,EAAE,MAAqB,EAAE,QAAW;IACvE,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACxC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,KAAK,CAAC,KAAa,EAAE,QAAgB,EAAE,GAAW,EA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B,EAAE,KAAK,CACzB,IAAI,CAAC,QAAQ,EAAE,oBAAoB,EAAE,SAAS,EAAE,oBAAoB,EAAE,CAAC,CAAC,oBAAoB,CAAC,EAC7F,CAAC,CAAC,oBAAoB,EACtB,CAAC,EACD,EAAE,CACH;QACD,SAAS,EAAE,sBAAsB,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC;KAC7E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Episodic note writer (planning-65) — routes task-log OUT of the injected core
|
|
3
|
+
* (MEMORY.md) into the searchable `memory/<topic>.md` archive tier.
|
|
4
|
+
*
|
|
5
|
+
* MEMORY.md is injected into every prompt (expensive); episodic records of "what
|
|
6
|
+
* happened" belong in `memory/*.md`, which the knowledge indexer already walks
|
|
7
|
+
* (`indexer.ts` → `walkMarkdown('memory')`) so the note stays retrievable via
|
|
8
|
+
* `memory_search` — recall is preserved, the prompt stays small.
|
|
9
|
+
*
|
|
10
|
+
* Security: the transcript that drives the dreaming reviewer is untrusted
|
|
11
|
+
* (prompt-injection surface), so the topic slug is validated against a strict
|
|
12
|
+
* regex AND the resolved path is realpath-confined under `<ws>/<episodicDir>/`.
|
|
13
|
+
* A topic that fails validation or escapes the directory is rejected — never
|
|
14
|
+
* written. Append-only (a dated bullet); never rewrites existing content, so it
|
|
15
|
+
* cannot destroy prior notes.
|
|
16
|
+
*/
|
|
17
|
+
/** Lowercase-kebab slug, 1..64 chars. No slashes/dots ⇒ cannot escape the dir. */
|
|
18
|
+
export declare const EPISODIC_SLUG_RE: RegExp;
|
|
19
|
+
/** Default episodic archive directory (relative to the agent workspace). */
|
|
20
|
+
export declare const DEFAULT_EPISODIC_DIR = "memory";
|
|
21
|
+
export declare function isValidTopicSlug(topic: unknown): topic is string;
|
|
22
|
+
/**
|
|
23
|
+
* Resolve `<ws>/<episodicDir>/<topic>.md`, confined under `<ws>/<episodicDir>`.
|
|
24
|
+
* Returns null for an invalid slug or any path that would escape the base dir
|
|
25
|
+
* (defense-in-depth on top of the slug regex).
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveEpisodicPath(workspaceDir: string, episodicDir: string, topic: string): string | null;
|
|
28
|
+
export interface EpisodicWriteResult {
|
|
29
|
+
topic: string;
|
|
30
|
+
/** Absolute path written, or '' when the write was rejected/failed. */
|
|
31
|
+
path: string;
|
|
32
|
+
ok: boolean;
|
|
33
|
+
bytesAppended: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Append a dated bullet to `memory/<topic>.md` (creating dir + file on first
|
|
37
|
+
* write). One entry per line — internal newlines are collapsed so a note stays a
|
|
38
|
+
* single searchable bullet. Never throws; a rejected/failed write returns
|
|
39
|
+
* `ok:false` and touches nothing.
|
|
40
|
+
*/
|
|
41
|
+
export declare function appendEpisodicNote(workspaceDir: string, episodicDir: string, topic: string, content: string, now: number): EpisodicWriteResult;
|
|
42
|
+
//# sourceMappingURL=episodic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"episodic.d.ts","sourceRoot":"","sources":["../../../src/agent/dreaming/episodic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,QAA+B,CAAC;AAG7D,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAE7C,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAOhE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,GACZ,MAAM,GAAG,IAAI,CAQf;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,OAAO,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,GACV,mBAAmB,CAqBrB"}
|