@visual-z/xeno 0.8.4 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -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
package/src/store/secrets.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The per-session vault behind `[[xeno-secret-N]]` placeholders (S.9).
|
|
3
|
-
*
|
|
4
|
-
* A separate append-only file, never a log event: projections, handoffs,
|
|
5
|
-
* exports and history pages read the log, so a value kept here cannot reach a
|
|
6
|
-
* model request or a shared transcript. 0600 like every session file. It is
|
|
7
|
-
* read back at start so a placeholder written by an earlier run still expands
|
|
8
|
-
* after a restart.
|
|
9
|
-
*/
|
|
10
|
-
import { copyFile, readFile } from "node:fs/promises";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
import { durableAppend } from "./atomic.ts";
|
|
13
|
-
import type { SecretEntry } from "../core/secrets.ts";
|
|
14
|
-
|
|
15
|
-
export const SECRETS_FILE = "secrets.jsonl";
|
|
16
|
-
|
|
17
|
-
export async function readVault(dir: string): Promise<SecretEntry[]> {
|
|
18
|
-
let text: string;
|
|
19
|
-
try { text = await readFile(join(dir, SECRETS_FILE), "utf8"); }
|
|
20
|
-
catch (error) { if ((error as { code?: string }).code === "ENOENT") return []; throw error; }
|
|
21
|
-
const entries: SecretEntry[] = [];
|
|
22
|
-
for (const line of text.split("\n")) {
|
|
23
|
-
if (!line) continue;
|
|
24
|
-
// A torn final line from a crash loses that one entry; its placeholder then
|
|
25
|
-
// stays literal rather than expanding to something else.
|
|
26
|
-
try {
|
|
27
|
-
const value = JSON.parse(line) as Partial<SecretEntry>;
|
|
28
|
-
if (Number.isSafeInteger(value.n) && typeof value.value === "string" && typeof value.rule === "string" &&
|
|
29
|
-
!entries.some(entry => entry.n === value.n)) entries.push({ n: value.n!, value: value.value, rule: value.rule });
|
|
30
|
-
} catch { /* see above */ }
|
|
31
|
-
}
|
|
32
|
-
return entries;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function appendVault(dir: string, entries: readonly SecretEntry[]): Promise<void> {
|
|
36
|
-
if (entries.length === 0) return;
|
|
37
|
-
await durableAppend(join(dir, SECRETS_FILE), entries.map(entry => JSON.stringify(entry) + "\n").join(""));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** A fork's log carries the parent's placeholders, so it needs their values. */
|
|
41
|
-
export async function copyVault(from: string, to: string): Promise<void> {
|
|
42
|
-
try { await copyFile(join(from, SECRETS_FILE), join(to, SECRETS_FILE)); }
|
|
43
|
-
catch (error) { if ((error as { code?: string }).code !== "ENOENT") throw error; }
|
|
44
|
-
}
|
package/src/store/serial.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** O.5: one in-process coordinator per journal; callers never nest the same key. */
|
|
2
|
-
import { resolve } from "node:path";
|
|
3
|
-
|
|
4
|
-
const tails = new Map<string, Promise<void>>();
|
|
5
|
-
export async function serialized<T>(key: string, run: () => Promise<T>): Promise<T> {
|
|
6
|
-
const id = resolve(key), previous = tails.get(id) ?? Promise.resolve();
|
|
7
|
-
let release!: () => void;
|
|
8
|
-
const current = new Promise<void>(done => { release = done; });
|
|
9
|
-
tails.set(id, current);
|
|
10
|
-
await previous;
|
|
11
|
-
try { return await run(); }
|
|
12
|
-
finally { release(); if (tails.get(id) === current) tails.delete(id); }
|
|
13
|
-
}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
/** Portable log graphs. No provider calls, workspace writes, or executable package payloads (D3/D8). */
|
|
2
|
-
import { createReadStream } from "node:fs";
|
|
3
|
-
import { lstat, mkdir, mkdtemp, open, readdir, rename, rm } from "node:fs/promises";
|
|
4
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
5
|
-
import { dirname, join, resolve } from "node:path";
|
|
6
|
-
import { archivePath } from "../core/session-archive.ts";
|
|
7
|
-
import { blobFilePath, digestFile, verifyBlob } from "./blobs.ts";
|
|
8
|
-
import { listNodes, readCursor, readCursorAt, readManifest, readNode, relocateSession, type Cursor } from "./log.ts";
|
|
9
|
-
import { readNodeHistory } from "./restore.ts";
|
|
10
|
-
import { replayContext } from "./replay.ts";
|
|
11
|
-
|
|
12
|
-
// Wire chunk size, not a content limit: bounded JSON lines keep large snapshots streamable.
|
|
13
|
-
const CHUNK = 64 * 1024;
|
|
14
|
-
type FileEntry = { path: string; source: string };
|
|
15
|
-
|
|
16
|
-
async function regular(path: string): Promise<void> {
|
|
17
|
-
if (!(await lstat(path)).isFile()) throw new Error(`Archive requires a regular file: ${path}`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function storedFiles(root: string, prefix = ""): Promise<FileEntry[]> {
|
|
21
|
-
const files: FileEntry[] = [];
|
|
22
|
-
for (const entry of await readdir(join(root, prefix), { withFileTypes: true })) {
|
|
23
|
-
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
24
|
-
if (archivePath(path)) { await regular(join(root, path)); files.push({ path, source: join(root, path) }); }
|
|
25
|
-
else if ((path === "artifacts" || /^artifacts\/[a-f0-9]{2}$/.test(path)) && entry.isDirectory()) files.push(...await storedFiles(root, path));
|
|
26
|
-
else if (path === "artifacts" || path === "blobs") {
|
|
27
|
-
if (!entry.isDirectory()) throw new Error(`Invalid archive store: ${path}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return files;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async function referencedBlobs(dir: string, fallback?: string): Promise<Map<string, string[]>> {
|
|
34
|
-
const refs = new Map<string, string[]>(), cursor = await readCursor(dir);
|
|
35
|
-
for (const node of await listNodes(dir)) {
|
|
36
|
-
const read = await readNode(dir, node);
|
|
37
|
-
if (!read.header || read.corrupt.length) throw new Error(`Corrupt archive node ${node}`);
|
|
38
|
-
const historical = await readCursorAt(dir, node);
|
|
39
|
-
const roots = [...new Set([historical?.blob_dir, cursor?.blob_dir, fallback, join(dir, "blobs")].filter((p): p is string => !!p))];
|
|
40
|
-
const add = (sha: string) => { refs.set(sha, [...new Set([...(refs.get(sha) ?? []), ...roots])]); };
|
|
41
|
-
for (const event of read.events) {
|
|
42
|
-
if (event.t === "checkpoint") for (const change of Object.values(event.changes)) {
|
|
43
|
-
if (change.before) add(change.before.sha256);
|
|
44
|
-
if (change.after) add(change.after.sha256);
|
|
45
|
-
}
|
|
46
|
-
if (event.t === "user" || event.t === "tool_result") for (const image of event.images ?? []) { add(image.sha256); if (image.original) add(image.original.sha256); }
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return refs;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function validateSession(dir: string): Promise<Cursor> {
|
|
53
|
-
const cursor = await readCursor(dir);
|
|
54
|
-
if (!cursor) throw new Error("Archive has no resumable cursor");
|
|
55
|
-
const manifest = await readManifest(dir), nodes = await listNodes(dir);
|
|
56
|
-
if (!nodes.includes(cursor.node)) throw new Error("Archive cursor points to a missing node");
|
|
57
|
-
for (const closed of manifest.nodes) {
|
|
58
|
-
if (!nodes.includes(closed.node) || await digestFile(join(dir, `node-${String(closed.node).padStart(4, "0")}.jsonl`)) !== closed.sha256) throw new Error("Archive closed node digest mismatch");
|
|
59
|
-
if (closed.handoff_ref) await regular(join(dir, `handoff-${String(closed.node).padStart(4, "0")}.yaml`));
|
|
60
|
-
}
|
|
61
|
-
const contexts = new Set<string>();
|
|
62
|
-
for (const node of nodes) {
|
|
63
|
-
const history = await readNodeHistory(dir, node);
|
|
64
|
-
if (!history.ok) throw new Error(`Invalid archive graph: ${history.error}`);
|
|
65
|
-
await replayContext(dir, node, manifest);
|
|
66
|
-
const state = await readCursorAt(dir, node); if (state?.context_ref) contexts.add(state.context_ref);
|
|
67
|
-
for (const event of (await readNode(dir, node)).events) if (event.t === "cut" && event.next_context_ref) contexts.add(event.next_context_ref);
|
|
68
|
-
}
|
|
69
|
-
if (cursor.context_ref) contexts.add(cursor.context_ref);
|
|
70
|
-
for (const sha of contexts) if (!await verifyBlob(join(dir, "artifacts"), sha)) throw new Error(`Missing frozen context ${sha}`);
|
|
71
|
-
return cursor;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export async function exportSessionArchive(dir: string, destination: string, blobDir?: string): Promise<void> {
|
|
75
|
-
await validateSession(dir);
|
|
76
|
-
const files = await storedFiles(dir);
|
|
77
|
-
for (const [sha, roots] of await referencedBlobs(dir, blobDir)) {
|
|
78
|
-
let source: string | undefined;
|
|
79
|
-
for (const root of roots) if (await verifyBlob(root, sha)) { source = blobFilePath(root, sha); break; }
|
|
80
|
-
if (!source) throw new Error(`Missing session blob ${sha}`);
|
|
81
|
-
files.push({ path: `blobs/${sha.slice(0, 2)}/${sha.slice(2)}`, source });
|
|
82
|
-
}
|
|
83
|
-
if (files.some(file => resolve(file.source) === resolve(destination))) throw new Error("Cannot export over session storage");
|
|
84
|
-
const temp = `${destination}.${randomUUID()}.tmp`, out = await open(temp, "wx", 0o600);
|
|
85
|
-
const digest = createHash("sha256"); let count = 0;
|
|
86
|
-
const emit = async (record: unknown, hashed = true) => { const line = JSON.stringify(record) + "\n"; if (hashed) digest.update(line); await out.writeFile(line); };
|
|
87
|
-
try {
|
|
88
|
-
await emit({ format: "xeno-session", version: 1 });
|
|
89
|
-
for (const file of files.sort((a, b) => a.path.localeCompare(b.path))) {
|
|
90
|
-
await regular(file.source);
|
|
91
|
-
const hash = createHash("sha256"); let size = 0;
|
|
92
|
-
await emit({ file: file.path });
|
|
93
|
-
for await (const chunk of createReadStream(file.source, { highWaterMark: CHUNK })) {
|
|
94
|
-
const bytes = chunk as Buffer; size += bytes.length; hash.update(bytes); await emit({ data: bytes.toString("base64") });
|
|
95
|
-
}
|
|
96
|
-
const sha256 = hash.digest("hex");
|
|
97
|
-
if (/^(artifacts|blobs)\//.test(file.path) && file.path.split("/").slice(1).join("") !== sha256) throw new Error(`Corrupt archive blob ${file.path}`);
|
|
98
|
-
await emit({ end: file.path, size, sha256 }); count++;
|
|
99
|
-
}
|
|
100
|
-
await emit({ complete: count, sha256: digest.digest("hex") }, false);
|
|
101
|
-
await out.sync(); await out.close(); await rename(temp, destination);
|
|
102
|
-
} finally { await out.close(); await rm(temp, { force: true }); }
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** Bound a hostile or truncated line before JSON parsing, without a whole-archive size cap. */
|
|
106
|
-
async function* lines(path: string): AsyncGenerator<string> {
|
|
107
|
-
let pending = "";
|
|
108
|
-
for await (const chunk of createReadStream(path, { encoding: "utf8", highWaterMark: CHUNK })) {
|
|
109
|
-
pending += chunk; let end: number;
|
|
110
|
-
while ((end = pending.indexOf("\n")) !== -1) {
|
|
111
|
-
if (end > CHUNK * 2) throw new Error("Archive line exceeds chunk envelope");
|
|
112
|
-
yield pending.slice(0, end); pending = pending.slice(end + 1);
|
|
113
|
-
}
|
|
114
|
-
if (pending.length > CHUNK * 2) throw new Error("Archive line exceeds chunk envelope");
|
|
115
|
-
}
|
|
116
|
-
if (pending) throw new Error("Incomplete archive tail");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** Only a validated staging directory is published; failed imports never become browser entries. */
|
|
120
|
-
export async function importSessionArchive(file: string, sessionRoot: string, workspace: string): Promise<string> {
|
|
121
|
-
await regular(file); await mkdir(sessionRoot, { recursive: true });
|
|
122
|
-
const stage = await mkdtemp(join(sessionRoot, ".xeno-import-"));
|
|
123
|
-
const destination = join(sessionRoot, `${Date.now().toString(36)}-${randomUUID().slice(0, 8)}`);
|
|
124
|
-
const seen = new Set<string>(), digest = createHash("sha256");
|
|
125
|
-
let header = false, complete = false, active: { path: string; file: Awaited<ReturnType<typeof open>>; hash: ReturnType<typeof createHash>; size: number } | undefined;
|
|
126
|
-
try {
|
|
127
|
-
for await (const line of lines(file)) {
|
|
128
|
-
if (complete) throw new Error("Unexpected data after archive footer");
|
|
129
|
-
const value: unknown = JSON.parse(line);
|
|
130
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid archive record");
|
|
131
|
-
const record = value as Record<string, unknown>;
|
|
132
|
-
if (!header) {
|
|
133
|
-
if (record["format"] !== "xeno-session" || record["version"] !== 1) throw new Error("Expected xeno-session v1 archive. Legacy event-only JSONL lacks recovery metadata; re-export the original session.");
|
|
134
|
-
header = true;
|
|
135
|
-
} else if (record["complete"] !== undefined) {
|
|
136
|
-
if (active || record["complete"] !== seen.size || record["sha256"] !== digest.digest("hex")) throw new Error("Archive completeness digest mismatch");
|
|
137
|
-
complete = true; continue;
|
|
138
|
-
} else if (record["file"] !== undefined) {
|
|
139
|
-
const path = record["file"];
|
|
140
|
-
if (active || !archivePath(path) || seen.has(path)) throw new Error("Invalid or duplicate archive path");
|
|
141
|
-
seen.add(path); await mkdir(dirname(join(stage, path)), { recursive: true });
|
|
142
|
-
active = { path, file: await open(join(stage, path), "wx", 0o600), hash: createHash("sha256"), size: 0 };
|
|
143
|
-
} else if (record["data"] !== undefined) {
|
|
144
|
-
const data = record["data"];
|
|
145
|
-
if (!active || typeof data !== "string" || data.length > Math.ceil(CHUNK / 3) * 4) throw new Error("Invalid archive chunk");
|
|
146
|
-
const bytes = Buffer.from(data, "base64");
|
|
147
|
-
if (bytes.toString("base64") !== data) throw new Error("Invalid archive base64");
|
|
148
|
-
active.hash.update(bytes); active.size += bytes.length; await active.file.writeFile(bytes);
|
|
149
|
-
} else if (record["end"] !== undefined) {
|
|
150
|
-
if (!active || record["end"] !== active.path || record["size"] !== active.size || record["sha256"] !== active.hash.digest("hex")) throw new Error("Archive file digest mismatch");
|
|
151
|
-
if (/^(artifacts|blobs)\//.test(active.path) && active.path.split("/").slice(1).join("") !== record["sha256"]) throw new Error("Archive blob address mismatch");
|
|
152
|
-
await active.file.sync(); await active.file.close(); active = undefined;
|
|
153
|
-
} else throw new Error("Unknown archive record");
|
|
154
|
-
digest.update(line + "\n");
|
|
155
|
-
}
|
|
156
|
-
if (!complete) throw new Error("Incomplete archive: missing footer");
|
|
157
|
-
await validateSession(stage);
|
|
158
|
-
for (const sha of (await referencedBlobs(stage)).keys()) if (!await verifyBlob(join(stage, "blobs"), sha)) throw new Error(`Missing session blob ${sha}`);
|
|
159
|
-
await mkdir(join(stage, "blobs"), { recursive: true });
|
|
160
|
-
await relocateSession(stage, workspace);
|
|
161
|
-
await rename(stage, destination);
|
|
162
|
-
const parent = await open(sessionRoot, "r"); try { await parent.sync(); } finally { await parent.close(); }
|
|
163
|
-
return destination;
|
|
164
|
-
} finally { await active?.file.close(); await rm(stage, { recursive: true, force: true }); }
|
|
165
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/** Location discovery only; session data is always read from its append-only journals (D3/D8). */
|
|
2
|
-
import { readdir, readFile, mkdir, rename, realpath } from "node:fs/promises";
|
|
3
|
-
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
import { randomUUID } from "node:crypto";
|
|
5
|
-
import { configDir } from "./config.ts";
|
|
6
|
-
import { atomicWrite } from "./atomic.ts";
|
|
7
|
-
import { serialized } from "./serial.ts";
|
|
8
|
-
import { readListed, type ListedSession } from "./sessions.ts";
|
|
9
|
-
import { readCursor, writeCursor } from "./log.ts";
|
|
10
|
-
|
|
11
|
-
export interface SessionRoot { path: string; workspace: string }
|
|
12
|
-
const registryPath = () => join(configDir(), "session-roots.json");
|
|
13
|
-
export async function sessionRoots(current: SessionRoot): Promise<SessionRoot[]> {
|
|
14
|
-
let rows: SessionRoot[] = [];
|
|
15
|
-
try {
|
|
16
|
-
const data: unknown = JSON.parse(await readFile(registryPath(), "utf8"));
|
|
17
|
-
if (!Array.isArray(data)) throw new Error("Session root registry is not an array");
|
|
18
|
-
rows = data.filter((row): row is SessionRoot => row !== null && typeof row === "object" && typeof row.path === "string" && typeof row.workspace === "string");
|
|
19
|
-
} catch (error) { if ((error as { code?: string }).code !== "ENOENT") throw error; }
|
|
20
|
-
return [...new Map([...rows, current].map(row => [resolve(row.path), { ...row, path: resolve(row.path), workspace: resolve(row.workspace) }])).values()];
|
|
21
|
-
}
|
|
22
|
-
export async function registerSessionRoot(root: SessionRoot): Promise<void> {
|
|
23
|
-
const path = registryPath();
|
|
24
|
-
return serialized(path, async () => {
|
|
25
|
-
const rows = await sessionRoots(root);
|
|
26
|
-
await mkdir(dirname(path), { recursive: true });
|
|
27
|
-
await atomicWrite(path, JSON.stringify(rows, null, 2) + "\n");
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
export interface SessionScan { sessions: ListedSession[]; loaded: number; total: number; root: string }
|
|
31
|
-
export async function* scanSessionRoots(roots: readonly SessionRoot[], signal?: AbortSignal): AsyncGenerator<SessionScan> {
|
|
32
|
-
const found: { id: string; path: string; workspace: string }[] = [];
|
|
33
|
-
for (const root of roots) {
|
|
34
|
-
if (signal?.aborted) return;
|
|
35
|
-
try {
|
|
36
|
-
const entries = await readdir(root.path, { withFileTypes: true });
|
|
37
|
-
found.push(...entries.filter(entry => entry.isDirectory() && !entry.name.startsWith(".")).map(entry => ({ id: entry.name, path: join(root.path, entry.name), workspace: root.workspace })));
|
|
38
|
-
} catch (error) {
|
|
39
|
-
if ((error as { code?: string }).code !== "ENOENT") yield { sessions: [{ ok: false, id: root.path, path: root.path, error: String(error) }], loaded: 0, total: 0, root: root.path };
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const unique = [...new Map(found.map(row => [resolve(row.path), row])).values()];
|
|
43
|
-
// Eight concurrent reads bound descriptors and let cancellation run between batches; no total-result cap.
|
|
44
|
-
for (let offset = 0; offset < unique.length; offset += 8) {
|
|
45
|
-
if (signal?.aborted) return;
|
|
46
|
-
const batch = unique.slice(offset, offset + 8);
|
|
47
|
-
const sessions = await Promise.all(batch.map(async row => {
|
|
48
|
-
try { return await readListed(row.id, row.path, { workspace: row.workspace, ...(signal ? { signal } : {}) }); }
|
|
49
|
-
catch (error) { return { ok: false as const, id: row.id, path: row.path, error: String(error) }; }
|
|
50
|
-
}));
|
|
51
|
-
if (signal?.aborted) return;
|
|
52
|
-
yield { sessions, loaded: Math.min(offset + batch.length, unique.length), total: unique.length, root: batch[0]!.workspace };
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
export async function renameSession(path: string, name: string): Promise<void> {
|
|
56
|
-
const cursor = await readCursor(path);
|
|
57
|
-
if (!cursor) throw new Error("This empty session has no saved cursor to rename");
|
|
58
|
-
await writeCursor(path, { ...cursor, name: name.trim() });
|
|
59
|
-
}
|
|
60
|
-
export async function archiveSession(path: string, active?: string): Promise<string> {
|
|
61
|
-
const target = await realpath(path);
|
|
62
|
-
if (active && target === await realpath(active)) throw new Error("Cannot remove the currently active session");
|
|
63
|
-
const trash = join(dirname(target), ".trash");
|
|
64
|
-
await mkdir(trash, { recursive: true });
|
|
65
|
-
const destination = join(trash, `${target.split(/[\\/]/).at(-1)!}-${randomUUID()}`);
|
|
66
|
-
await rename(target, destination);
|
|
67
|
-
return destination;
|
|
68
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/** Position lookup is shared by in-session navigation and copied forks (D8, Pi before/at semantics). */
|
|
2
|
-
import type { NodeRef } from "../core/events.ts";
|
|
3
|
-
import { digestNode, listNodes, nodePath, readCursorAt, readNode, type Basis, type Cursor } from "./log.ts";
|
|
4
|
-
|
|
5
|
-
export async function resolveHistoryPosition(dir: string, eventId: string, position: "at" | "before" = "at"): Promise<{
|
|
6
|
-
node: number; parent: NodeRef | null; basis: Basis; selection: Cursor | null; editorText?: string;
|
|
7
|
-
}> {
|
|
8
|
-
let found: Awaited<ReturnType<typeof readNode>> | undefined;
|
|
9
|
-
let node = -1;
|
|
10
|
-
for (const candidate of await listNodes(dir)) {
|
|
11
|
-
const read = await readNode(dir, candidate);
|
|
12
|
-
if (!read.events.some(e => e.id === eventId)) continue;
|
|
13
|
-
if (found) throw new Error(`ambiguous history event ${eventId}`);
|
|
14
|
-
if (!read.header || read.corrupt.length) throw new Error(`corrupt history node ${candidate}`);
|
|
15
|
-
node = candidate; found = read;
|
|
16
|
-
}
|
|
17
|
-
if (!found?.header) throw new Error(`NO_SUCH_EVENT: ${eventId}`);
|
|
18
|
-
const index = found.events.findIndex(e => e.id === eventId);
|
|
19
|
-
const event = found.events[index]!;
|
|
20
|
-
if (position === "before" && event.t !== "user") throw new Error("fork before requires a user message");
|
|
21
|
-
const selection = await readCursorAt(dir, node, eventId);
|
|
22
|
-
const cutoff = position === "before" ? found.events[index - 1]?.id : eventId;
|
|
23
|
-
const parent = cutoff === undefined ? found.header.parent
|
|
24
|
-
: { node, log_ref: nodePath(dir, node), sha256: await digestNode(dir, node), at_event: cutoff };
|
|
25
|
-
return { node, parent, basis: cutoff === undefined ? found.header.basis : "inherit", selection,
|
|
26
|
-
...(position === "before" && event.t === "user" ? { editorText: event.text } : {}) };
|
|
27
|
-
}
|