@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/apps/commands.ts
DELETED
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Slash-command dispatch as a pure function.
|
|
3
|
-
*
|
|
4
|
-
* Matching the first token, not a string prefix, is the whole point: a
|
|
5
|
-
* prompt that starts with `/backdrop` used to be swallowed as `/back`.
|
|
6
|
-
* Unknown lone `/word`s are `unknown`; a slash-like word followed by
|
|
7
|
-
* more text is a prompt, so ordinary sentences stay ordinary.
|
|
8
|
-
*
|
|
9
|
-
* Prompt templates and skills register names into the same space. Built-in
|
|
10
|
-
* commands win, then templates, then skills; a loser is named, never silent.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type { RewindMode } from "../runtime/loop.ts";
|
|
14
|
-
import { expandTemplate, type PromptTemplate } from "../core/prompts.ts";
|
|
15
|
-
import { skillInvocationMessage, type Skill } from "../core/skills.ts";
|
|
16
|
-
|
|
17
|
-
export type Command =
|
|
18
|
-
| { kind: "workflow"; mode: "build" | "plan" }
|
|
19
|
-
| { kind: "agent"; name?: string }
|
|
20
|
-
| { kind: "mcp"; action: "status" | "login" | "logout"; name?: string }
|
|
21
|
-
| { kind: "review" | "diff"; args: string }
|
|
22
|
-
| { kind: "extension"; name: string; args: string }
|
|
23
|
-
| { kind: "prompt"; text: string; skill?: Skill }
|
|
24
|
-
| { kind: "quit" }
|
|
25
|
-
| { kind: "usage" }
|
|
26
|
-
| { kind: "state" }
|
|
27
|
-
| { kind: "context" }
|
|
28
|
-
| { kind: "control" }
|
|
29
|
-
| { kind: "acceptance" }
|
|
30
|
-
| { kind: "tasks" }
|
|
31
|
-
| { kind: "branches"; action?: "wait" | "cancel" | "status"; node?: number }
|
|
32
|
-
| { kind: "processes" }
|
|
33
|
-
| { kind: "accept"; criterion: string }
|
|
34
|
-
| { kind: "goal"; action: "status" } | { kind: "goal"; action: "clear" } | { kind: "goal"; action: "accept"; pick: string }
|
|
35
|
-
| { kind: "goal"; action: "set"; objective: string }
|
|
36
|
-
| { kind: "model"; pattern?: string }
|
|
37
|
-
| { kind: "scoped-models" }
|
|
38
|
-
| { kind: "login"; provider?: string }
|
|
39
|
-
| { kind: "logout"; provider?: string }
|
|
40
|
-
| { kind: "back"; arg?: string; mode: RewindMode; confirm: boolean }
|
|
41
|
-
| { kind: "tree" }
|
|
42
|
-
| { kind: "new" }
|
|
43
|
-
| { kind: "resume"; id?: string }
|
|
44
|
-
| { kind: "name"; name: string }
|
|
45
|
-
| { kind: "session" }
|
|
46
|
-
| { kind: "help" }
|
|
47
|
-
| { kind: "trust"; target?: "here" | "parent" | "never" | "once" }
|
|
48
|
-
| { kind: "reload" }
|
|
49
|
-
| { kind: "config" }
|
|
50
|
-
| { kind: "models-refresh" }
|
|
51
|
-
| { kind: "settings"; field?: string; value?: string }
|
|
52
|
-
| { kind: "hotkeys" }
|
|
53
|
-
| { kind: "thinking"; level?: string }
|
|
54
|
-
| { kind: "export"; file?: string }
|
|
55
|
-
| { kind: "import"; file?: string }
|
|
56
|
-
| { kind: "debug"; file?: string }
|
|
57
|
-
| { kind: "changelog" }
|
|
58
|
-
| { kind: "update" }
|
|
59
|
-
| { kind: "copy" }
|
|
60
|
-
| { kind: "attachments" }
|
|
61
|
-
| { kind: "fork"; arg?: string }
|
|
62
|
-
| { kind: "clone" }
|
|
63
|
-
| { kind: "unknown"; input: string };
|
|
64
|
-
|
|
65
|
-
/** One catalog owns discoverability, parsing and busy-turn policy. */
|
|
66
|
-
export const COMMANDS = [
|
|
67
|
-
{ name: "model", description: "Choose a model", argumentHint: "[id]", busy: "idle" },
|
|
68
|
-
{ name: "scoped-models", description: "Enable and order models for cycling", busy: "idle" },
|
|
69
|
-
{ name: "thinking", description: "Set reasoning effort", argumentHint: "[level]", busy: "idle" },
|
|
70
|
-
{ name: "settings", description: "Configure appearance, input and model behavior", argumentHint: "[key value]", busy: "idle" },
|
|
71
|
-
{ name: "provider", description: "Connect and manage providers: account, API key, gateway or local server", argumentHint: "[provider]", busy: "idle" },
|
|
72
|
-
{ name: "logout", description: "Remove a stored credential", argumentHint: "[provider]", busy: "idle" },
|
|
73
|
-
{ name: "new", description: "Start a new session", busy: "idle" },
|
|
74
|
-
{ name: "resume", description: "Search saved sessions", argumentHint: "[id]", busy: "idle" },
|
|
75
|
-
{ name: "tree", description: "Navigate session context", busy: "run" },
|
|
76
|
-
{ name: "fork", description: "Fork at a user message", argumentHint: "[n]", busy: "idle" },
|
|
77
|
-
{ name: "clone", description: "Copy this branch into a new session", busy: "idle" },
|
|
78
|
-
{ name: "back", description: "Restore context or files explicitly", argumentHint: "[n [files|context|both] [confirm]]", busy: "idle" },
|
|
79
|
-
{ name: "name", description: "Name this session", argumentHint: "<name>", busy: "idle" },
|
|
80
|
-
{ name: "session", description: "Show session details", busy: "run" },
|
|
81
|
-
{ name: "usage", description: "Show token usage and costs", busy: "run" },
|
|
82
|
-
{ name: "state", description: "Show log and handoff state", busy: "run" },
|
|
83
|
-
{ name: "context", description: "Explain context sources, omissions and token estimates", busy: "run" },
|
|
84
|
-
{ name: "control", description: "Inspect the goal, evidence and context; control the active turn", busy: "run" },
|
|
85
|
-
{ name: "acceptance", description: "Show declared criteria and current evidence", busy: "idle" },
|
|
86
|
-
{ name: "tasks", description: "Show work dependencies, readiness and ownership", busy: "run" },
|
|
87
|
-
{ name: "branches", description: "Inspect or join owned background work", argumentHint: "[wait|cancel|status node]", busy: "idle" },
|
|
88
|
-
{ name: "processes", description: "Show process observations and available handles", busy: "run" },
|
|
89
|
-
{ name: "accept", description: "Record your acceptance of a human criterion", argumentHint: "<criterion ID>", busy: "idle" },
|
|
90
|
-
{ name: "goal", description: "Set a goal: the model drafts checks, you accept them, work continues until they pass", argumentHint: "<objective> | clear | accept all|1,3", busy: "idle" },
|
|
91
|
-
{ name: "export", description: "Export HTML or JSONL", argumentHint: "[file]", busy: "idle" },
|
|
92
|
-
{ name: "import", description: "Import a portable JSONL session", argumentHint: "<file>", busy: "idle" },
|
|
93
|
-
{ name: "debug", description: "Write local terminal diagnostics", argumentHint: "[file]", busy: "run" },
|
|
94
|
-
{ name: "changelog", description: "Show local release notes", busy: "run" },
|
|
95
|
-
{ name: "update", description: "Check for a newer xeno and install it; restart to use it", busy: "run" },
|
|
96
|
-
{ name: "copy", description: "Copy the last assistant reply", busy: "run" },
|
|
97
|
-
{ name: "attachments", description: "Remove images from the current draft", busy: "run" },
|
|
98
|
-
{ name: "models", description: "Refresh the model catalog", argumentHint: "<refresh>", busy: "idle" },
|
|
99
|
-
{ name: "trust", description: "Set workspace configuration trust", argumentHint: "[here|parent|never]", busy: "idle" },
|
|
100
|
-
{ name: "reload", description: "Reload settings, skills, prompts, themes and models", busy: "idle" },
|
|
101
|
-
{ name: "config", description: "Configure resource sources and enablement", busy: "idle" },
|
|
102
|
-
{ name: "hotkeys", description: "Show active keybindings", busy: "run" },
|
|
103
|
-
{ name: "help", description: "Show commands and input help", busy: "run" },
|
|
104
|
-
{ name: "quit", description: "Exit xeno", busy: "run" },
|
|
105
|
-
{ name: "exit", description: "Exit xeno", busy: "run" },
|
|
106
|
-
{ name: "plan", description: "Explore and plan with read-only capabilities", busy: "idle" },
|
|
107
|
-
{ name: "build", description: "Enable implementation at a resource checkpoint", busy: "idle" },
|
|
108
|
-
{ name: "agent", description: "List or select a reusable agent profile", argumentHint: "[name]", busy: "idle" },
|
|
109
|
-
{ name: "mcp", description: "Inspect MCP servers or log in/out", argumentHint: "[status|login|logout [name]]", busy: "idle" },
|
|
110
|
-
{ name: "diff", description: "Inspect current, branch, commit or last-turn changes", argumentHint: "[working|branch base|commit sha|last-turn]", busy: "idle" },
|
|
111
|
-
// /review already belongs to existing user prompt/skill resources. Keep it usable.
|
|
112
|
-
{ name: "review-code", description: "Run an independent read-only code review", argumentHint: "[working|branch base|commit sha|last-turn]", busy: "idle" },
|
|
113
|
-
] as const;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Hidden spellings of a listed command. Not in COMMANDS, so the `/` menu,
|
|
117
|
-
* the startup hint and completion show one entry per job.
|
|
118
|
-
*/
|
|
119
|
-
const ALIASES: Readonly<Record<string, string>> = { login: "provider", connect: "provider" };
|
|
120
|
-
|
|
121
|
-
// Hidden spellings still own their names, so resources cannot promise an unreachable route.
|
|
122
|
-
export const BUILTIN_COMMAND_NAMES: readonly string[] = [...COMMANDS.map(command => command.name), ...Object.keys(ALIASES)];
|
|
123
|
-
|
|
124
|
-
export function commandDefinition(input: string): (typeof COMMANDS)[number] | undefined {
|
|
125
|
-
const typed = input.trim().split(/\s/, 1)[0]?.slice(1).toLowerCase() ?? "";
|
|
126
|
-
const name = ALIASES[typed] ?? typed;
|
|
127
|
-
return COMMANDS.find((command) => command.name === name);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const BUILTIN_SET = new Set<string>(BUILTIN_COMMAND_NAMES);
|
|
131
|
-
|
|
132
|
-
export interface SlashCatalog {
|
|
133
|
-
readonly prompts: ReadonlyMap<string, PromptTemplate>;
|
|
134
|
-
readonly skills: ReadonlyMap<string, Skill>;
|
|
135
|
-
readonly skillCommands?: boolean;
|
|
136
|
-
readonly skillExecution?: boolean;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function resolveSlashCatalog(
|
|
140
|
-
prompts: readonly PromptTemplate[],
|
|
141
|
-
skills: readonly Skill[],
|
|
142
|
-
): { catalog: SlashCatalog; diagnostics: readonly string[] } {
|
|
143
|
-
const diagnostics: string[] = [];
|
|
144
|
-
const promptMap = new Map<string, PromptTemplate>();
|
|
145
|
-
const skillMap = new Map<string, Skill>();
|
|
146
|
-
|
|
147
|
-
for (const prompt of prompts) {
|
|
148
|
-
if (BUILTIN_SET.has(prompt.name)) {
|
|
149
|
-
diagnostics.push(
|
|
150
|
-
`prompt template "${prompt.name}" from ${prompt.filePath} is shadowed by a built-in command`,
|
|
151
|
-
);
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
promptMap.set(prompt.name, prompt);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
for (const skill of skills) {
|
|
158
|
-
if (BUILTIN_SET.has(skill.name)) {
|
|
159
|
-
diagnostics.push(
|
|
160
|
-
`skill "${skill.name}" from ${skill.filePath} is shadowed by a built-in command`,
|
|
161
|
-
);
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
const prompt = promptMap.get(skill.name);
|
|
165
|
-
if (prompt !== undefined) {
|
|
166
|
-
diagnostics.push(
|
|
167
|
-
`skill "${skill.name}" from ${skill.filePath} is shadowed by prompt template ${prompt.filePath}`,
|
|
168
|
-
);
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
skillMap.set(skill.name, skill);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return { catalog: { prompts: promptMap, skills: skillMap }, diagnostics };
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export function parseCommand(input: string, catalog?: SlashCatalog): Command {
|
|
178
|
-
const text = input.trim();
|
|
179
|
-
if (!text.startsWith("/")) return { kind: "prompt", text };
|
|
180
|
-
|
|
181
|
-
const [head, ...rest] = text.split(/\s+/);
|
|
182
|
-
const typed = (head ?? "").toLowerCase();
|
|
183
|
-
const token = `/${ALIASES[typed.slice(1)] ?? typed.slice(1)}`;
|
|
184
|
-
if (token === "/control") return { kind: "control" };
|
|
185
|
-
const arg = rest.join(" ");
|
|
186
|
-
|
|
187
|
-
if (!commandDefinition(text)) return resolveRegistered(token, arg, text, rest.length, catalog);
|
|
188
|
-
|
|
189
|
-
switch (token) {
|
|
190
|
-
case "/plan": return arg ? { kind: "unknown", input: text } : { kind: "workflow", mode: "plan" };
|
|
191
|
-
case "/build": return arg ? { kind: "unknown", input: text } : { kind: "workflow", mode: "build" };
|
|
192
|
-
case "/agent": return arg ? { kind: "agent", name: arg } : { kind: "agent" };
|
|
193
|
-
case "/mcp": { const [action = "status", name] = rest; return ["status", "login", "logout"].includes(action) && rest.length <= 2 ? { kind: "mcp", action: action as "status" | "login" | "logout", ...(name ? { name } : {}) } : { kind: "unknown", input: text }; }
|
|
194
|
-
case "/diff": return { kind: "diff", args: arg };
|
|
195
|
-
case "/review-code": return { kind: "review", args: arg };
|
|
196
|
-
case "/reload": return { kind: "reload" };
|
|
197
|
-
case "/config": return { kind: "config" };
|
|
198
|
-
case "/update": return arg === "" ? { kind: "update" } : { kind: "unknown", input: text };
|
|
199
|
-
case "/attachments": return { kind: "attachments" };
|
|
200
|
-
case "/scoped-models": return { kind: "scoped-models" };
|
|
201
|
-
case "/quit":
|
|
202
|
-
case "/exit":
|
|
203
|
-
return { kind: "quit" };
|
|
204
|
-
case "/usage":
|
|
205
|
-
return { kind: "usage" };
|
|
206
|
-
case "/state":
|
|
207
|
-
return { kind: "state" };
|
|
208
|
-
case "/context": return { kind: "context" };
|
|
209
|
-
case "/acceptance": return { kind: "acceptance" };
|
|
210
|
-
case "/tasks": return { kind: "tasks" };
|
|
211
|
-
case "/processes": return { kind: "processes" };
|
|
212
|
-
case "/branches": {
|
|
213
|
-
if (!arg) return { kind: "branches" };
|
|
214
|
-
const action = rest[0], node = Number(rest[1]);
|
|
215
|
-
return (action === "wait" || action === "cancel" || action === "status") && Number.isSafeInteger(node) && node >= 0 && rest.length === 2
|
|
216
|
-
? { kind: "branches", action, node } : { kind: "unknown", input: text };
|
|
217
|
-
}
|
|
218
|
-
case "/accept": return { kind: "accept", criterion: arg };
|
|
219
|
-
case "/goal":
|
|
220
|
-
if (!arg) return { kind: "goal", action: "status" };
|
|
221
|
-
if (arg === "clear") return { kind: "goal", action: "clear" };
|
|
222
|
-
if (rest[0] === "accept") return { kind: "goal", action: "accept", pick: rest.slice(1).join(" ") };
|
|
223
|
-
return { kind: "goal", action: "set", objective: arg };
|
|
224
|
-
case "/model":
|
|
225
|
-
return arg.length > 0 ? { kind: "model", pattern: arg } : { kind: "model" };
|
|
226
|
-
case "/provider":
|
|
227
|
-
return rest[0] === undefined ? { kind: "login" } : { kind: "login", provider: rest[0] };
|
|
228
|
-
case "/logout":
|
|
229
|
-
return rest[0] === undefined ? { kind: "logout" } : { kind: "logout", provider: rest[0] };
|
|
230
|
-
case "/back": {
|
|
231
|
-
const [n, ...flags] = rest;
|
|
232
|
-
const words = new Set(flags);
|
|
233
|
-
const mode: RewindMode =
|
|
234
|
-
words.has("files") ? "files" : words.has("context") ? "context" : "both";
|
|
235
|
-
const confirm = words.has("confirm");
|
|
236
|
-
return n === undefined
|
|
237
|
-
? { kind: "back", mode, confirm }
|
|
238
|
-
: { kind: "back", arg: n, mode, confirm };
|
|
239
|
-
}
|
|
240
|
-
case "/tree":
|
|
241
|
-
return { kind: "tree" };
|
|
242
|
-
case "/new":
|
|
243
|
-
return { kind: "new" };
|
|
244
|
-
case "/resume":
|
|
245
|
-
return arg.length > 0 ? { kind: "resume", id: arg } : { kind: "resume" };
|
|
246
|
-
case "/name":
|
|
247
|
-
return { kind: "name", name: arg };
|
|
248
|
-
case "/session":
|
|
249
|
-
return { kind: "session" };
|
|
250
|
-
case "/help":
|
|
251
|
-
return { kind: "help" };
|
|
252
|
-
case "/models":
|
|
253
|
-
return arg === "refresh" ? { kind: "models-refresh" } : { kind: "unknown", input: text };
|
|
254
|
-
case "/settings": {
|
|
255
|
-
if (rest.length === 0) return { kind: "settings" };
|
|
256
|
-
const field = rest[0];
|
|
257
|
-
if (field === undefined) return { kind: "settings" };
|
|
258
|
-
if (rest.length === 1) return { kind: "settings", field };
|
|
259
|
-
return { kind: "settings", field, value: rest.slice(1).join(" ") };
|
|
260
|
-
}
|
|
261
|
-
case "/hotkeys":
|
|
262
|
-
return { kind: "hotkeys" };
|
|
263
|
-
case "/thinking":
|
|
264
|
-
return arg.length > 0 ? { kind: "thinking", level: arg } : { kind: "thinking" };
|
|
265
|
-
case "/changelog": return { kind: "changelog" };
|
|
266
|
-
case "/export":
|
|
267
|
-
case "/import":
|
|
268
|
-
case "/debug": {
|
|
269
|
-
const kind = token.slice(1) as "export" | "import" | "debug";
|
|
270
|
-
const path = text.slice(head!.length).trim().replace(/^(?:"(.*)"|'(.*)')$/, (_m, double: string | undefined, single: string | undefined) => double ?? single ?? "");
|
|
271
|
-
return path ? { kind, file: path } : { kind };
|
|
272
|
-
}
|
|
273
|
-
case "/copy":
|
|
274
|
-
return { kind: "copy" };
|
|
275
|
-
case "/fork":
|
|
276
|
-
return arg.length > 0 ? { kind: "fork", arg } : { kind: "fork" };
|
|
277
|
-
case "/clone":
|
|
278
|
-
return { kind: "clone" };
|
|
279
|
-
case "/trust": {
|
|
280
|
-
if (!rest.length) return { kind: "trust" };
|
|
281
|
-
const word = (rest[0] ?? "here").toLowerCase();
|
|
282
|
-
if (word === "once") return { kind: "trust", target: "once" };
|
|
283
|
-
if (rest.length === 0 || word === "here" || word === "yes") {
|
|
284
|
-
return { kind: "trust", target: "here" };
|
|
285
|
-
}
|
|
286
|
-
if (word === "parent") return { kind: "trust", target: "parent" };
|
|
287
|
-
if (word === "never" || word === "no") return { kind: "trust", target: "never" };
|
|
288
|
-
return { kind: "unknown", input: text };
|
|
289
|
-
}
|
|
290
|
-
default:
|
|
291
|
-
return resolveRegistered(token, arg, text, rest.length, catalog);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function resolveRegistered(
|
|
296
|
-
token: string,
|
|
297
|
-
arg: string,
|
|
298
|
-
text: string,
|
|
299
|
-
restCount: number,
|
|
300
|
-
catalog: SlashCatalog | undefined,
|
|
301
|
-
): Command {
|
|
302
|
-
if (catalog !== undefined) {
|
|
303
|
-
if (token.startsWith("/skill:") && catalog.skillCommands !== false) {
|
|
304
|
-
const name = token.slice("/skill:".length);
|
|
305
|
-
const skill = catalog.skills.get(name);
|
|
306
|
-
if (skill !== undefined) {
|
|
307
|
-
if (skill.userInvocable === false) return { kind: "unknown", input: text };
|
|
308
|
-
return { kind: "prompt", text: skillInvocationMessage(skill, arg), ...(catalog.skillExecution ? { skill } : {}) };
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
const prompt = catalog.prompts.get(token.slice(1));
|
|
312
|
-
if (prompt !== undefined) {
|
|
313
|
-
return { kind: "prompt", text: expandTemplate(prompt.content, arg).text };
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
// A lone unknown /word is a failed command. More text means the user
|
|
317
|
-
// typed a sentence that happens to start with a slash-like token.
|
|
318
|
-
return restCount === 0 ? { kind: "unknown", input: text } : { kind: "prompt", text };
|
|
319
|
-
}
|
package/src/apps/completions.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What the composer offers for the text at the cursor. Pure given its
|
|
3
|
-
* sources, so the three cases are tested without a terminal:
|
|
4
|
-
* "/mo|" command names (the palette's own entries)
|
|
5
|
-
* "/thinking h|" the command's argument values
|
|
6
|
-
* "see @src/ap|" workspace paths (ranked fuzzy, quoted when they contain spaces)
|
|
7
|
-
* `@` inside a word (an e-mail) or after a backslash is not a reference.
|
|
8
|
-
*/
|
|
9
|
-
import type { App } from "./startup.ts";
|
|
10
|
-
import { SUBSCRIPTION_OPTIONS, subscriptionById } from "../runtime/oauth.ts";
|
|
11
|
-
import { supportedThinkingLevels } from "../core/thinking.ts";
|
|
12
|
-
import { interactiveSettingKeys } from "../core/settings.ts";
|
|
13
|
-
import { fuzzyFilter } from "../tui/fuzzy.ts";
|
|
14
|
-
import { COMMANDS, commandDefinition } from "./commands.ts";
|
|
15
|
-
import { commandCompletionRank } from "../core/completion-action.ts";
|
|
16
|
-
import type { Completion } from "../tui/ui/composer.ts";
|
|
17
|
-
import type { ListItem } from "../tui/ui/list-model.ts";
|
|
18
|
-
|
|
19
|
-
export interface CompletionSources {
|
|
20
|
-
readonly commands: readonly { name: string; description: string }[];
|
|
21
|
-
readonly argumentValues: (command: string) => readonly string[];
|
|
22
|
-
readonly paths: readonly string[];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Twelve rows: enough to see siblings of a path without hiding the composer. Assumed. */
|
|
26
|
-
const MAX_ITEMS = 12;
|
|
27
|
-
|
|
28
|
-
export function completionAt(text: string, cursor: number, sources: CompletionSources): Completion | undefined {
|
|
29
|
-
const before = text.slice(0, cursor);
|
|
30
|
-
const line = before.slice(before.lastIndexOf("\n") + 1);
|
|
31
|
-
const lineStart = cursor - line.length;
|
|
32
|
-
if (line.startsWith("/") && lineStart === 0) {
|
|
33
|
-
const space = line.indexOf(" ");
|
|
34
|
-
if (space < 0) {
|
|
35
|
-
const query = line.slice(1).toLowerCase();
|
|
36
|
-
const items = sources.commands
|
|
37
|
-
.map(command => ({ command, rank: commandCompletionRank(command.name, query) }))
|
|
38
|
-
.filter(item => Number.isFinite(item.rank)).sort((a, b) => a.rank - b.rank)
|
|
39
|
-
.map(({ command }) => ({ value: `/${command.name} `, label: `/${command.name}`, description: command.description }));
|
|
40
|
-
return items.length ? { kind: "command", start: 0, end: cursor, items: items.slice(0, MAX_ITEMS) } : undefined;
|
|
41
|
-
}
|
|
42
|
-
const command = line.slice(1, space).toLowerCase();
|
|
43
|
-
const arg = line.slice(space + 1);
|
|
44
|
-
if (arg.includes(" ")) return undefined;
|
|
45
|
-
const values = sources.argumentValues(command);
|
|
46
|
-
if (!values.length) return undefined;
|
|
47
|
-
const items = fuzzyFilter(values, arg).slice(0, MAX_ITEMS).map(value => ({ value, label: value }));
|
|
48
|
-
return items.length ? { kind: "argument", start: space + 1, end: cursor, items } : undefined;
|
|
49
|
-
}
|
|
50
|
-
const at = line.lastIndexOf("@");
|
|
51
|
-
if (at < 0) return undefined;
|
|
52
|
-
const prev = line[at - 1];
|
|
53
|
-
if (prev !== undefined && !/\s/.test(prev)) return undefined;
|
|
54
|
-
const query = line.slice(at + 1);
|
|
55
|
-
if (/\s/.test(query) && !query.startsWith("\"")) return undefined;
|
|
56
|
-
const bare = query.replace(/^"/, "");
|
|
57
|
-
const items: ListItem[] = fuzzyFilter(sources.paths, bare).slice(0, MAX_ITEMS)
|
|
58
|
-
.map(path => ({ value: `@${/\s/.test(path) ? JSON.stringify(path) : path} `, label: path }));
|
|
59
|
-
return items.length ? { kind: "path", start: lineStart + at, end: cursor, items } : undefined;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function completionSources(app: App, paths: readonly string[]): CompletionSources {
|
|
63
|
-
const providers = [...new Set([...app.catalog.map(m => m.provider).filter(provider => !subscriptionById(provider)), ...SUBSCRIPTION_OPTIONS.map(p => p.id)])];
|
|
64
|
-
const values: Record<string, () => string[]> = {
|
|
65
|
-
// Model identities belong to the searchable picker. The generic completer
|
|
66
|
-
// still handles arbitrary argument sources; this app supplies only one
|
|
67
|
-
// model selection surface, rather than a second list with different keys.
|
|
68
|
-
thinking: () => [...supportedThinkingLevels(app.providerConfig.spec)],
|
|
69
|
-
provider: () => providers, logout: () => Object.keys(app.auth).filter(provider => app.auth[provider] !== undefined),
|
|
70
|
-
settings: interactiveSettingKeys,
|
|
71
|
-
models: () => ["refresh"], trust: () => ["once", "here", "parent", "never"],
|
|
72
|
-
};
|
|
73
|
-
return {
|
|
74
|
-
commands: [...COMMANDS.filter(command => command.name !== "exit"), ...commandEntries(app)],
|
|
75
|
-
argumentValues: command => values[commandDefinition(`/${command}`)?.name ?? command.toLowerCase()]?.() ?? [],
|
|
76
|
-
paths,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Built-ins, then extension commands, prompt templates and skills: the same names the palette lists. */
|
|
81
|
-
export function commandEntries(app: App): { name: string; description: string; section: string }[] {
|
|
82
|
-
return [
|
|
83
|
-
...[...app.extensions?.commands ?? []].map(([name, command]) => ({ name, description: command.description ?? "extension command", section: "Extensions" })),
|
|
84
|
-
...[...(app.slash?.prompts.values() ?? [])].map(p => ({ name: p.name, description: p.description ?? "prompt template", section: "Prompts" })),
|
|
85
|
-
...(app.slash?.skillCommands === false ? [] : [...(app.slash?.skills.values() ?? [])].map(s => ({ name: `skill:${s.name}`, description: s.description ?? "skill", section: "Skills" }))),
|
|
86
|
-
];
|
|
87
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/** Q24: bounded local JSONL transport. No TCP listener or additional runtime dependency. */
|
|
2
|
-
import { createServer, type Socket } from "node:net";
|
|
3
|
-
import { chmodSync } from "node:fs";
|
|
4
|
-
import { lstat, mkdir, rm } from "node:fs/promises";
|
|
5
|
-
import { dirname, resolve } from "node:path";
|
|
6
|
-
import { CONTROL_SCHEMA } from "../core/control-protocol.ts";
|
|
7
|
-
import { ControlConnection, type RpcOutput } from "../runtime/control-connection.ts";
|
|
8
|
-
import type { SessionControl } from "../runtime/session-control.ts";
|
|
9
|
-
import type { SessionHub } from "../runtime/session-hub.ts";
|
|
10
|
-
|
|
11
|
-
export class ControlJsonl {
|
|
12
|
-
private buffer = Buffer.alloc(0);
|
|
13
|
-
private pending = 0;
|
|
14
|
-
private tail = Promise.resolve();
|
|
15
|
-
private closed = false;
|
|
16
|
-
readonly connection: ControlConnection;
|
|
17
|
-
private readonly stop: () => void;
|
|
18
|
-
private readonly output: (text: string) => void;
|
|
19
|
-
constructor(control: () => SessionControl, output: (text: string) => void, stop: () => void, denyOnClose = false, hub?: SessionHub) {
|
|
20
|
-
this.stop = stop;
|
|
21
|
-
this.output = text => { try { output(text); } catch { this.close(); this.stop(); } };
|
|
22
|
-
this.connection = new ControlConnection(control, message => this.write(message), { denyOnClose, ...(hub ? { hub } : {}) });
|
|
23
|
-
}
|
|
24
|
-
private write(message: RpcOutput): void {
|
|
25
|
-
if (this.closed) return;
|
|
26
|
-
const text = JSON.stringify(message) + "\n";
|
|
27
|
-
if (Buffer.byteLength(text) > CONTROL_SCHEMA.limits.frameBytes) {
|
|
28
|
-
if ("id" in message) this.output(JSON.stringify({ id: message.id, error: { code: -32002, message: "response exceeds frame limit; use paginated inspectors" } }) + "\n");
|
|
29
|
-
else this.fail("event exceeds frame limit; reconnect and resynchronize");
|
|
30
|
-
} else this.output(text);
|
|
31
|
-
}
|
|
32
|
-
private fail(message: string): void {
|
|
33
|
-
if (this.closed) return;
|
|
34
|
-
this.output(JSON.stringify({ id: null, error: { code: -32001, message } }) + "\n");
|
|
35
|
-
this.close(); this.stop();
|
|
36
|
-
}
|
|
37
|
-
feed(chunk: Uint8Array): void {
|
|
38
|
-
if (this.closed) return;
|
|
39
|
-
this.buffer = Buffer.concat([this.buffer, chunk]);
|
|
40
|
-
for (;;) {
|
|
41
|
-
const newline = this.buffer.indexOf(10);
|
|
42
|
-
if (newline < 0) { if (this.buffer.length > CONTROL_SCHEMA.limits.frameBytes) this.fail("input frame exceeds limit"); return; }
|
|
43
|
-
if (newline > CONTROL_SCHEMA.limits.frameBytes) { this.fail("input frame exceeds limit"); return; }
|
|
44
|
-
const line = this.buffer.subarray(0, newline).toString("utf8"); this.buffer = this.buffer.subarray(newline + 1);
|
|
45
|
-
if (!line.trim()) continue;
|
|
46
|
-
if (++this.pending > CONTROL_SCHEMA.limits.queuedRequests) { this.fail("request queue is full"); return; }
|
|
47
|
-
this.tail = this.tail.then(async () => {
|
|
48
|
-
if (this.closed) return;
|
|
49
|
-
let value: unknown;
|
|
50
|
-
try { value = JSON.parse(line); }
|
|
51
|
-
catch { this.write({ id: null, error: { code: -32700, message: "invalid JSON" } }); return; }
|
|
52
|
-
await this.connection.receive(value);
|
|
53
|
-
}).finally(() => { this.pending--; });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async drained(): Promise<void> { await this.tail; }
|
|
57
|
-
close(): void { this.closed = true; this.buffer = Buffer.alloc(0); this.connection.close(); }
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export async function listenControl(path: string, control: () => SessionControl): Promise<() => Promise<void>> {
|
|
61
|
-
const absolute = resolve(path), parent = dirname(absolute);
|
|
62
|
-
await mkdir(parent, { recursive: true, mode: 0o700 });
|
|
63
|
-
const directory = await lstat(parent);
|
|
64
|
-
if (!directory.isDirectory() || directory.mode & 0o077 || process.getuid && directory.uid !== process.getuid()) throw Error("control socket requires an owned private directory (mode 0700)");
|
|
65
|
-
try { await lstat(absolute); throw Error("control socket path already exists; refusing to replace it"); }
|
|
66
|
-
catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
|
|
67
|
-
const clients = new Map<Socket, ControlJsonl>();
|
|
68
|
-
const server = createServer(socket => {
|
|
69
|
-
// Assumed local adapter capacity; together with per-peer bounds this caps retained transport memory.
|
|
70
|
-
if (clients.size >= 32) { socket.destroy(); return; }
|
|
71
|
-
const peer = new ControlJsonl(control, text => {
|
|
72
|
-
if (socket.writableLength + Buffer.byteLength(text) > CONTROL_SCHEMA.limits.outputBytes) socket.destroy(); else socket.write(text);
|
|
73
|
-
}, () => socket.destroy());
|
|
74
|
-
clients.set(socket, peer);
|
|
75
|
-
socket.on("data", chunk => peer.feed(typeof chunk === "string" ? Buffer.from(chunk) : chunk));
|
|
76
|
-
socket.on("error", () => socket.destroy());
|
|
77
|
-
socket.on("close", () => { peer.close(); clients.delete(socket); });
|
|
78
|
-
});
|
|
79
|
-
await new Promise<void>((resolveReady, reject) => {
|
|
80
|
-
server.once("error", reject);
|
|
81
|
-
server.listen(absolute, () => { chmodSync(absolute, 0o600); resolveReady(); });
|
|
82
|
-
});
|
|
83
|
-
const owned = await lstat(absolute);
|
|
84
|
-
return async () => {
|
|
85
|
-
for (const [socket, peer] of clients) { peer.close(); socket.destroy(); }
|
|
86
|
-
await new Promise<void>((resolveClosed, reject) => server.close(error => error ? reject(error) : resolveClosed()));
|
|
87
|
-
try { const current = await lstat(absolute); if (current.ino === owned.ino && current.dev === owned.dev) await rm(absolute); }
|
|
88
|
-
catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
|
|
89
|
-
};
|
|
90
|
-
}
|
package/src/apps/export-cli.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/** Offline export is a local storage operation and never constructs an agent or loads extensions. */
|
|
2
|
-
import { mkdtemp, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
-
import { basename, join, resolve } from "node:path";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { toHtml } from "../core/export.ts";
|
|
6
|
-
import { readCursor } from "../store/log.ts";
|
|
7
|
-
import { readNodeHistory } from "../store/restore.ts";
|
|
8
|
-
import { importSessionArchive } from "../store/session-archive.ts";
|
|
9
|
-
import { findSessionByPrefix } from "../store/sessions.ts";
|
|
10
|
-
|
|
11
|
-
export async function exportHtmlFile(input: string, output: string | undefined, workspace: string): Promise<string> {
|
|
12
|
-
const source = resolve(workspace, input), temporary = await mkdtemp(join(tmpdir(), "xeno-export-"));
|
|
13
|
-
try {
|
|
14
|
-
let dir: string;
|
|
15
|
-
if (await stat(source).then(info => info.isFile(), () => false)) dir = await importSessionArchive(source, temporary, workspace);
|
|
16
|
-
else { const found = await findSessionByPrefix(workspace, input); if (!found.ok) throw new Error(found.reason); dir = found.session.path; }
|
|
17
|
-
const cursor = await readCursor(dir); if (!cursor) throw new Error("Session has no cursor");
|
|
18
|
-
const history = await readNodeHistory(dir, cursor.node); if (!history.ok) throw new Error(history.error);
|
|
19
|
-
const destination = resolve(workspace, output || basename(input).replace(/\.jsonl$/i, "") + ".html");
|
|
20
|
-
if (source === destination) throw new Error("Export destination must differ from its source");
|
|
21
|
-
await writeFile(destination, toHtml(history.nodes.flatMap(node => node.events), { title: cursor.name ?? basename(input), exportedAt: new Date().toISOString() }), { mode: 0o600 });
|
|
22
|
-
return destination;
|
|
23
|
-
} finally { await rm(temporary, { recursive: true, force: true }); }
|
|
24
|
-
}
|
package/src/apps/goal-flow.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The drafting half of /goal shared by the line shell and the TUI (S.2 / S.5):
|
|
3
|
-
* one read-only request, then the reply parsed into candidate criteria.
|
|
4
|
-
* Nothing here decides what is accepted; that is the user's pick.
|
|
5
|
-
*/
|
|
6
|
-
import { draftReply, GOAL_DRAFT_RETRIES, goalDraftRequest, goalDraftRetry, parseGoalDraft } from "../core/goal.ts";
|
|
7
|
-
import type { AcceptanceCriterion } from "../core/acceptance.ts";
|
|
8
|
-
import type { RequestOptions } from "../runtime/loop.ts";
|
|
9
|
-
import type { App } from "./startup.ts";
|
|
10
|
-
|
|
11
|
-
export type PendingGoal = { objective: string; draft: string; criteria: AcceptanceCriterion[] };
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Runs the draft request and reads the candidates from its reply; null when
|
|
15
|
-
* there is nothing to accept. `runDraft` answers false for a draft that was
|
|
16
|
-
* not sent or was cancelled. A draft that does not validate goes back to the
|
|
17
|
-
* model once with the parser's reasons (GOAL_DRAFT_RETRIES); a reported
|
|
18
|
-
* blocker is an answer and does not.
|
|
19
|
-
*/
|
|
20
|
-
export async function draftGoal(app: App, objective: string,
|
|
21
|
-
runDraft: (prompt: string, options: RequestOptions) => Promise<boolean>): Promise<PendingGoal | null> {
|
|
22
|
-
const C = app.io.palette;
|
|
23
|
-
let prompt = goalDraftRequest(objective);
|
|
24
|
-
for (let attempt = 0; ; attempt++) {
|
|
25
|
-
const mark = app.session.state.events.at(-1)?.id;
|
|
26
|
-
if (!await runDraft(prompt, { readOnly: true })) return null;
|
|
27
|
-
const events = app.session.state.events;
|
|
28
|
-
// Only what this run recorded. A segment cut meanwhile removes the mark, and then the whole segment is new.
|
|
29
|
-
const reply = draftReply(events.slice(events.findIndex(event => event.id === mark) + 1));
|
|
30
|
-
if (!reply) { app.io.say(C.yellow(" the goal draft produced no reply; the goal was not set")); return null; }
|
|
31
|
-
const parsed = parseGoalDraft(reply.text);
|
|
32
|
-
for (const error of parsed.errors) app.io.say(C.yellow(` draft ${error}`));
|
|
33
|
-
if (parsed.errors.length > 0 && !parsed.blocked && attempt < GOAL_DRAFT_RETRIES) {
|
|
34
|
-
app.io.say(C.dim(" the draft goes back to the model once to be corrected"));
|
|
35
|
-
prompt = goalDraftRetry(parsed.errors);
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (parsed.criteria.length === 0) {
|
|
39
|
-
app.io.say(C.yellow(parsed.blocked ? ` the model says this goal cannot be checked here: ${parsed.blocked}. The goal was not set`
|
|
40
|
-
: " the draft has no usable criteria; the goal was not set. Run /goal again or rephrase the objective"));
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
return { objective, draft: reply.id, criteria: parsed.criteria };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* One drafted criterion as the user decides on it, the same in the line shell
|
|
49
|
-
* and the TUI checklist: what runs, and whether it is a guard -- a check that
|
|
50
|
-
* must keep passing rather than one that shows the work was done (S.7).
|
|
51
|
-
*/
|
|
52
|
-
export function criterionSummary(item: AcceptanceCriterion): string {
|
|
53
|
-
return item.kind === "human" ? `human · ${item.description}` : `${item.guard ? "guard · " : ""}${item.command} · ${item.description}`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** `all`, or 1-based positions such as `1,3`. Unknown positions are refused, never skipped. */
|
|
57
|
-
export function pickCriteria(criteria: readonly AcceptanceCriterion[], pick: string): { ok: true; ids: string[] } | { ok: false; error: string } {
|
|
58
|
-
const text = pick.trim();
|
|
59
|
-
if (text === "all") return { ok: true, ids: criteria.map(item => item.id) };
|
|
60
|
-
const positions = text.split(/[\s,]+/).filter(Boolean);
|
|
61
|
-
if (positions.length === 0) return { ok: false, error: "name the criteria to accept: /goal accept all, or /goal accept 1,3" };
|
|
62
|
-
const ids: string[] = [];
|
|
63
|
-
for (const position of positions) {
|
|
64
|
-
const index = Number(position);
|
|
65
|
-
if (!Number.isSafeInteger(index) || index < 1 || index > criteria.length) return { ok: false, error: `no drafted criterion ${position}` };
|
|
66
|
-
const id = criteria[index - 1]!.id;
|
|
67
|
-
if (!ids.includes(id)) ids.push(id);
|
|
68
|
-
}
|
|
69
|
-
return { ok: true, ids };
|
|
70
|
-
}
|
package/src/apps/image-draft.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { draftImageInput, draftImageSpans, focusedDraftImage, imageMarker } from "../core/draft-images.ts";
|
|
2
|
-
import type { ImageRef } from "../core/images.ts";
|
|
3
|
-
|
|
4
|
-
/** D19: the renderer owns text and undo; the app only binds tokens to D8 blob identities. */
|
|
5
|
-
export interface ImageDraftEditor {
|
|
6
|
-
readonly text: string;
|
|
7
|
-
readonly cursor: number;
|
|
8
|
-
setAtoms(spans: (text: string) => readonly { start: number; end: number }[]): void;
|
|
9
|
-
insert(text: string): void;
|
|
10
|
-
removeAtom(label: string): void;
|
|
11
|
-
resetDraft(project: (text: string) => string): void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class ImageDraft {
|
|
15
|
-
private readonly editor: ImageDraftEditor;
|
|
16
|
-
private readonly registry = new Map<number, ImageRef>();
|
|
17
|
-
// Never reuse an ID: undo, kill/yank and local history can restore an earlier tag.
|
|
18
|
-
private nextId = 1;
|
|
19
|
-
|
|
20
|
-
constructor(editor: ImageDraftEditor) {
|
|
21
|
-
this.editor = editor;
|
|
22
|
-
editor.setAtoms(text => draftImageSpans(text, this.registry));
|
|
23
|
-
}
|
|
24
|
-
get images(): ImageRef[] { return this.input(this.editor.text).images; }
|
|
25
|
-
get focusedImage() { return focusedDraftImage(this.editor.text, this.editor.cursor, this.registry); }
|
|
26
|
-
input(text: string) { return draftImageInput(text, this.registry); }
|
|
27
|
-
|
|
28
|
-
insertImages(images: readonly ImageRef[]): void {
|
|
29
|
-
let labels = "";
|
|
30
|
-
for (const image of images) {
|
|
31
|
-
while (this.editor.text.includes(imageMarker(this.nextId))) this.nextId++;
|
|
32
|
-
const id = this.nextId++;
|
|
33
|
-
this.registry.set(id, image); labels += imageMarker(id);
|
|
34
|
-
}
|
|
35
|
-
if (labels) this.editor.insert(labels);
|
|
36
|
-
}
|
|
37
|
-
removeImage(index: number): void {
|
|
38
|
-
const ids = [...new Set(draftImageSpans(this.editor.text, this.registry).map(span => span.id))];
|
|
39
|
-
const id = ids[index];
|
|
40
|
-
if (id !== undefined) this.editor.removeAtom(imageMarker(id));
|
|
41
|
-
}
|
|
42
|
-
reset(): void {
|
|
43
|
-
this.editor.resetDraft(text => this.input(text).text);
|
|
44
|
-
this.registry.clear();
|
|
45
|
-
}
|
|
46
|
-
}
|