@code-yeongyu/senpi-agent-core 2026.9.12 → 2026.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/harness/agent-harness.d.ts +639 -384
- package/dist/harness/agent-harness.d.ts.map +1 -1
- package/dist/harness/agent-harness.js +5 -250
- package/dist/harness/agent-harness.js.map +1 -1
- package/dist/harness/compaction/branch-summarization.d.ts +12 -6
- package/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/harness/compaction/branch-summarization.js +33 -27
- package/dist/harness/compaction/branch-summarization.js.map +1 -1
- package/dist/harness/compaction/compaction.d.ts +30 -8
- package/dist/harness/compaction/compaction.d.ts.map +1 -1
- package/dist/harness/compaction/compaction.js +53 -64
- package/dist/harness/compaction/compaction.js.map +1 -1
- package/dist/harness/config.d.ts +9 -0
- package/dist/harness/config.d.ts.map +1 -0
- package/dist/harness/config.js +35 -0
- package/dist/harness/config.js.map +1 -0
- package/dist/harness/context.d.ts +9 -0
- package/dist/harness/context.d.ts.map +1 -0
- package/dist/harness/context.js +13 -0
- package/dist/harness/context.js.map +1 -0
- package/dist/harness/env/nodejs.d.ts +25 -28
- package/dist/harness/env/nodejs.d.ts.map +1 -1
- package/dist/harness/env/nodejs.js +368 -125
- package/dist/harness/env/nodejs.js.map +1 -1
- package/dist/harness/events.d.ts +20 -38
- package/dist/harness/events.d.ts.map +1 -1
- package/dist/harness/events.js +233 -55
- package/dist/harness/events.js.map +1 -1
- package/dist/harness/execution/assistant.d.ts +42 -0
- package/dist/harness/execution/assistant.d.ts.map +1 -0
- package/dist/harness/execution/assistant.js +82 -0
- package/dist/harness/execution/assistant.js.map +1 -0
- package/dist/harness/execution/effect-gate.d.ts +22 -0
- package/dist/harness/execution/effect-gate.d.ts.map +1 -0
- package/dist/harness/execution/effect-gate.js +48 -0
- package/dist/harness/execution/effect-gate.js.map +1 -0
- package/dist/harness/execution/tools.d.ts +67 -0
- package/dist/harness/execution/tools.d.ts.map +1 -0
- package/dist/harness/execution/tools.js +121 -0
- package/dist/harness/execution/tools.js.map +1 -0
- package/dist/harness/hooks.d.ts +38 -0
- package/dist/harness/hooks.d.ts.map +1 -0
- package/dist/harness/hooks.js +404 -0
- package/dist/harness/hooks.js.map +1 -0
- package/dist/harness/messages.d.ts +2 -2
- package/dist/harness/messages.d.ts.map +1 -1
- package/dist/harness/messages.js.map +1 -1
- package/dist/harness/prompt-templates.d.ts +3 -2
- package/dist/harness/prompt-templates.d.ts.map +1 -1
- package/dist/harness/prompt-templates.js +17 -17
- package/dist/harness/prompt-templates.js.map +1 -1
- package/dist/harness/result.d.ts +93 -0
- package/dist/harness/result.d.ts.map +1 -1
- package/dist/harness/result.js +39 -0
- package/dist/harness/result.js.map +1 -1
- package/dist/harness/runtime/drive/boundary.d.ts +28 -0
- package/dist/harness/runtime/drive/boundary.d.ts.map +1 -0
- package/dist/harness/runtime/drive/boundary.js +173 -0
- package/dist/harness/runtime/drive/boundary.js.map +1 -0
- package/dist/harness/runtime/drive/checkpoint.d.ts +8 -0
- package/dist/harness/runtime/drive/checkpoint.d.ts.map +1 -0
- package/dist/harness/runtime/drive/checkpoint.js +133 -0
- package/dist/harness/runtime/drive/checkpoint.js.map +1 -0
- package/dist/harness/runtime/drive/deferred.d.ts +15 -0
- package/dist/harness/runtime/drive/deferred.d.ts.map +1 -0
- package/dist/harness/runtime/drive/deferred.js +179 -0
- package/dist/harness/runtime/drive/deferred.js.map +1 -0
- package/dist/harness/runtime/drive/generation.d.ts +8 -0
- package/dist/harness/runtime/drive/generation.d.ts.map +1 -0
- package/dist/harness/runtime/drive/generation.js +205 -0
- package/dist/harness/runtime/drive/generation.js.map +1 -0
- package/dist/harness/runtime/drive/reconcile.d.ts +5 -0
- package/dist/harness/runtime/drive/reconcile.d.ts.map +1 -0
- package/dist/harness/runtime/drive/reconcile.js +140 -0
- package/dist/harness/runtime/drive/reconcile.js.map +1 -0
- package/dist/harness/runtime/drive/recovery.d.ts +8 -0
- package/dist/harness/runtime/drive/recovery.d.ts.map +1 -0
- package/dist/harness/runtime/drive/recovery.js +85 -0
- package/dist/harness/runtime/drive/recovery.js.map +1 -0
- package/dist/harness/runtime/drive/response.d.ts +23 -0
- package/dist/harness/runtime/drive/response.d.ts.map +1 -0
- package/dist/harness/runtime/drive/response.js +394 -0
- package/dist/harness/runtime/drive/response.js.map +1 -0
- package/dist/harness/runtime/drive/retry.d.ts +4 -0
- package/dist/harness/runtime/drive/retry.d.ts.map +1 -0
- package/dist/harness/runtime/drive/retry.js +34 -0
- package/dist/harness/runtime/drive/retry.js.map +1 -0
- package/dist/harness/runtime/drive/structural.d.ts +32 -0
- package/dist/harness/runtime/drive/structural.d.ts.map +1 -0
- package/dist/harness/runtime/drive/structural.js +929 -0
- package/dist/harness/runtime/drive/structural.js.map +1 -0
- package/dist/harness/runtime/drive/terminal.d.ts +7 -0
- package/dist/harness/runtime/drive/terminal.d.ts.map +1 -0
- package/dist/harness/runtime/drive/terminal.js +49 -0
- package/dist/harness/runtime/drive/terminal.js.map +1 -0
- package/dist/harness/runtime/drive/tool-placement.d.ts +14 -0
- package/dist/harness/runtime/drive/tool-placement.d.ts.map +1 -0
- package/dist/harness/runtime/drive/tool-placement.js +244 -0
- package/dist/harness/runtime/drive/tool-placement.js.map +1 -0
- package/dist/harness/runtime/drive/tools.d.ts +6 -0
- package/dist/harness/runtime/drive/tools.d.ts.map +1 -0
- package/dist/harness/runtime/drive/tools.js +449 -0
- package/dist/harness/runtime/drive/tools.js.map +1 -0
- package/dist/harness/runtime/drive.d.ts +6 -0
- package/dist/harness/runtime/drive.d.ts.map +1 -0
- package/dist/harness/runtime/drive.js +93 -0
- package/dist/harness/runtime/drive.js.map +1 -0
- package/dist/harness/runtime/harness.d.ts +59 -0
- package/dist/harness/runtime/harness.d.ts.map +1 -0
- package/dist/harness/runtime/harness.js +302 -0
- package/dist/harness/runtime/harness.js.map +1 -0
- package/dist/harness/runtime/index.d.ts +2 -0
- package/dist/harness/runtime/index.d.ts.map +1 -0
- package/dist/harness/runtime/index.js +2 -0
- package/dist/harness/runtime/index.js.map +1 -0
- package/dist/harness/runtime/lane.d.ts +118 -0
- package/dist/harness/runtime/lane.d.ts.map +1 -0
- package/dist/harness/runtime/lane.js +1559 -0
- package/dist/harness/runtime/lane.js.map +1 -0
- package/dist/harness/runtime/progress.d.ts +15 -0
- package/dist/harness/runtime/progress.d.ts.map +1 -0
- package/dist/harness/runtime/progress.js +66 -0
- package/dist/harness/runtime/progress.js.map +1 -0
- package/dist/harness/runtime/reducer.d.ts +5 -0
- package/dist/harness/runtime/reducer.d.ts.map +1 -0
- package/dist/harness/runtime/reducer.js +240 -0
- package/dist/harness/runtime/reducer.js.map +1 -0
- package/dist/harness/runtime/restore.d.ts +24 -0
- package/dist/harness/runtime/restore.d.ts.map +1 -0
- package/dist/harness/runtime/restore.js +117 -0
- package/dist/harness/runtime/restore.js.map +1 -0
- package/dist/harness/runtime/transcript.d.ts +21 -0
- package/dist/harness/runtime/transcript.d.ts.map +1 -0
- package/dist/harness/runtime/transcript.js +72 -0
- package/dist/harness/runtime/transcript.js.map +1 -0
- package/dist/harness/runtime/types.d.ts +105 -0
- package/dist/harness/runtime/types.d.ts.map +1 -0
- package/dist/harness/runtime/types.js +50 -0
- package/dist/harness/runtime/types.js.map +1 -0
- package/dist/harness/session/commit.d.ts +53 -0
- package/dist/harness/session/commit.d.ts.map +1 -0
- package/dist/harness/session/commit.js +57 -0
- package/dist/harness/session/commit.js.map +1 -0
- package/dist/harness/session/context.d.ts +6 -19
- package/dist/harness/session/context.d.ts.map +1 -1
- package/dist/harness/session/context.js +31 -53
- package/dist/harness/session/context.js.map +1 -1
- package/dist/harness/session/fork-policy.d.ts +21 -0
- package/dist/harness/session/fork-policy.d.ts.map +1 -0
- package/dist/harness/session/fork-policy.js +55 -0
- package/dist/harness/session/fork-policy.js.map +1 -0
- package/dist/harness/session/fork.d.ts +16 -0
- package/dist/harness/session/fork.d.ts.map +1 -0
- package/dist/harness/session/fork.js +79 -0
- package/dist/harness/session/fork.js.map +1 -0
- package/dist/harness/session/in-memory-storage-state.d.ts +39 -0
- package/dist/harness/session/in-memory-storage-state.d.ts.map +1 -0
- package/dist/harness/session/in-memory-storage-state.js +269 -0
- package/dist/harness/session/in-memory-storage-state.js.map +1 -0
- package/dist/harness/session/index.d.ts +9 -5
- package/dist/harness/session/index.d.ts.map +1 -1
- package/dist/harness/session/index.js +7 -4
- package/dist/harness/session/index.js.map +1 -1
- package/dist/harness/session/jsonl/codec.d.ts +19 -8
- package/dist/harness/session/jsonl/codec.d.ts.map +1 -1
- package/dist/harness/session/jsonl/codec.js +34 -219
- package/dist/harness/session/jsonl/codec.js.map +1 -1
- package/dist/harness/session/jsonl/fork.d.ts +38 -0
- package/dist/harness/session/jsonl/fork.d.ts.map +1 -0
- package/dist/harness/session/jsonl/fork.js +266 -0
- package/dist/harness/session/jsonl/fork.js.map +1 -0
- package/dist/harness/session/jsonl/index.d.ts +4 -0
- package/dist/harness/session/jsonl/index.d.ts.map +1 -0
- package/dist/harness/session/jsonl/index.js +4 -0
- package/dist/harness/session/jsonl/index.js.map +1 -0
- package/dist/harness/session/jsonl/io.d.ts +14 -0
- package/dist/harness/session/jsonl/io.d.ts.map +1 -0
- package/dist/harness/session/jsonl/io.js +86 -0
- package/dist/harness/session/jsonl/io.js.map +1 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts +44 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts.map +1 -0
- package/dist/harness/session/jsonl/legacy-v3.js +454 -0
- package/dist/harness/session/jsonl/legacy-v3.js.map +1 -0
- package/dist/harness/session/jsonl/repo.d.ts +27 -24
- package/dist/harness/session/jsonl/repo.d.ts.map +1 -1
- package/dist/harness/session/jsonl/repo.js +276 -151
- package/dist/harness/session/jsonl/repo.js.map +1 -1
- package/dist/harness/session/jsonl/storage.d.ts +39 -41
- package/dist/harness/session/jsonl/storage.d.ts.map +1 -1
- package/dist/harness/session/jsonl/storage.js +175 -196
- package/dist/harness/session/jsonl/storage.js.map +1 -1
- package/dist/harness/session/jsonl/types.d.ts +23 -22
- package/dist/harness/session/jsonl/types.d.ts.map +1 -1
- package/dist/harness/session/jsonl/types.js +2 -1
- package/dist/harness/session/jsonl/types.js.map +1 -1
- package/dist/harness/session/memory.d.ts +44 -40
- package/dist/harness/session/memory.d.ts.map +1 -1
- package/dist/harness/session/memory.js +333 -115
- package/dist/harness/session/memory.js.map +1 -1
- package/dist/harness/session/mutation-line.d.ts +8 -0
- package/dist/harness/session/mutation-line.d.ts.map +1 -0
- package/dist/harness/session/mutation-line.js +22 -0
- package/dist/harness/session/mutation-line.js.map +1 -0
- package/dist/harness/session/session.d.ts +78 -51
- package/dist/harness/session/session.d.ts.map +1 -1
- package/dist/harness/session/session.js +327 -207
- package/dist/harness/session/session.js.map +1 -1
- package/dist/harness/session/testing/benchmark/datasets.d.ts +12 -0
- package/dist/harness/session/testing/benchmark/datasets.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/datasets.js +24 -0
- package/dist/harness/session/testing/benchmark/datasets.js.map +1 -0
- package/dist/harness/session/testing/benchmark/session-repo.d.ts +42 -0
- package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/session-repo.js +127 -0
- package/dist/harness/session/testing/benchmark/session-repo.js.map +1 -0
- package/dist/harness/session/testing/benchmark/storage.d.ts +25 -0
- package/dist/harness/session/testing/benchmark/storage.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/storage.js +114 -0
- package/dist/harness/session/testing/benchmark/storage.js.map +1 -0
- package/dist/harness/session/testing/conformance/session-repo.d.ts +23 -0
- package/dist/harness/session/testing/conformance/session-repo.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance/session-repo.js +809 -0
- package/dist/harness/session/testing/conformance/session-repo.js.map +1 -0
- package/dist/harness/session/testing/conformance/storage.d.ts +4 -0
- package/dist/harness/session/testing/conformance/storage.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance/storage.js +600 -0
- package/dist/harness/session/testing/conformance/storage.js.map +1 -0
- package/dist/harness/session/testing/gating-storage.d.ts +26 -0
- package/dist/harness/session/testing/gating-storage.d.ts.map +1 -0
- package/dist/harness/session/testing/gating-storage.js +103 -0
- package/dist/harness/session/testing/gating-storage.js.map +1 -0
- package/dist/harness/session/testing/index.d.ts +9 -2
- package/dist/harness/session/testing/index.d.ts.map +1 -1
- package/dist/harness/session/testing/index.js +8 -1
- package/dist/harness/session/testing/index.js.map +1 -1
- package/dist/harness/session/testing/instrumented-storage.d.ts +11 -0
- package/dist/harness/session/testing/instrumented-storage.d.ts.map +1 -0
- package/dist/harness/session/testing/instrumented-storage.js +19 -0
- package/dist/harness/session/testing/instrumented-storage.js.map +1 -0
- package/dist/harness/session/testing/storage-decorator.d.ts +20 -0
- package/dist/harness/session/testing/storage-decorator.d.ts.map +1 -0
- package/dist/harness/session/testing/storage-decorator.js +40 -0
- package/dist/harness/session/testing/storage-decorator.js.map +1 -0
- package/dist/harness/session/testing/types.d.ts +5 -7
- package/dist/harness/session/testing/types.d.ts.map +1 -1
- package/dist/harness/session/testing/types.js.map +1 -1
- package/dist/harness/session/types.d.ts +425 -265
- package/dist/harness/session/types.d.ts.map +1 -1
- package/dist/harness/session/types.js +7 -7
- package/dist/harness/session/types.js.map +1 -1
- package/dist/harness/session/values.d.ts +95 -0
- package/dist/harness/session/values.d.ts.map +1 -0
- package/dist/harness/session/values.js +81 -0
- package/dist/harness/session/values.js.map +1 -0
- package/dist/harness/skills.d.ts +3 -2
- package/dist/harness/skills.d.ts.map +1 -1
- package/dist/harness/skills.js +29 -26
- package/dist/harness/skills.js.map +1 -1
- package/dist/harness/telemetry.d.ts +64 -43
- package/dist/harness/telemetry.d.ts.map +1 -1
- package/dist/harness/telemetry.js +45 -26
- package/dist/harness/telemetry.js.map +1 -1
- package/dist/harness/tools/bash.d.ts +4 -4
- package/dist/harness/tools/bash.d.ts.map +1 -1
- package/dist/harness/tools/bash.js +66 -93
- package/dist/harness/tools/bash.js.map +1 -1
- package/dist/harness/tools/edit.d.ts.map +1 -1
- package/dist/harness/tools/edit.js +17 -13
- package/dist/harness/tools/edit.js.map +1 -1
- package/dist/harness/tools/file-mutation-queue.d.ts +2 -1
- package/dist/harness/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/harness/tools/file-mutation-queue.js +5 -5
- package/dist/harness/tools/file-mutation-queue.js.map +1 -1
- package/dist/harness/tools/path-utils.d.ts +3 -2
- package/dist/harness/tools/path-utils.d.ts.map +1 -1
- package/dist/harness/tools/path-utils.js +5 -5
- package/dist/harness/tools/path-utils.js.map +1 -1
- package/dist/harness/tools/read.d.ts +2 -1
- package/dist/harness/tools/read.d.ts.map +1 -1
- package/dist/harness/tools/read.js +4 -6
- package/dist/harness/tools/read.js.map +1 -1
- package/dist/harness/tools/write.d.ts.map +1 -1
- package/dist/harness/tools/write.js +12 -8
- package/dist/harness/tools/write.js.map +1 -1
- package/dist/harness/types.d.ts +128 -45
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/utils/adaptive-publisher.d.ts +24 -0
- package/dist/harness/utils/adaptive-publisher.d.ts.map +1 -0
- package/dist/harness/utils/adaptive-publisher.js +79 -0
- package/dist/harness/utils/adaptive-publisher.js.map +1 -0
- package/dist/harness/utils/output-capture.d.ts +31 -0
- package/dist/harness/utils/output-capture.d.ts.map +1 -0
- package/dist/harness/utils/output-capture.js +217 -0
- package/dist/harness/utils/output-capture.js.map +1 -0
- package/dist/harness/utils/shell-output.d.ts +19 -5
- package/dist/harness/utils/shell-output.d.ts.map +1 -1
- package/dist/harness/utils/shell-output.js +65 -192
- package/dist/harness/utils/shell-output.js.map +1 -1
- package/dist/harness/utils/truncate.d.ts +1 -0
- package/dist/harness/utils/truncate.d.ts.map +1 -1
- package/dist/harness/utils/truncate.js +1 -1
- package/dist/harness/utils/truncate.js.map +1 -1
- package/dist/harness/utils/usage.d.ts +4 -0
- package/dist/harness/utils/usage.d.ts.map +1 -0
- package/dist/harness/utils/usage.js +33 -0
- package/dist/harness/utils/usage.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/dist/search/index.d.ts +24 -16
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +1 -1
- package/dist/search/index.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +27 -6
- package/dist/harness/reducer.d.ts +0 -100
- package/dist/harness/reducer.d.ts.map +0 -1
- package/dist/harness/reducer.js +0 -420
- package/dist/harness/reducer.js.map +0 -1
- package/dist/harness/session/jsonl/errors.d.ts +0 -9
- package/dist/harness/session/jsonl/errors.d.ts.map +0 -1
- package/dist/harness/session/jsonl/errors.js +0 -18
- package/dist/harness/session/jsonl/errors.js.map +0 -1
- package/dist/harness/session/jsonl.d.ts +0 -3
- package/dist/harness/session/jsonl.d.ts.map +0 -1
- package/dist/harness/session/jsonl.js +0 -2
- package/dist/harness/session/jsonl.js.map +0 -1
- package/dist/harness/session/state.d.ts +0 -65
- package/dist/harness/session/state.d.ts.map +0 -1
- package/dist/harness/session/state.js +0 -320
- package/dist/harness/session/state.js.map +0 -1
- package/dist/harness/session/testing/conformance.d.ts +0 -4
- package/dist/harness/session/testing/conformance.d.ts.map +0 -1
- package/dist/harness/session/testing/conformance.js +0 -762
- package/dist/harness/session/testing/conformance.js.map +0 -1
- package/dist/search/scanning.d.ts +0 -29
- package/dist/search/scanning.d.ts.map +0 -1
- package/dist/search/scanning.js +0 -103
- package/dist/search/scanning.js.map +0 -1
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SessionError } from "../types.js";
|
|
2
|
-
export class JsonlDecodeError extends Error {
|
|
3
|
-
constructor(kind, message, cause) {
|
|
4
|
-
super(message, cause === undefined ? undefined : { cause });
|
|
5
|
-
this.name = "JsonlDecodeError";
|
|
6
|
-
this.kind = kind;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export function fileResult(result, message) {
|
|
10
|
-
if (!result.ok) {
|
|
11
|
-
throw new SessionError(result.error.code === "not_found" ? "not_found" : "storage", `${message}: ${result.error.message}`, result.error);
|
|
12
|
-
}
|
|
13
|
-
return result.value;
|
|
14
|
-
}
|
|
15
|
-
export function invalidFile(path, line, cause) {
|
|
16
|
-
return new SessionError("invalid_entry", `Invalid JSONL v4 session ${path}: line ${line} ${cause.message}`, cause);
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/harness/session/jsonl/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAG1C,YAAY,IAAyB,EAAE,OAAe,EAAE,KAAa;QACpE,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAED,MAAM,UAAU,UAAU,CAAI,MAA4B,EAAE,OAAe;IAC1E,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QAChB,MAAM,IAAI,YAAY,CACrB,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,EAC3D,GAAG,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,EACrC,MAAM,CAAC,KAAK,CACZ,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,IAAY,EAAE,KAAY;IACnE,OAAO,IAAI,YAAY,CAAC,eAAe,EAAE,4BAA4B,IAAI,UAAU,IAAI,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;AACpH,CAAC","sourcesContent":["import type { FileError, Result } from \"../../types.ts\";\nimport { SessionError } from \"../types.ts\";\n\nexport class JsonlDecodeError extends Error {\n\treadonly kind: \"syntax\" | \"schema\";\n\n\tconstructor(kind: \"syntax\" | \"schema\", message: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"JsonlDecodeError\";\n\t\tthis.kind = kind;\n\t}\n}\n\nexport function fileResult<T>(result: Result<T, FileError>, message: string): T {\n\tif (!result.ok) {\n\t\tthrow new SessionError(\n\t\t\tresult.error.code === \"not_found\" ? \"not_found\" : \"storage\",\n\t\t\t`${message}: ${result.error.message}`,\n\t\t\tresult.error,\n\t\t);\n\t}\n\treturn result.value;\n}\n\nexport function invalidFile(path: string, line: number, cause: Error): SessionError {\n\treturn new SessionError(\"invalid_entry\", `Invalid JSONL v4 session ${path}: line ${line} ${cause.message}`, cause);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsonl.d.ts","sourceRoot":"","sources":["../../../src/harness/session/jsonl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EACX,yBAAyB,EACzB,uBAAuB,EACvB,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EACvB,aAAa,GACb,MAAM,kBAAkB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsonl.js","sourceRoot":"","sources":["../../../src/harness/session/jsonl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["export { JsonlSessionRepo } from \"./jsonl/repo.ts\";\nexport type {\n\tJsonlSessionCreateOptions,\n\tJsonlSessionListOptions,\n\tJsonlSessionMetadata,\n\tJsonlSessionRepoFileSystem,\n\tJsonlSessionRepoOptions,\n\tJsonlV4Header,\n} from \"./jsonl/types.ts\";\n"]}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { type BranchBounds, type Entry, type EntryQuery, type ForkOptions, type LanePointer, type LaneRecord, type LogItem, type LogOptions, type OperationStartedRecord, type RecordQuery, type SessionStats } from "./types.ts";
|
|
2
|
-
export type SessionMutation = {
|
|
3
|
-
kind: "entry";
|
|
4
|
-
lane?: string;
|
|
5
|
-
entry: Entry;
|
|
6
|
-
} | {
|
|
7
|
-
kind: "record";
|
|
8
|
-
record: LaneRecord;
|
|
9
|
-
} | {
|
|
10
|
-
kind: "lane";
|
|
11
|
-
seq: number;
|
|
12
|
-
lane: string;
|
|
13
|
-
leafId: string | null;
|
|
14
|
-
} | {
|
|
15
|
-
kind: "fact";
|
|
16
|
-
seq: number;
|
|
17
|
-
fact: "name";
|
|
18
|
-
name: string | undefined;
|
|
19
|
-
} | {
|
|
20
|
-
kind: "fact";
|
|
21
|
-
seq: number;
|
|
22
|
-
fact: "label";
|
|
23
|
-
targetId: string;
|
|
24
|
-
label: string | undefined;
|
|
25
|
-
};
|
|
26
|
-
type InvalidMutation = (message: string) => never;
|
|
27
|
-
export declare class SessionState {
|
|
28
|
-
private sequence;
|
|
29
|
-
private readonly usedIds;
|
|
30
|
-
private readonly entries;
|
|
31
|
-
private readonly entriesById;
|
|
32
|
-
private readonly records;
|
|
33
|
-
private readonly openOperationsByLane;
|
|
34
|
-
private readonly lanes;
|
|
35
|
-
private readonly log;
|
|
36
|
-
private readonly stats;
|
|
37
|
-
private name;
|
|
38
|
-
private readonly labels;
|
|
39
|
-
get nextSequence(): number;
|
|
40
|
-
getLanes(): LanePointer[];
|
|
41
|
-
requireLane(lane: string): string | null;
|
|
42
|
-
validateNewLane(lane: string): void;
|
|
43
|
-
validateTarget(targetId: string | null): void;
|
|
44
|
-
validateUnusedId(id: string): void;
|
|
45
|
-
applyMutation(mutation: SessionMutation, invalid?: InvalidMutation): void;
|
|
46
|
-
getEntry(id: string): Entry | undefined;
|
|
47
|
-
findEntries(query?: EntryQuery): Entry[];
|
|
48
|
-
findEntriesOnBranch(query: EntryQuery & BranchBounds & {
|
|
49
|
-
start: string;
|
|
50
|
-
}): Entry[];
|
|
51
|
-
findRecords(query?: RecordQuery): LaneRecord[];
|
|
52
|
-
findOpenOperations(lane: string, options?: {
|
|
53
|
-
limit?: number;
|
|
54
|
-
}): OperationStartedRecord[];
|
|
55
|
-
getLog(options?: LogOptions): LogItem[];
|
|
56
|
-
getName(): string | undefined;
|
|
57
|
-
getLabel(id: string): string | undefined;
|
|
58
|
-
getStats(): SessionStats;
|
|
59
|
-
createForkMutations(options: ForkOptions): SessionMutation[];
|
|
60
|
-
private walkToRoot;
|
|
61
|
-
private matchesEntryQuery;
|
|
62
|
-
private matchesRecordQuery;
|
|
63
|
-
}
|
|
64
|
-
export {};
|
|
65
|
-
//# sourceMappingURL=state.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/harness/session/state.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,KAAK,EAEV,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAEhB,KAAK,YAAY,EACjB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,eAAe,GACxB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MA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AAG,IAAI,CAElC;IAED,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAI5C;IAED,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAEjC;IAED,aAAa,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,GAAE,eAAiC,GAAG,IAAI,CAmFzF;IAED,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAEtC;IAED,WAAW,CAAC,KAAK,GAAE,UAAe,GAAG,KAAK,EAAE,CAU3C;IAED,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,KAAK,EAAE,CAiBjF;IAED,WAAW,CAAC,KAAK,GAAE,WAAgB,GAAG,UAAU,EAAE,CAUjD;IAED,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,sBAAsB,EAAE,CAKvF;IAED,MAAM,CAAC,OAAO,GAAE,UAAe,GAAG,OAAO,EAAE,CAU1C;IAED,OAAO,IAAI,MAAM,GAAG,SAAS,CAE5B;IAED,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEvC;IAED,QAAQ,IAAI,YAAY,CAEvB;IAED,mBAAmB,CAAC,OAAO,EAAE,WAAW,GAAG,eAAe,EAAE,CAuC3D;IAED,OAAO,CAAE,UAAU;IAqBnB,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,kBAAkB;CAa1B"}
|
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import { SessionError, } from "./types.js";
|
|
2
|
-
function invalidMutation(message) {
|
|
3
|
-
throw new SessionError("invalid_entry", `Invalid session mutation: ${message}`);
|
|
4
|
-
}
|
|
5
|
-
function assertValidLimit(limit) {
|
|
6
|
-
if (limit !== undefined && (!Number.isInteger(limit) || limit <= 0)) {
|
|
7
|
-
throw new SessionError("invalid_query", "limit must be a positive integer");
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function assertValidCursor(afterSeq) {
|
|
11
|
-
if (afterSeq !== undefined && (!Number.isInteger(afterSeq) || afterSeq < 0)) {
|
|
12
|
-
throw new SessionError("invalid_query", "cursor sequence must be a non-negative integer");
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function* ordered(items, order) {
|
|
16
|
-
if (order === "oldestFirst") {
|
|
17
|
-
yield* items;
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
for (let index = items.length - 1; index >= 0; index--)
|
|
21
|
-
yield items[index];
|
|
22
|
-
}
|
|
23
|
-
export class SessionState {
|
|
24
|
-
constructor() {
|
|
25
|
-
this.sequence = 0;
|
|
26
|
-
this.usedIds = new Set();
|
|
27
|
-
this.entries = [];
|
|
28
|
-
this.entriesById = new Map();
|
|
29
|
-
this.records = [];
|
|
30
|
-
this.openOperationsByLane = new Map();
|
|
31
|
-
this.lanes = new Map([["main", null]]);
|
|
32
|
-
this.log = [];
|
|
33
|
-
this.stats = {
|
|
34
|
-
messageCount: 0,
|
|
35
|
-
cachedTokens: 0,
|
|
36
|
-
uncachedTokens: 0,
|
|
37
|
-
totalTokens: 0,
|
|
38
|
-
costTotal: 0,
|
|
39
|
-
};
|
|
40
|
-
this.labels = new Map();
|
|
41
|
-
}
|
|
42
|
-
get nextSequence() {
|
|
43
|
-
return this.sequence + 1;
|
|
44
|
-
}
|
|
45
|
-
getLanes() {
|
|
46
|
-
return [...this.lanes].map(([lane, leafId]) => ({ lane, leafId }));
|
|
47
|
-
}
|
|
48
|
-
requireLane(lane) {
|
|
49
|
-
const leafId = this.lanes.get(lane);
|
|
50
|
-
if (leafId === undefined)
|
|
51
|
-
throw new SessionError("invalid_lane", `Lane not found: ${lane}`);
|
|
52
|
-
return leafId;
|
|
53
|
-
}
|
|
54
|
-
validateNewLane(lane) {
|
|
55
|
-
if (this.lanes.has(lane))
|
|
56
|
-
throw new SessionError("already_exists", `Lane already exists: ${lane}`);
|
|
57
|
-
}
|
|
58
|
-
validateTarget(targetId) {
|
|
59
|
-
if (targetId !== null && !this.entriesById.has(targetId)) {
|
|
60
|
-
throw new SessionError("not_found", `Entry not found: ${targetId}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
validateUnusedId(id) {
|
|
64
|
-
if (this.usedIds.has(id))
|
|
65
|
-
throw new SessionError("already_exists", `Session id already exists: ${id}`);
|
|
66
|
-
}
|
|
67
|
-
applyMutation(mutation, invalid = invalidMutation) {
|
|
68
|
-
const seq = mutation.kind === "entry"
|
|
69
|
-
? mutation.entry.seq
|
|
70
|
-
: mutation.kind === "record"
|
|
71
|
-
? mutation.record.seq
|
|
72
|
-
: mutation.seq;
|
|
73
|
-
if (seq !== this.sequence + 1)
|
|
74
|
-
invalid(`has non-consecutive seq ${seq}`);
|
|
75
|
-
switch (mutation.kind) {
|
|
76
|
-
case "entry": {
|
|
77
|
-
if (this.usedIds.has(mutation.entry.id))
|
|
78
|
-
invalid(`contains duplicate id ${mutation.entry.id}`);
|
|
79
|
-
if (mutation.lane !== undefined) {
|
|
80
|
-
const leafId = this.lanes.get(mutation.lane);
|
|
81
|
-
if (leafId === undefined)
|
|
82
|
-
invalid(`references missing lane ${mutation.lane}`);
|
|
83
|
-
if (mutation.entry.parentId !== leafId)
|
|
84
|
-
invalid("does not chain to the lane leaf");
|
|
85
|
-
}
|
|
86
|
-
if (mutation.entry.parentId !== null && !this.entriesById.has(mutation.entry.parentId)) {
|
|
87
|
-
invalid(`references missing parent ${mutation.entry.parentId}`);
|
|
88
|
-
}
|
|
89
|
-
this.sequence = seq;
|
|
90
|
-
this.usedIds.add(mutation.entry.id);
|
|
91
|
-
this.entries.push(mutation.entry);
|
|
92
|
-
this.entriesById.set(mutation.entry.id, mutation.entry);
|
|
93
|
-
if (mutation.lane !== undefined)
|
|
94
|
-
this.lanes.set(mutation.lane, mutation.entry.id);
|
|
95
|
-
this.log.push({ kind: "entry", seq, entry: mutation.entry });
|
|
96
|
-
if (mutation.entry.type === "message")
|
|
97
|
-
this.stats.messageCount += 1;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
case "record": {
|
|
101
|
-
if (!this.lanes.has(mutation.record.lane))
|
|
102
|
-
invalid(`references missing lane ${mutation.record.lane}`);
|
|
103
|
-
if (this.usedIds.has(mutation.record.id))
|
|
104
|
-
invalid(`contains duplicate id ${mutation.record.id}`);
|
|
105
|
-
this.sequence = seq;
|
|
106
|
-
this.usedIds.add(mutation.record.id);
|
|
107
|
-
this.records.push(mutation.record);
|
|
108
|
-
if (mutation.record.type === "operation_started") {
|
|
109
|
-
let openOperations = this.openOperationsByLane.get(mutation.record.lane);
|
|
110
|
-
if (!openOperations) {
|
|
111
|
-
openOperations = new Map();
|
|
112
|
-
this.openOperationsByLane.set(mutation.record.lane, openOperations);
|
|
113
|
-
}
|
|
114
|
-
openOperations.set(mutation.record.id, mutation.record);
|
|
115
|
-
}
|
|
116
|
-
else if (mutation.record.type === "operation_finished") {
|
|
117
|
-
this.openOperationsByLane.get(mutation.record.lane)?.delete(mutation.record.runId);
|
|
118
|
-
}
|
|
119
|
-
this.log.push({ kind: "record", seq, record: mutation.record });
|
|
120
|
-
if (mutation.record.type === "usage") {
|
|
121
|
-
this.stats.cachedTokens += mutation.record.usage.cacheRead;
|
|
122
|
-
this.stats.uncachedTokens += mutation.record.usage.input + mutation.record.usage.cacheWrite;
|
|
123
|
-
this.stats.totalTokens += mutation.record.usage.totalTokens;
|
|
124
|
-
this.stats.costTotal += mutation.record.usage.cost.total;
|
|
125
|
-
}
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
case "lane":
|
|
129
|
-
if (mutation.leafId !== null && !this.entriesById.has(mutation.leafId)) {
|
|
130
|
-
invalid(`references missing lane target ${mutation.leafId}`);
|
|
131
|
-
}
|
|
132
|
-
this.sequence = seq;
|
|
133
|
-
this.lanes.set(mutation.lane, mutation.leafId);
|
|
134
|
-
this.log.push({ kind: "lane", seq, lane: mutation.lane, leafId: mutation.leafId });
|
|
135
|
-
break;
|
|
136
|
-
case "fact":
|
|
137
|
-
if (mutation.fact === "label" && !this.entriesById.has(mutation.targetId)) {
|
|
138
|
-
invalid(`references missing label target ${mutation.targetId}`);
|
|
139
|
-
}
|
|
140
|
-
this.sequence = seq;
|
|
141
|
-
if (mutation.fact === "name") {
|
|
142
|
-
this.name = mutation.name;
|
|
143
|
-
this.log.push({ kind: "fact", seq, fact: "name", name: mutation.name });
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
if (mutation.label === undefined)
|
|
147
|
-
this.labels.delete(mutation.targetId);
|
|
148
|
-
else
|
|
149
|
-
this.labels.set(mutation.targetId, mutation.label);
|
|
150
|
-
this.log.push({
|
|
151
|
-
kind: "fact",
|
|
152
|
-
seq,
|
|
153
|
-
fact: "label",
|
|
154
|
-
targetId: mutation.targetId,
|
|
155
|
-
label: mutation.label,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
getEntry(id) {
|
|
162
|
-
return this.entriesById.get(id);
|
|
163
|
-
}
|
|
164
|
-
findEntries(query = {}) {
|
|
165
|
-
assertValidLimit(query.limit);
|
|
166
|
-
assertValidCursor(query.cursor?.afterSeq);
|
|
167
|
-
const results = [];
|
|
168
|
-
for (const entry of ordered(this.entries, query.order)) {
|
|
169
|
-
if (!this.matchesEntryQuery(entry, query))
|
|
170
|
-
continue;
|
|
171
|
-
results.push(entry);
|
|
172
|
-
if (results.length === query.limit)
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
return results;
|
|
176
|
-
}
|
|
177
|
-
findEntriesOnBranch(query) {
|
|
178
|
-
assertValidLimit(query.limit);
|
|
179
|
-
assertValidCursor(query.cursor?.afterSeq);
|
|
180
|
-
const results = [];
|
|
181
|
-
if (query.order === "oldestFirst") {
|
|
182
|
-
for (const entry of [...this.walkToRoot(query.start)].reverse()) {
|
|
183
|
-
const reachedBound = entry.id === query.stopAtId || entry.type === query.stopAtType;
|
|
184
|
-
if (this.matchesEntryQuery(entry, query))
|
|
185
|
-
results.push(entry);
|
|
186
|
-
if (reachedBound || results.length === query.limit)
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
for (const entry of this.walkToRoot(query.start, query)) {
|
|
192
|
-
if (this.matchesEntryQuery(entry, query))
|
|
193
|
-
results.push(entry);
|
|
194
|
-
if (results.length === query.limit)
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return results;
|
|
199
|
-
}
|
|
200
|
-
findRecords(query = {}) {
|
|
201
|
-
assertValidLimit(query.limit);
|
|
202
|
-
assertValidCursor(query.afterSeq);
|
|
203
|
-
const results = [];
|
|
204
|
-
for (const record of ordered(this.records, query.order)) {
|
|
205
|
-
if (!this.matchesRecordQuery(record, query))
|
|
206
|
-
continue;
|
|
207
|
-
results.push(record);
|
|
208
|
-
if (results.length === query.limit)
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
return results;
|
|
212
|
-
}
|
|
213
|
-
findOpenOperations(lane, options) {
|
|
214
|
-
assertValidLimit(options?.limit);
|
|
215
|
-
const openOperationsById = this.openOperationsByLane.get(lane);
|
|
216
|
-
const openOperations = openOperationsById ? [...openOperationsById.values()].reverse() : [];
|
|
217
|
-
return options?.limit === undefined ? openOperations : openOperations.slice(0, options.limit);
|
|
218
|
-
}
|
|
219
|
-
getLog(options = {}) {
|
|
220
|
-
assertValidLimit(options.limit);
|
|
221
|
-
assertValidCursor(options.afterSeq);
|
|
222
|
-
const results = [];
|
|
223
|
-
for (const item of this.log) {
|
|
224
|
-
if (options.afterSeq !== undefined && item.seq <= options.afterSeq)
|
|
225
|
-
continue;
|
|
226
|
-
results.push(item);
|
|
227
|
-
if (results.length === options.limit)
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
return results;
|
|
231
|
-
}
|
|
232
|
-
getName() {
|
|
233
|
-
return this.name;
|
|
234
|
-
}
|
|
235
|
-
getLabel(id) {
|
|
236
|
-
return this.labels.get(id);
|
|
237
|
-
}
|
|
238
|
-
getStats() {
|
|
239
|
-
return this.stats;
|
|
240
|
-
}
|
|
241
|
-
createForkMutations(options) {
|
|
242
|
-
let copiedEntries;
|
|
243
|
-
let forkLanes;
|
|
244
|
-
if (options.scope === "tree") {
|
|
245
|
-
copiedEntries = this.findEntries({ order: "oldestFirst" });
|
|
246
|
-
forkLanes = this.getLanes();
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
const selectedEntryId = options.entryId ?? this.requireLane("main");
|
|
250
|
-
let targetId = null;
|
|
251
|
-
if (selectedEntryId !== null) {
|
|
252
|
-
const entry = this.getEntry(selectedEntryId);
|
|
253
|
-
if (entry?.type !== "message") {
|
|
254
|
-
throw new SessionError("invalid_fork_target", `Fork target is not a message entry: ${selectedEntryId}`);
|
|
255
|
-
}
|
|
256
|
-
const position = options.position ?? (options.entryId === undefined ? "at" : "before");
|
|
257
|
-
targetId = position === "at" ? entry.id : entry.parentId;
|
|
258
|
-
}
|
|
259
|
-
copiedEntries = targetId === null ? [] : this.findEntriesOnBranch({ start: targetId, order: "oldestFirst" });
|
|
260
|
-
forkLanes = [{ lane: "main", leafId: targetId }];
|
|
261
|
-
}
|
|
262
|
-
const mutations = [];
|
|
263
|
-
let sequence = 1;
|
|
264
|
-
for (const sourceEntry of copiedEntries) {
|
|
265
|
-
mutations.push({ kind: "entry", entry: { ...structuredClone(sourceEntry), seq: sequence++ } });
|
|
266
|
-
}
|
|
267
|
-
for (const pointer of forkLanes) {
|
|
268
|
-
mutations.push({ kind: "lane", seq: sequence++, lane: pointer.lane, leafId: pointer.leafId });
|
|
269
|
-
}
|
|
270
|
-
if (this.name !== undefined) {
|
|
271
|
-
mutations.push({ kind: "fact", seq: sequence++, fact: "name", name: this.name });
|
|
272
|
-
}
|
|
273
|
-
for (const entry of copiedEntries) {
|
|
274
|
-
const label = this.labels.get(entry.id);
|
|
275
|
-
if (label !== undefined) {
|
|
276
|
-
mutations.push({ kind: "fact", seq: sequence++, fact: "label", targetId: entry.id, label });
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return mutations;
|
|
280
|
-
}
|
|
281
|
-
*walkToRoot(start, bounds) {
|
|
282
|
-
if (start === null)
|
|
283
|
-
return;
|
|
284
|
-
const visited = new Set();
|
|
285
|
-
let current = this.entriesById.get(start);
|
|
286
|
-
if (!current)
|
|
287
|
-
throw new SessionError("not_found", `Entry not found: ${start}`);
|
|
288
|
-
while (current) {
|
|
289
|
-
if (visited.has(current.id)) {
|
|
290
|
-
throw new SessionError("invalid_entry", `Session branch contains a cycle at ${current.id}`);
|
|
291
|
-
}
|
|
292
|
-
visited.add(current.id);
|
|
293
|
-
yield current;
|
|
294
|
-
if (current.id === bounds?.stopAtId || current.type === bounds?.stopAtType || current.parentId === null)
|
|
295
|
-
break;
|
|
296
|
-
const parentId = current.parentId;
|
|
297
|
-
current = this.entriesById.get(parentId);
|
|
298
|
-
if (!current)
|
|
299
|
-
throw new SessionError("invalid_entry", `Entry not found: ${parentId}`);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
matchesEntryQuery(entry, query) {
|
|
303
|
-
return ((query.type === undefined || entry.type === query.type) &&
|
|
304
|
-
(query.customType === undefined || (entry.type === "custom" && entry.customType === query.customType)) &&
|
|
305
|
-
(query.cursor === undefined ||
|
|
306
|
-
(query.order === "oldestFirst" ? entry.seq > query.cursor.afterSeq : entry.seq < query.cursor.afterSeq)));
|
|
307
|
-
}
|
|
308
|
-
matchesRecordQuery(record, query) {
|
|
309
|
-
return ((query.lane === undefined || record.lane === query.lane) &&
|
|
310
|
-
(query.type === undefined || record.type === query.type) &&
|
|
311
|
-
(query.runId === undefined ||
|
|
312
|
-
(record.type === "operation_started"
|
|
313
|
-
? record.id === query.runId
|
|
314
|
-
: "runId" in record && record.runId === query.runId)) &&
|
|
315
|
-
(query.operationKind === undefined ||
|
|
316
|
-
(record.type === "operation_started" && record.intent.kind === query.operationKind)) &&
|
|
317
|
-
(query.afterSeq === undefined || record.seq > query.afterSeq));
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
//# sourceMappingURL=state.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/harness/session/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAYN,YAAY,GAEZ,MAAM,YAAY,CAAC;AAWpB,SAAS,eAAe,CAAC,OAAe;IACvC,MAAM,IAAI,YAAY,CAAC,eAAe,EAAE,6BAA6B,OAAO,EAAE,CAAC,CAAC;AACjF,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAyB;IAClD,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,YAAY,CAAC,eAAe,EAAE,kCAAkC,CAAC,CAAC;IAC7E,CAAC;AACF,CAAC;AAED,SAAS,iBAAiB,CAAC,QAA4B;IACtD,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC,EAAE,CAAC;QAC7E,MAAM,IAAI,YAAY,CAAC,eAAe,EAAE,gDAAgD,CAAC,CAAC;IAC3F,CAAC;AACF,CAAC;AAED,QAAQ,CAAC,CAAC,OAAO,CAAI,KAAmB,EAAE,KAA6B;IACtE,IAAI,KAAK,KAAK,aAAa,EAAE,CAAC;QAC7B,KAAK,CAAC,CAAC,KAAK,CAAC;QACb,OAAO;IACR,CAAC;IACD,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EA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AC,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC;YACxD,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC;YACxD,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS;gBACzB,CAAC,MAAM,CAAC,IAAI,KAAK,mBAAmB;oBACnC,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,KAAK,CAAC,KAAK;oBAC3B,CAAC,CAAC,OAAO,IAAI,MAAM,IAAI,MAAM,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC;YACvD,CAAC,KAAK,CAAC,aAAa,KAAK,SAAS;gBACjC,CAAC,MAAM,CAAC,IAAI,KAAK,mBAAmB,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,aAAa,CAAC,CAAC;YACrF,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC,CAC7D,CAAC;IACH,CAAC;CACD","sourcesContent":["import {\n\ttype BranchBounds,\n\ttype Entry,\n\ttype EntryOrder,\n\ttype EntryQuery,\n\ttype ForkOptions,\n\ttype LanePointer,\n\ttype LaneRecord,\n\ttype LogItem,\n\ttype LogOptions,\n\ttype OperationStartedRecord,\n\ttype RecordQuery,\n\tSessionError,\n\ttype SessionStats,\n} from \"./types.ts\";\n\nexport type SessionMutation =\n\t| { kind: \"entry\"; lane?: string; entry: Entry }\n\t| { kind: \"record\"; record: LaneRecord }\n\t| { kind: \"lane\"; seq: number; lane: string; leafId: string | null }\n\t| { kind: \"fact\"; seq: number; fact: \"name\"; name: string | undefined }\n\t| { kind: \"fact\"; seq: number; fact: \"label\"; targetId: string; label: string | undefined };\n\ntype InvalidMutation = (message: string) => never;\n\nfunction invalidMutation(message: string): never {\n\tthrow new SessionError(\"invalid_entry\", `Invalid session mutation: ${message}`);\n}\n\nfunction assertValidLimit(limit: number | undefined): void {\n\tif (limit !== undefined && (!Number.isInteger(limit) || limit <= 0)) {\n\t\tthrow new SessionError(\"invalid_query\", \"limit must be a positive integer\");\n\t}\n}\n\nfunction assertValidCursor(afterSeq: number | undefined): void {\n\tif (afterSeq !== undefined && (!Number.isInteger(afterSeq) || afterSeq < 0)) {\n\t\tthrow new SessionError(\"invalid_query\", \"cursor sequence must be a non-negative integer\");\n\t}\n}\n\nfunction* ordered<T>(items: readonly T[], order: EntryOrder | undefined): IterableIterator<T> {\n\tif (order === \"oldestFirst\") {\n\t\tyield* items;\n\t\treturn;\n\t}\n\tfor (let index = items.length - 1; index >= 0; index--) yield items[index]!;\n}\n\nexport class SessionState {\n\tprivate sequence = 0;\n\tprivate readonly usedIds = new Set<string>();\n\tprivate readonly entries: Entry[] = [];\n\tprivate readonly entriesById = new Map<string, Entry>();\n\tprivate readonly records: LaneRecord[] = [];\n\tprivate readonly openOperationsByLane = new Map<string, Map<string, OperationStartedRecord>>();\n\tprivate readonly lanes = new Map<string, string | null>([[\"main\", null]]);\n\tprivate readonly log: LogItem[] = [];\n\tprivate readonly stats: SessionStats = {\n\t\tmessageCount: 0,\n\t\tcachedTokens: 0,\n\t\tuncachedTokens: 0,\n\t\ttotalTokens: 0,\n\t\tcostTotal: 0,\n\t};\n\tprivate name: string | undefined;\n\tprivate readonly labels = new Map<string, string>();\n\n\tget nextSequence(): number {\n\t\treturn this.sequence + 1;\n\t}\n\n\tgetLanes(): LanePointer[] {\n\t\treturn [...this.lanes].map(([lane, leafId]) => ({ lane, leafId }));\n\t}\n\n\trequireLane(lane: string): string | null {\n\t\tconst leafId = this.lanes.get(lane);\n\t\tif (leafId === undefined) throw new SessionError(\"invalid_lane\", `Lane not found: ${lane}`);\n\t\treturn leafId;\n\t}\n\n\tvalidateNewLane(lane: string): void {\n\t\tif (this.lanes.has(lane)) throw new SessionError(\"already_exists\", `Lane already exists: ${lane}`);\n\t}\n\n\tvalidateTarget(targetId: string | null): void {\n\t\tif (targetId !== null && !this.entriesById.has(targetId)) {\n\t\t\tthrow new SessionError(\"not_found\", `Entry not found: ${targetId}`);\n\t\t}\n\t}\n\n\tvalidateUnusedId(id: string): void {\n\t\tif (this.usedIds.has(id)) throw new SessionError(\"already_exists\", `Session id already exists: ${id}`);\n\t}\n\n\tapplyMutation(mutation: SessionMutation, invalid: InvalidMutation = invalidMutation): void {\n\t\tconst seq =\n\t\t\tmutation.kind === \"entry\"\n\t\t\t\t? mutation.entry.seq\n\t\t\t\t: mutation.kind === \"record\"\n\t\t\t\t\t? mutation.record.seq\n\t\t\t\t\t: mutation.seq;\n\t\tif (seq !== this.sequence + 1) invalid(`has non-consecutive seq ${seq}`);\n\n\t\tswitch (mutation.kind) {\n\t\t\tcase \"entry\": {\n\t\t\t\tif (this.usedIds.has(mutation.entry.id)) invalid(`contains duplicate id ${mutation.entry.id}`);\n\t\t\t\tif (mutation.lane !== undefined) {\n\t\t\t\t\tconst leafId = this.lanes.get(mutation.lane);\n\t\t\t\t\tif (leafId === undefined) invalid(`references missing lane ${mutation.lane}`);\n\t\t\t\t\tif (mutation.entry.parentId !== leafId) invalid(\"does not chain to the lane leaf\");\n\t\t\t\t}\n\t\t\t\tif (mutation.entry.parentId !== null && !this.entriesById.has(mutation.entry.parentId)) {\n\t\t\t\t\tinvalid(`references missing parent ${mutation.entry.parentId}`);\n\t\t\t\t}\n\t\t\t\tthis.sequence = seq;\n\t\t\t\tthis.usedIds.add(mutation.entry.id);\n\t\t\t\tthis.entries.push(mutation.entry);\n\t\t\t\tthis.entriesById.set(mutation.entry.id, mutation.entry);\n\t\t\t\tif (mutation.lane !== undefined) this.lanes.set(mutation.lane, mutation.entry.id);\n\t\t\t\tthis.log.push({ kind: \"entry\", seq, entry: mutation.entry });\n\t\t\t\tif (mutation.entry.type === \"message\") this.stats.messageCount += 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"record\": {\n\t\t\t\tif (!this.lanes.has(mutation.record.lane)) invalid(`references missing lane ${mutation.record.lane}`);\n\t\t\t\tif (this.usedIds.has(mutation.record.id)) invalid(`contains duplicate id ${mutation.record.id}`);\n\t\t\t\tthis.sequence = seq;\n\t\t\t\tthis.usedIds.add(mutation.record.id);\n\t\t\t\tthis.records.push(mutation.record);\n\t\t\t\tif (mutation.record.type === \"operation_started\") {\n\t\t\t\t\tlet openOperations = this.openOperationsByLane.get(mutation.record.lane);\n\t\t\t\t\tif (!openOperations) {\n\t\t\t\t\t\topenOperations = new Map();\n\t\t\t\t\t\tthis.openOperationsByLane.set(mutation.record.lane, openOperations);\n\t\t\t\t\t}\n\t\t\t\t\topenOperations.set(mutation.record.id, mutation.record);\n\t\t\t\t} else if (mutation.record.type === \"operation_finished\") {\n\t\t\t\t\tthis.openOperationsByLane.get(mutation.record.lane)?.delete(mutation.record.runId);\n\t\t\t\t}\n\t\t\t\tthis.log.push({ kind: \"record\", seq, record: mutation.record });\n\t\t\t\tif (mutation.record.type === \"usage\") {\n\t\t\t\t\tthis.stats.cachedTokens += mutation.record.usage.cacheRead;\n\t\t\t\t\tthis.stats.uncachedTokens += mutation.record.usage.input + mutation.record.usage.cacheWrite;\n\t\t\t\t\tthis.stats.totalTokens += mutation.record.usage.totalTokens;\n\t\t\t\t\tthis.stats.costTotal += mutation.record.usage.cost.total;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"lane\":\n\t\t\t\tif (mutation.leafId !== null && !this.entriesById.has(mutation.leafId)) {\n\t\t\t\t\tinvalid(`references missing lane target ${mutation.leafId}`);\n\t\t\t\t}\n\t\t\t\tthis.sequence = seq;\n\t\t\t\tthis.lanes.set(mutation.lane, mutation.leafId);\n\t\t\t\tthis.log.push({ kind: \"lane\", seq, lane: mutation.lane, leafId: mutation.leafId });\n\t\t\t\tbreak;\n\t\t\tcase \"fact\":\n\t\t\t\tif (mutation.fact === \"label\" && !this.entriesById.has(mutation.targetId)) {\n\t\t\t\t\tinvalid(`references missing label target ${mutation.targetId}`);\n\t\t\t\t}\n\t\t\t\tthis.sequence = seq;\n\t\t\t\tif (mutation.fact === \"name\") {\n\t\t\t\t\tthis.name = mutation.name;\n\t\t\t\t\tthis.log.push({ kind: \"fact\", seq, fact: \"name\", name: mutation.name });\n\t\t\t\t} else {\n\t\t\t\t\tif (mutation.label === undefined) this.labels.delete(mutation.targetId);\n\t\t\t\t\telse this.labels.set(mutation.targetId, mutation.label);\n\t\t\t\t\tthis.log.push({\n\t\t\t\t\t\tkind: \"fact\",\n\t\t\t\t\t\tseq,\n\t\t\t\t\t\tfact: \"label\",\n\t\t\t\t\t\ttargetId: mutation.targetId,\n\t\t\t\t\t\tlabel: mutation.label,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tgetEntry(id: string): Entry | undefined {\n\t\treturn this.entriesById.get(id);\n\t}\n\n\tfindEntries(query: EntryQuery = {}): Entry[] {\n\t\tassertValidLimit(query.limit);\n\t\tassertValidCursor(query.cursor?.afterSeq);\n\t\tconst results: Entry[] = [];\n\t\tfor (const entry of ordered(this.entries, query.order)) {\n\t\t\tif (!this.matchesEntryQuery(entry, query)) continue;\n\t\t\tresults.push(entry);\n\t\t\tif (results.length === query.limit) break;\n\t\t}\n\t\treturn results;\n\t}\n\n\tfindEntriesOnBranch(query: EntryQuery & BranchBounds & { start: string }): Entry[] {\n\t\tassertValidLimit(query.limit);\n\t\tassertValidCursor(query.cursor?.afterSeq);\n\t\tconst results: Entry[] = [];\n\t\tif (query.order === \"oldestFirst\") {\n\t\t\tfor (const entry of [...this.walkToRoot(query.start)].reverse()) {\n\t\t\t\tconst reachedBound = entry.id === query.stopAtId || entry.type === query.stopAtType;\n\t\t\t\tif (this.matchesEntryQuery(entry, query)) results.push(entry);\n\t\t\t\tif (reachedBound || results.length === query.limit) break;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (const entry of this.walkToRoot(query.start, query)) {\n\t\t\t\tif (this.matchesEntryQuery(entry, query)) results.push(entry);\n\t\t\t\tif (results.length === query.limit) break;\n\t\t\t}\n\t\t}\n\t\treturn results;\n\t}\n\n\tfindRecords(query: RecordQuery = {}): LaneRecord[] {\n\t\tassertValidLimit(query.limit);\n\t\tassertValidCursor(query.afterSeq);\n\t\tconst results: LaneRecord[] = [];\n\t\tfor (const record of ordered(this.records, query.order)) {\n\t\t\tif (!this.matchesRecordQuery(record, query)) continue;\n\t\t\tresults.push(record);\n\t\t\tif (results.length === query.limit) break;\n\t\t}\n\t\treturn results;\n\t}\n\n\tfindOpenOperations(lane: string, options?: { limit?: number }): OperationStartedRecord[] {\n\t\tassertValidLimit(options?.limit);\n\t\tconst openOperationsById = this.openOperationsByLane.get(lane);\n\t\tconst openOperations = openOperationsById ? [...openOperationsById.values()].reverse() : [];\n\t\treturn options?.limit === undefined ? openOperations : openOperations.slice(0, options.limit);\n\t}\n\n\tgetLog(options: LogOptions = {}): LogItem[] {\n\t\tassertValidLimit(options.limit);\n\t\tassertValidCursor(options.afterSeq);\n\t\tconst results: LogItem[] = [];\n\t\tfor (const item of this.log) {\n\t\t\tif (options.afterSeq !== undefined && item.seq <= options.afterSeq) continue;\n\t\t\tresults.push(item);\n\t\t\tif (results.length === options.limit) break;\n\t\t}\n\t\treturn results;\n\t}\n\n\tgetName(): string | undefined {\n\t\treturn this.name;\n\t}\n\n\tgetLabel(id: string): string | undefined {\n\t\treturn this.labels.get(id);\n\t}\n\n\tgetStats(): SessionStats {\n\t\treturn this.stats;\n\t}\n\n\tcreateForkMutations(options: ForkOptions): SessionMutation[] {\n\t\tlet copiedEntries: Entry[];\n\t\tlet forkLanes: LanePointer[];\n\t\tif (options.scope === \"tree\") {\n\t\t\tcopiedEntries = this.findEntries({ order: \"oldestFirst\" });\n\t\t\tforkLanes = this.getLanes();\n\t\t} else {\n\t\t\tconst selectedEntryId = options.entryId ?? this.requireLane(\"main\");\n\t\t\tlet targetId: string | null = null;\n\t\t\tif (selectedEntryId !== null) {\n\t\t\t\tconst entry = this.getEntry(selectedEntryId);\n\t\t\t\tif (entry?.type !== \"message\") {\n\t\t\t\t\tthrow new SessionError(\"invalid_fork_target\", `Fork target is not a message entry: ${selectedEntryId}`);\n\t\t\t\t}\n\t\t\t\tconst position = options.position ?? (options.entryId === undefined ? \"at\" : \"before\");\n\t\t\t\ttargetId = position === \"at\" ? entry.id : entry.parentId;\n\t\t\t}\n\t\t\tcopiedEntries = targetId === null ? [] : this.findEntriesOnBranch({ start: targetId, order: \"oldestFirst\" });\n\t\t\tforkLanes = [{ lane: \"main\", leafId: targetId }];\n\t\t}\n\n\t\tconst mutations: SessionMutation[] = [];\n\t\tlet sequence = 1;\n\t\tfor (const sourceEntry of copiedEntries) {\n\t\t\tmutations.push({ kind: \"entry\", entry: { ...structuredClone(sourceEntry), seq: sequence++ } });\n\t\t}\n\t\tfor (const pointer of forkLanes) {\n\t\t\tmutations.push({ kind: \"lane\", seq: sequence++, lane: pointer.lane, leafId: pointer.leafId });\n\t\t}\n\t\tif (this.name !== undefined) {\n\t\t\tmutations.push({ kind: \"fact\", seq: sequence++, fact: \"name\", name: this.name });\n\t\t}\n\t\tfor (const entry of copiedEntries) {\n\t\t\tconst label = this.labels.get(entry.id);\n\t\t\tif (label !== undefined) {\n\t\t\t\tmutations.push({ kind: \"fact\", seq: sequence++, fact: \"label\", targetId: entry.id, label });\n\t\t\t}\n\t\t}\n\t\treturn mutations;\n\t}\n\n\tprivate *walkToRoot(\n\t\tstart: string | null,\n\t\tbounds?: Pick<BranchBounds, \"stopAtId\" | \"stopAtType\">,\n\t): IterableIterator<Entry> {\n\t\tif (start === null) return;\n\t\tconst visited = new Set<string>();\n\t\tlet current = this.entriesById.get(start);\n\t\tif (!current) throw new SessionError(\"not_found\", `Entry not found: ${start}`);\n\t\twhile (current) {\n\t\t\tif (visited.has(current.id)) {\n\t\t\t\tthrow new SessionError(\"invalid_entry\", `Session branch contains a cycle at ${current.id}`);\n\t\t\t}\n\t\t\tvisited.add(current.id);\n\t\t\tyield current;\n\t\t\tif (current.id === bounds?.stopAtId || current.type === bounds?.stopAtType || current.parentId === null) break;\n\t\t\tconst parentId: string = current.parentId;\n\t\t\tcurrent = this.entriesById.get(parentId);\n\t\t\tif (!current) throw new SessionError(\"invalid_entry\", `Entry not found: ${parentId}`);\n\t\t}\n\t}\n\n\tprivate matchesEntryQuery(entry: Entry, query: EntryQuery): boolean {\n\t\treturn (\n\t\t\t(query.type === undefined || entry.type === query.type) &&\n\t\t\t(query.customType === undefined || (entry.type === \"custom\" && entry.customType === query.customType)) &&\n\t\t\t(query.cursor === undefined ||\n\t\t\t\t(query.order === \"oldestFirst\" ? entry.seq > query.cursor.afterSeq : entry.seq < query.cursor.afterSeq))\n\t\t);\n\t}\n\n\tprivate matchesRecordQuery(record: LaneRecord, query: RecordQuery): boolean {\n\t\treturn (\n\t\t\t(query.lane === undefined || record.lane === query.lane) &&\n\t\t\t(query.type === undefined || record.type === query.type) &&\n\t\t\t(query.runId === undefined ||\n\t\t\t\t(record.type === \"operation_started\"\n\t\t\t\t\t? record.id === query.runId\n\t\t\t\t\t: \"runId\" in record && record.runId === query.runId)) &&\n\t\t\t(query.operationKind === undefined ||\n\t\t\t\t(record.type === \"operation_started\" && record.intent.kind === query.operationKind)) &&\n\t\t\t(query.afterSeq === undefined || record.seq > query.afterSeq)\n\t\t);\n\t}\n}\n"]}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { SessionBackendConformanceCase, SessionBackendFixtureFactory } from "./types.ts";
|
|
2
|
-
/** Creates the session backend conformance cases. Each case creates and disposes its own fixture. */
|
|
3
|
-
export declare function createSessionBackendConformance(factory: SessionBackendFixtureFactory): readonly SessionBackendConformanceCase[];
|
|
4
|
-
//# sourceMappingURL=conformance.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conformance.d.ts","sourceRoot":"","sources":["../../../../src/harness/session/testing/conformance.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,6BAA6B,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AA+E9F,qGAAqG;AACrG,wBAAgB,+BAA+B,CAC9C,OAAO,EAAE,4BAA4B,GACnC,SAAS,6BAA6B,EAAE,CA05B1C"}
|