operon-agents-core 0.1.0-alpha.2 → 0.1.0-alpha.21
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/dist/agent/agent.d.ts +8 -7
- package/dist/agent/compose-hooks.d.ts +10 -1
- package/dist/agent/compose-hooks.js +61 -6
- package/dist/agent/concurrency.js +1 -1
- package/dist/agent/context-report.d.ts +2 -2
- package/dist/agent/durable-state.d.ts +22 -0
- package/dist/agent/durable-state.js +54 -0
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +1 -1
- package/dist/agent/instruction-context.d.ts +6 -6
- package/dist/agent/instruction-context.js +23 -23
- package/dist/agent/profile-builtins.js +1 -1
- package/dist/agent/run-support.d.ts +1 -1
- package/dist/agent/run-support.js +6 -5
- package/dist/agent/runner.d.ts +25 -22
- package/dist/agent/runner.js +217 -121
- package/dist/agent/session.d.ts +262 -156
- package/dist/agent/session.js +590 -418
- package/dist/agent/subagent-tools.js +3 -3
- package/dist/agent/subagent.js +28 -13
- package/dist/agent/toolset.d.ts +1 -0
- package/dist/agent/toolset.js +13 -7
- package/dist/agent/workflow/journal.d.ts +2 -2
- package/dist/agent/workflow/journal.js +2 -2
- package/dist/agent/workflow/manager.d.ts +1 -1
- package/dist/agent/workflow/manager.js +1 -1
- package/dist/agent/workflow/prompt.js +2 -2
- package/dist/agent/workflow/sandbox.d.ts +1 -1
- package/dist/agent/workflow/sandbox.js +1 -1
- package/dist/agent/workflow/tool.js +30 -43
- package/dist/agent/worktree.d.ts +8 -8
- package/dist/agent/worktree.js +15 -15
- package/dist/capabilities/assembler.d.ts +29 -5
- package/dist/capabilities/assembler.js +85 -9
- package/dist/capabilities/background/code-task.d.ts +43 -0
- package/dist/capabilities/background/code-task.js +75 -0
- package/dist/capabilities/background/command-task.d.ts +9 -2
- package/dist/capabilities/background/command-task.js +22 -6
- package/dist/capabilities/background/index.d.ts +6 -1
- package/dist/capabilities/background/index.js +26 -20
- package/dist/capabilities/background/manager.d.ts +57 -1
- package/dist/capabilities/background/manager.js +210 -45
- package/dist/capabilities/background/persist-disk.d.ts +1 -1
- package/dist/capabilities/background/persist-disk.js +1 -1
- package/dist/capabilities/background/persist.js +4 -2
- package/dist/capabilities/background/projections.d.ts +16 -0
- package/dist/capabilities/background/projections.js +86 -0
- package/dist/capabilities/background/stall-watchdog.d.ts +41 -0
- package/dist/capabilities/background/stall-watchdog.js +85 -0
- package/dist/capabilities/background/task.d.ts +8 -7
- package/dist/capabilities/background/tools.js +33 -7
- package/dist/capabilities/capability-data.d.ts +52 -0
- package/dist/capabilities/capability-data.js +88 -0
- package/dist/capabilities/capability-state.d.ts +2 -4
- package/dist/capabilities/capability-state.js +5 -23
- package/dist/capabilities/capability.d.ts +203 -38
- package/dist/capabilities/compaction/index.js +10 -4
- package/dist/capabilities/compaction/service.d.ts +20 -5
- package/dist/capabilities/compaction/service.js +27 -11
- package/dist/capabilities/goal/goal-store.d.ts +76 -12
- package/dist/capabilities/goal/goal-store.js +137 -53
- package/dist/capabilities/goal/index.d.ts +1 -1
- package/dist/capabilities/goal/index.js +30 -7
- package/dist/capabilities/index.d.ts +9 -6
- package/dist/capabilities/index.js +4 -3
- package/dist/capabilities/plan/index.js +22 -5
- package/dist/capabilities/plan/plan-mode.d.ts +30 -9
- package/dist/capabilities/plan/plan-mode.js +57 -32
- package/dist/capabilities/plan/tools.js +1 -1
- package/dist/capabilities/skills/flow-provider.js +3 -3
- package/dist/capabilities/skills/index.d.ts +13 -1
- package/dist/capabilities/skills/index.js +30 -21
- package/dist/capabilities/skills/parser.d.ts +2 -2
- package/dist/capabilities/skills/parser.js +3 -3
- package/dist/capabilities/skills/registry.d.ts +5 -6
- package/dist/capabilities/skills/registry.js +6 -9
- package/dist/capabilities/skills/scanner.d.ts +3 -3
- package/dist/capabilities/skills/scanner.js +14 -14
- package/dist/capabilities/skills/service.d.ts +2 -1
- package/dist/capabilities/skills/service.js +3 -3
- package/dist/capabilities/skills/skill-tool.d.ts +2 -0
- package/dist/capabilities/skills/skill-tool.js +1 -1
- package/dist/capabilities/task/index.js +2 -1
- package/dist/capabilities/task/persist-disk.d.ts +1 -1
- package/dist/capabilities/task/persist-disk.js +1 -1
- package/dist/capabilities/task/persist.js +1 -1
- package/dist/capabilities/todo/index.js +11 -6
- package/dist/capabilities/todo/injector.js +2 -1
- package/dist/capabilities/todo/todo-store.d.ts +28 -7
- package/dist/capabilities/todo/todo-store.js +44 -11
- package/dist/capabilities/todo/tools.js +8 -3
- package/dist/capabilities/tool-provider.d.ts +3 -3
- package/dist/capabilities/user-hooks/engine.d.ts +3 -3
- package/dist/capabilities/user-hooks/engine.js +7 -7
- package/dist/capabilities/user-hooks/index.js +2 -1
- package/dist/capabilities/workflow/index.d.ts +5 -3
- package/dist/capabilities/workflow/index.js +3 -2
- package/dist/commands/index.js +34 -32
- package/dist/config/index.d.ts +1 -1
- package/dist/config/provider-manager.js +0 -28
- package/dist/config/schema.d.ts +53 -4
- package/dist/config/schema.js +53 -1
- package/dist/events/events.d.ts +43 -11
- package/dist/events/events.js +1 -0
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.js +1 -1
- package/dist/events/projection.d.ts +49 -1
- package/dist/events/projection.js +144 -19
- package/dist/events/publisher.js +2 -21
- package/dist/home.d.ts +1 -1
- package/dist/home.js +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/internal.d.ts +5 -2
- package/dist/internal.js +5 -2
- package/dist/llm/define-model.d.ts +4 -0
- package/dist/llm/define-model.js +63 -25
- package/dist/llm/index.d.ts +1 -0
- package/dist/llm/index.js +1 -0
- package/dist/llm/model.d.ts +2 -0
- package/dist/llm/provider.d.ts +17 -0
- package/dist/llm/provider.js +14 -0
- package/dist/llm/retry.js +1 -1
- package/dist/loop/context.d.ts +21 -1
- package/dist/loop/context.js +47 -9
- package/dist/loop/events.d.ts +5 -1
- package/dist/loop/index.d.ts +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/interruption.d.ts +9 -4
- package/dist/loop/interruption.js +11 -25
- package/dist/loop/run-turn.d.ts +16 -3
- package/dist/loop/run-turn.js +13 -4
- package/dist/loop/steer.d.ts +78 -12
- package/dist/loop/steer.js +101 -38
- package/dist/loop/tool-call.d.ts +13 -2
- package/dist/loop/tool-call.js +135 -5
- package/dist/loop/turn-step.d.ts +13 -2
- package/dist/loop/turn-step.js +29 -7
- package/dist/loop/types.d.ts +6 -0
- package/dist/mcp/auth-tool.d.ts +3 -1
- package/dist/mcp/auth-tool.js +2 -2
- package/dist/mcp/capability.d.ts +13 -0
- package/dist/mcp/capability.js +36 -17
- package/dist/mcp/config-loader.d.ts +5 -5
- package/dist/mcp/config-loader.js +17 -17
- package/dist/mcp/credentials.d.ts +35 -0
- package/dist/mcp/credentials.js +2 -0
- package/dist/mcp/filter.d.ts +2 -2
- package/dist/mcp/index.d.ts +4 -3
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/manager.d.ts +108 -6
- package/dist/mcp/manager.js +262 -18
- package/dist/mcp/oauth/callback-server.d.ts +10 -1
- package/dist/mcp/oauth/callback-server.js +82 -16
- package/dist/mcp/oauth/index.d.ts +2 -2
- package/dist/mcp/oauth/provider.d.ts +18 -0
- package/dist/mcp/oauth/provider.js +31 -1
- package/dist/mcp/oauth/service.d.ts +9 -3
- package/dist/mcp/oauth/service.js +29 -4
- package/dist/mcp/sdk-transport.js +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/permission/auto-approver/prompts-data.d.ts +1 -1
- package/dist/permission/auto-approver/prompts-data.js +1 -1
- package/dist/permission/manager.d.ts +5 -3
- package/dist/permission/manager.js +7 -3
- package/dist/permission/policies.d.ts +2 -2
- package/dist/permission/policies.js +4 -4
- package/dist/plugins/fields.d.ts +14 -0
- package/dist/plugins/fields.js +30 -0
- package/dist/plugins/hooks.d.ts +2 -2
- package/dist/plugins/hooks.js +12 -12
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/manager.d.ts +8 -3
- package/dist/plugins/manager.js +18 -7
- package/dist/plugins/manifest.d.ts +2 -2
- package/dist/plugins/manifest.js +101 -91
- package/dist/plugins/marketplace.js +76 -57
- package/dist/plugins/store.d.ts +3 -3
- package/dist/plugins/store.js +6 -6
- package/dist/protocol/index.d.ts +1 -1
- package/dist/store/catalog-store.d.ts +4 -1
- package/dist/store/catalog-store.js +5 -1
- package/dist/store/checkpointing-store.d.ts +41 -0
- package/dist/store/checkpointing-store.js +86 -0
- package/dist/store/disk-store.d.ts +8 -0
- package/dist/store/disk-store.js +127 -5
- package/dist/store/index.d.ts +3 -2
- package/dist/store/index.js +2 -1
- package/dist/store/log-store.d.ts +9 -1
- package/dist/store/log-store.js +68 -4
- package/dist/store/migrate.d.ts +8 -2
- package/dist/store/migrate.js +9 -2
- package/dist/store/origin.d.ts +31 -6
- package/dist/store/origin.js +0 -14
- package/dist/store/pg.d.ts +1 -0
- package/dist/store/pg.js +37 -2
- package/dist/store/redis.d.ts +1 -0
- package/dist/store/redis.js +30 -0
- package/dist/store/repository.d.ts +13 -1
- package/dist/store/repository.js +45 -2
- package/dist/store/session-catalog.d.ts +4 -0
- package/dist/store/session-catalog.js +6 -0
- package/dist/store/storage.js +3 -0
- package/dist/store/store.d.ts +97 -34
- package/dist/store/store.js +64 -10
- package/dist/telemetry/appender.d.ts +43 -0
- package/dist/telemetry/appender.js +46 -0
- package/dist/telemetry/events.d.ts +142 -0
- package/dist/telemetry/events.js +141 -0
- package/dist/telemetry/index.d.ts +10 -0
- package/dist/telemetry/index.js +6 -0
- package/dist/telemetry/projection.d.ts +23 -0
- package/dist/telemetry/projection.js +185 -0
- package/dist/telemetry/redact.d.ts +20 -0
- package/dist/telemetry/redact.js +40 -0
- package/dist/telemetry/service.d.ts +49 -0
- package/dist/telemetry/service.js +137 -0
- package/dist/testing.d.ts +58 -0
- package/dist/testing.js +123 -0
- package/dist/tool/background.d.ts +9 -6
- package/dist/tool/background.js +7 -1
- package/dist/tool/builtin/ask-user-question.js +6 -5
- package/dist/tool/builtin/bash.d.ts +6 -0
- package/dist/tool/builtin/bash.js +79 -42
- package/dist/tool/builtin/edit.js +82 -109
- package/dist/tool/builtin/glob.js +13 -13
- package/dist/tool/builtin/grep.js +13 -13
- package/dist/tool/builtin/read.js +25 -15
- package/dist/tool/builtin/write.js +49 -33
- package/dist/tool/define.d.ts +14 -8
- package/dist/tool/define.js +8 -2
- package/dist/tool/{machine-base.d.ts → environment-base.d.ts} +37 -37
- package/dist/tool/{machine-base.js → environment-base.js} +45 -119
- package/dist/tool/{machine-local.d.ts → environment-local.d.ts} +9 -8
- package/dist/tool/{machine-local.js → environment-local.js} +60 -81
- package/dist/tool/{machine-null.d.ts → environment-null.d.ts} +9 -9
- package/dist/tool/{machine-null.js → environment-null.js} +9 -9
- package/dist/tool/{machine-ssh.d.ts → environment-ssh.d.ts} +33 -18
- package/dist/tool/{machine-ssh.js → environment-ssh.js} +118 -149
- package/dist/tool/{machine.d.ts → environment.d.ts} +53 -82
- package/dist/tool/environment.js +2 -0
- package/dist/tool/file-freshness.d.ts +33 -19
- package/dist/tool/file-freshness.js +39 -30
- package/dist/tool/filesystem-tools.d.ts +1 -1
- package/dist/tool/filesystem-tools.js +1 -1
- package/dist/tool/git-context.d.ts +2 -2
- package/dist/tool/git-context.js +8 -8
- package/dist/tool/index.d.ts +12 -12
- package/dist/tool/index.js +12 -10
- package/dist/tool/policies/path-access.d.ts +4 -4
- package/dist/tool/policies/path-access.js +12 -12
- package/dist/tool/questions.d.ts +8 -0
- package/dist/tool/search/catalog.d.ts +37 -0
- package/dist/tool/search/catalog.js +182 -0
- package/dist/tool/search/deferral.d.ts +3 -2
- package/dist/tool/search/loaded.d.ts +32 -0
- package/dist/tool/search/loaded.js +96 -0
- package/dist/tool/search/search-tool.d.ts +2 -6
- package/dist/tool/search/search-tool.js +16 -15
- package/dist/tool/shell-env.js +4 -0
- package/dist/tool/support/bash-paths.js +38 -7
- package/dist/tool/support/{machine-ops.d.ts → environment-ops.d.ts} +12 -14
- package/dist/tool/support/{machine-ops.js → environment-ops.js} +21 -2
- package/dist/tool/support/git-worktree.d.ts +3 -3
- package/dist/tool/support/git-worktree.js +6 -6
- package/dist/tool/support/rg-locator.d.ts +6 -6
- package/dist/tool/support/rg-locator.js +6 -6
- package/dist/tool/support/ripgrep-run.d.ts +5 -5
- package/dist/tool/support/ripgrep-run.js +3 -3
- package/dist/tool/support/tool-path.d.ts +3 -3
- package/dist/tool/support/tool-path.js +7 -7
- package/dist/tool/types.d.ts +54 -10
- package/dist/tool/web/fetch-url.js +1 -1
- package/dist/tool/web/web-search.js +1 -1
- package/dist/tool/workspace-spec.d.ts +3 -3
- package/dist/tool/workspace-spec.js +27 -27
- package/dist/tracing/bridge.d.ts +9 -1
- package/dist/tracing/bridge.js +307 -77
- package/dist/tracing/index.d.ts +2 -2
- package/dist/tracing/otel.d.ts +28 -1
- package/dist/tracing/otel.js +150 -38
- package/dist/tracing/processor.d.ts +22 -0
- package/dist/tracing/processor.js +2 -0
- package/dist/tracing/spans.d.ts +54 -0
- package/dist/tracing/spans.js +5 -0
- package/package.json +6 -2
- package/dist/tool/machine.js +0 -15
- package/dist/tool/search/activation.d.ts +0 -13
- package/dist/tool/search/activation.js +0 -31
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { SessionProjection } from "../events/projection.js";
|
|
2
|
+
import { AUDIT_ADDRESS, isCheckpointRecord, DEFAULT_ADDRESS, } from "./store.js";
|
|
3
|
+
/**
|
|
4
|
+
* Stamps every history checkpoint a session writes with the shard's lifecycle at that instant
|
|
5
|
+
* (`#frame`: agent, open turn, queued steers — see `FrameCheckpoint`).
|
|
6
|
+
*
|
|
7
|
+
* The stamp happens inside `appendRecord`, which a `ConversationContext` calls synchronously in
|
|
8
|
+
* the same block as the history reset — so it is of exactly the lifecycle every record before
|
|
9
|
+
* the checkpoint produced, and of nothing after it. Doing it here rather than in each context
|
|
10
|
+
* means no context, wherever it is built, can write a checkpoint without it. A record that
|
|
11
|
+
* already carries `checkpoint` passes through untouched.
|
|
12
|
+
*
|
|
13
|
+
* The lifecycle is folded here from every record that passes through: this store sits UNDER the
|
|
14
|
+
* event publisher, so the lifecycle records the publisher journals pass through it too, in
|
|
15
|
+
* exactly the order they reach the log. Session and capability state are not stamped — they are
|
|
16
|
+
* kept as current values in the store's key/value side (see `CapabilityDurableState`).
|
|
17
|
+
*/
|
|
18
|
+
export class CheckpointingSessionStore {
|
|
19
|
+
inner;
|
|
20
|
+
/** The lifecycle side of every shard written or restored in this process, without history. */
|
|
21
|
+
frames;
|
|
22
|
+
listStateKeys;
|
|
23
|
+
watch;
|
|
24
|
+
flush;
|
|
25
|
+
close;
|
|
26
|
+
rewrite;
|
|
27
|
+
storageDir;
|
|
28
|
+
constructor(inner, sessionId) {
|
|
29
|
+
this.inner = inner;
|
|
30
|
+
this.frames = new SessionProjection(sessionId, { history: false });
|
|
31
|
+
if (inner.listStateKeys !== undefined)
|
|
32
|
+
this.listStateKeys = () => inner.listStateKeys();
|
|
33
|
+
if (inner.watch !== undefined)
|
|
34
|
+
this.watch = (options) => inner.watch(options);
|
|
35
|
+
if (inner.flush !== undefined)
|
|
36
|
+
this.flush = () => inner.flush();
|
|
37
|
+
if (inner.close !== undefined)
|
|
38
|
+
this.close = () => inner.close();
|
|
39
|
+
if (inner.rewrite !== undefined)
|
|
40
|
+
this.rewrite = (address) => inner.rewrite(address);
|
|
41
|
+
if (inner.storageDir !== undefined)
|
|
42
|
+
this.storageDir = () => inner.storageDir();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Fold a shard's records read back from the log (from its checkpoint on, or whole) into the
|
|
46
|
+
* lifecycle state, before this process writes to it again. A shard already folded here is
|
|
47
|
+
* left alone: what this process wrote is newer than anything it could read.
|
|
48
|
+
*/
|
|
49
|
+
restoreFrame(address, records) {
|
|
50
|
+
if (this.frames.has(address))
|
|
51
|
+
return;
|
|
52
|
+
for (const record of records) {
|
|
53
|
+
if ((record.address ?? DEFAULT_ADDRESS) === address)
|
|
54
|
+
this.frames.applyRecord(record);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
appendRecord(record) {
|
|
58
|
+
// The audit shard has no lifecycle to fold, and no checkpoint is ever written to it.
|
|
59
|
+
if (record.address === AUDIT_ADDRESS)
|
|
60
|
+
return this.inner.appendRecord(record);
|
|
61
|
+
if (!isCheckpointRecord(record) || record.checkpoint !== undefined) {
|
|
62
|
+
this.frames.applyRecord(record);
|
|
63
|
+
return this.inner.appendRecord(record);
|
|
64
|
+
}
|
|
65
|
+
const address = record.address ?? DEFAULT_ADDRESS;
|
|
66
|
+
const stamped = { ...record, checkpoint: { "#frame": this.frames.frameCheckpoint(address) } };
|
|
67
|
+
this.frames.applyRecord(stamped);
|
|
68
|
+
return this.inner.appendRecord(stamped);
|
|
69
|
+
}
|
|
70
|
+
readRecords(filter) {
|
|
71
|
+
return this.inner.readRecords(filter);
|
|
72
|
+
}
|
|
73
|
+
readRecordPage(options) {
|
|
74
|
+
return this.inner.readRecordPage(options);
|
|
75
|
+
}
|
|
76
|
+
putState(key, value) {
|
|
77
|
+
return this.inner.putState(key, value);
|
|
78
|
+
}
|
|
79
|
+
getState(key) {
|
|
80
|
+
return this.inner.getState(key);
|
|
81
|
+
}
|
|
82
|
+
deleteState(key) {
|
|
83
|
+
return this.inner.deleteState(key);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=checkpointing-store.js.map
|
|
@@ -23,6 +23,12 @@ export declare class DiskSessionStore implements SessionStore {
|
|
|
23
23
|
lastActivityMs(): Promise<number>;
|
|
24
24
|
appendRecord(record: AgentRecord): Promise<string>;
|
|
25
25
|
readRecords(filter?: ReadRecordsFilter): AsyncIterable<AgentRecord>;
|
|
26
|
+
/**
|
|
27
|
+
* The shard's records from its indexed checkpoint on — the file read from that byte offset,
|
|
28
|
+
* nothing before it. Undefined when there is no index or it does not land on that checkpoint
|
|
29
|
+
* (the caller reads the whole shard instead, which is always correct).
|
|
30
|
+
*/
|
|
31
|
+
private readFromCheckpoint;
|
|
26
32
|
readRecordPage(options: ReadRecordPageOptions): Promise<RecordPage>;
|
|
27
33
|
putState(key: StateKey, value: unknown): Promise<void>;
|
|
28
34
|
getState(key: StateKey): Promise<unknown | null>;
|
|
@@ -48,6 +54,8 @@ export declare class DiskSessionStore implements SessionStore {
|
|
|
48
54
|
private ensureCurrentVersion;
|
|
49
55
|
private stampVersion;
|
|
50
56
|
private rewriteShard;
|
|
57
|
+
/** Every shard a read without an address covers: all of them but the audit shard. */
|
|
58
|
+
private conversationShards;
|
|
51
59
|
private listShards;
|
|
52
60
|
private readState;
|
|
53
61
|
private writeState;
|
package/dist/store/disk-store.js
CHANGED
|
@@ -4,7 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import { BlobStore, offloadRecord, rehydrateRecord } from "./blob-store.js";
|
|
5
5
|
import { compareSequence, pageRecords } from "./log-store.js";
|
|
6
6
|
import { migrateRecord, WIRE_PROTOCOL_VERSION, WIRE_VERSION_KEY } from "./migrate.js";
|
|
7
|
-
import { DEFAULT_ADDRESS, } from "./store.js";
|
|
7
|
+
import { AUDIT_ADDRESS, DEFAULT_ADDRESS, isCheckpointRecord, } from "./store.js";
|
|
8
8
|
const AGENTS_DIR = "agents";
|
|
9
9
|
const BLOBS_DIR = "blobs";
|
|
10
10
|
const LOG_FILE = "log.jsonl";
|
|
@@ -74,16 +74,72 @@ export class DiskSessionStore {
|
|
|
74
74
|
await this.ensureMetadata(address, dir);
|
|
75
75
|
const stamped = record.time !== undefined ? record : { ...record, time: Date.now() };
|
|
76
76
|
const stored = await offloadRecord(stamped, this.blobStore);
|
|
77
|
-
|
|
77
|
+
if (!isCheckpointRecord(record))
|
|
78
|
+
return this.appendStored(dir, stored);
|
|
79
|
+
// Index the shard's newest checkpoint by BYTE OFFSET, so a replay reads the file from
|
|
80
|
+
// there rather than from the top. Written after the line: a crash in between leaves the
|
|
81
|
+
// index at an older checkpoint, which is still a valid place to start.
|
|
82
|
+
const offset = await fileSize(join(dir, LOG_FILE));
|
|
83
|
+
const sequence = await this.appendStored(dir, stored);
|
|
84
|
+
await this.putState(checkpointOffsetKey(shardName(address)), { sequence, offset });
|
|
85
|
+
return sequence;
|
|
78
86
|
});
|
|
79
87
|
}
|
|
80
88
|
async *readRecords(filter) {
|
|
81
|
-
const shards = filter?.address !== undefined ? [shardName(filter.address)] : await this.
|
|
89
|
+
const shards = filter?.address !== undefined ? [shardName(filter.address)] : await this.conversationShards();
|
|
90
|
+
if (filter?.fromCheckpoint === true) {
|
|
91
|
+
const all = [];
|
|
92
|
+
for (const shard of shards) {
|
|
93
|
+
const tail = await this.readFromCheckpoint(shard);
|
|
94
|
+
if (tail !== undefined)
|
|
95
|
+
all.push(...tail);
|
|
96
|
+
else
|
|
97
|
+
for await (const item of this.readShardDecoded(shard))
|
|
98
|
+
all.push(item);
|
|
99
|
+
}
|
|
100
|
+
if (shards.length > 1)
|
|
101
|
+
all.sort((a, b) => compareSequence(a.sequence, b.sequence));
|
|
102
|
+
for (const item of all)
|
|
103
|
+
yield item.record;
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
82
106
|
for (const item of await this.readStored(shards))
|
|
83
107
|
yield item.record;
|
|
84
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* The shard's records from its indexed checkpoint on — the file read from that byte offset,
|
|
111
|
+
* nothing before it. Undefined when there is no index or it does not land on that checkpoint
|
|
112
|
+
* (the caller reads the whole shard instead, which is always correct).
|
|
113
|
+
*/
|
|
114
|
+
async readFromCheckpoint(shard) {
|
|
115
|
+
const index = await this.getState(checkpointOffsetKey(shard));
|
|
116
|
+
if (!isCheckpointOffset(index))
|
|
117
|
+
return undefined;
|
|
118
|
+
const filePath = join(this.sessionDir, AGENTS_DIR, shard, LOG_FILE);
|
|
119
|
+
const raw = await readFileFrom(filePath, index.offset);
|
|
120
|
+
if (raw === undefined)
|
|
121
|
+
return undefined;
|
|
122
|
+
const version = await this.version();
|
|
123
|
+
const out = [];
|
|
124
|
+
try {
|
|
125
|
+
for (const stored of parseLogLines(raw, filePath)) {
|
|
126
|
+
if (out.length === 0 && stored.sequence !== index.sequence)
|
|
127
|
+
return undefined;
|
|
128
|
+
const migrated = migrateRecord(stored.record, version);
|
|
129
|
+
if (migrated === null)
|
|
130
|
+
continue;
|
|
131
|
+
out.push({ sequence: stored.sequence, record: await rehydrateRecord(migrated, this.blobStore) });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// The offset no longer lands on a line boundary (the file was replaced underneath us).
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
const head = out[0];
|
|
139
|
+
return head !== undefined && head.sequence === index.sequence && isCheckpointRecord(head.record) ? out : undefined;
|
|
140
|
+
}
|
|
85
141
|
async readRecordPage(options) {
|
|
86
|
-
const shards = options.address !== undefined ? [shardName(options.address)] : await this.
|
|
142
|
+
const shards = options.address !== undefined ? [shardName(options.address)] : await this.conversationShards();
|
|
87
143
|
return pageRecords(await this.readStored(shards), options);
|
|
88
144
|
}
|
|
89
145
|
async putState(key, value) {
|
|
@@ -215,9 +271,27 @@ export class DiskSessionStore {
|
|
|
215
271
|
const withMeta = withLeadingMetadata(lines, shardAddress(shard));
|
|
216
272
|
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
217
273
|
const tmp = `${target}.tmp.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
218
|
-
|
|
274
|
+
const encoded = withMeta.map((line) => `${JSON.stringify(line)}\n`);
|
|
275
|
+
await writeFile(tmp, encoded.join(""), { encoding: "utf-8", mode: 0o600 });
|
|
219
276
|
await rename(tmp, target);
|
|
220
277
|
this.metadataChecked.add(shardAddress(shard));
|
|
278
|
+
// The rewrite moved every line, so re-point the checkpoint index at the new byte offset.
|
|
279
|
+
let offset = 0;
|
|
280
|
+
let newest;
|
|
281
|
+
for (let i = 0; i < withMeta.length; i++) {
|
|
282
|
+
if (isCheckpointRecord(withMeta[i].record))
|
|
283
|
+
newest = { sequence: withMeta[i].sequence, offset };
|
|
284
|
+
offset += Buffer.byteLength(encoded[i], "utf-8");
|
|
285
|
+
}
|
|
286
|
+
if (newest !== undefined)
|
|
287
|
+
await this.putState(checkpointOffsetKey(shard), newest);
|
|
288
|
+
else
|
|
289
|
+
await this.deleteState(checkpointOffsetKey(shard));
|
|
290
|
+
}
|
|
291
|
+
/** Every shard a read without an address covers: all of them but the audit shard. */
|
|
292
|
+
async conversationShards() {
|
|
293
|
+
const audit = shardName(AUDIT_ADDRESS);
|
|
294
|
+
return (await this.listShards()).filter((shard) => shard !== audit);
|
|
221
295
|
}
|
|
222
296
|
async listShards() {
|
|
223
297
|
try {
|
|
@@ -319,6 +393,50 @@ function shardName(address) {
|
|
|
319
393
|
function shardAddress(shard) {
|
|
320
394
|
return shard;
|
|
321
395
|
}
|
|
396
|
+
function checkpointOffsetKey(shard) {
|
|
397
|
+
return `checkpoint-offset:${shard}`;
|
|
398
|
+
}
|
|
399
|
+
function isCheckpointOffset(value) {
|
|
400
|
+
if (typeof value !== "object" || value === null)
|
|
401
|
+
return false;
|
|
402
|
+
const { sequence, offset } = value;
|
|
403
|
+
return typeof sequence === "string" && /^[1-9]\d*$/.test(sequence) && typeof offset === "number" && Number.isSafeInteger(offset) && offset >= 0;
|
|
404
|
+
}
|
|
405
|
+
async function fileSize(filePath) {
|
|
406
|
+
try {
|
|
407
|
+
return (await stat(filePath)).size;
|
|
408
|
+
}
|
|
409
|
+
catch {
|
|
410
|
+
return 0;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
/** The file's contents from byte `offset` to its end, or undefined when it is shorter than that. */
|
|
414
|
+
async function readFileFrom(filePath, offset) {
|
|
415
|
+
let handle;
|
|
416
|
+
try {
|
|
417
|
+
handle = await open(filePath, "r");
|
|
418
|
+
}
|
|
419
|
+
catch {
|
|
420
|
+
return undefined;
|
|
421
|
+
}
|
|
422
|
+
try {
|
|
423
|
+
const { size } = await handle.stat();
|
|
424
|
+
if (offset > size)
|
|
425
|
+
return undefined;
|
|
426
|
+
const buffer = Buffer.alloc(size - offset);
|
|
427
|
+
let read = 0;
|
|
428
|
+
while (read < buffer.length) {
|
|
429
|
+
const { bytesRead } = await handle.read(buffer, read, buffer.length - read, offset + read);
|
|
430
|
+
if (bytesRead === 0)
|
|
431
|
+
break;
|
|
432
|
+
read += bytesRead;
|
|
433
|
+
}
|
|
434
|
+
return buffer.subarray(0, read).toString("utf-8");
|
|
435
|
+
}
|
|
436
|
+
finally {
|
|
437
|
+
await handle.close();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
322
440
|
/** Yield each well-formed JSON record of a log file (a torn trailing line is tolerated). */
|
|
323
441
|
async function* readRawLines(filePath) {
|
|
324
442
|
let raw;
|
|
@@ -328,6 +446,10 @@ async function* readRawLines(filePath) {
|
|
|
328
446
|
catch {
|
|
329
447
|
return;
|
|
330
448
|
}
|
|
449
|
+
yield* parseLogLines(raw, filePath);
|
|
450
|
+
}
|
|
451
|
+
/** The records of a log file's text (all of it, or a suffix starting on a line boundary). */
|
|
452
|
+
function* parseLogLines(raw, filePath) {
|
|
331
453
|
const lines = raw.split("\n");
|
|
332
454
|
for (let i = 0; i < lines.length; i++) {
|
|
333
455
|
const line = lines[i].replace(/\r$/, "");
|
package/dist/store/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export type { AgentRecord, AgentRecordBody, SessionStore, StateKey, ReadRecordsFilter, StoredAgentRecord, RecordOrder, ReadRecordPageOptions, RecordPage, WatchRecordsOptions, } from "./store.ts";
|
|
2
|
-
export { DEFAULT_ADDRESS, reduceHistory, summaryMessage, customMessage, watchRecordsByPolling } from "./store.ts";
|
|
1
|
+
export type { AgentRecord, AgentRecordBody, SessionStore, StateKey, ReadRecordsFilter, StoredAgentRecord, RecordOrder, ReadRecordPageOptions, RecordPage, WatchRecordsOptions, CheckpointState, CheckpointRecord, } from "./store.ts";
|
|
2
|
+
export { DEFAULT_ADDRESS, reduceHistory, summaryMessage, customMessage, watchRecordsByPolling, isCheckpointRecord, checkpointIndexKey, AUDIT_ADDRESS, appendAudit, readAudit, durableStateKey, SESSION_PERMISSION_KEY, SESSION_USAGE_KEY, } from "./store.ts";
|
|
3
|
+
export { CheckpointingSessionStore } from "./checkpointing-store.ts";
|
|
3
4
|
export { MemorySessionLock, SessionBusyError } from "./lock.ts";
|
|
4
5
|
export type { SessionLock, SessionLease, AcquireLeaseOptions } from "./lock.ts";
|
|
5
6
|
export { LogSessionStore, MemoryStore } from "./log-store.ts";
|
package/dist/store/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { DEFAULT_ADDRESS, reduceHistory, summaryMessage, customMessage, watchRecordsByPolling } from "./store.js";
|
|
1
|
+
export { DEFAULT_ADDRESS, reduceHistory, summaryMessage, customMessage, watchRecordsByPolling, isCheckpointRecord, checkpointIndexKey, AUDIT_ADDRESS, appendAudit, readAudit, durableStateKey, SESSION_PERMISSION_KEY, SESSION_USAGE_KEY, } from "./store.js";
|
|
2
|
+
export { CheckpointingSessionStore } from "./checkpointing-store.js";
|
|
2
3
|
export { MemorySessionLock, SessionBusyError } from "./lock.js";
|
|
3
4
|
export { LogSessionStore, MemoryStore } from "./log-store.js";
|
|
4
5
|
export { DiskSessionStore } from "./disk-store.js";
|
|
@@ -14,7 +14,7 @@ export interface ReadLinesPageOptions {
|
|
|
14
14
|
readonly order: "asc" | "desc";
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* The **linear** session log implemented once over a tiny physical
|
|
17
|
+
* The **linear** session log implemented once over a tiny physical surface
|
|
18
18
|
* (raw line append/read/rewrite + key-value state + content-addressed blobs). A new backing
|
|
19
19
|
* (disk, Postgres, Redis, S3…) implements only those primitives; the flat append log, first-
|
|
20
20
|
* record `metadata` prepend, wire migration, and blob offload are written once here. Records are
|
|
@@ -48,6 +48,12 @@ export declare abstract class LogSessionStore implements SessionStore {
|
|
|
48
48
|
appendRecord(record: AgentRecord): Promise<string>;
|
|
49
49
|
private appendRecordNow;
|
|
50
50
|
readRecords(filter?: ReadRecordsFilter): AsyncIterable<AgentRecord>;
|
|
51
|
+
/**
|
|
52
|
+
* The shard's records from its indexed checkpoint on, or undefined when the index is missing
|
|
53
|
+
* or does not point at a checkpoint of this shard (a fork that renumbered the log, an index
|
|
54
|
+
* written by a crashed process) — the caller then reads the whole shard.
|
|
55
|
+
*/
|
|
56
|
+
private recordsFromCheckpoint;
|
|
51
57
|
readRecordPage(options: ReadRecordPageOptions): Promise<RecordPage>;
|
|
52
58
|
/** `readRecordPage` over a backing that can seek: read `limit + 1` lines to learn whether a
|
|
53
59
|
* next page exists, parse only those. Same validation and cursor semantics as `pageRecords`. */
|
|
@@ -59,6 +65,8 @@ export declare abstract class LogSessionStore implements SessionStore {
|
|
|
59
65
|
/** Parsed + wire-migrated records for an address, in append order (NOT blob-rehydrated).
|
|
60
66
|
* Records dropped by a migration are skipped. */
|
|
61
67
|
private parsedRecords;
|
|
68
|
+
/** Every shard a read without an address covers: all of them but the audit shard. */
|
|
69
|
+
private conversationAddresses;
|
|
62
70
|
private storedRecords;
|
|
63
71
|
/** Ensure the shard's log opens with a `metadata` record. Cheap after first touch. */
|
|
64
72
|
private ensureMetadata;
|
package/dist/store/log-store.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BlobStore, offloadRecord, rehydrateRecord } from "./blob-store.js";
|
|
2
2
|
import { migrateRecord, WIRE_PROTOCOL_VERSION, WIRE_VERSION_KEY } from "./migrate.js";
|
|
3
|
-
import { DEFAULT_ADDRESS, } from "./store.js";
|
|
3
|
+
import { AUDIT_ADDRESS, checkpointIndexKey, DEFAULT_ADDRESS, isCheckpointRecord, } from "./store.js";
|
|
4
4
|
/**
|
|
5
|
-
* The **linear** session log implemented once over a tiny physical
|
|
5
|
+
* The **linear** session log implemented once over a tiny physical surface
|
|
6
6
|
* (raw line append/read/rewrite + key-value state + content-addressed blobs). A new backing
|
|
7
7
|
* (disk, Postgres, Redis, S3…) implements only those primitives; the flat append log, first-
|
|
8
8
|
* record `metadata` prepend, wire migration, and blob offload are written once here. Records are
|
|
@@ -43,12 +43,72 @@ export class LogSessionStore {
|
|
|
43
43
|
await this.ensureMetadata(address);
|
|
44
44
|
const stamped = record.time !== undefined ? record : { ...record, time: Date.now() };
|
|
45
45
|
const stored = await offloadRecord(stamped, this.#blobs);
|
|
46
|
-
|
|
46
|
+
const sequence = await this.appendLine(address, JSON.stringify(stored));
|
|
47
|
+
// Index the shard's newest checkpoint so a replay can start there. Written after the line:
|
|
48
|
+
// a crash in between leaves the index at an OLDER checkpoint, which is still a valid start.
|
|
49
|
+
if (isCheckpointRecord(record))
|
|
50
|
+
await this.putState(checkpointIndexKey(address), sequence);
|
|
51
|
+
return sequence;
|
|
47
52
|
}
|
|
48
53
|
async *readRecords(filter) {
|
|
54
|
+
if (filter?.fromCheckpoint === true) {
|
|
55
|
+
const addresses = filter.address !== undefined ? [filter.address] : await this.conversationAddresses();
|
|
56
|
+
const all = [];
|
|
57
|
+
for (const address of addresses)
|
|
58
|
+
all.push(...((await this.recordsFromCheckpoint(address)) ?? (await this.parsedRecords(address))));
|
|
59
|
+
if (addresses.length > 1)
|
|
60
|
+
all.sort((a, b) => compareSequence(a.sequence, b.sequence));
|
|
61
|
+
for (const item of all)
|
|
62
|
+
yield item.record;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
49
65
|
for (const item of await this.storedRecords(filter?.address))
|
|
50
66
|
yield item.record;
|
|
51
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* The shard's records from its indexed checkpoint on, or undefined when the index is missing
|
|
70
|
+
* or does not point at a checkpoint of this shard (a fork that renumbered the log, an index
|
|
71
|
+
* written by a crashed process) — the caller then reads the whole shard.
|
|
72
|
+
*/
|
|
73
|
+
async recordsFromCheckpoint(address) {
|
|
74
|
+
const indexed = await this.getState(checkpointIndexKey(address));
|
|
75
|
+
if (typeof indexed !== "string" || !/^[1-9]\d*$/.test(indexed))
|
|
76
|
+
return undefined;
|
|
77
|
+
const start = BigInt(indexed);
|
|
78
|
+
const lines = [];
|
|
79
|
+
if (this.readLinesPage !== undefined) {
|
|
80
|
+
// `after` is exclusive; sequences are positive, so `start - 1` admits the checkpoint itself.
|
|
81
|
+
let after = start > 1n ? String(start - 1n) : undefined;
|
|
82
|
+
while (true) {
|
|
83
|
+
const page = await this.readLinesPage(address, { ...(after !== undefined ? { after } : {}), limit: 512, order: "asc" });
|
|
84
|
+
lines.push(...page);
|
|
85
|
+
if (page.length < 512)
|
|
86
|
+
break;
|
|
87
|
+
after = page[page.length - 1].sequence;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
for await (const storedLine of this.readLines(address)) {
|
|
92
|
+
if (lines.length > 0 || BigInt(storedLine.sequence) >= start)
|
|
93
|
+
lines.push(storedLine);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const first = lines[0];
|
|
97
|
+
if (first === undefined || first.sequence !== indexed)
|
|
98
|
+
return undefined;
|
|
99
|
+
const version = await this.version();
|
|
100
|
+
const out = [];
|
|
101
|
+
for (const storedLine of lines) {
|
|
102
|
+
const migrated = migrateRecord(JSON.parse(storedLine.line), version);
|
|
103
|
+
if (migrated === null)
|
|
104
|
+
continue;
|
|
105
|
+
out.push({ sequence: storedLine.sequence, record: await rehydrateRecord(migrated, this.#blobs) });
|
|
106
|
+
}
|
|
107
|
+
const head = out[0];
|
|
108
|
+
if (head === undefined || head.sequence !== indexed || !isCheckpointRecord(head.record))
|
|
109
|
+
return undefined;
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
52
112
|
async readRecordPage(options) {
|
|
53
113
|
if (options.address !== undefined && this.readLinesPage !== undefined) {
|
|
54
114
|
return this.readRecordPageSeeking(options.address, options);
|
|
@@ -123,11 +183,15 @@ export class LogSessionStore {
|
|
|
123
183
|
}
|
|
124
184
|
return out;
|
|
125
185
|
}
|
|
186
|
+
/** Every shard a read without an address covers: all of them but the audit shard. */
|
|
187
|
+
async conversationAddresses() {
|
|
188
|
+
return (await this.listShardAddresses()).filter((address) => address !== AUDIT_ADDRESS);
|
|
189
|
+
}
|
|
126
190
|
async storedRecords(address) {
|
|
127
191
|
if (address !== undefined)
|
|
128
192
|
return this.parsedRecords(address);
|
|
129
193
|
const all = [];
|
|
130
|
-
for (const shard of await this.
|
|
194
|
+
for (const shard of await this.conversationAddresses())
|
|
131
195
|
all.push(...(await this.parsedRecords(shard)));
|
|
132
196
|
all.sort((a, b) => compareSequence(a.sequence, b.sequence));
|
|
133
197
|
return all;
|
package/dist/store/migrate.d.ts
CHANGED
|
@@ -6,8 +6,13 @@ import type { AgentRecord } from "./store.ts";
|
|
|
6
6
|
*
|
|
7
7
|
* Version 1 introduced the linear `AgentRecord` format. Version 2 adds
|
|
8
8
|
* durable handoff linkage and seed provenance without invalidating version-1 records.
|
|
9
|
+
* Version 3 makes the history resets self-contained checkpoints: `context.apply_compaction`
|
|
10
|
+
* journals its kept tail (`kept`) instead of a `cutoff` into the history before it, and both
|
|
11
|
+
* resets may carry the session's state (`checkpoint`). A version-2 compaction record cannot be
|
|
12
|
+
* upgraded — its kept tail is not in the record — so it passes through unchanged and replay
|
|
13
|
+
* rejects it (see `foldCompactionRecord`).
|
|
9
14
|
*/
|
|
10
|
-
export declare const WIRE_PROTOCOL_VERSION =
|
|
15
|
+
export declare const WIRE_PROTOCOL_VERSION = 3;
|
|
11
16
|
/** KV state key under which a session stamps the version its log was written at. */
|
|
12
17
|
export declare const WIRE_VERSION_KEY = "wire_version";
|
|
13
18
|
/**
|
|
@@ -15,7 +20,8 @@ export declare const WIRE_VERSION_KEY = "wire_version";
|
|
|
15
20
|
* Returning `null` DROPS the record (for a record that has no place in the new format).
|
|
16
21
|
*/
|
|
17
22
|
export type RecordMigration = (raw: Record<string, unknown>) => Record<string, unknown> | null;
|
|
18
|
-
/** Version 2 adds durable handoff linkage/provenance; every version-1 record remains valid.
|
|
23
|
+
/** Version 2 adds durable handoff linkage/provenance; every version-1 record remains valid.
|
|
24
|
+
* Version 3 changes only the compaction record, which has no upgrade (see above). */
|
|
19
25
|
export declare const RECORD_MIGRATIONS: Readonly<Record<number, RecordMigration>>;
|
|
20
26
|
/**
|
|
21
27
|
* Apply the migration chain to bring a raw record from `fromVersion` up to `toVersion`.
|
package/dist/store/migrate.js
CHANGED
|
@@ -5,13 +5,20 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Version 1 introduced the linear `AgentRecord` format. Version 2 adds
|
|
7
7
|
* durable handoff linkage and seed provenance without invalidating version-1 records.
|
|
8
|
+
* Version 3 makes the history resets self-contained checkpoints: `context.apply_compaction`
|
|
9
|
+
* journals its kept tail (`kept`) instead of a `cutoff` into the history before it, and both
|
|
10
|
+
* resets may carry the session's state (`checkpoint`). A version-2 compaction record cannot be
|
|
11
|
+
* upgraded — its kept tail is not in the record — so it passes through unchanged and replay
|
|
12
|
+
* rejects it (see `foldCompactionRecord`).
|
|
8
13
|
*/
|
|
9
|
-
export const WIRE_PROTOCOL_VERSION =
|
|
14
|
+
export const WIRE_PROTOCOL_VERSION = 3;
|
|
10
15
|
/** KV state key under which a session stamps the version its log was written at. */
|
|
11
16
|
export const WIRE_VERSION_KEY = "wire_version";
|
|
12
|
-
/** Version 2 adds durable handoff linkage/provenance; every version-1 record remains valid.
|
|
17
|
+
/** Version 2 adds durable handoff linkage/provenance; every version-1 record remains valid.
|
|
18
|
+
* Version 3 changes only the compaction record, which has no upgrade (see above). */
|
|
13
19
|
export const RECORD_MIGRATIONS = {
|
|
14
20
|
1: (raw) => raw,
|
|
21
|
+
2: (raw) => raw,
|
|
15
22
|
};
|
|
16
23
|
/**
|
|
17
24
|
* Apply the migration chain to bring a raw record from `fromVersion` up to `toVersion`.
|
package/dist/store/origin.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ToolSchema } from "../protocol/tool-schema.ts";
|
|
1
2
|
/**
|
|
2
3
|
* `PromptOrigin` — a structured tag on a journaled message record saying WHERE the message
|
|
3
4
|
* came from. It is the persistence-layer replacement for parsing intent back out of rendered
|
|
@@ -14,12 +15,17 @@
|
|
|
14
15
|
*/
|
|
15
16
|
export interface UserPromptOrigin {
|
|
16
17
|
readonly kind: "user";
|
|
17
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Present when the message arrived via the SteerBus: the id of its `steer.queued` record.
|
|
20
|
+
* Still the user's OWN words — typed mid-turn, or handed over by whoever holds the session's
|
|
21
|
+
* control surface (an app-server client, a managed API caller). Contrast `external`, which
|
|
22
|
+
* relays another party's words.
|
|
23
|
+
*/
|
|
18
24
|
readonly steerId?: string;
|
|
19
25
|
}
|
|
20
26
|
export interface UserFollowUpPromptOrigin {
|
|
21
27
|
readonly kind: "user_follow_up";
|
|
22
|
-
/**
|
|
28
|
+
/** See `UserPromptOrigin.steerId`. */
|
|
23
29
|
readonly steerId?: string;
|
|
24
30
|
}
|
|
25
31
|
export interface InjectionOrigin {
|
|
@@ -64,8 +70,27 @@ export interface CronMissedOrigin {
|
|
|
64
70
|
/** Present when the message arrived via the SteerBus: the enqueue-time correlation id. */
|
|
65
71
|
readonly steerId?: string;
|
|
66
72
|
}
|
|
73
|
+
export interface LoadedToolSchema {
|
|
74
|
+
readonly sourceName: string;
|
|
75
|
+
readonly schema: ToolSchema;
|
|
76
|
+
}
|
|
67
77
|
export interface CompactionSummaryOrigin {
|
|
68
78
|
readonly kind: "compaction_summary";
|
|
79
|
+
/** Deferred-tool definitions the compacted prefix had loaded and the kept tail still calls.
|
|
80
|
+
* Recorded once per compaction so a surviving call stays declared and executable after its
|
|
81
|
+
* load point is gone (the counterpart of Claude Code's pre-compact discovered-tool list;
|
|
82
|
+
* definitions travel with it because nothing else durable holds them). */
|
|
83
|
+
readonly loadedTools?: readonly LoadedToolSchema[];
|
|
84
|
+
}
|
|
85
|
+
/** A catalog announcement actually present in this conversation's model-visible history. */
|
|
86
|
+
export interface ToolCatalogDeltaOrigin {
|
|
87
|
+
readonly kind: "tool_catalog_delta";
|
|
88
|
+
readonly added: readonly {
|
|
89
|
+
readonly name: string;
|
|
90
|
+
readonly sourceName: string;
|
|
91
|
+
readonly fingerprint: string;
|
|
92
|
+
}[];
|
|
93
|
+
readonly removed: readonly string[];
|
|
69
94
|
}
|
|
70
95
|
/** A message copied into a fresh conversation shard when ownership is handed to another agent. */
|
|
71
96
|
export interface HandoffSeedOrigin {
|
|
@@ -74,16 +99,16 @@ export interface HandoffSeedOrigin {
|
|
|
74
99
|
readonly fromAddress: string;
|
|
75
100
|
}
|
|
76
101
|
export type ExternalOriginMetadataValue = string | number | boolean | null;
|
|
77
|
-
/**
|
|
102
|
+
/** Another party's words, relayed onto the session by whoever holds its control surface (a
|
|
103
|
+
* peer network, a webhook bridge, a managed API caller declaring `origin: "external"`). */
|
|
78
104
|
export interface ExternalPromptOrigin {
|
|
79
105
|
readonly kind: "external";
|
|
80
106
|
readonly source: string;
|
|
81
|
-
readonly deliveryId: string;
|
|
82
107
|
readonly actor?: string;
|
|
83
108
|
readonly metadata?: Readonly<Record<string, ExternalOriginMetadataValue>>;
|
|
84
|
-
/**
|
|
109
|
+
/** The id of its `steer.queued` record — every external message arrives through the SteerBus. */
|
|
85
110
|
readonly steerId?: string;
|
|
86
111
|
}
|
|
87
|
-
export type PromptOrigin = UserPromptOrigin | UserFollowUpPromptOrigin | InjectionOrigin | BackgroundTaskOrigin | ExtensionMessageOrigin | CronJobOrigin | CronMissedOrigin | CompactionSummaryOrigin | HandoffSeedOrigin | ExternalPromptOrigin;
|
|
112
|
+
export type PromptOrigin = UserPromptOrigin | UserFollowUpPromptOrigin | InjectionOrigin | BackgroundTaskOrigin | ExtensionMessageOrigin | CronJobOrigin | CronMissedOrigin | CompactionSummaryOrigin | ToolCatalogDeltaOrigin | HandoffSeedOrigin | ExternalPromptOrigin;
|
|
88
113
|
export declare const USER_PROMPT_ORIGIN: UserPromptOrigin;
|
|
89
114
|
//# sourceMappingURL=origin.d.ts.map
|
package/dist/store/origin.js
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `PromptOrigin` — a structured tag on a journaled message record saying WHERE the message
|
|
3
|
-
* came from. It is the persistence-layer replacement for parsing intent back out of rendered
|
|
4
|
-
* text: a settle notification carries `{kind:'background_task', …}` so a reducer reads the entity
|
|
5
|
-
* id/status structurally instead of regexing a `<background-task-done>` tag.
|
|
6
|
-
*
|
|
7
|
-
* Lives at the store layer (below `loop`) so `AgentRecordBody` can carry it without a layer
|
|
8
|
-
* inversion. Fields are primitives only — no import of capabilities/background types — so this
|
|
9
|
-
* stays a leaf module. `status` is a plain string (the domain's own vocabulary).
|
|
10
|
-
*
|
|
11
|
-
* Pragmatic subset: only the kinds agent-framework produces today. Extensible by adding a
|
|
12
|
-
* member when a new kind appears — kept a CLOSED discriminated union (no open `kind`) so
|
|
13
|
-
* `origin.kind === '…'` narrows and exhaustiveness is checkable.
|
|
14
|
-
*/
|
|
15
1
|
export const USER_PROMPT_ORIGIN = { kind: "user" };
|
|
16
2
|
//# sourceMappingURL=origin.js.map
|
package/dist/store/pg.d.ts
CHANGED
|
@@ -83,6 +83,7 @@ export declare class PgSessionRepository implements SessionRepository {
|
|
|
83
83
|
fork(sourceId: string, input?: ForkSessionInput): Promise<SessionHandle>;
|
|
84
84
|
delete(id: string, options?: DeleteSessionOptions): Promise<void>;
|
|
85
85
|
restore(id: string): Promise<void>;
|
|
86
|
+
rename(id: string, title: string): Promise<void>;
|
|
86
87
|
close(): Promise<void>;
|
|
87
88
|
}
|
|
88
89
|
/** Postgres-backed {@link SessionStorage}. Inject a `pg.Pool`; tables are created on first use. */
|