@visual-z/xeno 0.8.4 → 0.9.1
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/CHANGELOG.md +19 -0
- package/README.md +31 -746
- package/bin/xeno.exe +26 -0
- package/install.cjs +88 -0
- package/package.json +18 -48
- package/docs/app-server.md +0 -115
- package/docs/foundations.md +0 -88
- package/docs/install.md +0 -244
- package/docs/providers.md +0 -172
- package/docs/research/foundation-clients-2026-10-09.md +0 -27
- package/docs/research/foundation-editing-2026-10-09.md +0 -56
- package/docs/research/foundation-network-2026-10-09.md +0 -37
- package/docs/research/foundation-workflow-2026-10-09.md +0 -37
- package/src/apps/acp-server.ts +0 -41
- package/src/apps/agent-profiles.ts +0 -19
- package/src/apps/app-server.ts +0 -30
- package/src/apps/approve.ts +0 -49
- package/src/apps/cli.ts +0 -99
- package/src/apps/commands.ts +0 -319
- package/src/apps/completions.ts +0 -87
- package/src/apps/control-transport.ts +0 -90
- package/src/apps/export-cli.ts +0 -24
- package/src/apps/goal-flow.ts +0 -70
- package/src/apps/image-draft.ts +0 -46
- package/src/apps/input.ts +0 -312
- package/src/apps/model-catalog.ts +0 -69
- package/src/apps/preferences.ts +0 -20
- package/src/apps/project-trust.ts +0 -9
- package/src/apps/provider-connect.ts +0 -346
- package/src/apps/question-ui.ts +0 -27
- package/src/apps/render.ts +0 -181
- package/src/apps/resources.ts +0 -66
- package/src/apps/review.ts +0 -109
- package/src/apps/session-hub.ts +0 -96
- package/src/apps/session-lifecycle.ts +0 -64
- package/src/apps/shell.ts +0 -2071
- package/src/apps/startup-input.ts +0 -135
- package/src/apps/startup.ts +0 -1677
- package/src/apps/ui/app.ts +0 -1818
- package/src/apps/ui/control-model.ts +0 -43
- package/src/apps/ui/extension-host.ts +0 -194
- package/src/apps/ui/image-cache.ts +0 -121
- package/src/apps/ui/palette.ts +0 -88
- package/src/apps/ui/project.ts +0 -127
- package/src/apps/ui/standalone.ts +0 -148
- package/src/apps/ui/status-model.ts +0 -68
- package/src/apps/ui/surface.ts +0 -91
- package/src/apps/ui/theme.ts +0 -86
- package/src/apps/update-check.ts +0 -112
- package/src/apps/workflow.ts +0 -58
- package/src/core/acceptance.ts +0 -139
- package/src/core/action-defaults.ts +0 -58
- package/src/core/activity-status.ts +0 -52
- package/src/core/agent-profile.ts +0 -130
- package/src/core/attachment-input.ts +0 -17
- package/src/core/blind-checks.ts +0 -72
- package/src/core/boundary.ts +0 -174
- package/src/core/branch-receipt.ts +0 -26
- package/src/core/catalog-merge.ts +0 -19
- package/src/core/checkpoints.ts +0 -85
- package/src/core/churn.ts +0 -61
- package/src/core/command-artifacts.ts +0 -94
- package/src/core/command-contract.ts +0 -151
- package/src/core/completion-action.ts +0 -20
- package/src/core/completion-review.ts +0 -98
- package/src/core/context-detail.ts +0 -37
- package/src/core/context-policy.ts +0 -133
- package/src/core/context-window.ts +0 -54
- package/src/core/continuation.ts +0 -130
- package/src/core/control-protocol.ts +0 -69
- package/src/core/control-view.ts +0 -39
- package/src/core/cycle.ts +0 -17
- package/src/core/data-query.ts +0 -201
- package/src/core/deadline.ts +0 -40
- package/src/core/derive.ts +0 -516
- package/src/core/draft-images.ts +0 -56
- package/src/core/edit-plan.ts +0 -200
- package/src/core/environment.ts +0 -181
- package/src/core/event-validation.ts +0 -220
- package/src/core/events.ts +0 -670
- package/src/core/evidence-ladder.ts +0 -62
- package/src/core/evidence-links.ts +0 -68
- package/src/core/evidence.ts +0 -240
- package/src/core/execution.ts +0 -18
- package/src/core/exhaustive.ts +0 -18
- package/src/core/export.ts +0 -179
- package/src/core/extension-flags.ts +0 -14
- package/src/core/external-effects.ts +0 -488
- package/src/core/failure-recovery.ts +0 -173
- package/src/core/file-precondition.ts +0 -78
- package/src/core/file-references.ts +0 -35
- package/src/core/frontmatter.ts +0 -213
- package/src/core/git-status.ts +0 -29
- package/src/core/goal-view.ts +0 -64
- package/src/core/goal.ts +0 -200
- package/src/core/handoff.ts +0 -479
- package/src/core/history-query.ts +0 -139
- package/src/core/history.ts +0 -237
- package/src/core/image-limits.ts +0 -72
- package/src/core/images.ts +0 -46
- package/src/core/integration-health.ts +0 -34
- package/src/core/json-event.ts +0 -131
- package/src/core/json-pointer.ts +0 -46
- package/src/core/keymap.ts +0 -153
- package/src/core/lsp-framing.ts +0 -34
- package/src/core/mcp-config.ts +0 -68
- package/src/core/model-picker.ts +0 -64
- package/src/core/model-preferences.ts +0 -28
- package/src/core/model-replay.ts +0 -22
- package/src/core/model-scope.ts +0 -53
- package/src/core/note-guidance.ts +0 -34
- package/src/core/oauth-fields.ts +0 -44
- package/src/core/observation-view.ts +0 -152
- package/src/core/outcome.ts +0 -44
- package/src/core/overflow.ts +0 -59
- package/src/core/packages.ts +0 -47
- package/src/core/patch.ts +0 -130
- package/src/core/path-suggestions.ts +0 -59
- package/src/core/permissions.ts +0 -410
- package/src/core/process-receipt.ts +0 -105
- package/src/core/process-state.ts +0 -37
- package/src/core/program-status.ts +0 -40
- package/src/core/progress.ts +0 -150
- package/src/core/project.ts +0 -431
- package/src/core/prompt-policy.ts +0 -46
- package/src/core/prompts.ts +0 -111
- package/src/core/question.ts +0 -94
- package/src/core/queue.ts +0 -78
- package/src/core/read-bounds.ts +0 -24
- package/src/core/read-observation.ts +0 -106
- package/src/core/recovery-sources.ts +0 -74
- package/src/core/regex-dialect.ts +0 -25
- package/src/core/request-budget.ts +0 -23
- package/src/core/request-progress.ts +0 -87
- package/src/core/request-state.ts +0 -273
- package/src/core/resource-selection.ts +0 -36
- package/src/core/response-recovery.ts +0 -59
- package/src/core/resume.ts +0 -59
- package/src/core/review.ts +0 -68
- package/src/core/ripgrep-release.ts +0 -64
- package/src/core/runtime-target.ts +0 -94
- package/src/core/scheduling.ts +0 -8
- package/src/core/search-observation.ts +0 -97
- package/src/core/secrets.ts +0 -188
- package/src/core/session-archive.ts +0 -4
- package/src/core/session-browser.ts +0 -82
- package/src/core/session-entry.ts +0 -61
- package/src/core/session-exit.ts +0 -42
- package/src/core/session-format.ts +0 -169
- package/src/core/session-position.ts +0 -26
- package/src/core/session-tree.ts +0 -147
- package/src/core/settings.ts +0 -192
- package/src/core/skills.ts +0 -165
- package/src/core/sql-query.ts +0 -211
- package/src/core/stall.ts +0 -128
- package/src/core/stop-report.ts +0 -68
- package/src/core/text-normalize.ts +0 -81
- package/src/core/theme.ts +0 -166
- package/src/core/thinking.ts +0 -26
- package/src/core/tokens.ts +0 -151
- package/src/core/tool-contract.ts +0 -153
- package/src/core/tool-discovery.ts +0 -87
- package/src/core/tool-failure.ts +0 -81
- package/src/core/tool-input.ts +0 -44
- package/src/core/transcript.ts +0 -108
- package/src/core/tui-mode.ts +0 -29
- package/src/core/update-check.ts +0 -157
- package/src/core/version.ts +0 -55
- package/src/core/web-content.ts +0 -80
- package/src/core/work-state.ts +0 -154
- package/src/core/workflow-mode.ts +0 -34
- package/src/core/working-set.ts +0 -119
- package/src/core/yaml.ts +0 -282
- package/src/runtime/acp-agent.ts +0 -289
- package/src/runtime/agent-profiles.ts +0 -21
- package/src/runtime/auth.ts +0 -367
- package/src/runtime/blind-check.ts +0 -36
- package/src/runtime/branch-jobs.ts +0 -36
- package/src/runtime/catalog.ts +0 -285
- package/src/runtime/clipboard.ts +0 -125
- package/src/runtime/command-artifacts.ts +0 -64
- package/src/runtime/connection-reuse.ts +0 -40
- package/src/runtime/control-client.ts +0 -149
- package/src/runtime/control-connection.ts +0 -139
- package/src/runtime/counter-check.ts +0 -74
- package/src/runtime/environment-tools.ts +0 -60
- package/src/runtime/evidence-notes.ts +0 -35
- package/src/runtime/exec-sessions.ts +0 -456
- package/src/runtime/execution-control.ts +0 -40
- package/src/runtime/extension-loader.ts +0 -37
- package/src/runtime/extension-ui.ts +0 -47
- package/src/runtime/extensions.ts +0 -370
- package/src/runtime/formatter-tool.ts +0 -38
- package/src/runtime/formatter.ts +0 -50
- package/src/runtime/foundation.ts +0 -116
- package/src/runtime/history-cache.ts +0 -57
- package/src/runtime/history-tools.ts +0 -168
- package/src/runtime/images.ts +0 -80
- package/src/runtime/integrations.ts +0 -216
- package/src/runtime/loop.ts +0 -3108
- package/src/runtime/lsp-client.ts +0 -201
- package/src/runtime/mcp-client.ts +0 -264
- package/src/runtime/mcp-oauth.ts +0 -168
- package/src/runtime/mcp-schema.ts +0 -51
- package/src/runtime/model-config.ts +0 -232
- package/src/runtime/model-data.LICENSE +0 -27
- package/src/runtime/model-data.ts +0 -21
- package/src/runtime/model-discovery.ts +0 -208
- package/src/runtime/model-replay.ts +0 -10
- package/src/runtime/model-scope.ts +0 -20
- package/src/runtime/model-sources.ts +0 -151
- package/src/runtime/model.ts +0 -686
- package/src/runtime/models-fetch.ts +0 -57
- package/src/runtime/oauth-device.ts +0 -86
- package/src/runtime/oauth.ts +0 -853
- package/src/runtime/open-image.ts +0 -42
- package/src/runtime/openai-responses.ts +0 -304
- package/src/runtime/openai.ts +0 -697
- package/src/runtime/output-schema.ts +0 -26
- package/src/runtime/package-manager.ts +0 -125
- package/src/runtime/patch-tool.ts +0 -38
- package/src/runtime/permission-resources.ts +0 -18
- package/src/runtime/pi-provider.ts +0 -423
- package/src/runtime/program-status.ts +0 -38
- package/src/runtime/progress.ts +0 -26
- package/src/runtime/provider-access.ts +0 -21
- package/src/runtime/provider-connect.ts +0 -109
- package/src/runtime/provider-presets.ts +0 -98
- package/src/runtime/provider-protocols.ts +0 -29
- package/src/runtime/provider-request.ts +0 -87
- package/src/runtime/provider-tool-policy.ts +0 -33
- package/src/runtime/provider.ts +0 -580
- package/src/runtime/question-tool.ts +0 -62
- package/src/runtime/retry.ts +0 -447
- package/src/runtime/review-tool.ts +0 -48
- package/src/runtime/rich-text.ts +0 -36
- package/src/runtime/runtime-target.ts +0 -149
- package/src/runtime/secrets.ts +0 -79
- package/src/runtime/self-update.ts +0 -74
- package/src/runtime/session-control.ts +0 -265
- package/src/runtime/session-hub.ts +0 -85
- package/src/runtime/stream-idle.ts +0 -80
- package/src/runtime/tool-broker.ts +0 -137
- package/src/runtime/tool-discovery.ts +0 -58
- package/src/runtime/tool-queue.ts +0 -77
- package/src/runtime/tools.ts +0 -1820
- package/src/runtime/turn-effects.ts +0 -31
- package/src/runtime/update-check.ts +0 -48
- package/src/runtime/usage.ts +0 -253
- package/src/runtime/version.ts +0 -12
- package/src/runtime/web-http.ts +0 -56
- package/src/runtime/web-tools.ts +0 -88
- package/src/runtime/working-notes.ts +0 -60
- package/src/runtime/workspace-lifecycle.ts +0 -141
- package/src/store/acceptance.ts +0 -15
- package/src/store/agent-profile-files.ts +0 -13
- package/src/store/atomic.ts +0 -31
- package/src/store/auth-store.ts +0 -50
- package/src/store/blind-checks.ts +0 -32
- package/src/store/blobs.ts +0 -143
- package/src/store/checkpoint-history.ts +0 -32
- package/src/store/command-artifacts.ts +0 -96
- package/src/store/command.ts +0 -111
- package/src/store/config.ts +0 -69
- package/src/store/context-files.ts +0 -436
- package/src/store/file-checkpoints.ts +0 -108
- package/src/store/file-index.ts +0 -174
- package/src/store/foundation-config.ts +0 -24
- package/src/store/git-checkpoints.ts +0 -67
- package/src/store/git-status.ts +0 -15
- package/src/store/history-search.ts +0 -19
- package/src/store/log.ts +0 -725
- package/src/store/lsp-document.ts +0 -30
- package/src/store/mcp-credentials.ts +0 -85
- package/src/store/models.ts +0 -60
- package/src/store/observations.ts +0 -224
- package/src/store/packages.ts +0 -98
- package/src/store/patch.ts +0 -92
- package/src/store/permission-paths.ts +0 -34
- package/src/store/process-receipts.ts +0 -34
- package/src/store/query-source.ts +0 -49
- package/src/store/recovery.ts +0 -44
- package/src/store/replay.ts +0 -76
- package/src/store/resource-index.ts +0 -170
- package/src/store/resources.ts +0 -285
- package/src/store/restore.ts +0 -110
- package/src/store/review.ts +0 -109
- package/src/store/runtime-target.ts +0 -64
- package/src/store/search.ts +0 -728
- package/src/store/secrets.ts +0 -44
- package/src/store/serial.ts +0 -13
- package/src/store/session-archive.ts +0 -165
- package/src/store/session-browser.ts +0 -68
- package/src/store/session-position.ts +0 -27
- package/src/store/sessions.ts +0 -525
- package/src/store/source-cancellation.ts +0 -6
- package/src/store/tool-binaries.ts +0 -90
- package/src/store/trust.ts +0 -82
- package/src/store/update-cache.ts +0 -36
- package/src/store/user-settings.ts +0 -30
- package/src/store/workspace-clone.ts +0 -42
- package/src/store/workspace-observation.ts +0 -113
- package/src/store/workspace.ts +0 -115
- package/src/store/worktree.ts +0 -278
- package/src/tui/ansi-spans.ts +0 -126
- package/src/tui/diff.ts +0 -160
- package/src/tui/exhaustive.ts +0 -14
- package/src/tui/fuzzy.ts +0 -75
- package/src/tui/style.ts +0 -208
- package/src/tui/ui/atomic-draft.ts +0 -121
- package/src/tui/ui/branch-panel.ts +0 -47
- package/src/tui/ui/canvas.ts +0 -96
- package/src/tui/ui/colors.ts +0 -70
- package/src/tui/ui/composer.ts +0 -199
- package/src/tui/ui/control-panel.ts +0 -25
- package/src/tui/ui/control-sidebar.ts +0 -49
- package/src/tui/ui/dialog.ts +0 -398
- package/src/tui/ui/draft.ts +0 -23
- package/src/tui/ui/duration.ts +0 -16
- package/src/tui/ui/edge.ts +0 -186
- package/src/tui/ui/image-size.ts +0 -44
- package/src/tui/ui/ink.ts +0 -210
- package/src/tui/ui/items.ts +0 -42
- package/src/tui/ui/keys.ts +0 -40
- package/src/tui/ui/layout.ts +0 -74
- package/src/tui/ui/list-model.ts +0 -86
- package/src/tui/ui/list-view.ts +0 -172
- package/src/tui/ui/mascot.ts +0 -67
- package/src/tui/ui/messages.ts +0 -518
- package/src/tui/ui/motion.ts +0 -28
- package/src/tui/ui/paths.ts +0 -10
- package/src/tui/ui/pictures.ts +0 -108
- package/src/tui/ui/prompt-history.ts +0 -60
- package/src/tui/ui/screen.ts +0 -579
- package/src/tui/ui/status.ts +0 -403
- package/src/tui/ui/styled.ts +0 -85
- package/src/tui/ui/tool-card.ts +0 -150
- package/src/tui/width.ts +0 -567
- package/src/vendor/pi-rich/LICENSE.upstream +0 -21
- package/src/vendor/pi-rich/UPSTREAM.json +0 -17
- package/src/vendor/pi-rich/clipboard-command.ts +0 -44
- package/src/vendor/pi-rich/exif-orientation.ts +0 -182
- package/src/vendor/pi-rich/html.ts +0 -51
- package/src/vendor/pi-rich/image-convert.ts +0 -49
- package/src/vendor/pi-rich/image-resize-core.ts +0 -164
- package/src/vendor/pi-rich/image-resize-worker.ts +0 -42
- package/src/vendor/pi-rich/image-resize.ts +0 -123
- package/src/vendor/pi-rich/mime.ts +0 -116
- package/src/vendor/pi-rich/photon.ts +0 -139
- package/src/vendor/pi-rich/syntax-highlight.ts +0 -214
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/** P.3: execution owns checkpoints; session opening owns no filesystem baseline. */
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
import type { CheckpointEvent, FileVersion, FileChanges, WorkspaceObservationEvent } from "../core/checkpoints.ts";
|
|
4
|
-
import { sameVersion } from "../core/checkpoints.ts";
|
|
5
|
-
import { blobAddress } from "../store/blobs.ts";
|
|
6
|
-
import { archiveEdit, replaceFile, readEditableFile } from "../store/file-checkpoints.ts";
|
|
7
|
-
import { GitCheckpoints, type GitCheckpoint } from "../store/git-checkpoints.ts";
|
|
8
|
-
import { observeWorkspace } from "../store/workspace-observation.ts";
|
|
9
|
-
import type { ToolResult } from "./tools.ts";
|
|
10
|
-
import type { JsonValue } from "../core/tool-contract.ts";
|
|
11
|
-
|
|
12
|
-
type Record = Omit<CheckpointEvent, "id" | "at"> | Omit<WorkspaceObservationEvent, "id" | "at">;
|
|
13
|
-
interface CommandCheckpoint { operation: string; snapshot?: GitCheckpoint; unavailable?: string; }
|
|
14
|
-
export class WorkspaceLifecycle {
|
|
15
|
-
readonly root: string;
|
|
16
|
-
readonly blobs: string;
|
|
17
|
-
readonly shellCheckpoints: boolean;
|
|
18
|
-
private readonly record: (event: Record) => Promise<void>;
|
|
19
|
-
private readonly ownedPaths: readonly string[];
|
|
20
|
-
private readonly git: GitCheckpoints;
|
|
21
|
-
private readonly pending = new Map<number, CommandCheckpoint>();
|
|
22
|
-
private fingerprint: string | undefined;
|
|
23
|
-
constructor(root: string, blobs: string, shellCheckpoints: boolean, record: (event: Record) => Promise<void>, checkpointStorage = blobs, ownedPaths: readonly string[] = []) {
|
|
24
|
-
this.root = root; this.blobs = blobs; this.shellCheckpoints = shellCheckpoints; this.record = record;
|
|
25
|
-
this.ownedPaths = ownedPaths;
|
|
26
|
-
this.git = new GitCheckpoints(root, checkpointStorage, ownedPaths);
|
|
27
|
-
}
|
|
28
|
-
private interfere(): void {
|
|
29
|
-
for (const checkpoint of this.pending.values()) checkpoint.unavailable = "overlapping mutations prevent attributing a command checkpoint";
|
|
30
|
-
}
|
|
31
|
-
async patch(changes: FileChanges, execute: () => Promise<void>, signal?: AbortSignal): Promise<void> {
|
|
32
|
-
signal?.throwIfAborted(); this.interfere();
|
|
33
|
-
const operation = randomUUID();
|
|
34
|
-
await this.record({ t: "checkpoint", operation, source: "edit", phase: "prepared", changes });
|
|
35
|
-
try {
|
|
36
|
-
await execute();
|
|
37
|
-
for (const [path, change] of Object.entries(changes)) if (!sameVersion((await readEditableFile(this.root, path)).version, change.after)) throw Error(`file changed concurrently after patch: ${path}`);
|
|
38
|
-
await this.record({ t: "checkpoint", operation, source: "edit", phase: "applied", changes });
|
|
39
|
-
} catch (error) {
|
|
40
|
-
await this.record({ t: "checkpoint", operation, source: "edit", phase: "unavailable", changes, reason: "patch did not establish the expected versions; inspect before retrying" });
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
async edit(path: string, before: { bytes: Uint8Array | null; version: FileVersion }, after: Uint8Array, signal?: AbortSignal): Promise<void> {
|
|
45
|
-
this.interfere();
|
|
46
|
-
await archiveEdit(this.blobs, before.bytes, after);
|
|
47
|
-
const operation = randomUUID();
|
|
48
|
-
const next = { sha256: blobAddress(after), mode: before.version?.mode ?? (0o666 & ~process.umask()) };
|
|
49
|
-
const changes = { [path]: { before: before.version, after: next } };
|
|
50
|
-
await this.record({ t: "checkpoint", operation, source: "edit", phase: "prepared", changes });
|
|
51
|
-
try {
|
|
52
|
-
await replaceFile(this.root, path, before.version, after, next.mode, signal);
|
|
53
|
-
const actual = (await readEditableFile(this.root, path)).version;
|
|
54
|
-
if (!sameVersion(actual, next)) throw new Error(`file changed concurrently after editing: ${path}`);
|
|
55
|
-
await this.record({ t: "checkpoint", operation, source: "edit", phase: "applied", changes });
|
|
56
|
-
} catch (error) {
|
|
57
|
-
await this.record({ t: "checkpoint", operation, source: "edit", phase: "unavailable", changes,
|
|
58
|
-
reason: "edit did not establish the expected file version; inspect before retrying" });
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async command(name: string, input: unknown, execute: () => Promise<ToolResult>, signal?: AbortSignal): Promise<ToolResult> {
|
|
63
|
-
const args = input as { session_id?: number };
|
|
64
|
-
let checkpoint: CommandCheckpoint | undefined;
|
|
65
|
-
if (name === "write_stdin") checkpoint = args.session_id === undefined ? undefined : this.pending.get(args.session_id);
|
|
66
|
-
else {
|
|
67
|
-
this.interfere();
|
|
68
|
-
if (this.shellCheckpoints) {
|
|
69
|
-
checkpoint = { operation: randomUUID() };
|
|
70
|
-
try {
|
|
71
|
-
if (this.pending.size) throw new Error("another command is still running");
|
|
72
|
-
checkpoint.snapshot = await this.git.capture(signal);
|
|
73
|
-
await this.record({ t: "checkpoint", operation: checkpoint.operation, source: "git", phase: "prepared", changes: {}, tree: checkpoint.snapshot.tree });
|
|
74
|
-
} catch (error) { checkpoint.unavailable = error instanceof Error ? error.message : "Git checkpoint unavailable"; }
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const result = await execute();
|
|
78
|
-
if (!checkpoint) return result;
|
|
79
|
-
const data = (result.data && typeof result.data === "object" && !Array.isArray(result.data) ? result.data : {}) as { readonly [key: string]: JsonValue };
|
|
80
|
-
const session = data["session_id"];
|
|
81
|
-
if (data["running"] === true && typeof session === "number") {
|
|
82
|
-
this.pending.set(session, checkpoint);
|
|
83
|
-
return { ...result, data: { ...data, checkpoint: "pending" } };
|
|
84
|
-
}
|
|
85
|
-
if (typeof args.session_id === "number") this.pending.delete(args.session_id);
|
|
86
|
-
try {
|
|
87
|
-
if (checkpoint.unavailable || !checkpoint.snapshot) throw new Error(checkpoint.unavailable ?? "missing command baseline");
|
|
88
|
-
const snapshot = await this.git.capture(signal);
|
|
89
|
-
const changes = await this.git.changes(checkpoint.snapshot, snapshot, this.blobs, signal);
|
|
90
|
-
await this.record({ t: "checkpoint", operation: checkpoint.operation, source: "git", phase: "applied", changes, tree: snapshot.tree });
|
|
91
|
-
return { ...result, data: { ...data, checkpoint: "captured" } };
|
|
92
|
-
} catch (error) {
|
|
93
|
-
const reason = error instanceof Error ? error.message : "Git checkpoint unavailable";
|
|
94
|
-
await this.record({ t: "checkpoint", operation: checkpoint.operation, source: "git", phase: "unavailable", changes: {}, reason });
|
|
95
|
-
return { ...result, content: `${result.content}\nFile recovery unavailable: ${reason}. The command result is unchanged.`, data: { ...data, checkpoint: "unavailable" } };
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async abandonCommands(): Promise<void> {
|
|
99
|
-
for (const checkpoint of this.pending.values()) await this.record({ t: "checkpoint", operation: checkpoint.operation,
|
|
100
|
-
source: "git", phase: "unavailable", changes: {}, reason: "process ended without an observed checkpoint boundary" });
|
|
101
|
-
this.pending.clear();
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* A full source snapshot through the private Git checkpoint store, or null
|
|
105
|
-
* where Git checkpoints cannot run (not a Git working directory, over
|
|
106
|
-
* budget). Never touches the user's HEAD, index or stash (P.3).
|
|
107
|
-
*/
|
|
108
|
-
async snapshot(signal?: AbortSignal): Promise<GitCheckpoint | null> {
|
|
109
|
-
try { return await this.git.capture(signal); } catch { return null; }
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** What changed between two snapshots, with both versions' bytes in the blob store. */
|
|
113
|
-
async snapshotChanges(before: GitCheckpoint, after: GitCheckpoint, signal?: AbortSignal): Promise<FileChanges> {
|
|
114
|
-
return this.git.changes(before, after, this.blobs, signal);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Records the workspace as a goal request begins, always: the state a
|
|
119
|
-
* counter-check must rebuild exactly before it may run (feat-counter-check).
|
|
120
|
-
*/
|
|
121
|
-
async baseline(signal?: AbortSignal): Promise<void> {
|
|
122
|
-
const observation = await observeWorkspace(this.root, signal, this.ownedPaths);
|
|
123
|
-
const fingerprint = observation.ok ? observation.fingerprint : undefined;
|
|
124
|
-
await this.record({ t: "workspace_observation", scope: "source-v1", baseline: true,
|
|
125
|
-
changed: !observation.ok || this.fingerprint !== undefined && fingerprint !== this.fingerprint,
|
|
126
|
-
...(observation.ok ? { fingerprint: observation.fingerprint } : { reason: observation.reason }) });
|
|
127
|
-
this.fingerprint = fingerprint;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async observe(previous?: string, signal?: AbortSignal): Promise<void> {
|
|
131
|
-
const observation = await observeWorkspace(this.root, signal, this.ownedPaths);
|
|
132
|
-
const fingerprint = observation.ok ? observation.fingerprint : undefined;
|
|
133
|
-
// S.1: an observation identical to the last known fingerprint adds no fact.
|
|
134
|
-
// Failures, a first look without a baseline, and changes are still recorded.
|
|
135
|
-
const known = previous ?? this.fingerprint;
|
|
136
|
-
if (fingerprint !== undefined && known !== undefined && fingerprint === known) { this.fingerprint = fingerprint; return; }
|
|
137
|
-
await this.record({ t: "workspace_observation", scope: "source-v1", changed: !observation.ok || (previous ?? this.fingerprint) !== undefined && fingerprint !== (previous ?? this.fingerprint),
|
|
138
|
-
...(observation.ok ? { fingerprint: observation.fingerprint } : { reason: observation.reason }) });
|
|
139
|
-
this.fingerprint = fingerprint;
|
|
140
|
-
}
|
|
141
|
-
}
|
package/src/store/acceptance.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** Explicit files or trusted project declarations; never infer natural-language criteria. */
|
|
2
|
-
import { join, resolve } from "node:path";
|
|
3
|
-
import { parseAcceptanceContract, type AcceptanceContract } from "../core/acceptance.ts";
|
|
4
|
-
import { blobAddress } from "./blobs.ts";
|
|
5
|
-
|
|
6
|
-
export async function loadAcceptanceContract(workspace: string, trusted: boolean, explicit?: string): Promise<AcceptanceContract | undefined> {
|
|
7
|
-
if (!explicit && !trusted) return undefined;
|
|
8
|
-
const path = explicit ? resolve(workspace, explicit) : join(workspace, ".xeno", "acceptance.json");
|
|
9
|
-
const file = Bun.file(path);
|
|
10
|
-
if (!await file.exists()) { if (explicit) throw new Error(`missing acceptance file: ${path}`); return undefined; }
|
|
11
|
-
if (file.size > 64000) throw new Error("acceptance file exceeds 64 KiB");
|
|
12
|
-
const text = await file.text();
|
|
13
|
-
const contract = parseAcceptanceContract(JSON.parse(text));
|
|
14
|
-
return { ...contract, scope: contract.scope ?? (explicit ? "request" : "changes"), source: { path, sha256: blobAddress(text) } };
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** R13: profile files are inert JSON; project trust is decided by the app. */
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
export async function readAgentProfileFile(path: string): Promise<{ value: unknown; diagnostic?: string } | null> {
|
|
5
|
-
let body: string;
|
|
6
|
-
try { body = await readFile(path, "utf8"); }
|
|
7
|
-
catch (error) {
|
|
8
|
-
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return null;
|
|
9
|
-
return { value: null, diagnostic: `${path}: unable to read agents configuration` };
|
|
10
|
-
}
|
|
11
|
-
try { return { value: JSON.parse(body) as unknown }; }
|
|
12
|
-
catch { return { value: null, diagnostic: `${path}: invalid JSON in agents configuration` }; }
|
|
13
|
-
}
|
package/src/store/atomic.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/** Durable replacement for small derived metadata (D3/D8). */
|
|
2
|
-
import { mkdir, open, rename, rm } from "node:fs/promises";
|
|
3
|
-
import { dirname, join, basename } from "node:path";
|
|
4
|
-
import { randomUUID } from "node:crypto";
|
|
5
|
-
|
|
6
|
-
export async function atomicWrite(path: string, content: string | Uint8Array): Promise<void> {
|
|
7
|
-
const directory = dirname(path);
|
|
8
|
-
await mkdir(directory, { recursive: true });
|
|
9
|
-
const temporary = join(directory, `.${basename(path)}.${randomUUID()}.tmp`);
|
|
10
|
-
try {
|
|
11
|
-
const file = await open(temporary, "wx", 0o600);
|
|
12
|
-
try {
|
|
13
|
-
await file.writeFile(content);
|
|
14
|
-
await file.sync();
|
|
15
|
-
} finally { await file.close(); }
|
|
16
|
-
await rename(temporary, path);
|
|
17
|
-
const folder = await open(directory, "r");
|
|
18
|
-
try { await folder.sync(); } finally { await folder.close(); }
|
|
19
|
-
} finally {
|
|
20
|
-
await rm(temporary, { force: true });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** The record must reach durable storage before its side effect is dispatched. */
|
|
25
|
-
export async function durableAppend(path: string, record: string): Promise<void> {
|
|
26
|
-
const file = await open(path, "a", 0o600);
|
|
27
|
-
try { await file.writeFile(record); await file.sync(); }
|
|
28
|
-
finally { await file.close(); }
|
|
29
|
-
const directory = await open(dirname(path), "r");
|
|
30
|
-
try { await directory.sync(); } finally { await directory.close(); }
|
|
31
|
-
}
|
package/src/store/auth-store.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Read-modify-write for `auth.json`.
|
|
3
|
-
*
|
|
4
|
-
* The file holds API keys and OAuth tokens under one lock so a refresh cannot
|
|
5
|
-
* clobber a login that landed between the read and the write. 0600 is applied
|
|
6
|
-
* on every write -- an older world-readable file would otherwise keep leaking
|
|
7
|
-
* after we started storing refresh tokens in it.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { authPath, readJsonFile, writeJsonFile } from "./config.ts";
|
|
11
|
-
|
|
12
|
-
export type StoredAuthEntry =
|
|
13
|
-
| { type: "api_key"; key: string }
|
|
14
|
-
| {
|
|
15
|
-
type: "oauth";
|
|
16
|
-
access: string;
|
|
17
|
-
refresh: string;
|
|
18
|
-
expires: number;
|
|
19
|
-
accountId?: string;
|
|
20
|
-
enterpriseUrl?: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type AuthFileContents = {
|
|
24
|
-
[provider: string]: StoredAuthEntry | undefined;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export async function readAuthFile(): Promise<AuthFileContents> {
|
|
28
|
-
const got = await readJsonFile<AuthFileContents>(authPath());
|
|
29
|
-
return got.value ?? {};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function writeAuthFile(auth: AuthFileContents): Promise<void> {
|
|
33
|
-
await writeJsonFile(authPath(), auth, true);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function upsertCredential(
|
|
37
|
-
provider: string,
|
|
38
|
-
credential: StoredAuthEntry,
|
|
39
|
-
): Promise<void> {
|
|
40
|
-
const current = await readAuthFile();
|
|
41
|
-
const next: AuthFileContents = { ...current, [provider]: credential };
|
|
42
|
-
await writeAuthFile(next);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function deleteCredential(provider: string): Promise<void> {
|
|
46
|
-
const current = await readAuthFile();
|
|
47
|
-
const next: AuthFileContents = { ...current };
|
|
48
|
-
delete next[provider];
|
|
49
|
-
await writeAuthFile(next);
|
|
50
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reading a blind check directory (feat-blind-checks). It must sit outside
|
|
3
|
-
* the workspace -- a check inside it is a file the model can open -- and is
|
|
4
|
-
* frozen into the session with every file's digest, so a resumed session
|
|
5
|
-
* runs exactly the checks it started with.
|
|
6
|
-
*/
|
|
7
|
-
import { readdir, readFile, realpath, stat } from "node:fs/promises";
|
|
8
|
-
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
9
|
-
import { BLIND_BYTES_LIMIT, BLIND_FILE_LIMIT, parseBlindManifest, type BlindChecks } from "../core/blind-checks.ts";
|
|
10
|
-
import { blobAddress } from "./blobs.ts";
|
|
11
|
-
|
|
12
|
-
export async function loadBlindChecks(dir: string, workspace: string): Promise<BlindChecks> {
|
|
13
|
-
const given = resolve(workspace, dir), root = await realpath(given), work = await realpath(workspace);
|
|
14
|
-
const inside = relative(work, root);
|
|
15
|
-
if (inside === "" || !inside.startsWith("..") && !isAbsolute(inside)) throw Error("--blind-checks must be outside the workspace, where the model cannot read it");
|
|
16
|
-
const files: Record<string, string> = {};
|
|
17
|
-
let bytes = 0;
|
|
18
|
-
const walk = async (path: string): Promise<void> => {
|
|
19
|
-
for (const entry of await readdir(path, { withFileTypes: true })) {
|
|
20
|
-
const full = join(path, entry.name), rel = relative(root, full);
|
|
21
|
-
if (entry.isDirectory()) { await walk(full); continue; }
|
|
22
|
-
if (!entry.isFile()) throw Error(`blind check ${rel} is not a regular file`);
|
|
23
|
-
if (Object.keys(files).length >= BLIND_FILE_LIMIT) throw Error(`--blind-checks holds more than ${BLIND_FILE_LIMIT} files`);
|
|
24
|
-
bytes += (await stat(full)).size;
|
|
25
|
-
if (bytes > BLIND_BYTES_LIMIT) throw Error(`--blind-checks holds more than ${BLIND_BYTES_LIMIT} bytes`);
|
|
26
|
-
files[rel] = blobAddress(await readFile(full));
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
await walk(root);
|
|
30
|
-
const manifest = parseBlindManifest(JSON.parse(await readFile(join(root, "blind.json"), "utf8")));
|
|
31
|
-
return { dir: root, aliases: given === root ? [] : [given], manifest, files };
|
|
32
|
-
}
|
package/src/store/blobs.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Content-addressed blob store.
|
|
3
|
-
*
|
|
4
|
-
* A directory of sha256-named files, sharded two hex digits deep so no single
|
|
5
|
-
* directory holds every blob. Writes are immutable: the same bytes always land
|
|
6
|
-
* at the same address, so storing a file twice costs nothing and a stored blob
|
|
7
|
-
* is never modified in place.
|
|
8
|
-
*
|
|
9
|
-
* Why not git's object database, which is exactly this and comes free with
|
|
10
|
-
* every repository: git's lifetime contract is REACHABILITY. A blob with no
|
|
11
|
-
* ref pointing at it is by definition unreachable, which is precisely what
|
|
12
|
-
* `git gc` deletes -- and gc runs automatically on pull, merge, rebase and
|
|
13
|
-
* commit. The default two-week grace period would be the only thing between a
|
|
14
|
-
* restore and data loss, and a write-heavy store also trips git's
|
|
15
|
-
* "too many unreachable loose objects" warning, after which git refuses
|
|
16
|
-
* further automatic cleanup until its log is cleared by hand. Keeping a ref
|
|
17
|
-
* per blob is more work than this file, and it would tie the lifetime of our
|
|
18
|
-
* data to the user's git operations.
|
|
19
|
-
*
|
|
20
|
-
* What that costs: no packing and no delta compression, so a large file
|
|
21
|
-
* edited many times is stored in full each time. Acceptable while the
|
|
22
|
-
* granularity is a turn rather than a keystroke, and revisitable behind this
|
|
23
|
-
* interface if it stops being.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import { readFile, access, mkdir, open, rename, rm, copyFile, stat, chmod } from "node:fs/promises";
|
|
27
|
-
import { createReadStream } from "node:fs";
|
|
28
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
29
|
-
import { join, dirname } from "node:path";
|
|
30
|
-
import { atomicWrite } from "./atomic.ts";
|
|
31
|
-
|
|
32
|
-
export function blobAddress(content: string | Uint8Array): string {
|
|
33
|
-
return createHash("sha256").update(content).digest("hex");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Hash and archive in bounded chunks, so large ordinary files need no cap. */
|
|
37
|
-
export async function digestFile(path: string): Promise<string> {
|
|
38
|
-
const hash = createHash("sha256");
|
|
39
|
-
for await (const chunk of createReadStream(path)) hash.update(chunk as Uint8Array);
|
|
40
|
-
return hash.digest("hex");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export async function putFileBlob(dir: string, source: string): Promise<string> {
|
|
44
|
-
await mkdir(dir, { recursive: true });
|
|
45
|
-
const temp = join(dir, `.${randomUUID()}.blob`);
|
|
46
|
-
const file = await open(temp, "wx", 0o600);
|
|
47
|
-
const hash = createHash("sha256");
|
|
48
|
-
try {
|
|
49
|
-
try {
|
|
50
|
-
for await (const chunk of createReadStream(source)) {
|
|
51
|
-
const bytes = chunk as Uint8Array;
|
|
52
|
-
hash.update(bytes);
|
|
53
|
-
await file.writeFile(bytes);
|
|
54
|
-
}
|
|
55
|
-
await file.sync();
|
|
56
|
-
} finally { await file.close(); }
|
|
57
|
-
const sha = hash.digest("hex");
|
|
58
|
-
const dest = blobFilePath(dir, sha);
|
|
59
|
-
if (await hasBlob(dir, sha)) {
|
|
60
|
-
if (await digestFile(dest) !== sha) throw new Error(`blob integrity failure: ${sha}`);
|
|
61
|
-
return sha;
|
|
62
|
-
}
|
|
63
|
-
await mkdir(dirname(dest), { recursive: true });
|
|
64
|
-
await rename(temp, dest);
|
|
65
|
-
const parent = await open(dirname(dest), "r");
|
|
66
|
-
try { await parent.sync(); } finally { await parent.close(); }
|
|
67
|
-
return sha;
|
|
68
|
-
} finally { await rm(temp, { force: true }); }
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export async function verifyBlob(dir: string, sha: string): Promise<boolean> {
|
|
72
|
-
try {
|
|
73
|
-
if (await digestFile(blobFilePath(dir, sha)) !== sha) throw new Error(`blob integrity failure: ${sha}`);
|
|
74
|
-
return true;
|
|
75
|
-
} catch (error) {
|
|
76
|
-
if ((error as { code?: string }).code === "ENOENT") return false;
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** Stage before replacing; never expose half of a large restored file. */
|
|
82
|
-
export async function restoreBlob(dir: string, sha: string, destination: string): Promise<void> {
|
|
83
|
-
await mkdir(dirname(destination), { recursive: true });
|
|
84
|
-
const temp = `${destination}.${randomUUID()}.restore`;
|
|
85
|
-
try {
|
|
86
|
-
await copyFile(blobFilePath(dir, sha), temp);
|
|
87
|
-
if (await digestFile(temp) !== sha) throw new Error(`blob integrity failure: ${sha}`);
|
|
88
|
-
try { await chmod(temp, (await stat(destination)).mode); }
|
|
89
|
-
catch (error) { if ((error as { code?: string }).code !== "ENOENT") throw error; }
|
|
90
|
-
const file = await open(temp, "r");
|
|
91
|
-
try { await file.sync(); } finally { await file.close(); }
|
|
92
|
-
await rename(temp, destination);
|
|
93
|
-
} finally { await rm(temp, { force: true }); }
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function blobFilePath(dir: string, sha: string): string {
|
|
97
|
-
if (!/^[a-f0-9]{64}$/.test(sha)) throw new Error("invalid blob digest");
|
|
98
|
-
// Two-digit shard: a flat directory of tens of thousands of files is slow
|
|
99
|
-
// to list on most filesystems, and listing is how a human inspects this.
|
|
100
|
-
return join(dir, sha.slice(0, 2), sha.slice(2));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** Stores content and returns its address. Storing the same bytes twice is free. */
|
|
104
|
-
export async function putBlob(dir: string, content: string | Uint8Array): Promise<string> {
|
|
105
|
-
const sha = blobAddress(content);
|
|
106
|
-
const path = blobFilePath(dir, sha);
|
|
107
|
-
// Content addressing means an existing blob already holds these exact
|
|
108
|
-
// bytes, so rewriting it could only turn a good file into a torn one.
|
|
109
|
-
if (await hasBlob(dir, sha)) {
|
|
110
|
-
await getBlobBytes(dir, sha);
|
|
111
|
-
return sha;
|
|
112
|
-
}
|
|
113
|
-
await atomicWrite(path, content);
|
|
114
|
-
return sha;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** Null rather than throwing: a missing blob is a state callers must handle. */
|
|
118
|
-
export async function getBlob(dir: string, sha: string): Promise<string | null> {
|
|
119
|
-
const bytes = await getBlobBytes(dir, sha);
|
|
120
|
-
return bytes === null ? null : Buffer.from(bytes).toString("utf8");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** Restore uses bytes; decoding binary data is an irreversible transformation. */
|
|
124
|
-
export async function getBlobBytes(dir: string, sha: string, maxBytes?: number): Promise<Uint8Array | null> {
|
|
125
|
-
try {
|
|
126
|
-
if (maxBytes !== undefined && (await stat(blobFilePath(dir, sha))).size > maxBytes) throw new RangeError("Blob exceeds byte limit");
|
|
127
|
-
const bytes = await readFile(blobFilePath(dir, sha));
|
|
128
|
-
if (blobAddress(bytes) !== sha) throw new Error(`blob integrity failure: ${sha}`);
|
|
129
|
-
return bytes;
|
|
130
|
-
} catch (err) {
|
|
131
|
-
if ((err as { code?: string }).code === "ENOENT") return null;
|
|
132
|
-
throw err;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export async function hasBlob(dir: string, sha: string): Promise<boolean> {
|
|
137
|
-
try {
|
|
138
|
-
await access(blobFilePath(dir, sha));
|
|
139
|
-
return true;
|
|
140
|
-
} catch {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/** File ancestry is independent of model-context ancestry (P.3). */
|
|
2
|
-
import { readNodeHistory, type RestoreTarget } from "./restore.ts";
|
|
3
|
-
import { planFileTransition, type CheckpointEvent, type FileChanges } from "../core/checkpoints.ts";
|
|
4
|
-
|
|
5
|
-
export async function checkpointHistory(dir: string, target: RestoreTarget, visited = new Set<string>()): Promise<CheckpointEvent[]> {
|
|
6
|
-
const position = typeof target === "number" ? { node: target } : target;
|
|
7
|
-
const key = `${position.node}:${position.atEvent ?? "end"}`;
|
|
8
|
-
if (visited.has(key) || visited.size >= 256) throw new Error("cyclic or excessively deep file history");
|
|
9
|
-
const next = new Set(visited).add(key);
|
|
10
|
-
const history = await readNodeHistory(dir, position.node);
|
|
11
|
-
if (!history.ok) throw new Error(history.error);
|
|
12
|
-
let checkpoints: CheckpointEvent[] = [];
|
|
13
|
-
for (const node of history.nodes) {
|
|
14
|
-
let events = node.events;
|
|
15
|
-
if (node.node === position.node && position.atEvent !== undefined) {
|
|
16
|
-
const at = events.findIndex(event => event.id === position.atEvent);
|
|
17
|
-
if (at < 0) throw new Error(`NO_SUCH_EVENT: ${position.atEvent}`);
|
|
18
|
-
events = events.slice(0, at + 1);
|
|
19
|
-
}
|
|
20
|
-
for (const event of events) {
|
|
21
|
-
if (event.t === "rewind" && event.files_from) {
|
|
22
|
-
checkpoints = await checkpointHistory(dir, { node: event.files_from.node,
|
|
23
|
-
...(event.files_from.at_event ? { atEvent: event.files_from.at_event } : {}) }, next);
|
|
24
|
-
} else if (event.t === "checkpoint") checkpoints.push(event);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return checkpoints;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function planCheckpointRestore(dir: string, current: RestoreTarget, target: RestoreTarget): Promise<FileChanges> {
|
|
31
|
-
return planFileTransition(await checkpointHistory(dir, current), await checkpointHistory(dir, target));
|
|
32
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/** R8: bounded observations over file descriptors; binaries themselves are not copied into the log. */
|
|
2
|
-
import { constants } from "node:fs";
|
|
3
|
-
import { lstat, open, realpath } from "node:fs/promises";
|
|
4
|
-
import { resolve, join, relative, sep } from "node:path";
|
|
5
|
-
import { createHash } from "node:crypto";
|
|
6
|
-
import { MAX_COMMAND_ARTIFACT_BYTES, COMMAND_ARTIFACT_SCOPE, sameArtifactIdentity, validArtifactPath,
|
|
7
|
-
type ArtifactFile, type ArtifactFileIdentity, type CommandArtifactPlan } from "../core/command-artifacts.ts";
|
|
8
|
-
import { archiveObservation } from "./observations.ts";
|
|
9
|
-
import { observeWorkspace, SOURCE_IGNORE } from "./workspace-observation.ts";
|
|
10
|
-
import { blobAddress } from "./blobs.ts";
|
|
11
|
-
|
|
12
|
-
// Assumed per-phase bounds, not performance measurements; exhaustion yields unknown.
|
|
13
|
-
const OBSERVATION_MS = 10_000;
|
|
14
|
-
const CHUNK_BYTES = 1024 * 1024;
|
|
15
|
-
type IdentityStat = { dev: bigint; ino: bigint; mtimeNs: bigint; ctimeNs: bigint; mode: bigint };
|
|
16
|
-
const identity = (info: IdentityStat): ArtifactFileIdentity => ({ device: String(info.dev), inode: String(info.ino),
|
|
17
|
-
mtime_ns: String(info.mtimeNs), ctime_ns: String(info.ctimeNs), mode: Number(info.mode) & 0o777 });
|
|
18
|
-
|
|
19
|
-
/** Both walks reject symlink components. This is a local observation, not an OS sandbox against hostile concurrent renames. */
|
|
20
|
-
async function ordinaryPath(root: string, path: string): Promise<string> {
|
|
21
|
-
let current = root;
|
|
22
|
-
const parts = path.split("/");
|
|
23
|
-
for (let i = 0; i < parts.length; i++) {
|
|
24
|
-
current = join(current, parts[i]!);
|
|
25
|
-
const info = await lstat(current);
|
|
26
|
-
if (info.isSymbolicLink() || (i === parts.length - 1 ? !info.isFile() : !info.isDirectory())) throw Object.assign(new Error("not an ordinary confined file"), { code: "EUNSAFE" });
|
|
27
|
-
}
|
|
28
|
-
if (await realpath(current) !== current) throw Object.assign(new Error("file path changed or follows a symlink"), { code: "EUNSAFE" });
|
|
29
|
-
return current;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function artifactExclusions(root: string, plan: CommandArtifactPlan, ownedPaths: readonly string[] = []): string[] {
|
|
33
|
-
const owned = ownedPaths.map(path => relative(resolve(root), resolve(path)))
|
|
34
|
-
.filter(path => path && path !== ".." && !path.startsWith(`..${sep}`) && !path.startsWith(sep) && !path.split(sep).some(part => SOURCE_IGNORE.includes(part)));
|
|
35
|
-
return [...new Set([...plan.output_roots, ...owned])].sort();
|
|
36
|
-
}
|
|
37
|
-
export async function observeArtifactInputs(root: string, exclusions: readonly string[], signal?: AbortSignal): Promise<{ sha256: string | null; reason?: string }> {
|
|
38
|
-
const bounded = AbortSignal.any([AbortSignal.timeout(OBSERVATION_MS), ...(signal ? [signal] : [])]);
|
|
39
|
-
const result = await observeWorkspace(root, bounded, exclusions.map(path => resolve(root, path)));
|
|
40
|
-
// A digest binds the declared finite scope as well as its bytes; it is never source-v1 evidence.
|
|
41
|
-
return result.ok && !bounded.aborted ? { sha256: blobAddress(JSON.stringify([COMMAND_ARTIFACT_SCOPE, SOURCE_IGNORE, exclusions, result.fingerprint])) }
|
|
42
|
-
: { sha256: null, reason: result.ok ? "input observation cancelled or timed out" : result.reason };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function observeArtifactFiles(root: string, paths: readonly string[], signal?: AbortSignal): Promise<ArtifactFile[]> {
|
|
46
|
-
const bounded = AbortSignal.any([AbortSignal.timeout(OBSERVATION_MS), ...(signal ? [signal] : [])]);
|
|
47
|
-
let remaining = MAX_COMMAND_ARTIFACT_BYTES;
|
|
48
|
-
const results: ArtifactFile[] = [];
|
|
49
|
-
let base: string;
|
|
50
|
-
try { base = await realpath(root); } catch { return paths.map(() => ({ state: "unknown", reason: "workspace unavailable" })); }
|
|
51
|
-
for (const path of paths) {
|
|
52
|
-
if (!validArtifactPath(path)) { results.push({ state: "unsafe", reason: "invalid workspace artifact path" }); continue; }
|
|
53
|
-
if (bounded.aborted) { results.push({ state: "unknown", reason: "artifact observation cancelled or timed out" }); continue; }
|
|
54
|
-
try {
|
|
55
|
-
const absolute = await ordinaryPath(base, path);
|
|
56
|
-
// O_NONBLOCK prevents a concurrent FIFO replacement from hanging before fstat rejects it.
|
|
57
|
-
const file = await open(absolute, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
58
|
-
try {
|
|
59
|
-
const before = await file.stat({ bigint: true });
|
|
60
|
-
if (!before.isFile()) { results.push({ state: "unsafe", reason: "opened object is not an ordinary file" }); continue; }
|
|
61
|
-
if (before.size > BigInt(remaining)) { results.push({ state: "unknown", reason: "artifact byte budget exceeded" }); continue; }
|
|
62
|
-
const limit = Number(before.size), buffer = Buffer.alloc(Math.min(CHUNK_BYTES, Math.max(1, limit + 1))), hash = createHash("sha256");
|
|
63
|
-
let bytes = 0, failed = false;
|
|
64
|
-
for (;;) {
|
|
65
|
-
if (bounded.aborted) { results.push({ state: "unknown", reason: "artifact observation cancelled or timed out" }); failed = true; break; }
|
|
66
|
-
const read = await file.read(buffer, 0, Math.min(buffer.length, limit + 1 - bytes), bytes);
|
|
67
|
-
bytes += read.bytesRead;
|
|
68
|
-
remaining -= read.bytesRead;
|
|
69
|
-
if (bytes > limit) { results.push({ state: "changed", reason: "file grew during observation" }); failed = true; break; }
|
|
70
|
-
if (read.bytesRead === 0) break;
|
|
71
|
-
hash.update(buffer.subarray(0, read.bytesRead));
|
|
72
|
-
}
|
|
73
|
-
if (failed) continue;
|
|
74
|
-
const after = await file.stat({ bigint: true });
|
|
75
|
-
await ordinaryPath(base, path);
|
|
76
|
-
const named = await lstat(absolute, { bigint: true });
|
|
77
|
-
if (bytes !== Number(before.size) || after.size !== before.size || named.size !== before.size ||
|
|
78
|
-
!sameArtifactIdentity(identity(before), identity(after)) || !sameArtifactIdentity(identity(after), identity(named))) {
|
|
79
|
-
results.push({ state: "changed", reason: "file contents or identity changed during observation" }); continue;
|
|
80
|
-
}
|
|
81
|
-
results.push({ state: "observed", sha256: hash.digest("hex"), bytes, identity: identity(after) });
|
|
82
|
-
} finally { await file.close(); }
|
|
83
|
-
} catch (error) {
|
|
84
|
-
const code = (error as { code?: string }).code;
|
|
85
|
-
results.push(code === "ENOENT" || code === "ENOTDIR" ? { state: "missing", reason: "artifact path was not found" }
|
|
86
|
-
: code === "EUNSAFE" || code === "ELOOP" ? { state: "unsafe", reason: "artifact path is not an ordinary confined file" }
|
|
87
|
-
: { state: "unknown", reason: "artifact file could not be observed" });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return results;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export async function archiveCommandArtifacts(outputStore: string, observation: unknown) {
|
|
94
|
-
async function* bytes() { yield new TextEncoder().encode(JSON.stringify(observation)); }
|
|
95
|
-
return (await archiveObservation(outputStore, bytes(), 0)).ref;
|
|
96
|
-
}
|