@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
package/src/store/restore.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Walking a node's ancestry for history: every ancestor's events, bounded by
|
|
3
|
-
* the fork point below each one.
|
|
4
|
-
*
|
|
5
|
-
* WHY THIS DOES NOT REUSE readAncestry. That walk stops at a cut, because a
|
|
6
|
-
* handoff basis means the parent's events do not replay -- correct for
|
|
7
|
-
* context, wrong for files and turns. File history (checkpoint-history.ts)
|
|
8
|
-
* therefore walks to the root whatever each node declared about context; the
|
|
9
|
-
* "context" scope stops at an explicit new root instead.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { readNode, readManifest, digestNode, MAX_ANCESTRY_DEPTH, type Manifest } from "./log.ts";
|
|
13
|
-
import type { LogEvent } from "../core/events.ts";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Where to move the workspace to. A bare node means the end of that node;
|
|
17
|
-
* `atEvent` names a point inside it, which is what makes an ordinary undo
|
|
18
|
-
* possible within the node being worked in.
|
|
19
|
-
*/
|
|
20
|
-
export type RestoreTarget = number | { node: number; atEvent?: string };
|
|
21
|
-
|
|
22
|
-
/** One ancestor's contribution: its events, bounded by any fork point below it. */
|
|
23
|
-
export interface NodeEvents {
|
|
24
|
-
node: number;
|
|
25
|
-
events: LogEvent[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type NodeHistoryResult =
|
|
29
|
-
| { ok: true; nodes: NodeEvents[] }
|
|
30
|
-
| { ok: false; error: string };
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Every ancestor's events, root-to-leaf, bounded by the fork points below.
|
|
34
|
-
*
|
|
35
|
-
* The one traversal both file history and turn history are built on. They
|
|
36
|
-
* have to agree about where a node's history begins, or a rewind would move
|
|
37
|
-
* the files to one point and the conversation to another.
|
|
38
|
-
*/
|
|
39
|
-
export async function readNodeHistory(
|
|
40
|
-
dir: string,
|
|
41
|
-
node: number,
|
|
42
|
-
manifest?: Manifest,
|
|
43
|
-
scope: "workspace" | "context" = "workspace",
|
|
44
|
-
): Promise<NodeHistoryResult> {
|
|
45
|
-
const index = manifest ?? await readManifest(dir);
|
|
46
|
-
const chain: NodeEvents[] = [];
|
|
47
|
-
const seen = new Set<number>();
|
|
48
|
-
let current: number | null = node;
|
|
49
|
-
// Set by a child's parent pointer: this ancestor contributes only the
|
|
50
|
-
// events up to and including that one.
|
|
51
|
-
let cutoff: string | undefined;
|
|
52
|
-
let depth = 0;
|
|
53
|
-
|
|
54
|
-
while (current !== null) {
|
|
55
|
-
if (seen.has(current)) {
|
|
56
|
-
return {
|
|
57
|
-
ok: false,
|
|
58
|
-
error: `CYCLE: parent chain from node ${node} revisits node ${current}`,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
seen.add(current);
|
|
62
|
-
if (depth++ >= MAX_ANCESTRY_DEPTH) {
|
|
63
|
-
return {
|
|
64
|
-
ok: false,
|
|
65
|
-
error: `TOO_DEEP: history of node ${node} exceeded ${MAX_ANCESTRY_DEPTH} nodes`,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const { header, events, corrupt } = await readNode(dir, current);
|
|
70
|
-
const sealed = index.nodes.find((n) => n.node === current);
|
|
71
|
-
if (sealed && sealed.sha256 !== await digestNode(dir, current)) {
|
|
72
|
-
return { ok: false, error: `INTEGRITY: node ${current} digest differs from its sealed record` };
|
|
73
|
-
}
|
|
74
|
-
if (header === null) {
|
|
75
|
-
return { ok: false, error: `MISSING_HEADER: node ${current} has no header line` };
|
|
76
|
-
}
|
|
77
|
-
if (corrupt.length > 0) {
|
|
78
|
-
return {
|
|
79
|
-
ok: false,
|
|
80
|
-
error: `CORRUPT: node ${current} has ${corrupt.length} unparsable line(s)`,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// The fork point is an event id in the node's whole stream, never a
|
|
85
|
-
// count of checkpoints: a turn that changed nothing writes none.
|
|
86
|
-
let contributed = events;
|
|
87
|
-
if (cutoff !== undefined) {
|
|
88
|
-
const at = events.findIndex((e) => e.id === cutoff);
|
|
89
|
-
if (at === -1) {
|
|
90
|
-
// Refused rather than falling back to the whole node. The fallback is
|
|
91
|
-
// the silent form of the bug the cutoff exists to prevent: it would
|
|
92
|
-
// restore exactly the work the fork was made to leave behind.
|
|
93
|
-
return {
|
|
94
|
-
ok: false,
|
|
95
|
-
error: `NO_SUCH_EVENT: node ${current} has no event ${cutoff} (fork point reached from ${node})`,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
contributed = events.slice(0, at + 1);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
chain.push({ node: current, events: contributed });
|
|
102
|
-
cutoff = header.parent?.at_event;
|
|
103
|
-
// A fresh subagent inherits files, not the parent's observations. Context
|
|
104
|
-
// history crosses compaction boundaries but stops at an explicit new root.
|
|
105
|
-
current = scope === "context" && header.basis === "none" ? null : header.parent?.node ?? null;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
chain.reverse();
|
|
109
|
-
return { ok: true, nodes: chain };
|
|
110
|
-
}
|
package/src/store/review.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/** Read-only Git review with fixed argv; project diff drivers cannot execute code. */
|
|
2
|
-
import { lstat } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import type { FileChanges } from "../core/checkpoints.ts";
|
|
5
|
-
import { changedPaths } from "../core/checkpoints.ts";
|
|
6
|
-
import { ToolFault, READ_ATTEMPTED } from "../core/tool-failure.ts";
|
|
7
|
-
import { unifiedFileDiff, type ReviewScope, type ReviewSnapshot } from "../core/review.ts";
|
|
8
|
-
import { gitBytes, MAX_UNTRACKED_BYTES } from "./workspace-observation.ts";
|
|
9
|
-
import { readEditableFile } from "./file-checkpoints.ts";
|
|
10
|
-
import { getBlobBytes, blobAddress } from "./blobs.ts";
|
|
11
|
-
|
|
12
|
-
// Assumed bounded review memory. Exceeding it is unavailable, never silently partial.
|
|
13
|
-
export const MAX_REVIEW_BYTES = 16 * 1024 * 1024;
|
|
14
|
-
const decode = (bytes: Uint8Array) => new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
15
|
-
const flags = ["--no-pager", "--literal-pathspecs", "-c", "core.hooksPath=/dev/null"];
|
|
16
|
-
const diffFlags = ["--no-ext-diff", "--no-textconv", "--no-renames", "--relative"];
|
|
17
|
-
const checkedText = (bytes: Uint8Array) => {
|
|
18
|
-
if (bytes.byteLength > MAX_REVIEW_BYTES) throw new Error("review exceeds the byte budget; choose a narrower scope");
|
|
19
|
-
return decode(bytes);
|
|
20
|
-
};
|
|
21
|
-
const ordinaryText = (bytes: Uint8Array): string | null => {
|
|
22
|
-
if (bytes.includes(0)) return null;
|
|
23
|
-
try { return decode(bytes); } catch { return null; }
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export async function readReview(root: string, scope: Exclude<ReviewScope, { kind: "last-turn" }>, signal?: AbortSignal, canRead?: (path: string) => Promise<boolean>): Promise<ReviewSnapshot> {
|
|
27
|
-
const git = (args: readonly string[], input?: Uint8Array) => gitBytes(root, [...flags, ...args], input, signal);
|
|
28
|
-
const revision = async (value: string) => {
|
|
29
|
-
if (!value || value.includes("\0") || value.startsWith("-")) throw new Error("review revision must name a commit or branch");
|
|
30
|
-
const sha = decode(await git(["rev-parse", "--verify", "--end-of-options", value + "^{commit}"])).trim();
|
|
31
|
-
if (!/^[a-f0-9]{40,64}$/.test(sha)) throw new Error("review revision did not resolve to a commit");
|
|
32
|
-
return sha;
|
|
33
|
-
};
|
|
34
|
-
const emptyTree = async () => decode(await git(["hash-object", "-t", "tree", "--stdin"], new Uint8Array())).trim();
|
|
35
|
-
let base: string, end: string | undefined, label: string;
|
|
36
|
-
if (scope.kind === "commit") {
|
|
37
|
-
end = await revision(scope.commit);
|
|
38
|
-
const parents = decode(await git(["rev-list", "--parents", "-n", "1", end])).trim().split(" ");
|
|
39
|
-
base = parents[1] ?? await emptyTree();
|
|
40
|
-
label = `commit ${end.slice(0, 12)}${parents.length > 2 ? " against its first parent" : ""}`;
|
|
41
|
-
} else if (scope.kind === "branch") {
|
|
42
|
-
const branch = await revision(scope.base), head = await revision("HEAD");
|
|
43
|
-
base = decode(await git(["merge-base", head, branch])).trim();
|
|
44
|
-
label = `changes against ${scope.base} (merge base ${base.slice(0, 12)})`;
|
|
45
|
-
} else {
|
|
46
|
-
try { base = await revision("HEAD"); }
|
|
47
|
-
catch {
|
|
48
|
-
// An unborn branch has no HEAD; a corrupt/missing existing HEAD stays unavailable.
|
|
49
|
-
const heads = decode(await git(["rev-list", "--all", "--count"])).trim();
|
|
50
|
-
if (heads !== "0") throw new Error("working review cannot resolve HEAD");
|
|
51
|
-
base = await emptyTree();
|
|
52
|
-
}
|
|
53
|
-
label = "current staged, unstaged and untracked changes";
|
|
54
|
-
}
|
|
55
|
-
const range = [base, ...(end === undefined ? [] : [end])];
|
|
56
|
-
const paths = decode(await git(["diff", ...diffFlags, "--name-only", "-z", ...range, "--", "."])).split("\0").filter(Boolean);
|
|
57
|
-
const untracked = scope.kind === "commit" ? [] : decode(await git(["ls-files", "--others", "--exclude-standard", "-z", "--", "."])).split("\0").filter(Boolean);
|
|
58
|
-
for (const path of [...new Set([...paths, ...untracked])]) if (canRead && !await canRead(path))
|
|
59
|
-
throw new ToolFault("permission_denied", `diff resource access denied: ${path}`, READ_ATTEMPTED);
|
|
60
|
-
// Freeze the authorized path set in the actual collection argv. A concurrent
|
|
61
|
-
// change to a different path must not widen this observation after admission.
|
|
62
|
-
const diff = paths.length ? checkedText(await git(["diff", ...diffFlags, ...range, "--", ...paths])) : "";
|
|
63
|
-
const parts = [diff], limitations: string[] = [];
|
|
64
|
-
let bytes = Buffer.byteLength(diff);
|
|
65
|
-
if (scope.kind !== "commit") {
|
|
66
|
-
for (const path of untracked.sort()) {
|
|
67
|
-
if (signal?.aborted) throw new Error("review cancelled");
|
|
68
|
-
const info = await lstat(join(root, path));
|
|
69
|
-
if (info.size > MAX_UNTRACKED_BYTES) { limitations.push(`Untracked file ${JSON.stringify(path)} exceeds ${MAX_UNTRACKED_BYTES} bytes and is unavailable.`); continue; }
|
|
70
|
-
let source: Awaited<ReturnType<typeof readEditableFile>>;
|
|
71
|
-
try { source = await readEditableFile(root, path); }
|
|
72
|
-
catch { limitations.push(`Untracked file ${JSON.stringify(path)} is not an ordinary confined file.`); continue; }
|
|
73
|
-
if (source.bytes === null) throw new Error(`untracked file disappeared during review: ${path}`);
|
|
74
|
-
const text = ordinaryText(source.bytes);
|
|
75
|
-
const addition = text === null ? `Binary untracked file ${JSON.stringify(path)}: ${source.bytes.byteLength} bytes, sha256 ${source.version!.sha256}\n`
|
|
76
|
-
: unifiedFileDiff(path, null, text);
|
|
77
|
-
bytes += Buffer.byteLength(addition);
|
|
78
|
-
if (bytes > MAX_REVIEW_BYTES) throw new Error("review exceeds the byte budget; choose a narrower scope");
|
|
79
|
-
parts.push(addition); paths.push(path);
|
|
80
|
-
if (text === null) limitations.push(`Binary untracked content is identified but cannot be reviewed as text: ${JSON.stringify(path)}.`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return { scope, label, diff: parts.join("\n"), paths: [...new Set(paths)].sort(), limitations, base };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** Build last-turn review from verified checkpoint blobs, independent of present disk bytes. */
|
|
87
|
-
export async function readCheckpointReview(blobs: string, changes: FileChanges, limitations: readonly string[] = [], canRead?: (path: string) => Promise<boolean>): Promise<ReviewSnapshot> {
|
|
88
|
-
const parts: string[] = [], notices = [...limitations], paths = changedPaths(changes);
|
|
89
|
-
for (const path of paths) if (canRead && !await canRead(path))
|
|
90
|
-
throw new ToolFault("permission_denied", `diff resource access denied: ${path}`, READ_ATTEMPTED);
|
|
91
|
-
let bytes = 0;
|
|
92
|
-
for (const path of paths) {
|
|
93
|
-
const firstPart = parts.length;
|
|
94
|
-
const { before, after } = changes[path]!;
|
|
95
|
-
const source = before === null ? null : await getBlobBytes(blobs, before.sha256);
|
|
96
|
-
const target = after === null ? null : await getBlobBytes(blobs, after.sha256);
|
|
97
|
-
if (before && (source === null || blobAddress(source) !== before.sha256) || after && (target === null || blobAddress(target) !== after.sha256))
|
|
98
|
-
throw new Error(`missing or corrupt last-turn checkpoint object: ${path}`);
|
|
99
|
-
const oldText = source === null ? null : ordinaryText(source), newText = target === null ? null : ordinaryText(target);
|
|
100
|
-
if (source !== null && oldText === null || target !== null && newText === null) {
|
|
101
|
-
parts.push(`Binary checkpoint change ${JSON.stringify(path)}: ${before?.sha256 ?? "absent"} -> ${after?.sha256 ?? "absent"}\n`);
|
|
102
|
-
notices.push(`Binary checkpoint content cannot be reviewed as text: ${JSON.stringify(path)}.`);
|
|
103
|
-
} else parts.push(unifiedFileDiff(path, oldText, newText));
|
|
104
|
-
if (before && after && before.mode !== after.mode) parts.push(`mode ${JSON.stringify(path)}: ${before.mode.toString(8)} -> ${after.mode.toString(8)}\n`);
|
|
105
|
-
bytes += parts.slice(firstPart).reduce((total, part) => total + Buffer.byteLength(part), 0);
|
|
106
|
-
if (bytes > MAX_REVIEW_BYTES) throw new Error("last-turn review exceeds the byte budget");
|
|
107
|
-
}
|
|
108
|
-
return { scope: { kind: "last-turn" }, label: "captured file changes in the last user turn", diff: parts.join("\n"), paths, limitations: notices };
|
|
109
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/** R8: OS inspection is confined to the exact owned PID; never discover a target by its name or port. */
|
|
2
|
-
import { realpath, readlink, stat } from "node:fs/promises";
|
|
3
|
-
import { dirname, basename, resolve, relative, sep } from "node:path";
|
|
4
|
-
import { connect } from "node:net";
|
|
5
|
-
import { observeArgvCommand } from "./command.ts";
|
|
6
|
-
import { readObservation } from "./observations.ts";
|
|
7
|
-
import { observeArtifactFiles, archiveCommandArtifacts } from "./command-artifacts.ts";
|
|
8
|
-
import { lsofOwnsImage, lsofOwnsPort } from "../core/runtime-target.ts";
|
|
9
|
-
import type { ArtifactRef } from "../core/events.ts";
|
|
10
|
-
|
|
11
|
-
// Assumed probe limits. Output beyond the budget and unavailable OS fields remain unknown.
|
|
12
|
-
const PROBE_BYTES = 64 * 1024;
|
|
13
|
-
const PROBE_MS = 2_000;
|
|
14
|
-
export async function targetDirectory(root: string, path: string): Promise<string> {
|
|
15
|
-
const base = await realpath(root), cwd = await realpath(resolve(base, path)), rel = relative(base, cwd);
|
|
16
|
-
if (rel === ".." || rel.startsWith(`..${sep}`) || rel.startsWith(sep) || !(await stat(cwd)).isDirectory()) throw Error("target workdir escapes the workspace or is not a directory");
|
|
17
|
-
return cwd;
|
|
18
|
-
}
|
|
19
|
-
export async function targetProgram(path: string, signal?: AbortSignal) {
|
|
20
|
-
const absolute = await realpath(path);
|
|
21
|
-
const [file] = await observeArtifactFiles(dirname(absolute), [basename(absolute)], signal);
|
|
22
|
-
if (file?.state !== "observed") throw Error("target executable cannot be observed as a stable ordinary file");
|
|
23
|
-
return { path: absolute, sha256: file.sha256, device: file.identity.device, inode: file.identity.inode };
|
|
24
|
-
}
|
|
25
|
-
export async function observeRuntimeIdentity(pid: number, program: { path: string; device: string; inode: string }, port: number | undefined,
|
|
26
|
-
outputStore: string, signal?: AbortSignal): Promise<{ image: boolean; port: boolean | null; known: boolean; raw: ArtifactRef[]; reason: string }> {
|
|
27
|
-
const raw: ArtifactRef[] = [];
|
|
28
|
-
const lsof = process.platform === "darwin" ? "/usr/sbin/lsof" : "/usr/bin/lsof";
|
|
29
|
-
const probe = async (args: string[]) => {
|
|
30
|
-
const result = await observeArgvCommand({ argv: [lsof, ...args], cwd: "/", outputStore, maxOutputBytes: PROBE_BYTES,
|
|
31
|
-
timeoutMs: PROBE_MS, outputLimitBytes: PROBE_BYTES, ...(signal ? { signal } : {}) });
|
|
32
|
-
raw.push(result.stdout, result.stderr);
|
|
33
|
-
raw.push(await archiveCommandArtifacts(outputStore, { argv: [lsof, ...args], cwd: "/", exit: result.exit, capture: result.capture,
|
|
34
|
-
stdout: result.stdout, stderr: result.stderr, stopped: result.stopped ?? null, cleanup: result.cleanup ?? null }));
|
|
35
|
-
if (result.stopped || result.cleanup || result.capture !== "complete" || result.stdout.bytes > PROBE_BYTES || ![0, 1].includes(result.exit)) throw Error("OS target observation was incomplete");
|
|
36
|
-
return (await readObservation(outputStore, result.stdout.sha256, 0, PROBE_BYTES)).text;
|
|
37
|
-
};
|
|
38
|
-
try {
|
|
39
|
-
let image: boolean;
|
|
40
|
-
if (process.platform === "darwin") image = lsofOwnsImage(await probe(["-a", "-p", String(pid), "-d", "txt", "-F0pftDin"]), pid, program.device, program.inode);
|
|
41
|
-
else if (process.platform === "linux") {
|
|
42
|
-
const path = `/proc/${pid}/exe`, observed = await stat(path, { bigint: true });
|
|
43
|
-
const link = await readlink(path), device = String(observed.dev), inode = String(observed.ino);
|
|
44
|
-
raw.push(await archiveCommandArtifacts(outputStore, { path, link, device, inode }));
|
|
45
|
-
image = link === program.path && device === program.device && inode === program.inode;
|
|
46
|
-
} else return { image: false, port: port === undefined ? null : false, known: false, raw, reason: "OS executable identity is unsupported on this platform" };
|
|
47
|
-
const ownsPort = port === undefined ? null : lsofOwnsPort(await probe(["-nP", "-a", "-p", String(pid), `-iTCP:${port}`, "-sTCP:LISTEN", "-F0pftPnT"]), pid, port);
|
|
48
|
-
const reachable = port === undefined ? null : ownsPort && await loopbackReady(port, signal);
|
|
49
|
-
return { image, port: reachable, known: true, raw, reason: !image ? "owned process executable does not match the launch observation" : reachable === false ? "the owned PID does not serve the declared IPv4 loopback port" : "owned executable and declared endpoint observed" };
|
|
50
|
-
} catch { return { image: false, port: port === undefined ? null : false, known: false, raw, reason: "OS target identity could not be established" }; }
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function loopbackReady(port: number, signal?: AbortSignal): Promise<boolean> {
|
|
54
|
-
if (signal?.aborted) return false;
|
|
55
|
-
return new Promise(resolve => {
|
|
56
|
-
const socket = connect({ host: "127.0.0.1", port });
|
|
57
|
-
const done = (ok: boolean) => { signal?.removeEventListener("abort", abort); socket.destroy(); resolve(ok); };
|
|
58
|
-
const abort = () => done(false);
|
|
59
|
-
socket.setTimeout(PROBE_MS, () => done(false));
|
|
60
|
-
socket.once("connect", () => done(true)); socket.once("error", () => done(false));
|
|
61
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
62
|
-
if (signal?.aborted) abort();
|
|
63
|
-
});
|
|
64
|
-
}
|