@visual-z/xeno 0.8.3 → 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 +24 -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 -2066
- package/src/apps/startup-input.ts +0 -135
- package/src/apps/startup.ts +0 -1677
- package/src/apps/ui/app.ts +0 -1713
- 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 -3001
- 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/canvas.ts +0 -96
- package/src/tui/ui/colors.ts +0 -70
- package/src/tui/ui/composer.ts +0 -200
- 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/screen.ts +0 -548
- 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/core/keymap.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Action id ↔ key chord. Pure: the file is read in store; this module
|
|
3
|
-
* parses, reports conflicts by name, and lets the last definition win.
|
|
4
|
-
*
|
|
5
|
-
* Silent drop of one side of a conflict is how a shortcut "just stops
|
|
6
|
-
* working" with no trail (feat-theming design). The action list is
|
|
7
|
-
* xeno's (core/action-defaults.ts, D20).
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { ACTION_DEFAULTS, ACTION_ALIASES } from "./action-defaults.ts";
|
|
11
|
-
export const ACTION_IDS = Object.keys(ACTION_DEFAULTS) as (keyof typeof ACTION_DEFAULTS)[];
|
|
12
|
-
|
|
13
|
-
export type ActionId = (typeof ACTION_IDS)[number];
|
|
14
|
-
|
|
15
|
-
export interface Chord {
|
|
16
|
-
readonly ctrl: boolean;
|
|
17
|
-
readonly alt: boolean;
|
|
18
|
-
readonly shift: boolean;
|
|
19
|
-
readonly super: boolean;
|
|
20
|
-
readonly key: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface Keymap {
|
|
24
|
-
readonly byKey: Readonly<Record<string, ActionId>>;
|
|
25
|
-
readonly byAction: Readonly<Record<string, readonly string[]>>;
|
|
26
|
-
readonly diagnostics: readonly string[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const ACTION_SET = new Set<string>(ACTION_IDS);
|
|
30
|
-
|
|
31
|
-
const NAMED_KEYS = new Set([
|
|
32
|
-
"escape",
|
|
33
|
-
"esc",
|
|
34
|
-
"enter",
|
|
35
|
-
"return",
|
|
36
|
-
"tab",
|
|
37
|
-
"space",
|
|
38
|
-
"backspace",
|
|
39
|
-
"delete",
|
|
40
|
-
"insert",
|
|
41
|
-
"home",
|
|
42
|
-
"end",
|
|
43
|
-
"pageup",
|
|
44
|
-
"pagedown",
|
|
45
|
-
"up",
|
|
46
|
-
"down",
|
|
47
|
-
"left",
|
|
48
|
-
"right",
|
|
49
|
-
]);
|
|
50
|
-
|
|
51
|
-
export function parseKey(spec: string): Chord | { error: string } {
|
|
52
|
-
const raw = spec.trim();
|
|
53
|
-
if (raw.length === 0) return { error: `unparseable key: ${JSON.stringify(spec)}` };
|
|
54
|
-
const parts = raw.split("+").map((p) => p.trim()).filter((p) => p.length > 0);
|
|
55
|
-
if (parts.length === 0) return { error: `unparseable key: ${JSON.stringify(spec)}` };
|
|
56
|
-
let ctrl = false;
|
|
57
|
-
let alt = false;
|
|
58
|
-
let shift = false;
|
|
59
|
-
let superKey = false;
|
|
60
|
-
const last = parts[parts.length - 1]!;
|
|
61
|
-
for (const part of parts.slice(0, -1)) {
|
|
62
|
-
const m = part.toLowerCase();
|
|
63
|
-
if (m === "ctrl" || m === "control") ctrl = true;
|
|
64
|
-
else if (m === "alt" || m === "option") alt = true;
|
|
65
|
-
else if (m === "shift") shift = true;
|
|
66
|
-
else if (m === "super" || m === "cmd" || m === "meta") superKey = true;
|
|
67
|
-
else return { error: `unparseable key: ${JSON.stringify(spec)}` };
|
|
68
|
-
}
|
|
69
|
-
const key = normalizeKeyName(last);
|
|
70
|
-
if (key === null) return { error: `unparseable key: ${JSON.stringify(spec)}` };
|
|
71
|
-
return { ctrl, alt, shift, super: superKey, key };
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function formatKey(chord: Chord): string {
|
|
75
|
-
const parts: string[] = [];
|
|
76
|
-
if (chord.ctrl) parts.push("ctrl");
|
|
77
|
-
if (chord.alt) parts.push("alt");
|
|
78
|
-
if (chord.shift) parts.push("shift");
|
|
79
|
-
if (chord.super) parts.push("super");
|
|
80
|
-
parts.push(chord.key);
|
|
81
|
-
return parts.join("+");
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function resolveAction(map: Keymap, spec: string): ActionId | undefined {
|
|
85
|
-
const parsed = parseKey(spec);
|
|
86
|
-
if ("error" in parsed) return undefined;
|
|
87
|
-
return map.byKey[formatKey(parsed)];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function defaultKeymap(platform: "posix" | "win32" | "wsl" = "posix"): Keymap {
|
|
91
|
-
// Windows has no job control; Ctrl+Z stays a plain key there.
|
|
92
|
-
return parseKeymap({ ...ACTION_DEFAULTS, ...(platform === "win32" ? { "app.suspend": [] } : {}) });
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** Scopes share chords on purpose: arrows mean history in the composer and movement in a list. */
|
|
96
|
-
export function actionScope(action: string): string {
|
|
97
|
-
if (action.startsWith("editor.")) return "editor";
|
|
98
|
-
if (action.startsWith("list.")) return "list";
|
|
99
|
-
return "global";
|
|
100
|
-
}
|
|
101
|
-
export function parseKeymap(json: unknown, base?: Keymap): Keymap {
|
|
102
|
-
const diagnostics = [...(base?.diagnostics ?? [])];
|
|
103
|
-
const byAction: Record<string,string[]> = Object.fromEntries(Object.entries(base?.byAction ?? {}).map(([k,v]) => [k,[...v]]));
|
|
104
|
-
if (json !== undefined && json !== null && (typeof json !== "object" || Array.isArray(json))) diagnostics.push("keybindings is not an object");
|
|
105
|
-
else for (const [rawAction,raw] of Object.entries(json ?? {})) {
|
|
106
|
-
const action = ACTION_ALIASES[rawAction] ?? rawAction;
|
|
107
|
-
if (!ACTION_SET.has(action)) { diagnostics.push("unknown action: " + rawAction); continue; }
|
|
108
|
-
const specs = keySpecs(raw);
|
|
109
|
-
if (!specs) { diagnostics.push(action + ": bindings must be a string or array of strings"); continue; }
|
|
110
|
-
const keys: string[] = [];
|
|
111
|
-
byAction[action] = keys;
|
|
112
|
-
for (const spec of specs) {
|
|
113
|
-
const parsed = parseKey(spec);
|
|
114
|
-
if ("error" in parsed) { diagnostics.push(parsed.error + " (action " + action + ")"); continue; }
|
|
115
|
-
const key = formatKey(parsed);
|
|
116
|
-
for (const [other, bindings] of Object.entries(byAction)) {
|
|
117
|
-
if (other !== action && actionScope(other) === actionScope(action) && bindings.includes(key)) {
|
|
118
|
-
diagnostics.push("key " + key + " is bound to both " + other + " and " + action + "; " + action + " wins");
|
|
119
|
-
byAction[other] = bindings.filter(k => k !== key);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (!keys.includes(key)) keys.push(key);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const byKey: Record<string,ActionId> = {};
|
|
126
|
-
for (const [action,keys] of Object.entries(byAction)) if (actionScope(action) === "global") for (const key of keys) byKey[key] = action as ActionId;
|
|
127
|
-
return { byKey, byAction, diagnostics };
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function listBindings(map: Keymap): { action: string; keys: readonly string[] }[] {
|
|
131
|
-
return ACTION_IDS.filter((a) => (map.byAction[a] ?? []).length > 0).map((action) => ({
|
|
132
|
-
action,
|
|
133
|
-
keys: map.byAction[action] ?? [],
|
|
134
|
-
}));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function keySpecs(raw: unknown): string[] | null {
|
|
138
|
-
if (typeof raw === "string") return [raw];
|
|
139
|
-
if (Array.isArray(raw) && raw.every((x) => typeof x === "string")) return raw as string[];
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function normalizeKeyName(raw: string): string | null {
|
|
144
|
-
const lower = raw.toLowerCase();
|
|
145
|
-
if (lower === "esc") return "escape";
|
|
146
|
-
if (lower === "return") return "enter";
|
|
147
|
-
if (lower === "pageup") return "pageup";
|
|
148
|
-
if (lower === "pagedown") return "pagedown";
|
|
149
|
-
if (NAMED_KEYS.has(lower)) return lower === "esc" ? "escape" : lower === "return" ? "enter" : lower;
|
|
150
|
-
if (/^f([1-9]|1[0-2])$/.test(lower)) return lower;
|
|
151
|
-
if (raw.length === 1) return lower;
|
|
152
|
-
return null;
|
|
153
|
-
}
|
package/src/core/lsp-framing.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/** LSP 3.17 uses byte-counted Content-Length, not line-delimited JSON. */
|
|
2
|
-
export type LspFrame = { body: Uint8Array; consumed: number };
|
|
3
|
-
// Operational ceiling for optional server output; this is not a context segment threshold.
|
|
4
|
-
export const MAX_LSP_FRAME = 8 * 1024 * 1024;
|
|
5
|
-
// An operational bound, independent of context-segment thresholds: reject unbounded headers.
|
|
6
|
-
export const MAX_LSP_HEADER = 8192;
|
|
7
|
-
export function nextLspFrame(bytes: Uint8Array): LspFrame | null {
|
|
8
|
-
let end = -1;
|
|
9
|
-
for (let i = 0; i + 3 < bytes.length; i++) if (bytes[i] === 13 && bytes[i + 1] === 10 && bytes[i + 2] === 13 && bytes[i + 3] === 10) { end = i; break; }
|
|
10
|
-
if (end < 0) { if (bytes.length > MAX_LSP_HEADER) throw Error("LSP header exceeds 8 KiB"); return null; }
|
|
11
|
-
if (end > MAX_LSP_HEADER || bytes.subarray(0, end).some(byte => byte > 127)) throw Error("invalid LSP ASCII header");
|
|
12
|
-
const headers = new TextDecoder("ascii").decode(bytes.subarray(0, end)).split("\r\n");
|
|
13
|
-
if (headers.some(header => !/^[a-zA-Z0-9-]+:[\t\x20-\x7e]*$/.test(header))) throw Error("invalid LSP header field");
|
|
14
|
-
const lengths = headers.filter(header => /^content-length:/i.test(header));
|
|
15
|
-
if (lengths.length !== 1 || !/^content-length:\s*[0-9]+\s*$/i.test(lengths[0]!)) throw Error("invalid LSP Content-Length");
|
|
16
|
-
const types = headers.filter(header => /^content-type:/i.test(header));
|
|
17
|
-
if (types.length > 1) throw Error("ambiguous LSP Content-Type");
|
|
18
|
-
const charsets = types.flatMap(header => header.split(";").slice(1).filter(parameter => /^\s*charset\s*=/i.test(parameter)));
|
|
19
|
-
if (charsets.length > 1 || charsets.some(parameter => !/^\s*charset\s*=\s*(utf-?8|"utf-?8")\s*$/i.test(parameter))) throw Error("unsupported LSP charset");
|
|
20
|
-
const length = Number(lengths[0]!.split(":")[1]!.trim());
|
|
21
|
-
if (!Number.isSafeInteger(length) || length > MAX_LSP_FRAME) throw Error("LSP frame exceeds 8 MiB");
|
|
22
|
-
const consumed = end + 4 + length;
|
|
23
|
-
return bytes.length < consumed ? null : { body: bytes.slice(end + 4, consumed), consumed };
|
|
24
|
-
}
|
|
25
|
-
/** Unversioned server diagnostics cannot prove that they describe the current owned file. */
|
|
26
|
-
export function diagnosticFreshness(observedVersion: number | undefined, currentVersion: number): "current" | "stale" | "unversioned" {
|
|
27
|
-
return observedVersion === undefined ? "unversioned" : observedVersion === currentVersion ? "current" : "stale";
|
|
28
|
-
}
|
|
29
|
-
export function encodeLspFrame(value: unknown): Uint8Array {
|
|
30
|
-
const body = new TextEncoder().encode(JSON.stringify(value));
|
|
31
|
-
if (body.length > MAX_LSP_FRAME) throw Error("LSP frame exceeds 8 MiB");
|
|
32
|
-
const header = new TextEncoder().encode(`Content-Length: ${body.length}\r\n\r\n`);
|
|
33
|
-
const frame = new Uint8Array(header.length + body.length); frame.set(header); frame.set(body, header.length); return frame;
|
|
34
|
-
}
|
package/src/core/mcp-config.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/** Explicit MCP configuration is authority; remote tool annotations never grant permissions (D11/D13). */
|
|
2
|
-
import { webUrl } from "./web-content.ts";
|
|
3
|
-
|
|
4
|
-
export interface McpOAuthConfig { clientId?: string; clientSecretEnv?: string; scope?: string; redirectUrl?: string }
|
|
5
|
-
interface McpCommonConfig { enabled?: boolean; timeoutMs?: number }
|
|
6
|
-
export type McpServerConfig = McpCommonConfig & ({ transport: "stdio"; command: string; args?: string[]; env?: Record<string, string> }
|
|
7
|
-
| { transport: "http"; url: string; bearerTokenEnv?: string; headers?: Record<string, string>; headersEnv?: Record<string, string>; oauth?: boolean | McpOAuthConfig });
|
|
8
|
-
export type McpServers = Readonly<Record<string, McpServerConfig>>;
|
|
9
|
-
function object(value: unknown, label: string): Record<string, unknown> {
|
|
10
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) throw Error(`${label} must be an object`);
|
|
11
|
-
return value as Record<string, unknown>;
|
|
12
|
-
}
|
|
13
|
-
function strings(value: unknown, label: string, envNames = false): Record<string, string> {
|
|
14
|
-
const source = object(value, label), result: Record<string, string> = Object.create(null);
|
|
15
|
-
for (const [key, entry] of Object.entries(source)) {
|
|
16
|
-
if (typeof entry !== "string" || /[\r\n\u0000]/.test(entry) || /[\r\n\u0000]/.test(key)) throw Error(`${label} must contain single-line string values`);
|
|
17
|
-
if (envNames && !/^[A-Za-z_][A-Za-z0-9_]*$/.test(entry)) throw Error(`${label} values must name environment variables`);
|
|
18
|
-
result[key] = entry;
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
function optionalString(source: Record<string, unknown>, key: string, envName = false): string | undefined {
|
|
23
|
-
const value = source[key];
|
|
24
|
-
if (value === undefined) return undefined;
|
|
25
|
-
if (typeof value !== "string" || !value || /[\r\n\u0000]/.test(value) || envName && !/^[A-Za-z_][A-Za-z0-9_]*$/.test(value)) throw Error(`${key} must be a valid ${envName ? "environment variable name" : "single-line string"}`);
|
|
26
|
-
return value;
|
|
27
|
-
}
|
|
28
|
-
export function mcpCallbackUrl(value: string): string {
|
|
29
|
-
const parsed = new URL(webUrl(value));
|
|
30
|
-
if (parsed.protocol !== "http:" || parsed.hostname !== "127.0.0.1" || parsed.search || !parsed.port || !parsed.pathname.startsWith("/"))
|
|
31
|
-
throw Error("OAuth redirectUrl must be an HTTP 127.0.0.1 URL with an explicit port and no query");
|
|
32
|
-
return parsed.href;
|
|
33
|
-
}
|
|
34
|
-
function oauth(value: unknown): boolean | McpOAuthConfig {
|
|
35
|
-
if (typeof value === "boolean") return value;
|
|
36
|
-
const source = object(value, "oauth");
|
|
37
|
-
if (Object.keys(source).some(key => !["clientId", "clientSecretEnv", "scope", "redirectUrl"].includes(key))) throw Error("oauth has an unsupported field");
|
|
38
|
-
const clientId = optionalString(source, "clientId"), clientSecretEnv = optionalString(source, "clientSecretEnv", true), scope = optionalString(source, "scope"), redirectUrl = optionalString(source, "redirectUrl");
|
|
39
|
-
if (clientSecretEnv && !clientId) throw Error("oauth.clientSecretEnv requires oauth.clientId");
|
|
40
|
-
return { ...(clientId ? { clientId } : {}), ...(clientSecretEnv ? { clientSecretEnv } : {}), ...(scope ? { scope } : {}), ...(redirectUrl ? { redirectUrl: mcpCallbackUrl(redirectUrl) } : {}) };
|
|
41
|
-
}
|
|
42
|
-
export function parseMcpServers(value: unknown): McpServers {
|
|
43
|
-
if (value === undefined || value === null) return {};
|
|
44
|
-
const source = object(value, "mcpServers"), result: Record<string, McpServerConfig> = Object.create(null);
|
|
45
|
-
for (const [name, raw] of Object.entries(source)) {
|
|
46
|
-
if (!/^[A-Za-z0-9_-]{1,64}$/.test(name)) throw Error("MCP server names must contain 1 to 64 letters, digits, underscores or hyphens");
|
|
47
|
-
const config = object(raw, `MCP server ${name}`), enabled = config["enabled"], timeout = config["timeoutMs"];
|
|
48
|
-
if (enabled !== undefined && typeof enabled !== "boolean") throw Error(`MCP server ${name}.enabled must be boolean`);
|
|
49
|
-
// Assumed cap protects startup and tool execution from a misconfigured peer, not an OS sandbox.
|
|
50
|
-
if (timeout !== undefined && (!Number.isSafeInteger(timeout) || Number(timeout) < 1 || Number(timeout) > 300_000)) throw Error("MCP timeoutMs must be an integer from 1 to 300000");
|
|
51
|
-
const common = { ...(typeof enabled === "boolean" ? { enabled } : {}), ...(typeof timeout === "number" ? { timeoutMs: timeout } : {}) };
|
|
52
|
-
if (config["transport"] === "stdio") {
|
|
53
|
-
if (Object.keys(config).some(key => !["transport", "command", "args", "env", "enabled", "timeoutMs"].includes(key))) throw Error(`MCP server ${name} has an unsupported stdio field`);
|
|
54
|
-
const command = optionalString(config, "command"), args = config["args"], env = config["env"];
|
|
55
|
-
if (!command) throw Error(`MCP server ${name}.command is required`);
|
|
56
|
-
if (args !== undefined && (!Array.isArray(args) || !args.every(arg => typeof arg === "string" && !arg.includes("\u0000")))) throw Error("MCP args must be strings without NUL");
|
|
57
|
-
result[name] = { transport: "stdio", command, ...common, ...(Array.isArray(args) ? { args: args.slice() as string[] } : {}), ...(env === undefined ? {} : { env: strings(env, "env") }) };
|
|
58
|
-
} else if (config["transport"] === "http") {
|
|
59
|
-
if (Object.keys(config).some(key => !["transport", "url", "bearerTokenEnv", "headers", "headersEnv", "oauth", "enabled", "timeoutMs"].includes(key))) throw Error(`MCP server ${name} has an unsupported HTTP field`);
|
|
60
|
-
const token = optionalString(config, "bearerTokenEnv", true), headers = config["headers"], headersEnv = config["headersEnv"];
|
|
61
|
-
if (config["oauth"] && token) throw Error("Use bearerTokenEnv or oauth for one MCP server, not both");
|
|
62
|
-
result[name] = { transport: "http", url: webUrl(config["url"]), ...common, ...(token ? { bearerTokenEnv: token } : {}),
|
|
63
|
-
...(headers === undefined ? {} : { headers: strings(headers, "headers") }), ...(headersEnv === undefined ? {} : { headersEnv: strings(headersEnv, "headersEnv", true) }),
|
|
64
|
-
...(config["oauth"] === undefined ? {} : { oauth: oauth(config["oauth"]) }) };
|
|
65
|
-
} else throw Error(`MCP server ${name}.transport must be stdio or http`);
|
|
66
|
-
}
|
|
67
|
-
return result;
|
|
68
|
-
}
|
package/src/core/model-picker.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `/model` list order. Pure: the catalog, readiness and recency go in,
|
|
3
|
-
* rows come out.
|
|
4
|
-
*
|
|
5
|
-
* The catalog holds thousands of entries across hundreds of providers; a
|
|
6
|
-
* picker that lists them all is the "every time I pick a model it's hard"
|
|
7
|
-
* report. The rule is OpenCode's (dialog-model.tsx): only models whose
|
|
8
|
-
* provider can actually authenticate, Recent first (bounded), then one
|
|
9
|
-
* group per provider, in catalog order. The current model is always shown, even when its
|
|
10
|
-
* credential stopped resolving, so the user can see why they are stuck.
|
|
11
|
-
*/
|
|
12
|
-
export interface PickerModel {
|
|
13
|
-
readonly key: string;
|
|
14
|
-
readonly provider: string;
|
|
15
|
-
readonly providerName: string;
|
|
16
|
-
readonly id: string;
|
|
17
|
-
readonly name: string;
|
|
18
|
-
readonly ready: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface PickerRow {
|
|
22
|
-
readonly key: string;
|
|
23
|
-
readonly section: "recent" | "provider";
|
|
24
|
-
/** Group heading: "Recent" or the provider's display name. */
|
|
25
|
-
readonly group: string;
|
|
26
|
-
readonly model: PickerModel;
|
|
27
|
-
readonly current: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Five recent models: one screen of a 10-row list stays for the provider groups. Assumed. */
|
|
31
|
-
export const RECENT_LIMIT = 5;
|
|
32
|
-
|
|
33
|
-
export function pickerRows(models: readonly PickerModel[], opts: { readonly current: string; readonly recent: readonly string[]; readonly limit?: number }): PickerRow[] {
|
|
34
|
-
const visible = models.filter(model => model.ready || model.key === opts.current);
|
|
35
|
-
const byKey = new Map(visible.map(model => [model.key, model]));
|
|
36
|
-
const rows: PickerRow[] = [];
|
|
37
|
-
const used = new Set<string>();
|
|
38
|
-
for (const key of opts.recent) {
|
|
39
|
-
if (rows.length >= (opts.limit ?? RECENT_LIMIT)) break;
|
|
40
|
-
const model = byKey.get(key);
|
|
41
|
-
if (!model || used.has(key)) continue;
|
|
42
|
-
used.add(key);
|
|
43
|
-
rows.push({ key, section: "recent", group: "Recent", model, current: key === opts.current });
|
|
44
|
-
}
|
|
45
|
-
const groups = new Map<string, PickerModel[]>();
|
|
46
|
-
for (const model of visible) {
|
|
47
|
-
if (used.has(model.key)) continue;
|
|
48
|
-
used.add(model.key);
|
|
49
|
-
const list = groups.get(model.provider) ?? [];
|
|
50
|
-
list.push(model);
|
|
51
|
-
groups.set(model.provider, list);
|
|
52
|
-
}
|
|
53
|
-
// Catalog order is curated (flagship models first), so it is kept for
|
|
54
|
-
// both the groups and the models inside them instead of re-sorting.
|
|
55
|
-
for (const [, list] of groups) {
|
|
56
|
-
for (const model of list) rows.push({ key: model.key, section: "provider", group: model.providerName, model, current: model.key === opts.current });
|
|
57
|
-
}
|
|
58
|
-
return rows;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** Most recent first, deduplicated, bounded. Recording is a pure update of the stored list. */
|
|
62
|
-
export function recordRecent(recent: readonly string[], key: string, limit = 10): string[] {
|
|
63
|
-
return [key, ...recent.filter(entry => entry !== key)].slice(0, limit);
|
|
64
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/** User selections become startup preferences; restored session state stays in the log (D8/Q.25). */
|
|
2
|
-
import { recordRecent } from "./model-picker.ts";
|
|
3
|
-
import { modelKey } from "./session-position.ts";
|
|
4
|
-
import { settingsToWrite, type Settings } from "./settings.ts";
|
|
5
|
-
import type { ThinkingLevel } from "./thinking.ts";
|
|
6
|
-
|
|
7
|
-
interface ModelIdentity { readonly provider: string; readonly id: string }
|
|
8
|
-
|
|
9
|
-
/** Keep the effective effort with its model, without changing another model's saved effort. */
|
|
10
|
-
export function modelPreferencePatch(model: ModelIdentity, recent: readonly string[], effort: ThinkingLevel): Settings {
|
|
11
|
-
return { defaultProvider: model.provider, defaultModel: model.id, recentModels: recordRecent(recent, modelKey(model)),
|
|
12
|
-
modelThinkingLevels: { [modelKey(model)]: effort } };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function thinkingPreferencePatch(model: ModelIdentity, effort: ThinkingLevel): Settings {
|
|
16
|
-
return { defaultThinking: effort, modelThinkingLevels: { [modelKey(model)]: effort } };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Patch only known preferences; retain future keys and nested fields not owned by this selection. */
|
|
20
|
-
export function mergePreferenceJson(previous: Readonly<Record<string, unknown>>, patch: Settings): Record<string, unknown> {
|
|
21
|
-
const next = { ...previous, ...settingsToWrite(patch) };
|
|
22
|
-
for (const key of ["terminal", "images", "markdown", "modelThinkingLevels"] as const) {
|
|
23
|
-
if (patch[key] === undefined) continue;
|
|
24
|
-
const old = previous[key];
|
|
25
|
-
next[key] = { ...(old !== null && typeof old === "object" && !Array.isArray(old) ? old : {}), ...patch[key] };
|
|
26
|
-
}
|
|
27
|
-
return next;
|
|
28
|
-
}
|
package/src/core/model-replay.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { LogEvent } from "./events.ts";
|
|
2
|
-
|
|
3
|
-
export interface ReplayModel {
|
|
4
|
-
provider: string; id: string; api: string; driver?: string; wireId?: string; baseUrl?: string;
|
|
5
|
-
compat?: unknown; nativeCompat?: unknown; thinkingLevelMap?: unknown;
|
|
6
|
-
}
|
|
7
|
-
function canonical(value: unknown): unknown {
|
|
8
|
-
if (Array.isArray(value)) return value.map(canonical);
|
|
9
|
-
if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => [key, canonical(item)]));
|
|
10
|
-
return value;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** D8: replay identity excludes prices, UI labels, credentials and sampling choices. */
|
|
14
|
-
export function replayDescriptor(model: ReplayModel): string {
|
|
15
|
-
return JSON.stringify(canonical([model.provider, model.id, model.api, model.driver ?? "legacy", model.wireId ?? model.id,
|
|
16
|
-
model.baseUrl ?? "", model.compat ?? null, model.nativeCompat ?? null, model.thinkingLevelMap ?? null]));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Old native profiles have no provable wire identity. One checkpoint makes subsequent replay explicit. */
|
|
20
|
-
export function needsReplayCheckpoint(events: readonly LogEvent[], key: string, requireKnown: boolean): boolean {
|
|
21
|
-
return events.some(event => event.t === "assistant" && (event.replay_key === undefined ? requireKnown : event.replay_key !== key));
|
|
22
|
-
}
|
package/src/core/model-scope.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/** Ordered model identities are session state until explicitly saved. D13: never resolve bare IDs here. */
|
|
2
|
-
import { asThinkingLevel, type ThinkingLevel } from "./thinking.ts";
|
|
3
|
-
import { modelKey } from "./session-position.ts";
|
|
4
|
-
|
|
5
|
-
export interface ScopedModel<T> { model: T; thinking?: ThinkingLevel }
|
|
6
|
-
|
|
7
|
-
/** Exact full references win before suffix parsing, including IDs whose colon is literal (Pi 02eed88). */
|
|
8
|
-
export function resolveScope<T extends { id: string; provider: string }>(
|
|
9
|
-
patterns: readonly string[], match: (pattern: string) => readonly T[], strict = false,
|
|
10
|
-
): { entries: ScopedModel<T>[]; diagnostics: string[] } {
|
|
11
|
-
const entries: ScopedModel<T>[] = [], diagnostics: string[] = [], seen = new Set<string>();
|
|
12
|
-
for (const pattern of patterns) {
|
|
13
|
-
let matches = match(pattern), thinking: ThinkingLevel | undefined;
|
|
14
|
-
if (!matches.length) {
|
|
15
|
-
const colon = pattern.lastIndexOf(":");
|
|
16
|
-
if (colon > 0) {
|
|
17
|
-
const suffix = pattern.slice(colon + 1), level = asThinkingLevel(suffix);
|
|
18
|
-
if (level || !strict) {
|
|
19
|
-
matches = match(pattern.slice(0, colon));
|
|
20
|
-
if (matches.length) {
|
|
21
|
-
thinking = level;
|
|
22
|
-
if (!level) diagnostics.push(`Invalid thinking level ${JSON.stringify(suffix)} in ${JSON.stringify(pattern)}; using the default`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (!matches.length) diagnostics.push(`No models match ${JSON.stringify(pattern)}`);
|
|
28
|
-
for (const model of matches) {
|
|
29
|
-
const key = modelKey(model); if (seen.has(key)) continue; seen.add(key);
|
|
30
|
-
entries.push({ model, ...(thinking === undefined ? {} : { thinking }) });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return { entries, diagnostics };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function scopeReference<T extends { id: string; provider: string }>(entry: ScopedModel<T>): string {
|
|
37
|
-
return modelKey(entry.model) + (entry.thinking ? `:${entry.thinking}` : "");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type ScopeChange = { readonly kind: "toggle"; readonly ids: readonly string[] } |
|
|
41
|
-
{ readonly kind: "enable" | "disable"; readonly ids: readonly string[] } |
|
|
42
|
-
{ readonly kind: "move"; readonly id: string; readonly delta: -1 | 1 };
|
|
43
|
-
export function changeModelScope(current: readonly string[], change: ScopeChange): string[] {
|
|
44
|
-
const next = [...new Set(current)];
|
|
45
|
-
if (change.kind === "move") {
|
|
46
|
-
const index = next.indexOf(change.id), target = index + change.delta;
|
|
47
|
-
if (index >= 0 && target >= 0 && target < next.length) [next[index], next[target]] = [next[target]!, next[index]!];
|
|
48
|
-
return next;
|
|
49
|
-
}
|
|
50
|
-
const ids = new Set(change.ids);
|
|
51
|
-
const disable = change.kind === "disable" || change.kind === "toggle" && change.ids.every(id => next.includes(id));
|
|
52
|
-
return disable ? next.filter(id => !ids.has(id)) : [...next, ...[...ids].filter(id => !next.includes(id))];
|
|
53
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/** Q.22: recovery advice must use the same evidence rules as the handoff. */
|
|
2
|
-
import type { LogEvent } from "./events.ts";
|
|
3
|
-
import { resolveEvidence, type EvidenceResolution } from "./evidence.ts";
|
|
4
|
-
import type { ToolDiagnostic } from "./tool-contract.ts";
|
|
5
|
-
import { failureDiagnostic, NOT_STARTED } from "./tool-failure.ts";
|
|
6
|
-
|
|
7
|
-
type Claim = Extract<LogEvent, { t: "claim" }>;
|
|
8
|
-
|
|
9
|
-
/** Only unknown work may suggest the existing unscoped completion path. */
|
|
10
|
-
export function unknownWorkClaimDiagnostic(events: readonly LogEvent[], claim: Claim): ToolDiagnostic {
|
|
11
|
-
const proof = resolveEvidence(events, claim.evidence);
|
|
12
|
-
const message = `unknown work_id ${claim.work_id}; no work item was created or completed`;
|
|
13
|
-
const diagnostic = failureDiagnostic("invalid_input", message, NOT_STARTED);
|
|
14
|
-
if (!proof.ok) return { ...diagnostic,
|
|
15
|
-
next: "For tracked work, record next before doing and verifying it. For a one-off task, omit work_id from done after an actual successful verification. A done note is optional." };
|
|
16
|
-
return { ...diagnostic,
|
|
17
|
-
next: "A current successful verification already exists. For this one-off completion, omit work_id; do not create next after verification or rerun the command just to record a note.",
|
|
18
|
-
recover: { tool: "note", input: { kind: "done", what: claim.what, proof: proof.evidence.command } } };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** A persisted claim is a known state change, even when its proof is insufficient. */
|
|
22
|
-
export function unverifiedNoteDiagnostic(reason: Extract<EvidenceResolution, { ok: false }>, event: string, openedAt?: string): ToolDiagnostic {
|
|
23
|
-
const cause = reason.reason === "nonzero_exit" ? `the matching command exited ${reason.exit}`
|
|
24
|
-
: reason.reason === "stale_workspace" ? "the verification no longer matches the observed workspace"
|
|
25
|
-
: openedAt ? `no matching verification was observed after work activation ${openedAt} in this segment`
|
|
26
|
-
: "no matching verification was observed in this segment";
|
|
27
|
-
const message = `Claim ${event} was recorded but remains unverified: ${cause}.`;
|
|
28
|
-
return { ...failureDiagnostic("execution_failed", message, { execution: "started", effects: "possible" }),
|
|
29
|
-
next: "The claim is already recorded; do not replay it unchanged. " + (reason.reason === "nonzero_exit"
|
|
30
|
-
? "Inspect the command's original output, fix the cause and verify again before claiming completion."
|
|
31
|
-
: reason.reason === "stale_workspace" ? "Verify the current workspace before claiming completion."
|
|
32
|
-
: openedAt ? "Run the verifier for this work activation before claiming completion; reopening never reuses an older verification."
|
|
33
|
-
: "Cite an actual successful command from this segment, or run the required verification first.") };
|
|
34
|
-
}
|
package/src/core/oauth-fields.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/** Validated wire data only; the runtime owns HTTP, time, polling and persistence. */
|
|
2
|
-
export interface OAuthTokens { access: string; refresh: string; expiresIn: number }
|
|
3
|
-
export interface DeviceAuthorization {
|
|
4
|
-
deviceCode: string;
|
|
5
|
-
userCode: string;
|
|
6
|
-
verificationUri: string;
|
|
7
|
-
verificationUriComplete?: string;
|
|
8
|
-
expiresIn: number;
|
|
9
|
-
interval?: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function record(value: unknown): Record<string, unknown> | undefined {
|
|
13
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
|
|
14
|
-
}
|
|
15
|
-
function positive(value: unknown): value is number { return typeof value === "number" && Number.isFinite(value) && value > 0; }
|
|
16
|
-
function token(value: unknown): value is string { return typeof value === "string" && value.length > 0 && !/[\s\x00-\x1f\x7f]/.test(value); }
|
|
17
|
-
|
|
18
|
-
/** Refresh rotation is optional; omission preserves the existing refresh capability. */
|
|
19
|
-
export function parseOAuthTokens(value: unknown, previousRefresh?: string): OAuthTokens | undefined {
|
|
20
|
-
const data = record(value);
|
|
21
|
-
const access = data?.["access_token"], refresh = data?.["refresh_token"] ?? previousRefresh, expiresIn = data?.["expires_in"];
|
|
22
|
-
if (!token(access) || !token(refresh) || !positive(expiresIn)) return undefined;
|
|
23
|
-
return { access, refresh, expiresIn };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function trustedOAuthUrl(value: unknown, origins: readonly string[]): value is string {
|
|
27
|
-
if (typeof value !== "string" || /[\x00-\x20\x7f]/.test(value)) return false;
|
|
28
|
-
try {
|
|
29
|
-
const url = new URL(value);
|
|
30
|
-
return url.protocol === "https:" && !url.username && !url.password && origins.includes(url.origin);
|
|
31
|
-
} catch { return false; }
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Never open an issuer-supplied arbitrary origin or print its control characters. */
|
|
35
|
-
export function parseDeviceAuthorization(value: unknown, origins: readonly string[]): DeviceAuthorization | undefined {
|
|
36
|
-
const data = record(value);
|
|
37
|
-
const deviceCode = data?.["device_code"], userCode = data?.["user_code"], verificationUri = data?.["verification_uri"];
|
|
38
|
-
const complete = data?.["verification_uri_complete"], expiresIn = data?.["expires_in"], interval = data?.["interval"];
|
|
39
|
-
if (!token(deviceCode) || typeof userCode !== "string" || !/^[A-Za-z0-9-]+$/.test(userCode)
|
|
40
|
-
|| !trustedOAuthUrl(verificationUri, origins) || !positive(expiresIn)
|
|
41
|
-
|| (complete !== undefined && !trustedOAuthUrl(complete, origins)) || (interval !== undefined && !positive(interval))) return undefined;
|
|
42
|
-
return { deviceCode, userCode, verificationUri, expiresIn,
|
|
43
|
-
...(typeof complete === "string" ? { verificationUriComplete: complete } : {}), ...(typeof interval === "number" ? { interval } : {}) };
|
|
44
|
-
}
|