@inbrowser/agent 0.0.0-placeholder → 0.2.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/AGENTS.md +270 -0
- package/LICENSE +21 -0
- package/README.md +117 -2
- package/bin/agent.ts +10 -0
- package/dist/cli/commands/describe.d.ts +14 -0
- package/dist/cli/commands/describe.d.ts.map +1 -0
- package/dist/cli/commands/describe.js +179 -0
- package/dist/cli/commands/describe.js.map +1 -0
- package/dist/cli/commands/events.d.ts +21 -0
- package/dist/cli/commands/events.d.ts.map +1 -0
- package/dist/cli/commands/events.js +59 -0
- package/dist/cli/commands/events.js.map +1 -0
- package/dist/cli/commands/fleet.d.ts +15 -0
- package/dist/cli/commands/fleet.d.ts.map +1 -0
- package/dist/cli/commands/fleet.js +149 -0
- package/dist/cli/commands/fleet.js.map +1 -0
- package/dist/cli/commands/help.d.ts +15 -0
- package/dist/cli/commands/help.d.ts.map +1 -0
- package/dist/cli/commands/help.js +93 -0
- package/dist/cli/commands/help.js.map +1 -0
- package/dist/cli/commands/migrate.d.ts +27 -0
- package/dist/cli/commands/migrate.d.ts.map +1 -0
- package/dist/cli/commands/migrate.js +109 -0
- package/dist/cli/commands/migrate.js.map +1 -0
- package/dist/cli/commands/run.d.ts +38 -0
- package/dist/cli/commands/run.d.ts.map +1 -0
- package/dist/cli/commands/run.js +535 -0
- package/dist/cli/commands/run.js.map +1 -0
- package/dist/cli/commands/schema.d.ts +8 -0
- package/dist/cli/commands/schema.d.ts.map +1 -0
- package/dist/cli/commands/schema.js +12 -0
- package/dist/cli/commands/schema.js.map +1 -0
- package/dist/cli/commands/serve.d.ts +39 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/serve.js +65 -0
- package/dist/cli/commands/serve.js.map +1 -0
- package/dist/cli/commands/undo.d.ts +36 -0
- package/dist/cli/commands/undo.d.ts.map +1 -0
- package/dist/cli/commands/undo.js +132 -0
- package/dist/cli/commands/undo.js.map +1 -0
- package/dist/cli/fixtures.d.ts +17 -0
- package/dist/cli/fixtures.d.ts.map +1 -0
- package/dist/cli/fixtures.js +107 -0
- package/dist/cli/fixtures.js.map +1 -0
- package/dist/cli/hardening.d.ts +39 -0
- package/dist/cli/hardening.d.ts.map +1 -0
- package/dist/cli/hardening.js +68 -0
- package/dist/cli/hardening.js.map +1 -0
- package/dist/cli/index.d.ts +28 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +19 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/llm/openrouter.d.ts +33 -0
- package/dist/cli/llm/openrouter.d.ts.map +1 -0
- package/dist/cli/llm/openrouter.js +285 -0
- package/dist/cli/llm/openrouter.js.map +1 -0
- package/dist/cli/main.d.ts +32 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +106 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/output.d.ts +36 -0
- package/dist/cli/output.d.ts.map +1 -0
- package/dist/cli/output.js +95 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/cli/parse.d.ts +26 -0
- package/dist/cli/parse.d.ts.map +1 -0
- package/dist/cli/parse.js +160 -0
- package/dist/cli/parse.js.map +1 -0
- package/dist/cli/session-log.d.ts +34 -0
- package/dist/cli/session-log.d.ts.map +1 -0
- package/dist/cli/session-log.js +52 -0
- package/dist/cli/session-log.js.map +1 -0
- package/dist/cli/spec.d.ts +62 -0
- package/dist/cli/spec.d.ts.map +1 -0
- package/dist/cli/spec.js +510 -0
- package/dist/cli/spec.js.map +1 -0
- package/dist/cli/ui/RunView.d.ts +134 -0
- package/dist/cli/ui/RunView.d.ts.map +1 -0
- package/dist/cli/ui/RunView.js +341 -0
- package/dist/cli/ui/RunView.js.map +1 -0
- package/dist/diagnostics/index.d.ts +5 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/index.js +3 -0
- package/dist/diagnostics/index.js.map +1 -0
- package/dist/diagnostics/timing.d.ts +48 -0
- package/dist/diagnostics/timing.d.ts.map +1 -0
- package/dist/diagnostics/timing.js +85 -0
- package/dist/diagnostics/timing.js.map +1 -0
- package/dist/diagnostics/truthfulness.d.ts +36 -0
- package/dist/diagnostics/truthfulness.d.ts.map +1 -0
- package/dist/diagnostics/truthfulness.js +180 -0
- package/dist/diagnostics/truthfulness.js.map +1 -0
- package/dist/dispatch-memoization.d.ts +84 -0
- package/dist/dispatch-memoization.d.ts.map +1 -0
- package/dist/dispatch-memoization.js +197 -0
- package/dist/dispatch-memoization.js.map +1 -0
- package/dist/eval/comparison-report.d.ts +164 -0
- package/dist/eval/comparison-report.d.ts.map +1 -0
- package/dist/eval/comparison-report.js +316 -0
- package/dist/eval/comparison-report.js.map +1 -0
- package/dist/eval/fixture.d.ts +74 -0
- package/dist/eval/fixture.d.ts.map +1 -0
- package/dist/eval/fixture.js +217 -0
- package/dist/eval/fixture.js.map +1 -0
- package/dist/eval/index.d.ts +13 -0
- package/dist/eval/index.d.ts.map +1 -0
- package/dist/eval/index.js +7 -0
- package/dist/eval/index.js.map +1 -0
- package/dist/eval/load-node.d.ts +16 -0
- package/dist/eval/load-node.d.ts.map +1 -0
- package/dist/eval/load-node.js +58 -0
- package/dist/eval/load-node.js.map +1 -0
- package/dist/eval/metric-collector.d.ts +209 -0
- package/dist/eval/metric-collector.d.ts.map +1 -0
- package/dist/eval/metric-collector.js +293 -0
- package/dist/eval/metric-collector.js.map +1 -0
- package/dist/eval/run-record.d.ts +76 -0
- package/dist/eval/run-record.d.ts.map +1 -0
- package/dist/eval/run-record.js +32 -0
- package/dist/eval/run-record.js.map +1 -0
- package/dist/eval/runner.d.ts +140 -0
- package/dist/eval/runner.d.ts.map +1 -0
- package/dist/eval/runner.js +310 -0
- package/dist/eval/runner.js.map +1 -0
- package/dist/eval/spec-framework.d.ts +113 -0
- package/dist/eval/spec-framework.d.ts.map +1 -0
- package/dist/eval/spec-framework.js +100 -0
- package/dist/eval/spec-framework.js.map +1 -0
- package/dist/eval/spec-helpers.d.ts +245 -0
- package/dist/eval/spec-helpers.d.ts.map +1 -0
- package/dist/eval/spec-helpers.js +605 -0
- package/dist/eval/spec-helpers.js.map +1 -0
- package/dist/events/codec.d.ts +79 -0
- package/dist/events/codec.d.ts.map +1 -0
- package/dist/events/codec.js +142 -0
- package/dist/events/codec.js.map +1 -0
- package/dist/events/log-core.d.ts +76 -0
- package/dist/events/log-core.d.ts.map +1 -0
- package/dist/events/log-core.js +73 -0
- package/dist/events/log-core.js.map +1 -0
- package/dist/events/log.d.ts +60 -0
- package/dist/events/log.d.ts.map +1 -0
- package/dist/events/log.js +193 -0
- package/dist/events/log.js.map +1 -0
- package/dist/events/replay.d.ts +106 -0
- package/dist/events/replay.d.ts.map +1 -0
- package/dist/events/replay.js +137 -0
- package/dist/events/replay.js.map +1 -0
- package/dist/events/wrap.d.ts +100 -0
- package/dist/events/wrap.d.ts.map +1 -0
- package/dist/events/wrap.js +141 -0
- package/dist/events/wrap.js.map +1 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/llm-adapter.d.ts +96 -0
- package/dist/llm-adapter.d.ts.map +1 -0
- package/dist/llm-adapter.js +132 -0
- package/dist/llm-adapter.js.map +1 -0
- package/dist/mcp/serve.d.ts +70 -0
- package/dist/mcp/serve.d.ts.map +1 -0
- package/dist/mcp/serve.js +154 -0
- package/dist/mcp/serve.js.map +1 -0
- package/dist/metrics/runs.d.ts +58 -0
- package/dist/metrics/runs.d.ts.map +1 -0
- package/dist/metrics/runs.js +99 -0
- package/dist/metrics/runs.js.map +1 -0
- package/dist/metrics.d.ts +38 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +123 -0
- package/dist/metrics.js.map +1 -0
- package/dist/node.d.ts +23 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +23 -0
- package/dist/node.js.map +1 -0
- package/dist/planner-executor.d.ts +132 -0
- package/dist/planner-executor.d.ts.map +1 -0
- package/dist/planner-executor.js +274 -0
- package/dist/planner-executor.js.map +1 -0
- package/dist/session.d.ts +10 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +179 -0
- package/dist/session.js.map +1 -0
- package/dist/skill-catalog.d.ts +81 -0
- package/dist/skill-catalog.d.ts.map +1 -0
- package/dist/skill-catalog.js +388 -0
- package/dist/skill-catalog.js.map +1 -0
- package/dist/skill-router.d.ts +95 -0
- package/dist/skill-router.d.ts.map +1 -0
- package/dist/skill-router.js +130 -0
- package/dist/skill-router.js.map +1 -0
- package/dist/storage.d.ts +14 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +58 -0
- package/dist/storage.js.map +1 -0
- package/dist/strategy.d.ts +45 -0
- package/dist/strategy.d.ts.map +1 -0
- package/dist/strategy.js +520 -0
- package/dist/strategy.js.map +1 -0
- package/dist/tools.d.ts +40 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +147 -0
- package/dist/tools.js.map +1 -0
- package/dist/types/agent.d.ts +94 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +17 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/capabilities.d.ts +17 -0
- package/dist/types/capabilities.d.ts.map +1 -0
- package/dist/types/capabilities.js +13 -0
- package/dist/types/capabilities.js.map +1 -0
- package/dist/types/chat.d.ts +74 -0
- package/dist/types/chat.d.ts.map +1 -0
- package/dist/types/chat.js +10 -0
- package/dist/types/chat.js.map +1 -0
- package/dist/types/events.d.ts +115 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +30 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/llm.d.ts +89 -0
- package/dist/types/llm.d.ts.map +1 -0
- package/dist/types/llm.js +12 -0
- package/dist/types/llm.js.map +1 -0
- package/dist/types/metrics.d.ts +34 -0
- package/dist/types/metrics.d.ts.map +1 -0
- package/dist/types/metrics.js +10 -0
- package/dist/types/metrics.js.map +1 -0
- package/dist/types/observer.d.ts +41 -0
- package/dist/types/observer.d.ts.map +1 -0
- package/dist/types/observer.js +41 -0
- package/dist/types/observer.js.map +1 -0
- package/dist/types/project-context.d.ts +18 -0
- package/dist/types/project-context.d.ts.map +1 -0
- package/dist/types/project-context.js +11 -0
- package/dist/types/project-context.js.map +1 -0
- package/dist/types/runtime.d.ts +71 -0
- package/dist/types/runtime.d.ts.map +1 -0
- package/dist/types/runtime.js +21 -0
- package/dist/types/runtime.js.map +1 -0
- package/dist/types/session.d.ts +103 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +11 -0
- package/dist/types/session.js.map +1 -0
- package/dist/types/storage.d.ts +20 -0
- package/dist/types/storage.d.ts.map +1 -0
- package/dist/types/storage.js +41 -0
- package/dist/types/storage.js.map +1 -0
- package/dist/types/strategy.d.ts +124 -0
- package/dist/types/strategy.d.ts.map +1 -0
- package/dist/types/strategy.js +10 -0
- package/dist/types/strategy.js.map +1 -0
- package/dist/types/tools.d.ts +154 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +11 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/types/trace.d.ts +175 -0
- package/dist/types/trace.d.ts.map +1 -0
- package/dist/types/trace.js +26 -0
- package/dist/types/trace.js.map +1 -0
- package/dist/types/workspace.d.ts +29 -0
- package/dist/types/workspace.d.ts.map +1 -0
- package/dist/types/workspace.js +18 -0
- package/dist/types/workspace.js.map +1 -0
- package/package.json +45 -14
- package/skills/agent-cli.md +218 -0
- package/index.js +0 -2
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `replayEvents()` — forward replay of a project's event log against a
|
|
3
|
+
* caller-supplied `ToolDispatch`.
|
|
4
|
+
*
|
|
5
|
+
* Pair to `wrapMutating()` + `agent undo`:
|
|
6
|
+
* - `wrapMutating` writes structured events as a side effect of
|
|
7
|
+
* running tools.
|
|
8
|
+
* - `undoCommand` walks the log backwards (commit → rollback) to
|
|
9
|
+
* reverse a single mutation.
|
|
10
|
+
* - `replayEvents()` walks the log forwards (`commit` events in id
|
|
11
|
+
* order) and re-dispatches each tool with its recorded args, so
|
|
12
|
+
* the same mutations can be re-applied to a *different* dispatch
|
|
13
|
+
* (typical case: dev simulator → production registry).
|
|
14
|
+
*
|
|
15
|
+
* Idempotency:
|
|
16
|
+
* - Each successfully-applied event gets a `migrate_applied` marker
|
|
17
|
+
* event written back to the same log (or a separate target log
|
|
18
|
+
* when `targetLog` is provided). Re-running `replayEvents()` skips
|
|
19
|
+
* events whose marker is already present, so partial-failure +
|
|
20
|
+
* retry is safe.
|
|
21
|
+
* - The caller can additionally provide `shouldApply` to gate
|
|
22
|
+
* events. The callback fires for every event (it is NOT a
|
|
23
|
+
* conflict-only hook); the caller is responsible for whatever
|
|
24
|
+
* state-read or business logic decides apply / skip / abort.
|
|
25
|
+
*
|
|
26
|
+
* Boundaries:
|
|
27
|
+
* - This function calls `dispatch.execute()`. It is therefore
|
|
28
|
+
* *not* CLI-safe — it expects a real dispatch wired to real
|
|
29
|
+
* services. The `agent migrate` subcommand only PLANS replay; the
|
|
30
|
+
* host runs `replayEvents()` against its prod dispatch.
|
|
31
|
+
* - **The dispatch handlers MUST be unwrapped.** If you re-apply
|
|
32
|
+
* `wrapMutating()` at replay time, each replayed event spawns a
|
|
33
|
+
* fresh plan/commit pair on the target log — and a subsequent
|
|
34
|
+
* replay run would try to re-replay those. Wrap on the system
|
|
35
|
+
* that PRODUCES the log; do not wrap on the system that CONSUMES
|
|
36
|
+
* it via replay.
|
|
37
|
+
*/
|
|
38
|
+
import type { MutationEvent } from '../types/events.js';
|
|
39
|
+
import type { ToolContext, ToolDispatch, ToolResult } from '../types/tools.js';
|
|
40
|
+
import type { EventLog } from './log-core.js';
|
|
41
|
+
export interface ReplayOptions {
|
|
42
|
+
/** Source log to read commits from. */
|
|
43
|
+
log: EventLog;
|
|
44
|
+
/** Dispatch to invoke each replayed tool against.
|
|
45
|
+
* **MUST register unwrapped handlers** — see file header. */
|
|
46
|
+
dispatch: ToolDispatch;
|
|
47
|
+
/** Factory producing a fresh `ToolContext` per dispatch call. */
|
|
48
|
+
toolContext(): ToolContext;
|
|
49
|
+
/** Replay only events with id >= this id (inclusive). Lexically
|
|
50
|
+
* compared — works because event ids are time-prefixed base36. */
|
|
51
|
+
sinceEventId?: string;
|
|
52
|
+
/** Restrict to these tool names. Unset → replay every commit. */
|
|
53
|
+
toolAllowlist?: readonly string[];
|
|
54
|
+
/** Skip events whose `target.path` matches any of these. */
|
|
55
|
+
pathDenyList?: readonly string[];
|
|
56
|
+
/**
|
|
57
|
+
* Per-event resolver. Fires for every event *after* it passes the
|
|
58
|
+
* tool / path / already-applied filters. Use it to read target
|
|
59
|
+
* state and decide apply / skip / abort — replayEvents itself does
|
|
60
|
+
* not read target state. Default: 'apply' for all events.
|
|
61
|
+
*
|
|
62
|
+
* Renamed from the previous `onConflict` to better reflect what it
|
|
63
|
+
* actually does (it is not a conflict-only hook).
|
|
64
|
+
*/
|
|
65
|
+
shouldApply?: (event: MutationEvent) => 'apply' | 'skip' | 'abort';
|
|
66
|
+
/** When true: emit `plan` progress events but do NOT call dispatch.
|
|
67
|
+
* No `migrate_applied` markers are written. */
|
|
68
|
+
dryRun?: boolean;
|
|
69
|
+
/** Optional separate log to write the `migrate_applied` markers
|
|
70
|
+
* into. Defaults to the source log. Useful when the prod
|
|
71
|
+
* environment maintains its own event log. */
|
|
72
|
+
targetLog?: EventLog;
|
|
73
|
+
/** Agent identifier stamped on the `migrate_applied` markers.
|
|
74
|
+
* Defaults to 'replay'. */
|
|
75
|
+
agent?: string;
|
|
76
|
+
/** Session id stamped on markers. Defaults to a synthesized id. */
|
|
77
|
+
sessionId?: string;
|
|
78
|
+
}
|
|
79
|
+
export type ReplayProgress = {
|
|
80
|
+
type: 'plan';
|
|
81
|
+
event: MutationEvent;
|
|
82
|
+
} | {
|
|
83
|
+
type: 'applied';
|
|
84
|
+
event: MutationEvent;
|
|
85
|
+
markerId: string;
|
|
86
|
+
result: ToolResult;
|
|
87
|
+
} | {
|
|
88
|
+
type: 'skipped';
|
|
89
|
+
event: MutationEvent;
|
|
90
|
+
reason: 'already_applied' | 'tool_denied' | 'path_denied' | 'shouldapply_skip';
|
|
91
|
+
} | {
|
|
92
|
+
type: 'error';
|
|
93
|
+
event: MutationEvent;
|
|
94
|
+
message: string;
|
|
95
|
+
} | {
|
|
96
|
+
type: 'done';
|
|
97
|
+
total: number;
|
|
98
|
+
applied: number;
|
|
99
|
+
skipped: number;
|
|
100
|
+
errors: number;
|
|
101
|
+
};
|
|
102
|
+
export declare class ReplayInvariantError extends Error {
|
|
103
|
+
readonly name = "ReplayInvariantError";
|
|
104
|
+
}
|
|
105
|
+
export declare function replayEvents(opts: ReplayOptions): AsyncIterable<ReplayProgress>;
|
|
106
|
+
//# sourceMappingURL=replay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/events/replay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,GAAG,EAAE,QAAQ,CAAC;IACd;kEAC8D;IAC9D,QAAQ,EAAE,YAAY,CAAC;IACvB,iEAAiE;IACjE,WAAW,IAAI,WAAW,CAAC;IAC3B;uEACmE;IACnE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iEAAiE;IACjE,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,4DAA4D;IAC5D,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;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
|
4
|
+
*
|
|
5
|
+
* Pair to `wrapMutating()` + `agent undo`:
|
|
6
|
+
* - `wrapMutating` writes structured events as a side effect of
|
|
7
|
+
* running tools.
|
|
8
|
+
* - `undoCommand` walks the log backwards (commit → rollback) to
|
|
9
|
+
* reverse a single mutation.
|
|
10
|
+
* - `replayEvents()` walks the log forwards (`commit` events in id
|
|
11
|
+
* order) and re-dispatches each tool with its recorded args, so
|
|
12
|
+
* the same mutations can be re-applied to a *different* dispatch
|
|
13
|
+
* (typical case: dev simulator → production registry).
|
|
14
|
+
*
|
|
15
|
+
* Idempotency:
|
|
16
|
+
* - Each successfully-applied event gets a `migrate_applied` marker
|
|
17
|
+
* event written back to the same log (or a separate target log
|
|
18
|
+
* when `targetLog` is provided). Re-running `replayEvents()` skips
|
|
19
|
+
* events whose marker is already present, so partial-failure +
|
|
20
|
+
* retry is safe.
|
|
21
|
+
* - The caller can additionally provide `shouldApply` to gate
|
|
22
|
+
* events. The callback fires for every event (it is NOT a
|
|
23
|
+
* conflict-only hook); the caller is responsible for whatever
|
|
24
|
+
* state-read or business logic decides apply / skip / abort.
|
|
25
|
+
*
|
|
26
|
+
* Boundaries:
|
|
27
|
+
* - This function calls `dispatch.execute()`. It is therefore
|
|
28
|
+
* *not* CLI-safe — it expects a real dispatch wired to real
|
|
29
|
+
* services. The `agent migrate` subcommand only PLANS replay; the
|
|
30
|
+
* host runs `replayEvents()` against its prod dispatch.
|
|
31
|
+
* - **The dispatch handlers MUST be unwrapped.** If you re-apply
|
|
32
|
+
* `wrapMutating()` at replay time, each replayed event spawns a
|
|
33
|
+
* fresh plan/commit pair on the target log — and a subsequent
|
|
34
|
+
* replay run would try to re-replay those. Wrap on the system
|
|
35
|
+
* that PRODUCES the log; do not wrap on the system that CONSUMES
|
|
36
|
+
* it via replay.
|
|
37
|
+
*/
|
|
38
|
+
const APPLIED_MARKER_TYPE = 'migrate_applied';
|
|
39
|
+
export class ReplayInvariantError extends Error {
|
|
40
|
+
name = 'ReplayInvariantError';
|
|
41
|
+
}
|
|
42
|
+
export async function* replayEvents(opts) {
|
|
43
|
+
const targetLog = opts.targetLog ?? opts.log;
|
|
44
|
+
const agent = opts.agent ?? 'replay';
|
|
45
|
+
const sessionId = opts.sessionId ?? `replay-${Date.now().toString(36)}`;
|
|
46
|
+
const toolAllow = opts.toolAllowlist ? new Set(opts.toolAllowlist) : null;
|
|
47
|
+
const pathDeny = opts.pathDenyList ? new Set(opts.pathDenyList) : null;
|
|
48
|
+
const applied = opts.dryRun ? new Set() : targetLog.appliedEventIds();
|
|
49
|
+
const all = opts.log
|
|
50
|
+
.read({ phase: 'commit' })
|
|
51
|
+
// Markers written by a prior `replayEvents()` run are themselves
|
|
52
|
+
// commit-phase events — exclude them so re-runs don't try to
|
|
53
|
+
// replay bookkeeping rows.
|
|
54
|
+
.filter((e) => e.metadata?.type !== APPLIED_MARKER_TYPE);
|
|
55
|
+
// Stable in-emission-order (event ids are lexically sortable by ts prefix).
|
|
56
|
+
all.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
57
|
+
let total = 0;
|
|
58
|
+
let appliedCount = 0;
|
|
59
|
+
let skippedCount = 0;
|
|
60
|
+
let errorCount = 0;
|
|
61
|
+
for (const event of all) {
|
|
62
|
+
if (opts.sinceEventId && event.id < opts.sinceEventId)
|
|
63
|
+
continue;
|
|
64
|
+
total += 1;
|
|
65
|
+
if (toolAllow && !toolAllow.has(event.tool)) {
|
|
66
|
+
yield { type: 'skipped', event, reason: 'tool_denied' };
|
|
67
|
+
skippedCount += 1;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (pathDeny && pathDeny.has(event.target.path)) {
|
|
71
|
+
yield { type: 'skipped', event, reason: 'path_denied' };
|
|
72
|
+
skippedCount += 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (event.args === undefined) {
|
|
76
|
+
// Every commit event written by wrapMutating carries args. An
|
|
77
|
+
// event without args is either a bookkeeping marker (caught
|
|
78
|
+
// above) or a manually-appended commit that didn't follow the
|
|
79
|
+
// protocol — fail loudly rather than silently skipping.
|
|
80
|
+
throw new ReplayInvariantError(`event ${event.id} has phase=commit and target.kind=${event.target.kind} but no args. ` +
|
|
81
|
+
`Commit events emitted by wrapMutating always carry args. ` +
|
|
82
|
+
`If you're appending commits manually, include args. ` +
|
|
83
|
+
`Reading log: ${opts.log.path}`);
|
|
84
|
+
}
|
|
85
|
+
if (!opts.dryRun && applied.has(event.id)) {
|
|
86
|
+
yield { type: 'skipped', event, reason: 'already_applied' };
|
|
87
|
+
skippedCount += 1;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (opts.dryRun) {
|
|
91
|
+
yield { type: 'plan', event };
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const decision = opts.shouldApply ? opts.shouldApply(event) : 'apply';
|
|
95
|
+
if (decision === 'abort') {
|
|
96
|
+
yield { type: 'error', event, message: 'shouldApply returned abort' };
|
|
97
|
+
errorCount += 1;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (decision === 'skip') {
|
|
101
|
+
yield { type: 'skipped', event, reason: 'shouldapply_skip' };
|
|
102
|
+
skippedCount += 1;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const result = await opts.dispatch.execute({ id: `replay-${event.id}`, name: event.tool, args: event.args }, opts.toolContext());
|
|
107
|
+
if (!result.ok) {
|
|
108
|
+
yield { type: 'error', event, message: result.summary };
|
|
109
|
+
errorCount += 1;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const marker = targetLog.append({
|
|
113
|
+
agent,
|
|
114
|
+
sessionId,
|
|
115
|
+
tool: event.tool,
|
|
116
|
+
phase: 'commit',
|
|
117
|
+
target: { kind: 'other', path: `replay/${event.id}` },
|
|
118
|
+
reversible: false,
|
|
119
|
+
irreversibleReason: 'migrate_applied markers are bookkeeping, not state changes',
|
|
120
|
+
metadata: {
|
|
121
|
+
type: APPLIED_MARKER_TYPE,
|
|
122
|
+
appliedEventId: event.id,
|
|
123
|
+
originalTool: event.tool,
|
|
124
|
+
originalTarget: event.target,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
yield { type: 'applied', event, markerId: marker.id, result };
|
|
128
|
+
appliedCount += 1;
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
yield { type: 'error', event, message: err instanceof Error ? err.message : String(err) };
|
|
132
|
+
errorCount += 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
yield { type: 'done', total, applied: appliedCount, skipped: skippedCount, errors: errorCount };
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=replay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.js","sourceRoot":"","sources":["../../src/events/replay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAwDH,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAE9C,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC3B,IAAI,GAAG,sBAAsB,CAAC;CACjD;AAED,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,YAAY,CAAC,IAAmB;IACrD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC;IACrC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,UAAU,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IACxE,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1E,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC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,QAAQ,EAAE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC;YAC9D,YAAY,IAAI,CAAC,CAAC;QACpB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1F,UAAU,IAAI,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wrapMutating()` — decorate a `ToolHandler` so every invocation emits
|
|
3
|
+
* plan + commit (or plan + rollback) events to a project's event log.
|
|
4
|
+
*
|
|
5
|
+
* Each wrapped handler is still a regular `ToolHandler` — it can be
|
|
6
|
+
* registered in any `ToolRegistry` and dispatched normally. The
|
|
7
|
+
* wrapping is invisible to the strategy / session.
|
|
8
|
+
*
|
|
9
|
+
* ## CRITICAL INVARIANT: wrap on the producer, NOT on the consumer
|
|
10
|
+
*
|
|
11
|
+
* Wrap your handlers on the system that PRODUCES the log (the dev
|
|
12
|
+
* environment, the agent session generating mutations). Do NOT wrap
|
|
13
|
+
* the handlers on the system that CONSUMES the log via
|
|
14
|
+
* `replayEvents()`. If you do:
|
|
15
|
+
*
|
|
16
|
+
* 1. Each replayed event spawns its own plan/commit pair on the
|
|
17
|
+
* target log (not just a `migrate_applied` marker).
|
|
18
|
+
* 2. A subsequent replay run sees those new commits and tries to
|
|
19
|
+
* re-replay them — loop possible.
|
|
20
|
+
*
|
|
21
|
+
* In code: dev registers `wrapMutating(setDoc, {...})`. Prod
|
|
22
|
+
* registers the BARE `setDoc` (no wrap). `replayEvents` dispatches
|
|
23
|
+
* dev's log against prod's bare registry. Markers go to the log;
|
|
24
|
+
* mutations go to prod state. Auditable from either side.
|
|
25
|
+
*
|
|
26
|
+
* Use `isWrappedHandler(handler)` to assert: a defensive check
|
|
27
|
+
* before dispatching unknown registries through replay.
|
|
28
|
+
*
|
|
29
|
+
* ## Pattern
|
|
30
|
+
*
|
|
31
|
+
* const wrapped = wrapMutating(writeRulesHandler, {
|
|
32
|
+
* log,
|
|
33
|
+
* sessionId: 'sess-1',
|
|
34
|
+
* target: (args) => ({ kind: 'workspace', path: 'workspace.rules' }),
|
|
35
|
+
* snapshot: async (_args, ctx) => ctx.workspace.rules,
|
|
36
|
+
* reverseOp: (args, _result) => ({
|
|
37
|
+
* tool: 'writeRules',
|
|
38
|
+
* args: { source: args.previousSource },
|
|
39
|
+
* }),
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* ## Failure semantics
|
|
43
|
+
*
|
|
44
|
+
* - Handler throws / promise rejects → emit rollback event with
|
|
45
|
+
* `reason: 'failure'`, re-throw. The strategy / dispatcher sees
|
|
46
|
+
* the error normally.
|
|
47
|
+
* - Handler returns `{ ok: false }` → still emit commit (the
|
|
48
|
+
* mutation didn't happen, but the *intent* was reached and the
|
|
49
|
+
* audit log should show the attempt + result). Most external API
|
|
50
|
+
* handlers follow this pattern.
|
|
51
|
+
*/
|
|
52
|
+
import type { MutationTarget, ReverseOp } from '../types/events.js';
|
|
53
|
+
import type { ToolContext, ToolHandler, ToolResult } from '../types/tools.js';
|
|
54
|
+
import { type EventLog } from './log-core.js';
|
|
55
|
+
export interface WrapMutatingOptions<A, D> {
|
|
56
|
+
/** Where to append events. */
|
|
57
|
+
log: EventLog;
|
|
58
|
+
/** Session id used on every event. Same id as the active AgentSession. */
|
|
59
|
+
sessionId: string;
|
|
60
|
+
/** Naming the agent that's invoking this tool. Default: `'host'`. */
|
|
61
|
+
agent?: string;
|
|
62
|
+
/** Compute the `target` field from the handler's args. Called for
|
|
63
|
+
* both the plan and commit events. */
|
|
64
|
+
target: (args: A, ctx: ToolContext) => MutationTarget;
|
|
65
|
+
/** Optional snapshot of the *before* state. Called once, before
|
|
66
|
+
* execute. Returned value lands on the plan event AND the commit
|
|
67
|
+
* event so an auditor can diff. */
|
|
68
|
+
snapshot?: (args: A, ctx: ToolContext) => Promise<unknown> | unknown;
|
|
69
|
+
/** Compute the reverse operation. Called after a successful execute.
|
|
70
|
+
* Receives the `before` value `opts.snapshot` returned (or `undefined`
|
|
71
|
+
* when no snapshot was configured) so the reverse can restore the
|
|
72
|
+
* exact pre-mutation state. Return `null` (or omit the option) for
|
|
73
|
+
* irreversible mutations — the commit event then carries
|
|
74
|
+
* `reversible: false`. */
|
|
75
|
+
reverseOp?: (args: A, result: ToolResult<D>, ctx: ToolContext, before: unknown) => ReverseOp | null;
|
|
76
|
+
/** When `reverseOp` is omitted entirely (not just returning null on
|
|
77
|
+
* a given call), default to false. Set to true for handlers that
|
|
78
|
+
* *could* be reversible but don't need to declare the reverse op
|
|
79
|
+
* ahead of time (rare). */
|
|
80
|
+
reversibleByDefault?: boolean;
|
|
81
|
+
/** When the mutation is irreversible, why. Surfaced to `agent undo`. */
|
|
82
|
+
irreversibleReason?: string;
|
|
83
|
+
/** Optional static metadata stamped on every event from this tool. */
|
|
84
|
+
metadata?: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Non-enumerable marker added to every `wrapMutating()` output.
|
|
88
|
+
* Used by `isWrappedHandler` to assert "this handler is NOT what
|
|
89
|
+
* you want in a prod replay target."
|
|
90
|
+
*/
|
|
91
|
+
export declare const WRAPPED_MARKER: unique symbol;
|
|
92
|
+
/**
|
|
93
|
+
* Returns true when `handler` was produced by `wrapMutating()`.
|
|
94
|
+
* Use this in your replay target's setup to assert that no handler
|
|
95
|
+
* is wrapped — wrapped handlers in a replay target spawn runaway
|
|
96
|
+
* plan/commit cascades. See `wrapMutating`'s header.
|
|
97
|
+
*/
|
|
98
|
+
export declare function isWrappedHandler(handler: ToolHandler): boolean;
|
|
99
|
+
export declare function wrapMutating<A = unknown, D = unknown>(handler: ToolHandler<A, D>, opts: WrapMutatingOptions<A, D>): ToolHandler<A, D>;
|
|
100
|
+
//# sourceMappingURL=wrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../src/events/wrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,KAAK,EAAiB,cAAc,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,KAAK,QAAQ,EAAqC,MAAM,eAAe,CAAC;AAEjF,MAAM,WAAW,mBAAmB,CAAC,CAAC,EAAE,CAAC;IACvC,8BAA8B;IAC9B,GAAG,EAAE,QAAQ,CAAC;IACd,0EAA0E;IAC1E,SAAS,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;2CACuC;IACvC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,WAAW,KAAK,cAAc,CAAC;IACtD;;wCAEoC;IACpC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACrE;;;;;+BAK2B;IAC3B,SAAS,CAAC,EAAE,CACV,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,OAAO,KACZ,SAAS,GAAG,IAAI,CAAC;IACtB;;;gCAG4B;IAC5B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,wEAAwE;IACxE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,MAAoD,CAAC;AAEzF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAE9D;AAED,wBAAgB,YAAY,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EACnD,OAAO,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,IAAI,EAAE,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,GAC9B,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CA+EnB"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wrapMutating()` — decorate a `ToolHandler` so every invocation emits
|
|
3
|
+
* plan + commit (or plan + rollback) events to a project's event log.
|
|
4
|
+
*
|
|
5
|
+
* Each wrapped handler is still a regular `ToolHandler` — it can be
|
|
6
|
+
* registered in any `ToolRegistry` and dispatched normally. The
|
|
7
|
+
* wrapping is invisible to the strategy / session.
|
|
8
|
+
*
|
|
9
|
+
* ## CRITICAL INVARIANT: wrap on the producer, NOT on the consumer
|
|
10
|
+
*
|
|
11
|
+
* Wrap your handlers on the system that PRODUCES the log (the dev
|
|
12
|
+
* environment, the agent session generating mutations). Do NOT wrap
|
|
13
|
+
* the handlers on the system that CONSUMES the log via
|
|
14
|
+
* `replayEvents()`. If you do:
|
|
15
|
+
*
|
|
16
|
+
* 1. Each replayed event spawns its own plan/commit pair on the
|
|
17
|
+
* target log (not just a `migrate_applied` marker).
|
|
18
|
+
* 2. A subsequent replay run sees those new commits and tries to
|
|
19
|
+
* re-replay them — loop possible.
|
|
20
|
+
*
|
|
21
|
+
* In code: dev registers `wrapMutating(setDoc, {...})`. Prod
|
|
22
|
+
* registers the BARE `setDoc` (no wrap). `replayEvents` dispatches
|
|
23
|
+
* dev's log against prod's bare registry. Markers go to the log;
|
|
24
|
+
* mutations go to prod state. Auditable from either side.
|
|
25
|
+
*
|
|
26
|
+
* Use `isWrappedHandler(handler)` to assert: a defensive check
|
|
27
|
+
* before dispatching unknown registries through replay.
|
|
28
|
+
*
|
|
29
|
+
* ## Pattern
|
|
30
|
+
*
|
|
31
|
+
* const wrapped = wrapMutating(writeRulesHandler, {
|
|
32
|
+
* log,
|
|
33
|
+
* sessionId: 'sess-1',
|
|
34
|
+
* target: (args) => ({ kind: 'workspace', path: 'workspace.rules' }),
|
|
35
|
+
* snapshot: async (_args, ctx) => ctx.workspace.rules,
|
|
36
|
+
* reverseOp: (args, _result) => ({
|
|
37
|
+
* tool: 'writeRules',
|
|
38
|
+
* args: { source: args.previousSource },
|
|
39
|
+
* }),
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* ## Failure semantics
|
|
43
|
+
*
|
|
44
|
+
* - Handler throws / promise rejects → emit rollback event with
|
|
45
|
+
* `reason: 'failure'`, re-throw. The strategy / dispatcher sees
|
|
46
|
+
* the error normally.
|
|
47
|
+
* - Handler returns `{ ok: false }` → still emit commit (the
|
|
48
|
+
* mutation didn't happen, but the *intent* was reached and the
|
|
49
|
+
* audit log should show the attempt + result). Most external API
|
|
50
|
+
* handlers follow this pattern.
|
|
51
|
+
*/
|
|
52
|
+
import { HOST_AGENT_ID, buildRollbackEvent } from './log-core.js';
|
|
53
|
+
/**
|
|
54
|
+
* Non-enumerable marker added to every `wrapMutating()` output.
|
|
55
|
+
* Used by `isWrappedHandler` to assert "this handler is NOT what
|
|
56
|
+
* you want in a prod replay target."
|
|
57
|
+
*/
|
|
58
|
+
export const WRAPPED_MARKER = Symbol.for('@inbrowser/agent/wrapMutating');
|
|
59
|
+
/**
|
|
60
|
+
* Returns true when `handler` was produced by `wrapMutating()`.
|
|
61
|
+
* Use this in your replay target's setup to assert that no handler
|
|
62
|
+
* is wrapped — wrapped handlers in a replay target spawn runaway
|
|
63
|
+
* plan/commit cascades. See `wrapMutating`'s header.
|
|
64
|
+
*/
|
|
65
|
+
export function isWrappedHandler(handler) {
|
|
66
|
+
return handler[WRAPPED_MARKER] === true;
|
|
67
|
+
}
|
|
68
|
+
export function wrapMutating(handler, opts) {
|
|
69
|
+
const agent = opts.agent ?? HOST_AGENT_ID;
|
|
70
|
+
const wrapped = {
|
|
71
|
+
name: handler.name,
|
|
72
|
+
description: handler.description,
|
|
73
|
+
parameters: handler.parameters,
|
|
74
|
+
...(handler.available ? { available: handler.available } : {}),
|
|
75
|
+
async execute(args, ctx) {
|
|
76
|
+
const target = opts.target(args, ctx);
|
|
77
|
+
const before = opts.snapshot ? await opts.snapshot(args, ctx) : undefined;
|
|
78
|
+
const planEvent = opts.log.append({
|
|
79
|
+
agent,
|
|
80
|
+
sessionId: opts.sessionId,
|
|
81
|
+
tool: handler.name,
|
|
82
|
+
args,
|
|
83
|
+
phase: 'plan',
|
|
84
|
+
target,
|
|
85
|
+
...(before !== undefined ? { before } : {}),
|
|
86
|
+
reversible: opts.reversibleByDefault ?? !!opts.reverseOp,
|
|
87
|
+
...(opts.irreversibleReason ? { irreversibleReason: opts.irreversibleReason } : {}),
|
|
88
|
+
...(opts.metadata ? { metadata: opts.metadata } : {}),
|
|
89
|
+
});
|
|
90
|
+
void planEvent;
|
|
91
|
+
let result;
|
|
92
|
+
try {
|
|
93
|
+
result = await handler.execute(args, ctx);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
opts.log.append(buildRollbackEvent({
|
|
97
|
+
original: planEvent,
|
|
98
|
+
reason: 'failure',
|
|
99
|
+
agent,
|
|
100
|
+
sessionId: opts.sessionId,
|
|
101
|
+
}));
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
104
|
+
const reverseOp = opts.reverseOp ? opts.reverseOp(args, result, ctx, before) : null;
|
|
105
|
+
opts.log.append({
|
|
106
|
+
agent,
|
|
107
|
+
sessionId: opts.sessionId,
|
|
108
|
+
tool: handler.name,
|
|
109
|
+
args,
|
|
110
|
+
phase: 'commit',
|
|
111
|
+
target,
|
|
112
|
+
...(before !== undefined ? { before } : {}),
|
|
113
|
+
after: result.data,
|
|
114
|
+
reversible: !!reverseOp,
|
|
115
|
+
...(reverseOp ? { reverseOp } : {}),
|
|
116
|
+
...(reverseOp
|
|
117
|
+
? {}
|
|
118
|
+
: opts.irreversibleReason
|
|
119
|
+
? { irreversibleReason: opts.irreversibleReason }
|
|
120
|
+
: {}),
|
|
121
|
+
metadata: {
|
|
122
|
+
...(opts.metadata ?? {}),
|
|
123
|
+
planEventId: planEvent.id,
|
|
124
|
+
ok: result.ok,
|
|
125
|
+
...(result.summary ? { summary: result.summary } : {}),
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
return result;
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
// Stamp the wrapped marker as a non-enumerable property so it
|
|
132
|
+
// doesn't leak into JSON serialization (e.g. inside tool decls).
|
|
133
|
+
Object.defineProperty(wrapped, WRAPPED_MARKER, {
|
|
134
|
+
value: true,
|
|
135
|
+
enumerable: false,
|
|
136
|
+
writable: false,
|
|
137
|
+
configurable: false,
|
|
138
|
+
});
|
|
139
|
+
return wrapped;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=wrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap.js","sourceRoot":"","sources":["../../src/events/wrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAIH,OAAO,EAAiB,aAAa,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAuCjF;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAkB,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAEzF;;;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C,SAAS;oBACX,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC,IAAI,CAAC,kBAAkB;wBACvB,CAAC,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,EAAE;wBACjD,CAAC,CAAC,EAAE,CAAC;gBACT,QAAQ,EAAE;oBACR,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;oBACxB,WAAW,EAAE,SAAS,CAAC,EAAE;oBACzB,EAAE,EAAE,MAAM,CAAC,EAAE;oBACb,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACvD;aACF,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;IACF,8DAA8D;IAC9D,iEAAiE;IACjE,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE;QAC7C,KAAK,EAAE,IAAI;QACX,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@inbrowser/agent` — agent runtime + agent-friendly CLI.
|
|
3
|
+
*
|
|
4
|
+
* The library surface (this module) exports the primitives the
|
|
5
|
+
* playground UI consumes: `AgentSession`, `AgentStrategy`, `ToolRegistry`,
|
|
6
|
+
* `LlmClient`, `MetricsCollector`, `SandboxObserver`, plus the default
|
|
7
|
+
* `createReactLoopStrategy()` and `createAgentSession()`.
|
|
8
|
+
*
|
|
9
|
+
* The CLI surface lives under `@inbrowser/agent/cli` and the `agent` binary
|
|
10
|
+
* — see `src/cli/main.ts` and the package's `AGENTS.md` for invariants.
|
|
11
|
+
*
|
|
12
|
+
* No React, no DOM, no localStorage, no fetch. All I/O is via injected
|
|
13
|
+
* interfaces.
|
|
14
|
+
*/
|
|
15
|
+
export type { Workspace, StitchContext } from './types/workspace.js';
|
|
16
|
+
export { EMPTY_WORKSPACE } from './types/workspace.js';
|
|
17
|
+
export type { ProjectContext } from './types/project-context.js';
|
|
18
|
+
export type { RuntimeState, TerminalSection, TerminalEntry, RunSummary, DeployState, DeployMessage, ParseError, UiError, } from './types/runtime.js';
|
|
19
|
+
export { EMPTY_RUNTIME } from './types/runtime.js';
|
|
20
|
+
export type { ChatMessage, ChatRole, ToolCall as ChatToolCall, TurnMetrics, TurnDetails, NormalizedMessage, } from './types/chat.js';
|
|
21
|
+
export type { LlmClient, LlmClientFactory, LlmConfig, ChatRequest, ChatEvent, ToolDeclaration, JsonSchema, RawUsage, } from './types/llm.js';
|
|
22
|
+
export { legacyProviderAsLlmClient } from './llm-adapter.js';
|
|
23
|
+
export type { LegacyProvider, LegacyChatTurnResult, LegacyChatCallbacks, LegacyChatMessage, LegacyToolDecl, LegacyProviderUsage, LegacyTurnDetails, } from './llm-adapter.js';
|
|
24
|
+
export type { ToolHandler, ToolContext, ToolResult, ToolCall, ToolRegistry, ToolDispatch, SandboxHandle, LintFn, LintWarning, StitchClient, } from './types/tools.js';
|
|
25
|
+
export { createToolRegistry, createDispatch, isParallelSafe, isPure } from './tools.js';
|
|
26
|
+
export type { MemoKeyComponent, MemoOptions, MemoStats, MemoizedDispatch, } from './dispatch-memoization.js';
|
|
27
|
+
export { createMemoizedDispatch } from './dispatch-memoization.js';
|
|
28
|
+
export type { Capabilities } from './types/capabilities.js';
|
|
29
|
+
export { DEFAULT_CAPABILITIES } from './types/capabilities.js';
|
|
30
|
+
export type { AgentSession, AgentSessionConfig, SessionEvent, } from './types/session.js';
|
|
31
|
+
export { createAgentSession } from './session.js';
|
|
32
|
+
export type { AgentStrategy, ReflexionConfig, StrategyRunInput, StrategyEvent, } from './types/strategy.js';
|
|
33
|
+
export { createReactLoopStrategy } from './strategy.js';
|
|
34
|
+
export type { PlanStep, SkillCatalog, SkillCatalogEntry } from './skill-catalog.js';
|
|
35
|
+
export { SKILL_CATALOG, getSkillEntry, listSkillNames } from './skill-catalog.js';
|
|
36
|
+
export type { RouterDecision, RouterMatch, RouterOptions } from './skill-router.js';
|
|
37
|
+
export { routeSkill } from './skill-router.js';
|
|
38
|
+
export type { PlannerExecutorOptions, SkillRouter, SkillRouterDecision, SkillRouterMatch, } from './planner-executor.js';
|
|
39
|
+
export { createPlannerExecutorStrategy, defaultKeywordRouter } from './planner-executor.js';
|
|
40
|
+
export type { Tracer, TraceEvent, LlmRequestTrace, LlmResponseTrace, TurnDispatchCompleteTrace, ToolDeclarationView, } from './types/trace.js';
|
|
41
|
+
export type { TurnTimingRow } from './diagnostics/timing.js';
|
|
42
|
+
export { turnTimingTable } from './diagnostics/timing.js';
|
|
43
|
+
export type { TruthfulnessFlag, TruthfulnessFlagCategory, TruthfulnessReport, } from './diagnostics/index.js';
|
|
44
|
+
export { analyzeTruthfulness } from './diagnostics/index.js';
|
|
45
|
+
export type { PartialWorkspace, RunSnapshot, SkillName, SpecFn, SpecRegistry, SpecResult, SuccessSpecReference, TaskFixture, ValidationError, ValidationResult, } from './eval/index.js';
|
|
46
|
+
export { CUSTOM_SPEC_NAMES, SKILL_NAMES, SPEC_FINAL_RULES_EXCLUDES_LITERAL, SPEC_FINAL_RULES_INCLUDES_LITERAL, SPEC_FINAL_RUNTIME_RUN_SUMMARY_OK, SPEC_GAME_RULES_SIMULATOR_ACCEPTS_POSITIVE_AND_REJECTS_CHEAT, SPEC_PYRIC_AGENTS_LINT_CLEAN_AND_RULE_REJECTS_CHEAT, SPEC_REPORT_MENTIONS_ALL_OF, SPEC_REPORT_MENTIONS_AT_LEAST_ONE_OF, SPEC_TRACE_CONTAINS_TOOL_CALL_BY_NAME, STARTER_SPEC_NAMES, applyWorkspaceOverrides, createSpecRegistry, evaluateSpec, finalRulesExcludesLiteral, finalRulesIncludesLiteral, finalRuntimeRunSummaryOk, gameRulesSimulatorAcceptsPositiveAndRejectsCheat, parseFixture, pyricAgentsLintCleanAndRuleRejectsCheat, registerAllSpecs, registerCustomSpecs, registerStarterSpecs, reportMentionsAllOf, reportMentionsAtLeastOneOf, traceContainsToolCallByName, validateFixture, } from './eval/index.js';
|
|
47
|
+
export type { RunRecord as EvalRunRecord } from './eval/run-record.js';
|
|
48
|
+
export type { RunFixtureInput, RunFixturesDeps, RunFixturesOptions, } from './eval/runner.js';
|
|
49
|
+
export { defaultSystemPromptBuilder, runFixture, runFixtures } from './eval/runner.js';
|
|
50
|
+
export type { AggregateStat, AggregatedMetrics, CollectMetricsInput, MetricsTable, TrialMetrics, } from './eval/metric-collector.js';
|
|
51
|
+
export { aggregateTrials, collectMetrics, extractTrialMetrics, } from './eval/metric-collector.js';
|
|
52
|
+
export type { CompareMetricsInput, ComparisonFixture, ComparisonLabel, ComparisonMetricName, ComparisonReport, ComparisonRow, Polarity, } from './eval/comparison-report.js';
|
|
53
|
+
export { POLARITY, compareMetrics, renderJson, renderMarkdown, } from './eval/comparison-report.js';
|
|
54
|
+
export type { MetricsCollector, RecordTurnInput, SessionTotals, } from './types/metrics.js';
|
|
55
|
+
export { computeTurnMetrics, createMetricsCollector, findPricing, } from './metrics.js';
|
|
56
|
+
export type { Storage } from './types/storage.js';
|
|
57
|
+
export { noopStorage, createMemoryStorage } from './types/storage.js';
|
|
58
|
+
export { createLocalStorageAdapter } from './storage.js';
|
|
59
|
+
export type { ObserverEvent, SandboxObserver, } from './types/observer.js';
|
|
60
|
+
export { combineObservers, noopObserver } from './types/observer.js';
|
|
61
|
+
export type { AgentDefinition, AgentTool, AgentContext, AgentToolResult, } from './types/agent.js';
|
|
62
|
+
export type { ServeAgentsOptions, ServeAgentsHandle } from './mcp/serve.js';
|
|
63
|
+
export type { RunRecord, RunRecordFilter, RunLog, OpenRunLogOptions, } from './metrics/runs.js';
|
|
64
|
+
export type { MutationEvent, MutationEventFilter, MutationPhase, MutationTarget, ReverseOp, TargetKind, } from './types/events.js';
|
|
65
|
+
export { wrapMutating, isWrappedHandler, WRAPPED_MARKER } from './events/wrap.js';
|
|
66
|
+
export type { WrapMutatingOptions } from './events/wrap.js';
|
|
67
|
+
export { replayEvents, ReplayInvariantError } from './events/replay.js';
|
|
68
|
+
export type { ReplayOptions, ReplayProgress } from './events/replay.js';
|
|
69
|
+
export { defaultEventValueCodec, identityCodec, composeCodecs, walkValue, ENVELOPE_KEY, } from './events/codec.js';
|
|
70
|
+
export type { EventValueCodec } from './events/codec.js';
|
|
71
|
+
export type { EventLog, AppendDraft } from './events/log-core.js';
|
|
72
|
+
export type { EventLogIO, OpenEventLogOptions } from './events/log.js';
|
|
73
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,YAAY,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE,YAAY,EACV,YAAY,EACZ,eAAe,EACf,aAAa,EACb,UAAU,EACV,WAAW,EACX,aAAa,EACb,UAAU,EACV,OAAO,GACR,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,YAAY,EACV,WAAW,EACX,QAAQ,EACR,QAAQ,IAAI,YAAY,EACxB,WAAW,EACX,WAAW,EACX,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,SAAS,EACT,eAAe,EACf,UAAU,EACV,QAAQ,GACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,E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AkB,CAAC;AAClF,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACxE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,SAAS,EACT,YAAY,GACb,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAOzD,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAClE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@inbrowser/agent` — agent runtime + agent-friendly CLI.
|
|
3
|
+
*
|
|
4
|
+
* The library surface (this module) exports the primitives the
|
|
5
|
+
* playground UI consumes: `AgentSession`, `AgentStrategy`, `ToolRegistry`,
|
|
6
|
+
* `LlmClient`, `MetricsCollector`, `SandboxObserver`, plus the default
|
|
7
|
+
* `createReactLoopStrategy()` and `createAgentSession()`.
|
|
8
|
+
*
|
|
9
|
+
* The CLI surface lives under `@inbrowser/agent/cli` and the `agent` binary
|
|
10
|
+
* — see `src/cli/main.ts` and the package's `AGENTS.md` for invariants.
|
|
11
|
+
*
|
|
12
|
+
* No React, no DOM, no localStorage, no fetch. All I/O is via injected
|
|
13
|
+
* interfaces.
|
|
14
|
+
*/
|
|
15
|
+
export { EMPTY_WORKSPACE } from './types/workspace.js';
|
|
16
|
+
export { EMPTY_RUNTIME } from './types/runtime.js';
|
|
17
|
+
export { legacyProviderAsLlmClient } from './llm-adapter.js';
|
|
18
|
+
export { createToolRegistry, createDispatch, isParallelSafe, isPure } from './tools.js';
|
|
19
|
+
export { createMemoizedDispatch } from './dispatch-memoization.js';
|
|
20
|
+
export { DEFAULT_CAPABILITIES } from './types/capabilities.js';
|
|
21
|
+
export { createAgentSession } from './session.js';
|
|
22
|
+
export { createReactLoopStrategy } from './strategy.js';
|
|
23
|
+
export { SKILL_CATALOG, getSkillEntry, listSkillNames } from './skill-catalog.js';
|
|
24
|
+
export { routeSkill } from './skill-router.js';
|
|
25
|
+
export { createPlannerExecutorStrategy, defaultKeywordRouter } from './planner-executor.js';
|
|
26
|
+
export { turnTimingTable } from './diagnostics/timing.js';
|
|
27
|
+
export { analyzeTruthfulness } from './diagnostics/index.js';
|
|
28
|
+
export { CUSTOM_SPEC_NAMES, SKILL_NAMES, SPEC_FINAL_RULES_EXCLUDES_LITERAL, SPEC_FINAL_RULES_INCLUDES_LITERAL, SPEC_FINAL_RUNTIME_RUN_SUMMARY_OK, SPEC_GAME_RULES_SIMULATOR_ACCEPTS_POSITIVE_AND_REJECTS_CHEAT, SPEC_PYRIC_AGENTS_LINT_CLEAN_AND_RULE_REJECTS_CHEAT, SPEC_REPORT_MENTIONS_ALL_OF, SPEC_REPORT_MENTIONS_AT_LEAST_ONE_OF, SPEC_TRACE_CONTAINS_TOOL_CALL_BY_NAME, STARTER_SPEC_NAMES, applyWorkspaceOverrides, createSpecRegistry, evaluateSpec, finalRulesExcludesLiteral, finalRulesIncludesLiteral, finalRuntimeRunSummaryOk, gameRulesSimulatorAcceptsPositiveAndRejectsCheat, parseFixture, pyricAgentsLintCleanAndRuleRejectsCheat, registerAllSpecs, registerCustomSpecs, registerStarterSpecs, reportMentionsAllOf, reportMentionsAtLeastOneOf, traceContainsToolCallByName, validateFixture, } from './eval/index.js';
|
|
29
|
+
export { defaultSystemPromptBuilder, runFixture, runFixtures } from './eval/runner.js';
|
|
30
|
+
export { aggregateTrials, collectMetrics, extractTrialMetrics, } from './eval/metric-collector.js';
|
|
31
|
+
export { POLARITY, compareMetrics, renderJson, renderMarkdown, } from './eval/comparison-report.js';
|
|
32
|
+
export { computeTurnMetrics, createMetricsCollector, findPricing, } from './metrics.js';
|
|
33
|
+
export { noopStorage, createMemoryStorage } from './types/storage.js';
|
|
34
|
+
export { createLocalStorageAdapter } from './storage.js';
|
|
35
|
+
export { combineObservers, noopObserver } from './types/observer.js';
|
|
36
|
+
// Browser-safe events utilities — wrap, replay, codec. These live
|
|
37
|
+
// in files that don't import `node:fs` / `node:os`, so they're safe
|
|
38
|
+
// on the universal entry. Import them DIRECTLY (not via
|
|
39
|
+
// `./events/index.js`) because that barrel re-exports `./events/log.js`,
|
|
40
|
+
// which DOES pull in Node builtins.
|
|
41
|
+
//
|
|
42
|
+
// Node-only event log values (openEventLog, defaultProjectLogDir,
|
|
43
|
+
// HOST_AGENT_ID, etc.) live on `@inbrowser/agent/node` — see src/node.ts.
|
|
44
|
+
export { wrapMutating, isWrappedHandler, WRAPPED_MARKER } from './events/wrap.js';
|
|
45
|
+
export { replayEvents, ReplayInvariantError } from './events/replay.js';
|
|
46
|
+
export { defaultEventValueCodec, identityCodec, composeCodecs, walkValue, ENVELOPE_KEY, } from './events/codec.js';
|
|
47
|
+
//# sourceMappingURL=index.js.map
|