@visual-z/xeno 0.1.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/README.md +498 -0
- package/docs/install.md +130 -0
- package/package.json +43 -0
- package/src/apps/approve.ts +49 -0
- package/src/apps/cli.ts +37 -0
- package/src/apps/commands.ts +226 -0
- package/src/apps/completions.ts +28 -0
- package/src/apps/input.ts +297 -0
- package/src/apps/render.ts +207 -0
- package/src/apps/shell.ts +2353 -0
- package/src/apps/startup.ts +1302 -0
- package/src/core/benchmark.ts +195 -0
- package/src/core/boundary.ts +174 -0
- package/src/core/churn.ts +59 -0
- package/src/core/completion-review.ts +66 -0
- package/src/core/context-policy.ts +60 -0
- package/src/core/context-window.ts +54 -0
- package/src/core/continuation.ts +114 -0
- package/src/core/cycle.ts +17 -0
- package/src/core/data-query.ts +201 -0
- package/src/core/deadline.ts +39 -0
- package/src/core/derive.ts +489 -0
- package/src/core/edit-plan.ts +200 -0
- package/src/core/environment.ts +29 -0
- package/src/core/event-validation.ts +99 -0
- package/src/core/events.ts +486 -0
- package/src/core/evidence-links.ts +71 -0
- package/src/core/evidence.ts +89 -0
- package/src/core/execution.ts +12 -0
- package/src/core/exhaustive.ts +18 -0
- package/src/core/experiment.ts +40 -0
- package/src/core/export.ts +169 -0
- package/src/core/file-references.ts +35 -0
- package/src/core/frontmatter.ts +213 -0
- package/src/core/handoff.ts +397 -0
- package/src/core/harness-comparison.ts +90 -0
- package/src/core/history-query.ts +103 -0
- package/src/core/history.ts +100 -0
- package/src/core/json-event.ts +135 -0
- package/src/core/json-pointer.ts +46 -0
- package/src/core/keymap.ts +241 -0
- package/src/core/observation-view.ts +87 -0
- package/src/core/outcome.ts +45 -0
- package/src/core/overflow.ts +59 -0
- package/src/core/permissions.ts +182 -0
- package/src/core/policy-evaluation.ts +55 -0
- package/src/core/progress.ts +101 -0
- package/src/core/project.ts +372 -0
- package/src/core/prompts.ts +83 -0
- package/src/core/queue.ts +60 -0
- package/src/core/read-bounds.ts +15 -0
- package/src/core/recall-analysis.ts +90 -0
- package/src/core/recall-trial.ts +153 -0
- package/src/core/response-recovery.ts +46 -0
- package/src/core/scheduling.ts +8 -0
- package/src/core/settings.ts +174 -0
- package/src/core/skills.ts +121 -0
- package/src/core/stall.ts +48 -0
- package/src/core/text-normalize.ts +81 -0
- package/src/core/theme.ts +179 -0
- package/src/core/tokens.ts +149 -0
- package/src/core/tool-contract.ts +102 -0
- package/src/core/tool-input.ts +38 -0
- package/src/core/transcript.ts +60 -0
- package/src/core/window-trial.ts +65 -0
- package/src/core/work-state.ts +103 -0
- package/src/core/yaml.ts +282 -0
- package/src/index.ts +10 -0
- package/src/runtime/auth.ts +255 -0
- package/src/runtime/benchmark.ts +187 -0
- package/src/runtime/catalog.ts +365 -0
- package/src/runtime/evidence-notes.ts +33 -0
- package/src/runtime/exec-sessions.ts +214 -0
- package/src/runtime/execution-control.ts +39 -0
- package/src/runtime/harness-comparison.ts +356 -0
- package/src/runtime/history-tools.ts +108 -0
- package/src/runtime/loop.ts +1983 -0
- package/src/runtime/model.ts +614 -0
- package/src/runtime/models-fetch.ts +155 -0
- package/src/runtime/oauth-device.ts +86 -0
- package/src/runtime/oauth.ts +759 -0
- package/src/runtime/openai-responses.ts +286 -0
- package/src/runtime/openai.ts +675 -0
- package/src/runtime/provider.ts +498 -0
- package/src/runtime/recall-trial.ts +226 -0
- package/src/runtime/resume.ts +66 -0
- package/src/runtime/retry.ts +297 -0
- package/src/runtime/tools.ts +1193 -0
- package/src/runtime/usage.ts +225 -0
- package/src/runtime/window-trial.ts +140 -0
- package/src/runtime/working-notes.ts +30 -0
- package/src/store/atomic.ts +31 -0
- package/src/store/auth-store.ts +50 -0
- package/src/store/blobs.ts +142 -0
- package/src/store/command.ts +75 -0
- package/src/store/config.ts +69 -0
- package/src/store/context-files.ts +356 -0
- package/src/store/file-index.ts +81 -0
- package/src/store/git-branch.ts +35 -0
- package/src/store/history-search.ts +19 -0
- package/src/store/log.ts +642 -0
- package/src/store/models.ts +41 -0
- package/src/store/observations.ts +181 -0
- package/src/store/query-source.ts +44 -0
- package/src/store/recovery.ts +39 -0
- package/src/store/replay.ts +63 -0
- package/src/store/resources.ts +361 -0
- package/src/store/restore.ts +302 -0
- package/src/store/search.ts +644 -0
- package/src/store/serial.ts +13 -0
- package/src/store/sessions.ts +463 -0
- package/src/store/trust.ts +69 -0
- package/src/store/workspace.ts +256 -0
- package/src/store/worktree.ts +233 -0
- package/src/tui/ansi.ts +67 -0
- package/src/tui/autocomplete.ts +29 -0
- package/src/tui/complete.ts +87 -0
- package/src/tui/diff.ts +160 -0
- package/src/tui/editor.ts +893 -0
- package/src/tui/exhaustive.ts +14 -0
- package/src/tui/fuzzy.ts +75 -0
- package/src/tui/host.ts +223 -0
- package/src/tui/input.ts +69 -0
- package/src/tui/keys.ts +378 -0
- package/src/tui/markdown.ts +17 -0
- package/src/tui/render.ts +153 -0
- package/src/tui/select.ts +240 -0
- package/src/tui/settings.ts +40 -0
- package/src/tui/statusline.ts +162 -0
- package/src/tui/style.ts +205 -0
- package/src/tui/terminal.ts +30 -0
- package/src/tui/text.ts +52 -0
- package/src/tui/toolview.ts +386 -0
- package/src/tui/transcript.ts +71 -0
- package/src/tui/tree.ts +405 -0
- package/src/tui/width.ts +567 -0
- package/src/vendor/pi-tui/LICENSE.upstream +21 -0
- package/src/vendor/pi-tui/VENDOR.md +23 -0
- package/src/vendor/pi-tui/alt-screen-search.ts +327 -0
- package/src/vendor/pi-tui/autocomplete.ts +835 -0
- package/src/vendor/pi-tui/components/alt-screen-flash.ts +51 -0
- package/src/vendor/pi-tui/components/box.ts +167 -0
- package/src/vendor/pi-tui/components/cancellable-loader.ts +40 -0
- package/src/vendor/pi-tui/components/editor.ts +2470 -0
- package/src/vendor/pi-tui/components/h-stack.ts +44 -0
- package/src/vendor/pi-tui/components/image.ts +127 -0
- package/src/vendor/pi-tui/components/input.ts +494 -0
- package/src/vendor/pi-tui/components/loader.ts +101 -0
- package/src/vendor/pi-tui/components/markdown.ts +1015 -0
- package/src/vendor/pi-tui/components/mouse-region.ts +33 -0
- package/src/vendor/pi-tui/components/scroll-view.ts +224 -0
- package/src/vendor/pi-tui/components/select-list.ts +273 -0
- package/src/vendor/pi-tui/components/settings-list.ts +328 -0
- package/src/vendor/pi-tui/components/spacer.ts +28 -0
- package/src/vendor/pi-tui/components/stack.ts +154 -0
- package/src/vendor/pi-tui/components/text.ts +107 -0
- package/src/vendor/pi-tui/components/truncated-text.ts +65 -0
- package/src/vendor/pi-tui/components/v-stack.ts +33 -0
- package/src/vendor/pi-tui/editor-component.ts +74 -0
- package/src/vendor/pi-tui/fuzzy.ts +138 -0
- package/src/vendor/pi-tui/index.ts +156 -0
- package/src/vendor/pi-tui/keybindings.ts +320 -0
- package/src/vendor/pi-tui/keys.ts +1401 -0
- package/src/vendor/pi-tui/kill-ring.ts +46 -0
- package/src/vendor/pi-tui/latex.ts +1506 -0
- package/src/vendor/pi-tui/layout-node.ts +51 -0
- package/src/vendor/pi-tui/layout.ts +449 -0
- package/src/vendor/pi-tui/native-modifiers.ts +13 -0
- package/src/vendor/pi-tui/native-module-path.ts +31 -0
- package/src/vendor/pi-tui/native-platform.ts +63 -0
- package/src/vendor/pi-tui/stdin-buffer.ts +444 -0
- package/src/vendor/pi-tui/terminal-colors.ts +73 -0
- package/src/vendor/pi-tui/terminal-image.ts +696 -0
- package/src/vendor/pi-tui/terminal.ts +547 -0
- package/src/vendor/pi-tui/tui-alt-screen.ts +1742 -0
- package/src/vendor/pi-tui/tui-main-screen.ts +655 -0
- package/src/vendor/pi-tui/tui.ts +1456 -0
- package/src/vendor/pi-tui/undo-stack.ts +28 -0
- package/src/vendor/pi-tui/utils.ts +1345 -0
- package/src/vendor/pi-tui/word-navigation.ts +117 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/** N.2: one ancestry-scoped reader for query, exact event, and structured pages. */
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { deriveHandoff } from "../core/derive.ts";
|
|
4
|
+
import type { Handoff } from "../core/handoff.ts";
|
|
5
|
+
import { HISTORY_SECTIONS, historyPage, type HistorySection } from "../core/history.ts";
|
|
6
|
+
import { historyEntries, historyHits, historyIndex, queryHistory, type HistoryEntry } from "../core/history-query.ts";
|
|
7
|
+
import { resourceKey } from "../core/evidence-links.ts";
|
|
8
|
+
import { canonicalValue } from "../core/continuation.ts";
|
|
9
|
+
import { digestNode, nodePath, readManifest } from "../store/log.ts";
|
|
10
|
+
import { readNodeHistory } from "../store/restore.ts";
|
|
11
|
+
import { archiveObservation, readObservation } from "../store/observations.ts";
|
|
12
|
+
import { observationContains } from "../store/history-search.ts";
|
|
13
|
+
import { presentObservation, type ToolContext, type ToolResult } from "./tools.ts";
|
|
14
|
+
|
|
15
|
+
export async function runHistoryTool(logDir: string, currentNode: number, ctx: ToolContext, input: unknown): Promise<ToolResult> {
|
|
16
|
+
try {
|
|
17
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) throw new Error("history expects an object");
|
|
18
|
+
const args = input as Record<string, unknown>;
|
|
19
|
+
const archive = ctx.outputStore ?? join(logDir, "artifacts");
|
|
20
|
+
if (typeof args["artifact"] === "string") return { ok: true, content: JSON.stringify(await readObservation(archive,
|
|
21
|
+
args["artifact"], typeof args["offset"] === "number" ? args["offset"] : 0,
|
|
22
|
+
Math.max(1, Math.floor(ctx.maxOutputBytes / 3)))) };
|
|
23
|
+
const index = await readManifest(logDir);
|
|
24
|
+
const history = await readNodeHistory(logDir, currentNode, index);
|
|
25
|
+
if (!history.ok) throw new Error(history.error);
|
|
26
|
+
const entries = historyEntries(history.nodes);
|
|
27
|
+
const indexed = historyIndex(entries);
|
|
28
|
+
if (args["events"] !== undefined) {
|
|
29
|
+
const requested = args["events"];
|
|
30
|
+
if (!Array.isArray(requested) || requested.length < 1 || requested.length > 100 || requested.some(event => typeof event !== "string" || !event)) {
|
|
31
|
+
throw new Error("history events must contain 1..100 event ids");
|
|
32
|
+
}
|
|
33
|
+
const items = requested.map(event => indexed.byEvent.get(event) ?? { event, missing: true });
|
|
34
|
+
const missing = requested.filter(event => !indexed.byEvent.has(event));
|
|
35
|
+
return { ...await historyValue(ctx, { items, missing }), ok: missing.length === 0 };
|
|
36
|
+
}
|
|
37
|
+
if (typeof args["event"] === "string") {
|
|
38
|
+
const found = indexed.byEvent.get(args["event"]);
|
|
39
|
+
if (!found) throw new Error("event is not readable in the active ancestry");
|
|
40
|
+
return historyValue(ctx, found);
|
|
41
|
+
}
|
|
42
|
+
if (typeof args["query"] === "string" || args["recent"] === true || typeof args["resource"] === "string" || typeof args["work_id"] === "string") {
|
|
43
|
+
const query = typeof args["query"] === "string" ? args["query"] : "";
|
|
44
|
+
if (query.length > 2000) throw new Error("history query is limited to 2000 characters; use a more specific query");
|
|
45
|
+
const tool = typeof args["tool"] === "string" ? args["tool"] : undefined;
|
|
46
|
+
const limit = args["limit"] === undefined ? 10 : args["limit"];
|
|
47
|
+
if (typeof limit !== "number" || !Number.isSafeInteger(limit) || limit < 1 || limit > 100) throw new Error("history limit must be 1..100");
|
|
48
|
+
const terms = query.toLowerCase().trim().split(/\s+/).filter(Boolean);
|
|
49
|
+
const matches: (HistoryEntry & { hits: { line: number; text: string }[] })[] = [];
|
|
50
|
+
let selected: readonly HistoryEntry[] = entries;
|
|
51
|
+
if (typeof args["work_id"] === "string") selected = indexed.byWork.get(args["work_id"]) ?? [];
|
|
52
|
+
if (typeof args["resource"] === "string") {
|
|
53
|
+
const resources = new Set(indexed.byResource.get(resourceKey(args["resource"])) ?? []);
|
|
54
|
+
selected = selected.filter(entry => resources.has(entry));
|
|
55
|
+
}
|
|
56
|
+
for (const entry of selected.toReversed()) {
|
|
57
|
+
if (tool !== undefined && entry.tool !== tool) continue;
|
|
58
|
+
const inline = `${entry.text}\n${canonicalValue(entry.input)}`.toLowerCase();
|
|
59
|
+
const missing = terms.filter((term) => !inline.includes(term));
|
|
60
|
+
if (missing.length > 0 && !(entry.artifact && await observationContains(archive, entry.artifact, missing))) continue;
|
|
61
|
+
// This is an index excerpt, not replacement evidence. Exact event/artifact
|
|
62
|
+
// readers retain every omitted byte, with a stable snapshot for pagination.
|
|
63
|
+
// Hits show where the terms are, so a match deep in a long observation
|
|
64
|
+
// does not force reading the whole original back (N.2).
|
|
65
|
+
matches.push({ ...entry, text: entry.text.slice(0, 200), hits: historyHits(entry.text, terms) });
|
|
66
|
+
}
|
|
67
|
+
// Keep empty-query ordering identical to the pure reference search.
|
|
68
|
+
if (terms.length === 0 && matches.length !== queryHistory(selected, "", tool).length) throw new Error("history index mismatch");
|
|
69
|
+
async function* serialized(): AsyncGenerator<Uint8Array> {
|
|
70
|
+
for (const match of matches) yield new TextEncoder().encode(JSON.stringify(match) + "\n");
|
|
71
|
+
}
|
|
72
|
+
const saved = await archiveObservation(archive, serialized(), ctx.maxOutputBytes);
|
|
73
|
+
const page = matches.slice(0, limit);
|
|
74
|
+
const render = () => JSON.stringify({ matches: matches.length, items: page,
|
|
75
|
+
full_results: { artifact: saved.ref.sha256, format: "jsonl", offset: 0 },
|
|
76
|
+
instruction: "Use event for original evidence; artifact and offset page this immutable search result." });
|
|
77
|
+
let response = render();
|
|
78
|
+
while (page.length > 0 && new TextEncoder().encode(response).length > ctx.maxOutputBytes) { page.pop(); response = render(); }
|
|
79
|
+
if (new TextEncoder().encode(response).length > ctx.maxOutputBytes) response = `history artifact: ${saved.ref.sha256}; ${matches.length} matches; offset 0`;
|
|
80
|
+
// The snapshot itself is a first-class observation so copy/fork preserves it.
|
|
81
|
+
return { ok: true, content: response, content_ref: saved.ref, content_sha256: saved.ref.sha256 };
|
|
82
|
+
}
|
|
83
|
+
if (!Number.isSafeInteger(args["node"]) || typeof args["section"] !== "string" ||
|
|
84
|
+
!(HISTORY_SECTIONS as readonly string[]).includes(args["section"])) throw new Error("history requires query, recent, event, artifact, or node and section");
|
|
85
|
+
const node = args["node"] as number;
|
|
86
|
+
if (!index.nodes.some((entry) => entry.node === node) || !history.nodes.some((entry) => entry.node === node)) throw new Error("history source must be a sealed node in the active ancestry");
|
|
87
|
+
// Fold only the events contributed to this ancestry, respecting rewind points.
|
|
88
|
+
let full: Handoff | null = null;
|
|
89
|
+
let depth = 0;
|
|
90
|
+
for (const part of history.nodes) {
|
|
91
|
+
full = deriveHandoff({ prev: full, depth: ++depth, events: part.events,
|
|
92
|
+
self: { node: part.node, log_ref: nodePath(logDir, part.node), sha256: await digestNode(logDir, part.node) },
|
|
93
|
+
config: { maxUserTurns: Infinity, maxUserTurnBytes: Infinity } });
|
|
94
|
+
if (part.node === node) break;
|
|
95
|
+
}
|
|
96
|
+
if (full === null) throw new Error("empty history");
|
|
97
|
+
const page = historyPage(full, args["section"] as HistorySection,
|
|
98
|
+
typeof args["offset"] === "number" ? args["offset"] : 0,
|
|
99
|
+
typeof args["limit"] === "number" ? Math.min(args["limit"], 100) : 20);
|
|
100
|
+
return { ok: true, ...await presentObservation(ctx, JSON.stringify({ source: full.predecessor, section: args["section"], ...page })) };
|
|
101
|
+
} catch (error) { return { ok: false, content: `history: ${String(error)}` }; }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function historyValue(ctx: ToolContext, value: unknown): Promise<ToolResult> {
|
|
105
|
+
const content = JSON.stringify(value);
|
|
106
|
+
const observation = await presentObservation(ctx, content);
|
|
107
|
+
return { ok: true, ...observation, data: observation.content_ref ? { artifact: observation.content_ref, format: "json" } : JSON.parse(content) };
|
|
108
|
+
}
|