vellum 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -2
- package/bun.lock +5 -2
- package/package.json +4 -2
- package/scripts/capture-x-graphql.ts +562 -0
- package/scripts/ipc/check-swift-decoder-drift.ts +2 -1
- package/scripts/test.sh +5 -0
- package/src/__tests__/__snapshots__/ipc-snapshot.test.ts.snap +133 -34
- package/src/__tests__/account-registry.test.ts +2 -1
- package/src/__tests__/agent-heartbeat-service.test.ts +250 -0
- package/src/__tests__/asset-materialize-tool.test.ts +16 -15
- package/src/__tests__/asset-search-tool.test.ts +23 -22
- package/src/__tests__/attachments-store.test.ts +56 -127
- package/src/__tests__/browser-skill-baseline-tool-payload.test.ts +5 -4
- package/src/__tests__/browser-skill-endstate.test.ts +4 -3
- package/src/__tests__/call-bridge.test.ts +385 -0
- package/src/__tests__/call-constants.test.ts +40 -0
- package/src/__tests__/call-orchestrator.test.ts +130 -4
- package/src/__tests__/call-recovery.test.ts +518 -0
- package/src/__tests__/call-routes-http.test.ts +459 -0
- package/src/__tests__/call-state-machine.test.ts +143 -0
- package/src/__tests__/call-store.test.ts +216 -1
- package/src/__tests__/cli-discover.test.ts +1 -1
- package/src/__tests__/commit-message-enrichment-service.test.ts +148 -7
- package/src/__tests__/compaction.benchmark.test.ts +176 -0
- package/src/__tests__/computer-use-tools.test.ts +250 -0
- package/src/__tests__/config-schema.test.ts +299 -3
- package/src/__tests__/conflict-store.test.ts +2 -1
- package/src/__tests__/contacts-tools.test.ts +331 -0
- package/src/__tests__/conversation-store.test.ts +30 -32
- package/src/__tests__/credential-security-invariants.test.ts +4 -0
- package/src/__tests__/date-context.test.ts +373 -0
- package/src/__tests__/db-schedule-syntax-migration.test.ts +129 -0
- package/src/__tests__/fixtures/media-reuse-fixtures.ts +3 -3
- package/src/__tests__/followup-tools.test.ts +303 -0
- package/src/__tests__/handlers-twitter-config.test.ts +718 -0
- package/src/__tests__/intent-routing.test.ts +64 -57
- package/src/__tests__/ipc-roundtrip.benchmark.test.ts +237 -0
- package/src/__tests__/ipc-snapshot.test.ts +62 -28
- package/src/__tests__/llm-usage-store.test.ts +3 -8
- package/src/__tests__/media-generate-image.test.ts +1 -1
- package/src/__tests__/media-reuse-story.e2e.test.ts +7 -7
- package/src/__tests__/memory-retrieval.benchmark.test.ts +430 -0
- package/src/__tests__/parallel-tool.benchmark.test.ts +294 -0
- package/src/__tests__/playbook-tools.test.ts +342 -0
- package/src/__tests__/profile-compiler.test.ts +2 -1
- package/src/__tests__/provider-streaming.benchmark.test.ts +773 -0
- package/src/__tests__/recurrence-engine-rruleset.test.ts +78 -0
- package/src/__tests__/recurrence-engine.test.ts +69 -0
- package/src/__tests__/recurrence-types.test.ts +71 -0
- package/src/__tests__/registry.test.ts +5 -3
- package/src/__tests__/relay-server.test.ts +633 -0
- package/src/__tests__/reminder-store.test.ts +6 -3
- package/src/__tests__/reminder.test.ts +43 -77
- package/src/__tests__/run-orchestrator-assistant-events.test.ts +8 -4
- package/src/__tests__/run-orchestrator.test.ts +4 -4
- package/src/__tests__/runtime-attachment-metadata.test.ts +7 -6
- package/src/__tests__/runtime-runs-http.test.ts +4 -4
- package/src/__tests__/runtime-runs.test.ts +4 -4
- package/src/__tests__/schedule-store.test.ts +482 -0
- package/src/__tests__/schedule-tools.test.ts +700 -0
- package/src/__tests__/scheduler-recurrence.test.ts +329 -0
- package/src/__tests__/server-history-render.test.ts +14 -13
- package/src/__tests__/session-error.test.ts +28 -0
- package/src/__tests__/session-init.benchmark.test.ts +462 -0
- package/src/__tests__/session-queue.test.ts +71 -48
- package/src/__tests__/session-runtime-assembly.test.ts +161 -0
- package/src/__tests__/session-surfaces-task-progress.test.ts +104 -0
- package/src/__tests__/signup-e2e.test.ts +2 -1
- package/src/__tests__/skill-projection.benchmark.test.ts +328 -0
- package/src/__tests__/skill-script-runner.test.ts +159 -0
- package/src/__tests__/speaker-identification.test.ts +52 -0
- package/src/__tests__/subagent-manager-notify.test.ts +42 -10
- package/src/__tests__/subagent-tools.test.ts +141 -41
- package/src/__tests__/task-compiler.test.ts +2 -1
- package/src/__tests__/task-runner.test.ts +2 -1
- package/src/__tests__/task-scheduler.test.ts +2 -1
- package/src/__tests__/task-tools.test.ts +49 -56
- package/src/__tests__/tool-audit-listener.test.ts +1 -0
- package/src/__tests__/tool-domain-event-publisher.test.ts +2 -0
- package/src/__tests__/tool-execution-pipeline.benchmark.test.ts +500 -0
- package/src/__tests__/tool-executor.test.ts +13 -17
- package/src/__tests__/turn-commit.test.ts +218 -3
- package/src/__tests__/twilio-provider.test.ts +143 -0
- package/src/__tests__/twilio-routes.test.ts +789 -0
- package/src/__tests__/twitter-auth-handler.test.ts +581 -0
- package/src/__tests__/view-image-tool.test.ts +217 -0
- package/src/__tests__/workspace-git-service.test.ts +186 -0
- package/src/__tests__/workspace-heartbeat-service.test.ts +13 -3
- package/src/agent-heartbeat/agent-heartbeat-service.ts +155 -0
- package/src/bundler/app-bundler.ts +12 -8
- package/src/calls/call-bridge.ts +95 -0
- package/src/calls/call-constants.ts +43 -5
- package/src/calls/call-domain.ts +276 -0
- package/src/calls/call-orchestrator.ts +43 -17
- package/src/calls/call-recovery.ts +207 -0
- package/src/calls/call-state-machine.ts +68 -0
- package/src/calls/call-store.ts +192 -5
- package/src/calls/relay-server.ts +41 -4
- package/src/calls/speaker-identification.ts +213 -0
- package/src/calls/twilio-provider.ts +10 -6
- package/src/calls/twilio-routes.ts +90 -76
- package/src/calls/types.ts +1 -1
- package/src/cli/config-commands.ts +334 -0
- package/src/cli/core-commands.ts +776 -0
- package/src/cli/doordash.ts +251 -1
- package/src/cli/ipc-client.ts +82 -0
- package/src/cli/map.ts +246 -0
- package/src/cli/twitter.ts +575 -0
- package/src/cli.ts +7 -5
- package/src/commands/__tests__/cc-command-registry.test.ts +319 -0
- package/src/commands/cc-command-registry.ts +209 -0
- package/src/config/bundled-skills/contacts/SKILL.md +39 -0
- package/src/config/bundled-skills/contacts/TOOLS.json +122 -0
- package/src/config/bundled-skills/contacts/tools/contact-merge.ts +9 -0
- package/src/config/bundled-skills/contacts/tools/contact-search.ts +9 -0
- package/src/config/bundled-skills/contacts/tools/contact-upsert.ts +9 -0
- package/src/config/bundled-skills/document/SKILL.md +18 -0
- package/src/config/bundled-skills/document/TOOLS.json +53 -0
- package/src/config/bundled-skills/document/tools/document-create.ts +9 -0
- package/src/config/bundled-skills/document/tools/document-update.ts +9 -0
- package/src/config/bundled-skills/doordash/SKILL.md +82 -23
- package/src/config/bundled-skills/followups/SKILL.md +32 -0
- package/src/config/bundled-skills/followups/TOOLS.json +100 -0
- package/src/config/bundled-skills/followups/tools/followup-create.ts +9 -0
- package/src/config/bundled-skills/followups/tools/followup-list.ts +9 -0
- package/src/config/bundled-skills/followups/tools/followup-resolve.ts +9 -0
- package/src/config/bundled-skills/image-studio/tools/media-generate-image.ts +1 -23
- package/src/config/bundled-skills/messaging/tools/messaging-analyze-style.ts +2 -1
- package/src/config/bundled-skills/playbooks/SKILL.md +31 -0
- package/src/config/bundled-skills/playbooks/TOOLS.json +126 -0
- package/src/config/bundled-skills/playbooks/tools/playbook-create.ts +9 -0
- package/src/config/bundled-skills/playbooks/tools/playbook-delete.ts +9 -0
- package/src/config/bundled-skills/playbooks/tools/playbook-list.ts +9 -0
- package/src/config/bundled-skills/playbooks/tools/playbook-update.ts +9 -0
- package/src/config/bundled-skills/reminder/SKILL.md +20 -0
- package/src/config/bundled-skills/reminder/TOOLS.json +67 -0
- package/src/config/bundled-skills/reminder/tools/reminder-cancel.ts +9 -0
- package/src/config/bundled-skills/reminder/tools/reminder-create.ts +9 -0
- package/src/config/bundled-skills/reminder/tools/reminder-list.ts +9 -0
- package/src/config/bundled-skills/schedule/SKILL.md +74 -0
- package/src/config/bundled-skills/schedule/TOOLS.json +135 -0
- package/src/config/bundled-skills/schedule/tools/schedule-create.ts +9 -0
- package/src/config/bundled-skills/schedule/tools/schedule-delete.ts +9 -0
- package/src/config/bundled-skills/schedule/tools/schedule-list.ts +9 -0
- package/src/config/bundled-skills/schedule/tools/schedule-update.ts +9 -0
- package/src/config/bundled-skills/subagent/SKILL.md +25 -0
- package/src/config/bundled-skills/subagent/TOOLS.json +107 -0
- package/src/config/bundled-skills/subagent/tools/subagent-abort.ts +9 -0
- package/src/config/bundled-skills/subagent/tools/subagent-message.ts +9 -0
- package/src/config/bundled-skills/subagent/tools/subagent-read.ts +9 -0
- package/src/config/bundled-skills/subagent/tools/subagent-spawn.ts +9 -0
- package/src/config/bundled-skills/subagent/tools/subagent-status.ts +9 -0
- package/src/config/bundled-skills/tasks/SKILL.md +28 -0
- package/src/config/bundled-skills/tasks/TOOLS.json +256 -0
- package/src/config/bundled-skills/tasks/tools/task-delete.ts +9 -0
- package/src/config/bundled-skills/tasks/tools/task-list-add.ts +9 -0
- package/src/config/bundled-skills/tasks/tools/task-list-remove.ts +9 -0
- package/src/config/bundled-skills/tasks/tools/task-list-show.ts +9 -0
- package/src/config/bundled-skills/tasks/tools/task-list-update.ts +9 -0
- package/src/config/bundled-skills/tasks/tools/task-list.ts +9 -0
- package/src/config/bundled-skills/tasks/tools/task-run.ts +9 -0
- package/src/config/bundled-skills/tasks/tools/task-save.ts +9 -0
- package/src/config/bundled-skills/twitter/SKILL.md +134 -0
- package/src/config/bundled-skills/watcher/SKILL.md +27 -0
- package/src/config/bundled-skills/watcher/TOOLS.json +147 -0
- package/src/config/bundled-skills/watcher/tools/watcher-create.ts +9 -0
- package/src/config/bundled-skills/watcher/tools/watcher-delete.ts +9 -0
- package/src/config/bundled-skills/watcher/tools/watcher-digest.ts +9 -0
- package/src/config/bundled-skills/watcher/tools/watcher-list.ts +9 -0
- package/src/config/bundled-skills/watcher/tools/watcher-update.ts +9 -0
- package/src/config/defaults.ts +33 -0
- package/src/config/loader.ts +4 -1
- package/src/config/schema.ts +161 -1
- package/src/config/system-prompt.ts +61 -16
- package/src/config/templates/IDENTITY.md +7 -0
- package/src/config/types.ts +4 -0
- package/src/contacts/contact-store.ts +4 -4
- package/src/daemon/assistant-attachments.ts +10 -0
- package/src/daemon/classifier.ts +3 -1
- package/src/daemon/computer-use-session.ts +3 -1
- package/src/daemon/date-context.ts +136 -0
- package/src/daemon/handlers/apps.ts +16 -1
- package/src/daemon/handlers/browser.ts +54 -0
- package/src/daemon/handlers/computer-use.ts +7 -1
- package/src/daemon/handlers/config.ts +163 -5
- package/src/daemon/handlers/diagnostics.ts +5 -1
- package/src/daemon/handlers/documents.ts +18 -29
- package/src/daemon/handlers/home-base.ts +5 -1
- package/src/daemon/handlers/index.ts +40 -277
- package/src/daemon/handlers/misc.ts +9 -1
- package/src/daemon/handlers/publish.ts +6 -1
- package/src/daemon/handlers/sessions.ts +65 -12
- package/src/daemon/handlers/shared.ts +36 -1
- package/src/daemon/handlers/signing.ts +37 -0
- package/src/daemon/handlers/skills.ts +20 -6
- package/src/daemon/handlers/subagents.ts +8 -3
- package/src/daemon/handlers/twitter-auth.ts +169 -0
- package/src/daemon/handlers/work-items.ts +384 -68
- package/src/daemon/ipc-contract-inventory.json +28 -4
- package/src/daemon/ipc-contract.ts +133 -37
- package/src/daemon/ipc-protocol.ts +7 -2
- package/src/daemon/lifecycle.ts +21 -0
- package/src/daemon/main.ts +10 -4
- package/src/daemon/ride-shotgun-handler.ts +74 -10
- package/src/daemon/server.ts +143 -26
- package/src/daemon/session-agent-loop.ts +887 -0
- package/src/daemon/session-attachments.ts +28 -5
- package/src/daemon/session-error.ts +24 -3
- package/src/daemon/session-lifecycle.ts +147 -0
- package/src/daemon/session-media-retry.ts +147 -0
- package/src/daemon/session-messaging.ts +145 -0
- package/src/daemon/session-notifiers.ts +164 -0
- package/src/daemon/session-process.ts +2 -2
- package/src/daemon/session-queue-manager.ts +1 -0
- package/src/daemon/session-runtime-assembly.ts +52 -0
- package/src/daemon/session-skill-tools.ts +124 -5
- package/src/daemon/session-slash.ts +3 -0
- package/src/daemon/session-surfaces.ts +77 -2
- package/src/daemon/session-tool-setup.ts +216 -2
- package/src/daemon/session-usage.ts +0 -2
- package/src/daemon/session.ts +114 -1404
- package/src/daemon/video-thumbnail.ts +60 -0
- package/src/doordash/client.ts +121 -27
- package/src/doordash/queries.ts +1 -2
- package/src/export/formatter.ts +3 -1
- package/src/followups/followup-store.ts +4 -2
- package/src/followups/types.ts +6 -0
- package/src/hooks/templates.ts +1 -1
- package/src/index.ts +32 -1153
- package/src/memory/attachments-store.ts +28 -83
- package/src/memory/channel-delivery-store.ts +7 -21
- package/src/memory/clarification-resolver.ts +6 -5
- package/src/memory/contradiction-checker.ts +3 -2
- package/src/memory/conversation-key-store.ts +10 -29
- package/src/memory/conversation-store.ts +2 -1
- package/src/memory/db.ts +96 -2
- package/src/memory/entity-extractor.ts +6 -3
- package/src/memory/items-extractor.ts +5 -4
- package/src/memory/jobs-store.ts +3 -2
- package/src/memory/llm-usage-store.ts +1 -2
- package/src/memory/runs-store.ts +1 -2
- package/src/memory/schema.ts +23 -2
- package/src/messaging/style-analyzer.ts +3 -2
- package/src/messaging/thread-summarizer.ts +8 -12
- package/src/messaging/triage-engine.ts +4 -2
- package/src/providers/openrouter/client.ts +20 -0
- package/src/providers/registry.ts +8 -0
- package/src/runtime/http-server.ts +108 -20
- package/src/runtime/routes/attachment-routes.ts +2 -3
- package/src/runtime/routes/call-routes.ts +140 -0
- package/src/runtime/routes/channel-routes.ts +5 -10
- package/src/runtime/routes/conversation-routes.ts +5 -5
- package/src/runtime/routes/run-routes.ts +2 -2
- package/src/runtime/run-orchestrator.ts +9 -3
- package/src/schedule/recurrence-engine.ts +138 -0
- package/src/schedule/recurrence-types.ts +67 -0
- package/src/schedule/schedule-store.ts +102 -57
- package/src/schedule/scheduler.ts +9 -6
- package/src/security/oauth2.ts +29 -4
- package/src/security/secret-allowlist.ts +46 -0
- package/src/skills/clawhub.ts +1 -1
- package/src/subagent/manager.ts +40 -8
- package/src/swarm/backend-claude-code.ts +64 -9
- package/src/swarm/worker-prompts.ts +2 -1
- package/src/tasks/SPEC.md +34 -28
- package/src/tasks/ephemeral-permissions.ts +16 -7
- package/src/tasks/task-compiler.ts +5 -4
- package/src/tasks/task-runner.ts +10 -5
- package/src/tasks/task-scheduler.ts +1 -1
- package/src/tasks/tool-sanitizer.ts +36 -0
- package/src/tools/assets/search.ts +4 -4
- package/src/tools/browser/api-map.ts +220 -0
- package/src/tools/browser/auto-navigate.ts +270 -0
- package/src/tools/browser/browser-execution.ts +2 -1
- package/src/tools/browser/browser-manager.ts +2 -2
- package/src/tools/browser/network-recorder.ts +5 -4
- package/src/tools/browser/x-auto-navigate.ts +207 -0
- package/src/tools/calls/call-end.ts +17 -67
- package/src/tools/calls/call-start.ts +24 -85
- package/src/tools/calls/call-status.ts +35 -51
- package/src/tools/claude-code/claude-code.ts +77 -11
- package/src/tools/contacts/contact-merge.ts +46 -78
- package/src/tools/contacts/contact-search.ts +35 -79
- package/src/tools/contacts/contact-upsert.ts +35 -108
- package/src/tools/credentials/vault.ts +20 -4
- package/src/tools/document/document-tool.ts +71 -144
- package/src/tools/executor.ts +129 -10
- package/src/tools/followups/followup_create.ts +46 -88
- package/src/tools/followups/followup_list.ts +34 -74
- package/src/tools/followups/followup_resolve.ts +31 -66
- package/src/tools/host-terminal/cli-discover.ts +2 -1
- package/src/tools/host-terminal/host-shell.ts +10 -0
- package/src/tools/memory/handlers.ts +5 -4
- package/src/tools/network/__tests__/web-search.test.ts +427 -0
- package/src/tools/network/script-proxy/__tests__/logging.test.ts +248 -0
- package/src/tools/network/script-proxy/__tests__/policy.test.ts +234 -0
- package/src/tools/network/script-proxy/__tests__/router.test.ts +76 -0
- package/src/tools/network/web-fetch.ts +18 -6
- package/src/tools/playbooks/index.ts +4 -5
- package/src/tools/playbooks/playbook-create.ts +3 -47
- package/src/tools/playbooks/playbook-delete.ts +1 -25
- package/src/tools/playbooks/playbook-list.ts +1 -28
- package/src/tools/playbooks/playbook-update.ts +3 -51
- package/src/tools/reminder/reminder.ts +5 -78
- package/src/tools/schedule/create.ts +69 -74
- package/src/tools/schedule/delete.ts +21 -47
- package/src/tools/schedule/list.ts +55 -74
- package/src/tools/schedule/update.ts +77 -84
- package/src/tools/subagent/abort.ts +29 -58
- package/src/tools/subagent/message.ts +30 -63
- package/src/tools/subagent/read.ts +53 -84
- package/src/tools/subagent/spawn.ts +43 -82
- package/src/tools/subagent/status.ts +42 -71
- package/src/tools/swarm/delegate.ts +2 -1
- package/src/tools/tasks/index.ts +8 -8
- package/src/tools/tasks/task-delete.ts +60 -88
- package/src/tools/tasks/task-list.ts +31 -52
- package/src/tools/tasks/task-run.ts +72 -108
- package/src/tools/tasks/task-save.ts +33 -65
- package/src/tools/tasks/work-item-enqueue.ts +183 -215
- package/src/tools/tasks/work-item-list.ts +33 -63
- package/src/tools/tasks/work-item-remove.ts +45 -97
- package/src/tools/tasks/work-item-update.ts +91 -163
- package/src/tools/terminal/backends/native.ts +3 -1
- package/src/tools/tool-manifest.ts +0 -62
- package/src/tools/types.ts +6 -0
- package/src/tools/ui-surface/definitions.ts +3 -1
- package/src/tools/watch/screen-watch.ts +3 -1
- package/src/tools/watcher/create.ts +52 -98
- package/src/tools/watcher/delete.ts +20 -46
- package/src/tools/watcher/digest.ts +36 -70
- package/src/tools/watcher/list.ts +49 -79
- package/src/tools/watcher/update.ts +45 -91
- package/src/twitter/client.ts +690 -0
- package/src/twitter/session.ts +91 -0
- package/src/usage/types.ts +0 -1
- package/src/util/truncate.ts +6 -0
- package/src/watcher/providers/slack.ts +2 -1
- package/src/watcher/watcher-store.ts +3 -2
- package/src/work-items/work-item-store.ts +27 -2
- package/src/workspace/commit-message-enrichment-service.ts +31 -7
- package/src/workspace/git-service.ts +87 -22
- package/src/workspace/provider-commit-message-generator.ts +242 -0
- package/src/workspace/turn-commit.ts +62 -3
- package/src/tools/contacts/index.ts +0 -4
- package/src/tools/document/index.ts +0 -5
- package/src/tools/followups/index.ts +0 -3
- package/src/tools/subagent/index.ts +0 -5
- /package/src/__tests__/{memory-context-benchmark.test.ts → memory-context-benchmark.benchmark.test.ts} +0 -0
package/src/index.ts
CHANGED
|
@@ -2,1182 +2,61 @@
|
|
|
2
2
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
|
-
import * as net from 'node:net';
|
|
6
5
|
import { dirname, join } from 'node:path';
|
|
6
|
+
import { spawn } from 'node:child_process';
|
|
7
7
|
|
|
8
8
|
const require = createRequire(import.meta.url);
|
|
9
9
|
const { version } = require('../package.json') as { version: string };
|
|
10
|
+
|
|
10
11
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import { getSocketPath, readSessionToken, getRootDir, getDataDir, getDbPath, getLogPath, getWorkspaceDir, getWorkspaceSkillsDir, getWorkspaceHooksDir } from './util/platform.js';
|
|
20
|
-
import {
|
|
21
|
-
serialize,
|
|
22
|
-
createMessageParser,
|
|
23
|
-
type ClientMessage,
|
|
24
|
-
type ServerMessage,
|
|
25
|
-
} from './daemon/ipc-protocol.js';
|
|
26
|
-
import { IpcError } from './util/errors.js';
|
|
27
|
-
import { getCliLogger } from './util/logger.js';
|
|
28
|
-
import { timeAgo } from './util/time.js';
|
|
29
|
-
import { shouldAutoStartDaemon, hasSocketOverride } from './daemon/connection-policy.js';
|
|
30
|
-
import {
|
|
31
|
-
loadRawConfig,
|
|
32
|
-
saveRawConfig,
|
|
33
|
-
getNestedValue,
|
|
34
|
-
setNestedValue,
|
|
35
|
-
getConfig,
|
|
36
|
-
API_KEY_PROVIDERS,
|
|
37
|
-
} from './config/loader.js';
|
|
38
|
-
import {
|
|
39
|
-
getAllRules,
|
|
40
|
-
removeRule,
|
|
41
|
-
clearAllRules,
|
|
42
|
-
} from './permissions/trust-store.js';
|
|
43
|
-
import { getSecureKey, setSecureKey, deleteSecureKey } from './security/secure-keys.js';
|
|
44
|
-
import { getRecentInvocations } from './memory/tool-usage-store.js';
|
|
45
|
-
import {
|
|
46
|
-
getConversation,
|
|
47
|
-
getMessages,
|
|
48
|
-
listConversations,
|
|
49
|
-
clearAll as clearAllConversations,
|
|
50
|
-
} from './memory/conversation-store.js';
|
|
51
|
-
import { initializeDb } from './memory/db.js';
|
|
52
|
-
import { initQdrantClient } from './memory/qdrant-client.js';
|
|
53
|
-
import { formatMarkdown, formatJson } from './export/formatter.js';
|
|
12
|
+
registerDefaultAction,
|
|
13
|
+
registerDaemonCommand,
|
|
14
|
+
registerDevCommand,
|
|
15
|
+
registerSessionsCommand,
|
|
16
|
+
registerAuditCommand,
|
|
17
|
+
registerDoctorCommand,
|
|
18
|
+
registerCompletionsCommand,
|
|
19
|
+
} from './cli/core-commands.js';
|
|
54
20
|
import {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
} from './memory/admin.js';
|
|
21
|
+
registerConfigCommand,
|
|
22
|
+
registerKeysCommand,
|
|
23
|
+
registerTrustCommand,
|
|
24
|
+
registerMemoryCommand,
|
|
25
|
+
} from './cli/config-commands.js';
|
|
61
26
|
import { registerHooksCommand } from './hooks/cli.js';
|
|
62
27
|
import { registerEmailCommand } from './cli/email.js';
|
|
63
28
|
import { registerContactsCommand } from './cli/contacts.js';
|
|
64
29
|
import { registerAutonomyCommand } from './cli/autonomy.js';
|
|
65
30
|
import { registerDoordashCommand } from './cli/doordash.js';
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
msg: ClientMessage,
|
|
69
|
-
): Promise<ServerMessage> {
|
|
70
|
-
return new Promise((resolve, reject) => {
|
|
71
|
-
const socket = net.createConnection(getSocketPath());
|
|
72
|
-
const parser = createMessageParser();
|
|
73
|
-
let resolved = false;
|
|
74
|
-
let authenticated = false;
|
|
75
|
-
|
|
76
|
-
socket.on('connect', () => {
|
|
77
|
-
// Authenticate first — the daemon requires a valid session token
|
|
78
|
-
// before it will accept any other messages.
|
|
79
|
-
const token = readSessionToken();
|
|
80
|
-
if (!token) {
|
|
81
|
-
resolved = true;
|
|
82
|
-
reject(new IpcError('Session token not found — is the daemon running?'));
|
|
83
|
-
socket.destroy();
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
socket.write(serialize({ type: 'auth', token }));
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
socket.on('data', (data) => {
|
|
90
|
-
const messages = parser.feed(data.toString()) as ServerMessage[];
|
|
91
|
-
for (const m of messages) {
|
|
92
|
-
// Handle auth handshake
|
|
93
|
-
if (!authenticated) {
|
|
94
|
-
if (m.type === 'auth_result') {
|
|
95
|
-
if ((m as { success: boolean }).success) {
|
|
96
|
-
authenticated = true;
|
|
97
|
-
// Now send the actual message
|
|
98
|
-
socket.write(serialize(msg));
|
|
99
|
-
} else {
|
|
100
|
-
resolved = true;
|
|
101
|
-
reject(new IpcError((m as { message?: string }).message ?? 'Authentication failed'));
|
|
102
|
-
socket.destroy();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Skip push messages that aren't responses to our request
|
|
109
|
-
if (m.type === 'daemon_status') {
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
// On auto-auth sockets the server may send a second auth_result
|
|
113
|
-
// in response to the client's auth message after we're already
|
|
114
|
-
// authenticated — ignore it so it doesn't resolve as the response.
|
|
115
|
-
if (m.type === 'auth_result') {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (m.type === 'session_info' && msg.type !== 'session_create') {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
resolved = true;
|
|
122
|
-
socket.end();
|
|
123
|
-
resolve(m);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
socket.on('error', (err) => {
|
|
129
|
-
if (!resolved) reject(err);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
socket.on('close', () => {
|
|
133
|
-
if (!resolved) {
|
|
134
|
-
reject(new IpcError('Socket closed before receiving a response'));
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const log = getCliLogger('cli');
|
|
31
|
+
import { registerTwitterCommand } from './cli/twitter.js';
|
|
32
|
+
import { registerMapCommand } from './cli/map.js';
|
|
141
33
|
|
|
142
34
|
const program = new Command();
|
|
143
35
|
|
|
144
36
|
program
|
|
145
37
|
.name('vellum')
|
|
146
38
|
.description('Local AI assistant')
|
|
147
|
-
.version(version)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
.description('Start the daemon')
|
|
160
|
-
.action(async () => {
|
|
161
|
-
const result = await startDaemon();
|
|
162
|
-
if (result.alreadyRunning) {
|
|
163
|
-
log.info(`Daemon already running (pid ${result.pid})`);
|
|
164
|
-
} else {
|
|
165
|
-
log.info(`Daemon started (pid ${result.pid})`);
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
daemon
|
|
170
|
-
.command('stop')
|
|
171
|
-
.description('Stop the daemon')
|
|
172
|
-
.action(async () => {
|
|
173
|
-
const result = await stopDaemon();
|
|
174
|
-
if (result.stopped) {
|
|
175
|
-
log.info('Daemon stopped');
|
|
176
|
-
} else if (result.reason === 'stop_failed') {
|
|
177
|
-
log.error('Failed to stop daemon — process survived SIGKILL');
|
|
178
|
-
process.exit(1);
|
|
179
|
-
} else {
|
|
180
|
-
log.info('Daemon is not running');
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
daemon
|
|
185
|
-
.command('restart')
|
|
186
|
-
.description('Restart the daemon')
|
|
187
|
-
.action(async () => {
|
|
188
|
-
const stopResult = await stopDaemon();
|
|
189
|
-
if (stopResult.stopped) {
|
|
190
|
-
log.info('Daemon stopped');
|
|
191
|
-
} else if (stopResult.reason === 'stop_failed') {
|
|
192
|
-
log.error('Failed to stop daemon — process survived SIGKILL, cannot restart');
|
|
193
|
-
process.exit(1);
|
|
194
|
-
}
|
|
195
|
-
const startResult = await startDaemon();
|
|
196
|
-
log.info(`Daemon started (pid ${startResult.pid})`);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
daemon
|
|
200
|
-
.command('status')
|
|
201
|
-
.description('Show daemon status')
|
|
202
|
-
.action(() => {
|
|
203
|
-
const status = getDaemonStatus();
|
|
204
|
-
if (status.running) {
|
|
205
|
-
log.info(`Daemon is running (pid ${status.pid})`);
|
|
206
|
-
} else {
|
|
207
|
-
log.info('Daemon is not running');
|
|
208
|
-
}
|
|
209
|
-
log.info(`Socket path: ${getSocketPath()}${hasSocketOverride() ? ' (override)' : ''}`);
|
|
210
|
-
log.info(`Autostart: ${shouldAutoStartDaemon() ? 'enabled' : 'disabled'}`);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
// --- Dev command ---
|
|
214
|
-
program
|
|
215
|
-
.command('dev')
|
|
216
|
-
.description('Run the daemon in dev mode with auto-restart on file changes')
|
|
217
|
-
.action(async () => {
|
|
218
|
-
// Stop any existing daemon first
|
|
219
|
-
const status = getDaemonStatus();
|
|
220
|
-
if (status.running) {
|
|
221
|
-
log.info('Stopping existing daemon...');
|
|
222
|
-
const stopResult = await stopDaemon();
|
|
223
|
-
if (!stopResult.stopped && stopResult.reason === 'stop_failed') {
|
|
224
|
-
log.error('Failed to stop existing daemon — process survived SIGKILL');
|
|
225
|
-
process.exit(1);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const mainPath = `${import.meta.dirname}/daemon/main.ts`;
|
|
230
|
-
|
|
231
|
-
log.info('Starting daemon in dev mode (Ctrl+C to stop)');
|
|
232
|
-
|
|
233
|
-
const repoRoot = join(import.meta.dirname, '..', '..');
|
|
234
|
-
const child = spawn('bun', ['--watch', 'run', mainPath], {
|
|
235
|
-
stdio: 'inherit',
|
|
236
|
-
env: {
|
|
237
|
-
...process.env,
|
|
238
|
-
BASE_DATA_DIR: repoRoot,
|
|
239
|
-
VELLUM_LOG_STDERR: '1',
|
|
240
|
-
VELLUM_DEBUG: '1',
|
|
241
|
-
},
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
const forward = (signal: NodeJS.Signals) => {
|
|
245
|
-
child.kill(signal);
|
|
246
|
-
};
|
|
247
|
-
process.on('SIGINT', () => forward('SIGINT'));
|
|
248
|
-
process.on('SIGTERM', () => forward('SIGTERM'));
|
|
249
|
-
|
|
250
|
-
child.on('exit', (code) => {
|
|
251
|
-
process.exit(code ?? 0);
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
const sessions = program.command('sessions').description('Manage sessions');
|
|
256
|
-
|
|
257
|
-
sessions
|
|
258
|
-
.command('list')
|
|
259
|
-
.description('List all sessions')
|
|
260
|
-
.action(async () => {
|
|
261
|
-
if (shouldAutoStartDaemon()) await ensureDaemonRunning();
|
|
262
|
-
const response = await sendOneMessage({ type: 'session_list' });
|
|
263
|
-
if (response.type === 'session_list_response') {
|
|
264
|
-
if (response.sessions.length === 0) {
|
|
265
|
-
log.info('No sessions');
|
|
266
|
-
} else {
|
|
267
|
-
for (const s of response.sessions) {
|
|
268
|
-
log.info(` ${s.id} ${s.title} ${timeAgo(s.updatedAt)}`);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
} else if (response.type === 'error') {
|
|
272
|
-
log.error(`Error: ${response.message}`);
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
sessions
|
|
277
|
-
.command('new [title]')
|
|
278
|
-
.description('Create a new session')
|
|
279
|
-
.action(async (title?: string) => {
|
|
280
|
-
if (shouldAutoStartDaemon()) await ensureDaemonRunning();
|
|
281
|
-
const response = await sendOneMessage({
|
|
282
|
-
type: 'session_create',
|
|
283
|
-
title,
|
|
284
|
-
});
|
|
285
|
-
if (response.type === 'session_info') {
|
|
286
|
-
log.info(`Created session: ${response.title} (${response.sessionId})`);
|
|
287
|
-
} else if (response.type === 'error') {
|
|
288
|
-
log.error(`Error: ${response.message}`);
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
sessions
|
|
293
|
-
.command('export [sessionId]')
|
|
294
|
-
.description('Export a conversation as markdown or JSON')
|
|
295
|
-
.option('-f, --format <format>', 'Output format: md or json', 'md')
|
|
296
|
-
.option('-o, --output <file>', 'Write to file instead of stdout')
|
|
297
|
-
.action(async (sessionId?: string, opts?: { format: string; output?: string }) => {
|
|
298
|
-
initializeDb();
|
|
299
|
-
const format = opts?.format ?? 'md';
|
|
300
|
-
if (format !== 'md' && format !== 'json') {
|
|
301
|
-
log.error('Error: format must be "md" or "json"');
|
|
302
|
-
process.exit(1);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// If no session ID given, pick the most recent one
|
|
306
|
-
let id = sessionId;
|
|
307
|
-
if (!id) {
|
|
308
|
-
const all = listConversations(1);
|
|
309
|
-
if (all.length === 0) {
|
|
310
|
-
log.error('No sessions found');
|
|
311
|
-
process.exit(1);
|
|
312
|
-
}
|
|
313
|
-
id = all[0].id;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Support prefix matching for session IDs
|
|
317
|
-
let conversation = getConversation(id);
|
|
318
|
-
if (!conversation) {
|
|
319
|
-
const all = listConversations(Number.MAX_SAFE_INTEGER);
|
|
320
|
-
const match = all.find((c) => c.id.startsWith(id!));
|
|
321
|
-
if (match) {
|
|
322
|
-
conversation = match;
|
|
323
|
-
} else {
|
|
324
|
-
log.error(`Session not found: ${id}`);
|
|
325
|
-
process.exit(1);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const msgs = getMessages(conversation.id);
|
|
330
|
-
const exportData = {
|
|
331
|
-
...conversation,
|
|
332
|
-
messages: msgs.map((m) => ({
|
|
333
|
-
role: m.role,
|
|
334
|
-
content: JSON.parse(m.content),
|
|
335
|
-
createdAt: m.createdAt,
|
|
336
|
-
})),
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
const output = format === 'json'
|
|
340
|
-
? formatJson(exportData)
|
|
341
|
-
: formatMarkdown(exportData);
|
|
342
|
-
|
|
343
|
-
if (opts?.output) {
|
|
344
|
-
const { writeFileSync } = await import('node:fs');
|
|
345
|
-
writeFileSync(opts.output, output);
|
|
346
|
-
log.info(`Exported to ${opts.output}`);
|
|
347
|
-
} else {
|
|
348
|
-
process.stdout.write(output);
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
sessions
|
|
353
|
-
.command('clear')
|
|
354
|
-
.description('Clear all conversations, messages, and vector data (dev only)')
|
|
355
|
-
.action(async () => {
|
|
356
|
-
log.info('This will permanently delete all conversations, messages, and vector data.');
|
|
357
|
-
|
|
358
|
-
const readline = await import('node:readline');
|
|
359
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
360
|
-
const answer = await new Promise<string>((resolve) => {
|
|
361
|
-
rl.question('Are you sure? (y/N) ', resolve);
|
|
362
|
-
});
|
|
363
|
-
rl.close();
|
|
364
|
-
if (answer.toLowerCase() !== 'y') {
|
|
365
|
-
log.info('Cancelled');
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
initializeDb();
|
|
370
|
-
const result = clearAllConversations();
|
|
371
|
-
log.info(`Cleared ${result.conversations} conversations, ${result.messages} messages`);
|
|
372
|
-
|
|
373
|
-
// Notify a running daemon to drop its in-memory sessions so it
|
|
374
|
-
// doesn't keep serving stale history from deleted conversation rows.
|
|
375
|
-
try {
|
|
376
|
-
await sendOneMessage({ type: 'sessions_clear' });
|
|
377
|
-
} catch {
|
|
378
|
-
// Daemon may not be running — that's fine, no sessions to invalidate.
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
const config = getConfig();
|
|
382
|
-
const qdrantUrl = process.env.QDRANT_URL?.trim() || config.memory.qdrant.url;
|
|
383
|
-
const qdrant = initQdrantClient({
|
|
384
|
-
url: qdrantUrl,
|
|
385
|
-
collection: config.memory.qdrant.collection,
|
|
386
|
-
vectorSize: config.memory.qdrant.vectorSize,
|
|
387
|
-
onDisk: config.memory.qdrant.onDisk,
|
|
388
|
-
quantization: config.memory.qdrant.quantization,
|
|
389
|
-
});
|
|
390
|
-
const deleted = await qdrant.deleteCollection();
|
|
391
|
-
if (deleted) {
|
|
392
|
-
log.info(`Deleted Qdrant collection "${config.memory.qdrant.collection}"`);
|
|
393
|
-
} else {
|
|
394
|
-
log.info('Qdrant collection not found or not reachable (skipped)');
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
log.info('Done.');
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
// --- Config commands ---
|
|
401
|
-
const config = program.command('config').description('Manage configuration');
|
|
402
|
-
|
|
403
|
-
config
|
|
404
|
-
.command('set <key> <value>')
|
|
405
|
-
.description('Set a config value (supports dotted paths like apiKeys.anthropic)')
|
|
406
|
-
.action((key: string, value: string) => {
|
|
407
|
-
const raw = loadRawConfig();
|
|
408
|
-
// Try to parse as JSON for booleans/numbers, fall back to string
|
|
409
|
-
let parsed: unknown = value;
|
|
410
|
-
try {
|
|
411
|
-
parsed = JSON.parse(value);
|
|
412
|
-
} catch {
|
|
413
|
-
// keep as string
|
|
414
|
-
}
|
|
415
|
-
setNestedValue(raw, key, parsed);
|
|
416
|
-
saveRawConfig(raw);
|
|
417
|
-
log.info(`Set ${key} = ${JSON.stringify(parsed)}`);
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
config
|
|
421
|
-
.command('get <key>')
|
|
422
|
-
.description('Get a config value (supports dotted paths)')
|
|
423
|
-
.action((key: string) => {
|
|
424
|
-
const raw = loadRawConfig();
|
|
425
|
-
const value = getNestedValue(raw, key);
|
|
426
|
-
if (value === undefined) {
|
|
427
|
-
log.info(`(not set)`);
|
|
428
|
-
} else {
|
|
429
|
-
log.info(typeof value === 'object' ? JSON.stringify(value, null, 2) : String(value));
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
config
|
|
434
|
-
.command('list')
|
|
435
|
-
.description('List all config values')
|
|
436
|
-
.action(() => {
|
|
437
|
-
const raw = loadRawConfig();
|
|
438
|
-
if (Object.keys(raw).length === 0) {
|
|
439
|
-
log.info('No configuration set');
|
|
440
|
-
} else {
|
|
441
|
-
log.info(JSON.stringify(raw, null, 2));
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
// --- Keys commands ---
|
|
446
|
-
const keys = program.command('keys').description('Manage API keys in secure storage');
|
|
447
|
-
|
|
448
|
-
keys
|
|
449
|
-
.command('list')
|
|
450
|
-
.description('List all stored API key names')
|
|
451
|
-
.action(() => {
|
|
452
|
-
const stored: string[] = [];
|
|
453
|
-
for (const provider of API_KEY_PROVIDERS) {
|
|
454
|
-
const value = getSecureKey(provider);
|
|
455
|
-
if (value) stored.push(provider);
|
|
456
|
-
}
|
|
457
|
-
if (stored.length === 0) {
|
|
458
|
-
log.info('No API keys stored');
|
|
459
|
-
} else {
|
|
460
|
-
for (const name of stored) {
|
|
461
|
-
log.info(` ${name}`);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
keys
|
|
467
|
-
.command('set <provider> <key>')
|
|
468
|
-
.description('Store an API key (e.g. vellum keys set anthropic sk-ant-...)')
|
|
469
|
-
.action((provider: string, key: string) => {
|
|
470
|
-
if (setSecureKey(provider, key)) {
|
|
471
|
-
log.info(`Stored API key for "${provider}"`);
|
|
472
|
-
} else {
|
|
473
|
-
log.error(`Failed to store API key for "${provider}"`);
|
|
474
|
-
process.exit(1);
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
keys
|
|
479
|
-
.command('delete <provider>')
|
|
480
|
-
.description('Delete a stored API key')
|
|
481
|
-
.action((provider: string) => {
|
|
482
|
-
if (deleteSecureKey(provider)) {
|
|
483
|
-
log.info(`Deleted API key for "${provider}"`);
|
|
484
|
-
} else {
|
|
485
|
-
log.error(`No API key found for "${provider}"`);
|
|
486
|
-
process.exit(1);
|
|
487
|
-
}
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
// --- Trust commands ---
|
|
491
|
-
const trust = program.command('trust').description('Manage trust rules');
|
|
492
|
-
|
|
493
|
-
trust
|
|
494
|
-
.command('list')
|
|
495
|
-
.description('List all trust rules')
|
|
496
|
-
.action(() => {
|
|
497
|
-
const rules = getAllRules();
|
|
498
|
-
if (rules.length === 0) {
|
|
499
|
-
log.info('No trust rules');
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
// Table header
|
|
503
|
-
const idW = 8;
|
|
504
|
-
const toolW = 12;
|
|
505
|
-
const patternW = 30;
|
|
506
|
-
const scopeW = 20;
|
|
507
|
-
const decW = 6;
|
|
508
|
-
const priW = 4;
|
|
509
|
-
log.info(
|
|
510
|
-
'ID'.padEnd(idW) +
|
|
511
|
-
'Tool'.padEnd(toolW) +
|
|
512
|
-
'Pattern'.padEnd(patternW) +
|
|
513
|
-
'Scope'.padEnd(scopeW) +
|
|
514
|
-
'Dcn'.padEnd(decW) +
|
|
515
|
-
'Pri'.padEnd(priW) +
|
|
516
|
-
'Created',
|
|
517
|
-
);
|
|
518
|
-
log.info('-'.repeat(idW + toolW + patternW + scopeW + decW + priW + 20));
|
|
519
|
-
for (const r of rules) {
|
|
520
|
-
const id = r.id.slice(0, 8);
|
|
521
|
-
const created = new Date(r.createdAt).toISOString().slice(0, 10);
|
|
522
|
-
log.info(
|
|
523
|
-
id.padEnd(idW) +
|
|
524
|
-
r.tool.padEnd(toolW) +
|
|
525
|
-
r.pattern.slice(0, patternW - 2).padEnd(patternW) +
|
|
526
|
-
r.scope.slice(0, scopeW - 2).padEnd(scopeW) +
|
|
527
|
-
r.decision.slice(0, decW - 1).padEnd(decW) +
|
|
528
|
-
String(r.priority).padEnd(priW) +
|
|
529
|
-
created,
|
|
530
|
-
);
|
|
531
|
-
}
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
trust
|
|
535
|
-
.command('remove <id>')
|
|
536
|
-
.description('Remove a trust rule by ID (or prefix)')
|
|
537
|
-
.action((id: string) => {
|
|
538
|
-
// Support prefix matching
|
|
539
|
-
const rules = getAllRules();
|
|
540
|
-
const match = rules.find((r) => r.id.startsWith(id));
|
|
541
|
-
if (!match) {
|
|
542
|
-
log.error(`No rule found matching "${id}"`);
|
|
543
|
-
process.exit(1);
|
|
544
|
-
}
|
|
545
|
-
try {
|
|
546
|
-
removeRule(match.id);
|
|
547
|
-
} catch (err) {
|
|
548
|
-
log.error(err instanceof Error ? err.message : String(err));
|
|
549
|
-
process.exit(1);
|
|
550
|
-
}
|
|
551
|
-
log.info(`Removed rule ${match.id.slice(0, 8)} (${match.tool}: ${match.pattern})`);
|
|
552
|
-
});
|
|
553
|
-
|
|
554
|
-
trust
|
|
555
|
-
.command('clear')
|
|
556
|
-
.description('Remove all trust rules')
|
|
557
|
-
.action(async () => {
|
|
558
|
-
const rules = getAllRules();
|
|
559
|
-
if (rules.length === 0) {
|
|
560
|
-
log.info('No trust rules to clear');
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
// Confirmation prompt
|
|
564
|
-
const readline = await import('node:readline');
|
|
565
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
566
|
-
const answer = await new Promise<string>((resolve) => {
|
|
567
|
-
rl.question(`Remove all ${rules.length} trust rules? (y/N) `, resolve);
|
|
568
|
-
});
|
|
569
|
-
rl.close();
|
|
570
|
-
if (answer.toLowerCase() === 'y') {
|
|
571
|
-
clearAllRules();
|
|
572
|
-
log.info(`Cleared ${rules.length} trust rules`);
|
|
573
|
-
} else {
|
|
574
|
-
log.info('Cancelled');
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
// --- Memory commands ---
|
|
579
|
-
const memory = program.command('memory').description('Manage long-term memory indexing/retrieval');
|
|
580
|
-
|
|
581
|
-
memory
|
|
582
|
-
.command('status')
|
|
583
|
-
.description('Show memory subsystem status')
|
|
584
|
-
.action(() => {
|
|
585
|
-
initializeDb();
|
|
586
|
-
const status = getMemorySystemStatus();
|
|
587
|
-
log.info(`Memory enabled: ${status.enabled ? 'yes' : 'no'}`);
|
|
588
|
-
log.info(`Memory degraded: ${status.degraded ? 'yes' : 'no'}`);
|
|
589
|
-
if (status.reason) log.info(`Reason: ${status.reason}`);
|
|
590
|
-
if (status.provider && status.model) {
|
|
591
|
-
log.info(`Embedding backend: ${status.provider}/${status.model}`);
|
|
592
|
-
} else {
|
|
593
|
-
log.info('Embedding backend: none');
|
|
594
|
-
}
|
|
595
|
-
log.info(`Segments: ${status.counts.segments.toLocaleString()}`);
|
|
596
|
-
log.info(`Items: ${status.counts.items.toLocaleString()}`);
|
|
597
|
-
log.info(`Summaries: ${status.counts.summaries.toLocaleString()}`);
|
|
598
|
-
log.info(`Embeddings: ${status.counts.embeddings.toLocaleString()}`);
|
|
599
|
-
log.info(`Pending conflicts: ${status.conflicts.pending.toLocaleString()}`);
|
|
600
|
-
log.info(`Resolved conflicts: ${status.conflicts.resolved.toLocaleString()}`);
|
|
601
|
-
if (status.conflicts.oldestPendingAgeMs !== null) {
|
|
602
|
-
const oldestMinutes = Math.floor(status.conflicts.oldestPendingAgeMs / 60_000);
|
|
603
|
-
log.info(`Oldest pending conflict age: ${oldestMinutes} min`);
|
|
604
|
-
} else {
|
|
605
|
-
log.info('Oldest pending conflict age: n/a');
|
|
606
|
-
}
|
|
607
|
-
log.info(`Cleanup backlog (resolved conflicts): ${status.cleanup.resolvedBacklog.toLocaleString()}`);
|
|
608
|
-
log.info(`Cleanup backlog (superseded items): ${status.cleanup.supersededBacklog.toLocaleString()}`);
|
|
609
|
-
log.info(`Cleanup throughput 24h (resolved conflicts): ${status.cleanup.resolvedCompleted24h.toLocaleString()}`);
|
|
610
|
-
log.info(`Cleanup throughput 24h (superseded items): ${status.cleanup.supersededCompleted24h.toLocaleString()}`);
|
|
611
|
-
log.info('Jobs:');
|
|
612
|
-
for (const [key, value] of Object.entries(status.jobs)) {
|
|
613
|
-
log.info(` ${key}: ${value}`);
|
|
614
|
-
}
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
memory
|
|
618
|
-
.command('backfill')
|
|
619
|
-
.description('Queue a memory backfill job')
|
|
620
|
-
.option('-f, --force', 'Restart backfill from the beginning')
|
|
621
|
-
.action((opts: { force?: boolean }) => {
|
|
622
|
-
initializeDb();
|
|
623
|
-
const jobId = requestMemoryBackfill(Boolean(opts?.force));
|
|
624
|
-
log.info(`Queued backfill job: ${jobId}`);
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
memory
|
|
628
|
-
.command('cleanup')
|
|
629
|
-
.description('Queue cleanup jobs for resolved conflicts and stale superseded items')
|
|
630
|
-
.option('--retention-ms <ms>', 'Optional retention threshold in milliseconds')
|
|
631
|
-
.action((opts: { retentionMs?: string }) => {
|
|
632
|
-
initializeDb();
|
|
633
|
-
const retentionMs = opts.retentionMs ? Number.parseInt(opts.retentionMs, 10) : undefined;
|
|
634
|
-
const jobs = requestMemoryCleanup(Number.isFinite(retentionMs) ? retentionMs : undefined);
|
|
635
|
-
log.info(`Queued cleanup_resolved_conflicts job: ${jobs.resolvedConflictsJobId}`);
|
|
636
|
-
log.info(`Queued cleanup_stale_superseded_items job: ${jobs.staleSupersededItemsJobId}`);
|
|
637
|
-
});
|
|
638
|
-
|
|
639
|
-
memory
|
|
640
|
-
.command('query <text>')
|
|
641
|
-
.description('Run a memory recall query and print the injected memory payload')
|
|
642
|
-
.option('-s, --session <id>', 'Optional conversation/session ID')
|
|
643
|
-
.action(async (text: string, opts?: { session?: string }) => {
|
|
644
|
-
initializeDb();
|
|
645
|
-
let sessionId = opts?.session;
|
|
646
|
-
if (!sessionId) {
|
|
647
|
-
const latest = listConversations(1)[0];
|
|
648
|
-
sessionId = latest?.id ?? '';
|
|
649
|
-
}
|
|
650
|
-
const result = await queryMemory(text, sessionId ?? '');
|
|
651
|
-
if (result.degraded) {
|
|
652
|
-
log.info(`Memory degraded: ${result.reason ?? 'unknown reason'}`);
|
|
653
|
-
}
|
|
654
|
-
log.info(`Lexical hits: ${result.lexicalHits}`);
|
|
655
|
-
log.info(`Semantic hits: ${result.semanticHits}`);
|
|
656
|
-
log.info(`Recency hits: ${result.recencyHits}`);
|
|
657
|
-
log.info(`Entity hits: ${result.entityHits}`);
|
|
658
|
-
log.info(`Injected tokens: ${result.injectedTokens}`);
|
|
659
|
-
log.info(`Latency: ${result.latencyMs}ms`);
|
|
660
|
-
if (result.injectedText.length > 0) {
|
|
661
|
-
log.info('');
|
|
662
|
-
log.info(result.injectedText);
|
|
663
|
-
} else {
|
|
664
|
-
log.info('No memory injected.');
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
|
|
668
|
-
memory
|
|
669
|
-
.command('rebuild-index')
|
|
670
|
-
.description('Queue a memory FTS+embedding index rebuild job')
|
|
671
|
-
.action(() => {
|
|
672
|
-
initializeDb();
|
|
673
|
-
const jobId = requestMemoryRebuildIndex();
|
|
674
|
-
log.info(`Queued rebuild-index job: ${jobId}`);
|
|
675
|
-
});
|
|
676
|
-
|
|
677
|
-
// --- Audit command ---
|
|
678
|
-
program
|
|
679
|
-
.command('audit')
|
|
680
|
-
.description('Show recent tool invocations')
|
|
681
|
-
.option('-l, --limit <n>', 'Number of entries to show', '20')
|
|
682
|
-
.action((opts: { limit: string }) => {
|
|
683
|
-
const limit = parseInt(opts.limit, 10) || 20;
|
|
684
|
-
const rows = getRecentInvocations(limit);
|
|
685
|
-
if (rows.length === 0) {
|
|
686
|
-
log.info('No tool invocations recorded');
|
|
687
|
-
return;
|
|
688
|
-
}
|
|
689
|
-
const tsW = 20;
|
|
690
|
-
const toolW = 14;
|
|
691
|
-
const inputW = 30;
|
|
692
|
-
const decW = 8;
|
|
693
|
-
const riskW = 8;
|
|
694
|
-
const durW = 8;
|
|
695
|
-
log.info(
|
|
696
|
-
'Timestamp'.padEnd(tsW) +
|
|
697
|
-
'Tool'.padEnd(toolW) +
|
|
698
|
-
'Input'.padEnd(inputW) +
|
|
699
|
-
'Decision'.padEnd(decW) +
|
|
700
|
-
'Risk'.padEnd(riskW) +
|
|
701
|
-
'Duration',
|
|
702
|
-
);
|
|
703
|
-
log.info('-'.repeat(tsW + toolW + inputW + decW + riskW + durW));
|
|
704
|
-
for (const r of rows) {
|
|
705
|
-
const ts = new Date(r.createdAt).toISOString().slice(0, 19).replace('T', ' ');
|
|
706
|
-
// Summarize input: take first meaningful chunk
|
|
707
|
-
let inputSummary = '';
|
|
708
|
-
try {
|
|
709
|
-
const parsed = JSON.parse(r.input);
|
|
710
|
-
if (parsed.command) inputSummary = parsed.command;
|
|
711
|
-
else if (parsed.path) inputSummary = parsed.path;
|
|
712
|
-
else inputSummary = r.input;
|
|
713
|
-
} catch {
|
|
714
|
-
inputSummary = r.input;
|
|
715
|
-
}
|
|
716
|
-
if (inputSummary.length > inputW - 2) {
|
|
717
|
-
inputSummary = inputSummary.slice(0, inputW - 4) + '..';
|
|
718
|
-
}
|
|
719
|
-
const dur = r.durationMs < 1000 ? `${r.durationMs}ms` : `${(r.durationMs / 1000).toFixed(1)}s`;
|
|
720
|
-
log.info(
|
|
721
|
-
ts.padEnd(tsW) +
|
|
722
|
-
r.toolName.padEnd(toolW) +
|
|
723
|
-
inputSummary.padEnd(inputW) +
|
|
724
|
-
r.decision.padEnd(decW) +
|
|
725
|
-
r.riskLevel.padEnd(riskW) +
|
|
726
|
-
dur,
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
});
|
|
730
|
-
|
|
731
|
-
// --- Doctor command ---
|
|
732
|
-
program
|
|
733
|
-
.command('doctor')
|
|
734
|
-
.description('Run diagnostic checks')
|
|
735
|
-
.action(async () => {
|
|
736
|
-
const pass = (label: string) => log.info(` \u2713 ${label}`);
|
|
737
|
-
const fail = (label: string, detail?: string) =>
|
|
738
|
-
log.info(` \u2717 ${label}${detail ? ` — ${detail}` : ''}`);
|
|
739
|
-
|
|
740
|
-
log.info('Vellum Doctor\n');
|
|
741
|
-
|
|
742
|
-
// 0. Connection policy info
|
|
743
|
-
const socketPath = getSocketPath();
|
|
744
|
-
const isOverride = hasSocketOverride();
|
|
745
|
-
const autostart = shouldAutoStartDaemon();
|
|
746
|
-
log.info(` Socket: ${socketPath}${isOverride ? ' (override via VELLUM_DAEMON_SOCKET)' : ''}`);
|
|
747
|
-
log.info(` Autostart: ${autostart ? 'enabled' : 'disabled'}\n`);
|
|
748
|
-
|
|
749
|
-
// 1. Bun installed
|
|
750
|
-
try {
|
|
751
|
-
execSync('bun --version', { stdio: 'pipe' });
|
|
752
|
-
pass('Bun is installed');
|
|
753
|
-
} catch {
|
|
754
|
-
fail('Bun is installed', 'bun not found in PATH');
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
// 2. Provider/API key configured
|
|
758
|
-
const raw = loadRawConfig();
|
|
759
|
-
const provider = typeof raw.provider === 'string' ? raw.provider : 'anthropic';
|
|
760
|
-
const providerEnvVar: Record<string, string> = {
|
|
761
|
-
anthropic: 'ANTHROPIC_API_KEY',
|
|
762
|
-
openai: 'OPENAI_API_KEY',
|
|
763
|
-
gemini: 'GEMINI_API_KEY',
|
|
764
|
-
ollama: 'OLLAMA_API_KEY',
|
|
765
|
-
fireworks: 'FIREWORKS_API_KEY',
|
|
766
|
-
};
|
|
767
|
-
const configKey = (raw.apiKeys as Record<string, string> | undefined)?.[provider];
|
|
768
|
-
const envVar = providerEnvVar[provider];
|
|
769
|
-
const envKey = envVar ? process.env[envVar] : undefined;
|
|
770
|
-
|
|
771
|
-
if (provider === 'ollama') {
|
|
772
|
-
pass('Provider configured (Ollama; API key optional)');
|
|
773
|
-
} else if (envKey || configKey) {
|
|
774
|
-
pass('API key configured');
|
|
775
|
-
} else {
|
|
776
|
-
fail(
|
|
777
|
-
'API key configured',
|
|
778
|
-
envVar
|
|
779
|
-
? `set ${envVar} or run: vellum config set apiKeys.${provider} <key>`
|
|
780
|
-
: `set API key for provider "${provider}"`,
|
|
781
|
-
);
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
// 3. Daemon reachable
|
|
785
|
-
try {
|
|
786
|
-
const sock = getSocketPath();
|
|
787
|
-
if (!existsSync(sock)) {
|
|
788
|
-
fail('Daemon reachable', 'socket not found (is the daemon running?)');
|
|
789
|
-
} else {
|
|
790
|
-
await new Promise<void>((resolve, reject) => {
|
|
791
|
-
const s = net.createConnection(sock);
|
|
792
|
-
const timer = setTimeout(() => { s.destroy(); reject(new IpcError('timeout')); }, 2000);
|
|
793
|
-
s.on('connect', () => { clearTimeout(timer); s.end(); resolve(); });
|
|
794
|
-
s.on('error', (err) => { clearTimeout(timer); reject(err); });
|
|
795
|
-
});
|
|
796
|
-
pass('Daemon reachable');
|
|
797
|
-
}
|
|
798
|
-
} catch {
|
|
799
|
-
fail('Daemon reachable', 'could not connect to daemon socket');
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
// 4. DB exists and readable
|
|
803
|
-
const dbPath = getDbPath();
|
|
804
|
-
if (existsSync(dbPath)) {
|
|
805
|
-
try {
|
|
806
|
-
const { Database } = await import('bun:sqlite');
|
|
807
|
-
const db = new Database(dbPath, { readonly: true });
|
|
808
|
-
db.query('SELECT 1').get();
|
|
809
|
-
db.close();
|
|
810
|
-
pass('Database exists and readable');
|
|
811
|
-
} catch {
|
|
812
|
-
fail('Database exists and readable', 'file exists but cannot be read');
|
|
813
|
-
}
|
|
814
|
-
} else {
|
|
815
|
-
fail('Database exists and readable', `not found at ${dbPath}`);
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
// 5. ~/.vellum/ directory structure (workspace layout)
|
|
819
|
-
const rootDir = getRootDir();
|
|
820
|
-
const dataDir = getDataDir();
|
|
821
|
-
const workspaceDir = getWorkspaceDir();
|
|
822
|
-
const requiredDirs = [rootDir, workspaceDir, dataDir, `${dataDir}/db`, `${dataDir}/logs`, getWorkspaceSkillsDir(), getWorkspaceHooksDir(), `${rootDir}/protected`];
|
|
823
|
-
const missing = requiredDirs.filter((d) => !existsSync(d));
|
|
824
|
-
if (missing.length === 0) {
|
|
825
|
-
pass('Directory structure exists');
|
|
826
|
-
} else {
|
|
827
|
-
fail('Directory structure exists', `missing: ${missing.join(', ')}`);
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
// 6. Disk space
|
|
831
|
-
try {
|
|
832
|
-
const output = execSync(`df -k "${rootDir}"`, { stdio: 'pipe', encoding: 'utf-8' });
|
|
833
|
-
const lines = output.trim().split('\n');
|
|
834
|
-
if (lines.length >= 2) {
|
|
835
|
-
const cols = lines[1].trim().split(/\s+/);
|
|
836
|
-
// df -k output: Filesystem 1K-blocks Used Available ...
|
|
837
|
-
const availKB = parseInt(cols[3], 10);
|
|
838
|
-
if (isNaN(availKB)) {
|
|
839
|
-
fail('Disk space', 'could not parse available space');
|
|
840
|
-
} else if (availKB < 100 * 1024) {
|
|
841
|
-
fail('Disk space', `only ${Math.round(availKB / 1024)}MB free (< 100MB)`);
|
|
842
|
-
} else {
|
|
843
|
-
pass(`Disk space (${Math.round(availKB / 1024)}MB free)`);
|
|
844
|
-
}
|
|
845
|
-
} else {
|
|
846
|
-
fail('Disk space', 'unexpected df output');
|
|
847
|
-
}
|
|
848
|
-
} catch {
|
|
849
|
-
fail('Disk space', 'could not check disk space');
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
// 7. Log file size
|
|
853
|
-
const logPath = getLogPath();
|
|
854
|
-
if (existsSync(logPath)) {
|
|
855
|
-
try {
|
|
856
|
-
const logStat = statSync(logPath);
|
|
857
|
-
const logSizeMB = logStat.size / (1024 * 1024);
|
|
858
|
-
if (logSizeMB > 50) {
|
|
859
|
-
fail('Log file size', `${logSizeMB.toFixed(1)}MB (> 50MB)`);
|
|
860
|
-
} else {
|
|
861
|
-
pass(`Log file size (${logSizeMB.toFixed(1)}MB)`);
|
|
862
|
-
}
|
|
863
|
-
} catch {
|
|
864
|
-
fail('Log file size', 'could not stat log file');
|
|
865
|
-
}
|
|
866
|
-
} else {
|
|
867
|
-
pass('Log file size (no log file yet)');
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
// 8. DB integrity check
|
|
871
|
-
if (existsSync(dbPath)) {
|
|
872
|
-
try {
|
|
873
|
-
const { Database } = await import('bun:sqlite');
|
|
874
|
-
const db = new Database(dbPath, { readonly: true });
|
|
875
|
-
const result = db.query('PRAGMA integrity_check').get() as { integrity_check: string } | null;
|
|
876
|
-
db.close();
|
|
877
|
-
if (result?.integrity_check === 'ok') {
|
|
878
|
-
pass('Database integrity check');
|
|
879
|
-
} else {
|
|
880
|
-
fail('Database integrity check', result?.integrity_check ?? 'unknown result');
|
|
881
|
-
}
|
|
882
|
-
} catch (err) {
|
|
883
|
-
fail('Database integrity check', err instanceof Error ? err.message : 'unknown error');
|
|
884
|
-
}
|
|
885
|
-
} else {
|
|
886
|
-
fail('Database integrity check', 'database file not found');
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
// 9. Socket permissions
|
|
890
|
-
const sockPath = getSocketPath();
|
|
891
|
-
if (existsSync(sockPath)) {
|
|
892
|
-
try {
|
|
893
|
-
const sockStat = statSync(sockPath);
|
|
894
|
-
const mode = sockStat.mode & 0o777;
|
|
895
|
-
if (mode === 0o600 || mode === 0o700) {
|
|
896
|
-
pass(`Socket permissions (${mode.toString(8).padStart(4, '0')})`);
|
|
897
|
-
} else {
|
|
898
|
-
fail('Socket permissions', `expected 0600 or 0700, got 0${mode.toString(8)}`);
|
|
899
|
-
}
|
|
900
|
-
} catch {
|
|
901
|
-
fail('Socket permissions', 'could not stat socket');
|
|
902
|
-
}
|
|
903
|
-
} else {
|
|
904
|
-
pass('Socket permissions (socket not present — daemon not running)');
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
// 10. Trust rule syntax
|
|
908
|
-
const trustPath = `${rootDir}/protected/trust.json`;
|
|
909
|
-
if (existsSync(trustPath)) {
|
|
910
|
-
try {
|
|
911
|
-
const raw = readFileSync(trustPath, 'utf-8');
|
|
912
|
-
const data = JSON.parse(raw);
|
|
913
|
-
if (typeof data !== 'object' || data === null) {
|
|
914
|
-
fail('Trust rule syntax', 'trust.json is not a JSON object');
|
|
915
|
-
} else if (typeof data.version !== 'number') {
|
|
916
|
-
fail('Trust rule syntax', 'missing or invalid "version" field');
|
|
917
|
-
} else if (!Array.isArray(data.rules)) {
|
|
918
|
-
fail('Trust rule syntax', 'missing or invalid "rules" array');
|
|
919
|
-
} else {
|
|
920
|
-
const invalid = data.rules.filter(
|
|
921
|
-
(r: unknown) =>
|
|
922
|
-
typeof r !== 'object' || r === null ||
|
|
923
|
-
typeof (r as Record<string, unknown>).tool !== 'string' ||
|
|
924
|
-
typeof (r as Record<string, unknown>).pattern !== 'string' ||
|
|
925
|
-
typeof (r as Record<string, unknown>).scope !== 'string',
|
|
926
|
-
);
|
|
927
|
-
if (invalid.length > 0) {
|
|
928
|
-
fail('Trust rule syntax', `${invalid.length} rule(s) have invalid structure`);
|
|
929
|
-
} else {
|
|
930
|
-
pass(`Trust rule syntax (${data.rules.length} rule(s))`);
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
} catch (err) {
|
|
934
|
-
fail('Trust rule syntax', err instanceof Error ? err.message : 'could not parse');
|
|
935
|
-
}
|
|
936
|
-
} else {
|
|
937
|
-
pass('Trust rule syntax (no trust.json yet)');
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
// 11. WASM files
|
|
941
|
-
const wasmFiles = [
|
|
942
|
-
'node_modules/web-tree-sitter/web-tree-sitter.wasm',
|
|
943
|
-
'node_modules/tree-sitter-bash/tree-sitter-bash.wasm',
|
|
944
|
-
];
|
|
945
|
-
let wasmOk = true;
|
|
946
|
-
const missingWasm: string[] = [];
|
|
947
|
-
for (const wasm of wasmFiles) {
|
|
948
|
-
// Resolve relative to the assistant package directory
|
|
949
|
-
const fullPath = `${import.meta.dirname}/../${wasm}`;
|
|
950
|
-
if (!existsSync(fullPath)) {
|
|
951
|
-
missingWasm.push(wasm);
|
|
952
|
-
wasmOk = false;
|
|
953
|
-
} else {
|
|
954
|
-
try {
|
|
955
|
-
const wasmStat = statSync(fullPath);
|
|
956
|
-
if (wasmStat.size === 0) {
|
|
957
|
-
missingWasm.push(`${wasm} (empty)`);
|
|
958
|
-
wasmOk = false;
|
|
959
|
-
}
|
|
960
|
-
} catch {
|
|
961
|
-
missingWasm.push(`${wasm} (unreadable)`);
|
|
962
|
-
wasmOk = false;
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
if (wasmOk) {
|
|
967
|
-
pass('WASM files present and non-empty');
|
|
968
|
-
} else {
|
|
969
|
-
fail('WASM files', missingWasm.join(', '));
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
// 12. Browser runtime (Playwright + Chromium)
|
|
973
|
-
const { checkBrowserRuntime } = await import('./tools/browser/runtime-check.js');
|
|
974
|
-
const browserStatus = await checkBrowserRuntime();
|
|
975
|
-
if (browserStatus.playwrightAvailable && browserStatus.chromiumInstalled) {
|
|
976
|
-
pass('Browser runtime (Playwright + Chromium)');
|
|
977
|
-
} else if (!browserStatus.playwrightAvailable) {
|
|
978
|
-
fail('Browser runtime', 'playwright not available');
|
|
979
|
-
} else {
|
|
980
|
-
fail('Browser runtime', browserStatus.error ?? 'Chromium not installed');
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
// 13. Sandbox backend diagnostics
|
|
984
|
-
const { runSandboxDiagnostics } = await import('./tools/terminal/sandbox-diagnostics.js');
|
|
985
|
-
const sandbox = runSandboxDiagnostics();
|
|
986
|
-
log.info(`\n Sandbox: ${sandbox.config.enabled ? 'enabled' : 'disabled'}`);
|
|
987
|
-
log.info(` Backend: ${sandbox.config.backend}`);
|
|
988
|
-
log.info(` Reason: ${sandbox.activeBackendReason}`);
|
|
989
|
-
if (sandbox.config.backend === 'docker') {
|
|
990
|
-
log.info(` Image: ${sandbox.config.dockerImage}`);
|
|
991
|
-
}
|
|
992
|
-
log.info('');
|
|
993
|
-
for (const check of sandbox.checks) {
|
|
994
|
-
if (check.ok) {
|
|
995
|
-
pass(check.label);
|
|
996
|
-
} else {
|
|
997
|
-
fail(check.label, check.detail);
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
});
|
|
1001
|
-
|
|
1002
|
-
// --- Hooks commands ---
|
|
39
|
+
.version(version);
|
|
40
|
+
|
|
41
|
+
registerDefaultAction(program);
|
|
42
|
+
registerDaemonCommand(program);
|
|
43
|
+
registerDevCommand(program);
|
|
44
|
+
registerSessionsCommand(program);
|
|
45
|
+
registerConfigCommand(program);
|
|
46
|
+
registerKeysCommand(program);
|
|
47
|
+
registerTrustCommand(program);
|
|
48
|
+
registerMemoryCommand(program);
|
|
49
|
+
registerAuditCommand(program);
|
|
50
|
+
registerDoctorCommand(program);
|
|
1003
51
|
registerHooksCommand(program);
|
|
1004
|
-
|
|
1005
|
-
// --- Email commands ---
|
|
1006
52
|
registerEmailCommand(program);
|
|
1007
|
-
|
|
1008
|
-
// --- Contacts commands ---
|
|
1009
53
|
registerContactsCommand(program);
|
|
1010
|
-
|
|
1011
|
-
// --- Autonomy commands ---
|
|
1012
54
|
registerAutonomyCommand(program);
|
|
1013
|
-
|
|
1014
|
-
// --- DoorDash commands ---
|
|
1015
55
|
registerDoordashCommand(program);
|
|
56
|
+
registerCompletionsCommand(program);
|
|
1016
57
|
|
|
1017
|
-
|
|
1018
|
-
program
|
|
1019
|
-
.command('completions')
|
|
1020
|
-
.argument('<shell>', 'Shell type: bash, zsh, or fish')
|
|
1021
|
-
.description('Generate shell completion script (e.g. vellum completions bash >> ~/.bashrc)')
|
|
1022
|
-
.action((shell: string) => {
|
|
1023
|
-
const subcommands: Record<string, string[]> = {
|
|
1024
|
-
daemon: ['start', 'stop', 'restart', 'status'],
|
|
1025
|
-
sessions: ['list', 'new', 'export', 'clear'],
|
|
1026
|
-
config: ['set', 'get', 'list'],
|
|
1027
|
-
keys: ['list', 'set', 'delete'],
|
|
1028
|
-
trust: ['list', 'remove', 'clear'],
|
|
1029
|
-
memory: ['status', 'backfill', 'query', 'rebuild-index'],
|
|
1030
|
-
hooks: ['list', 'enable', 'disable', 'install', 'remove'],
|
|
1031
|
-
contacts: ['list', 'get', 'merge'],
|
|
1032
|
-
autonomy: ['get', 'set'],
|
|
1033
|
-
};
|
|
1034
|
-
const topLevel = [
|
|
1035
|
-
'daemon', 'dev', 'sessions', 'config', 'keys', 'trust', 'memory',
|
|
1036
|
-
'hooks', 'contacts', 'autonomy', 'audit', 'doctor', 'completions', 'help',
|
|
1037
|
-
];
|
|
1038
|
-
|
|
1039
|
-
switch (shell) {
|
|
1040
|
-
case 'bash':
|
|
1041
|
-
process.stdout.write(generateBashCompletion(topLevel, subcommands));
|
|
1042
|
-
break;
|
|
1043
|
-
case 'zsh':
|
|
1044
|
-
process.stdout.write(generateZshCompletion(topLevel, subcommands));
|
|
1045
|
-
break;
|
|
1046
|
-
case 'fish':
|
|
1047
|
-
process.stdout.write(generateFishCompletion(topLevel, subcommands));
|
|
1048
|
-
break;
|
|
1049
|
-
default:
|
|
1050
|
-
log.error(`Unknown shell: ${shell}. Supported shells: bash, zsh, fish`);
|
|
1051
|
-
process.exit(1);
|
|
1052
|
-
}
|
|
1053
|
-
});
|
|
1054
|
-
|
|
1055
|
-
function generateBashCompletion(
|
|
1056
|
-
topLevel: string[],
|
|
1057
|
-
subcommands: Record<string, string[]>,
|
|
1058
|
-
): string {
|
|
1059
|
-
const subcmdCases = Object.entries(subcommands)
|
|
1060
|
-
.map(([cmd, subs]) => ` ${cmd}) COMPREPLY=( $(compgen -W "${subs.join(' ')}" -- "$cur") ) ;;`)
|
|
1061
|
-
.join('\n');
|
|
1062
|
-
|
|
1063
|
-
return `# vellum bash completion
|
|
1064
|
-
# Add to ~/.bashrc: eval "$(vellum completions bash)"
|
|
1065
|
-
_vellum_completions() {
|
|
1066
|
-
local cur prev words cword
|
|
1067
|
-
_init_completion || return
|
|
1068
|
-
|
|
1069
|
-
if [[ $cword -eq 1 ]]; then
|
|
1070
|
-
COMPREPLY=( $(compgen -W "${topLevel.join(' ')} --help --version" -- "$cur") )
|
|
1071
|
-
return
|
|
1072
|
-
fi
|
|
1073
|
-
|
|
1074
|
-
case "\${words[1]}" in
|
|
1075
|
-
${subcmdCases}
|
|
1076
|
-
audit) COMPREPLY=( $(compgen -W "--limit -l" -- "$cur") ) ;;
|
|
1077
|
-
completions) COMPREPLY=( $(compgen -W "bash zsh fish" -- "$cur") ) ;;
|
|
1078
|
-
esac
|
|
1079
|
-
}
|
|
1080
|
-
complete -F _vellum_completions vellum
|
|
1081
|
-
`;
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
function generateZshCompletion(
|
|
1085
|
-
topLevel: string[],
|
|
1086
|
-
subcommands: Record<string, string[]>,
|
|
1087
|
-
): string {
|
|
1088
|
-
const subcmdCases = Object.entries(subcommands)
|
|
1089
|
-
.map(([cmd, subs]) => ` ${cmd}) compadd ${subs.join(' ')} ;;`)
|
|
1090
|
-
.join('\n');
|
|
1091
|
-
|
|
1092
|
-
return `#compdef vellum
|
|
1093
|
-
# vellum zsh completion
|
|
1094
|
-
# Add to ~/.zshrc: eval "$(vellum completions zsh)"
|
|
1095
|
-
_vellum() {
|
|
1096
|
-
local -a commands
|
|
1097
|
-
commands=(
|
|
1098
|
-
'daemon:Manage the daemon process'
|
|
1099
|
-
'dev:Run daemon in dev mode with auto-restart'
|
|
1100
|
-
'sessions:Manage sessions'
|
|
1101
|
-
'config:Manage configuration'
|
|
1102
|
-
'keys:Manage API keys in secure storage'
|
|
1103
|
-
'trust:Manage trust rules'
|
|
1104
|
-
'memory:Manage long-term memory'
|
|
1105
|
-
'hooks:Manage hooks'
|
|
1106
|
-
'contacts:Manage the contact graph'
|
|
1107
|
-
'autonomy:View and configure autonomy tiers'
|
|
1108
|
-
'audit:Show recent tool invocations'
|
|
1109
|
-
'doctor:Run diagnostic checks'
|
|
1110
|
-
'completions:Generate shell completion script'
|
|
1111
|
-
'help:Display help'
|
|
1112
|
-
)
|
|
1113
|
-
|
|
1114
|
-
if (( CURRENT == 2 )); then
|
|
1115
|
-
_describe 'command' commands
|
|
1116
|
-
_arguments '--help[Show help]' '--version[Show version]'
|
|
1117
|
-
return
|
|
1118
|
-
fi
|
|
1119
|
-
|
|
1120
|
-
case "\${words[2]}" in
|
|
1121
|
-
${subcmdCases}
|
|
1122
|
-
audit) _arguments '-l[Number of entries]' '--limit[Number of entries]' ;;
|
|
1123
|
-
completions) compadd bash zsh fish ;;
|
|
1124
|
-
esac
|
|
1125
|
-
}
|
|
1126
|
-
compdef _vellum vellum
|
|
1127
|
-
`;
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
function generateFishCompletion(
|
|
1131
|
-
topLevel: string[],
|
|
1132
|
-
subcommands: Record<string, string[]>,
|
|
1133
|
-
): string {
|
|
1134
|
-
let script = `# vellum fish completion
|
|
1135
|
-
# Add to ~/.config/fish/completions/vellum.fish or eval: vellum completions fish | source
|
|
1136
|
-
`;
|
|
1137
|
-
|
|
1138
|
-
// Disable file completions
|
|
1139
|
-
script += `complete -c vellum -f\n`;
|
|
1140
|
-
|
|
1141
|
-
// Top-level commands
|
|
1142
|
-
const descriptions: Record<string, string> = {
|
|
1143
|
-
daemon: 'Manage the daemon process',
|
|
1144
|
-
dev: 'Run daemon in dev mode with auto-restart',
|
|
1145
|
-
sessions: 'Manage sessions',
|
|
1146
|
-
config: 'Manage configuration',
|
|
1147
|
-
keys: 'Manage API keys in secure storage',
|
|
1148
|
-
trust: 'Manage trust rules',
|
|
1149
|
-
memory: 'Manage long-term memory',
|
|
1150
|
-
hooks: 'Manage hooks',
|
|
1151
|
-
contacts: 'Manage the contact graph',
|
|
1152
|
-
autonomy: 'View and configure autonomy tiers',
|
|
1153
|
-
audit: 'Show recent tool invocations',
|
|
1154
|
-
doctor: 'Run diagnostic checks',
|
|
1155
|
-
completions: 'Generate shell completion script',
|
|
1156
|
-
help: 'Display help',
|
|
1157
|
-
};
|
|
1158
|
-
|
|
1159
|
-
for (const cmd of topLevel) {
|
|
1160
|
-
const desc = descriptions[cmd] ?? '';
|
|
1161
|
-
script += `complete -c vellum -n '__fish_use_subcommand' -a '${cmd}' -d '${desc}'\n`;
|
|
1162
|
-
}
|
|
1163
|
-
script += `complete -c vellum -n '__fish_use_subcommand' -l help -d 'Show help'\n`;
|
|
1164
|
-
script += `complete -c vellum -n '__fish_use_subcommand' -l version -d 'Show version'\n`;
|
|
1165
|
-
|
|
1166
|
-
// Subcommands
|
|
1167
|
-
for (const [cmd, subs] of Object.entries(subcommands)) {
|
|
1168
|
-
for (const sub of subs) {
|
|
1169
|
-
script += `complete -c vellum -n '__fish_seen_subcommand_from ${cmd}' -a '${sub}'\n`;
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
// Audit options
|
|
1174
|
-
script += `complete -c vellum -n '__fish_seen_subcommand_from audit' -s l -l limit -d 'Number of entries'\n`;
|
|
1175
|
-
|
|
1176
|
-
// Completions shell argument
|
|
1177
|
-
script += `complete -c vellum -n '__fish_seen_subcommand_from completions' -a 'bash zsh fish'\n`;
|
|
1178
|
-
|
|
1179
|
-
return script;
|
|
1180
|
-
}
|
|
58
|
+
registerTwitterCommand(program);
|
|
59
|
+
registerMapCommand(program);
|
|
1181
60
|
|
|
1182
61
|
const knownCommands = new Set(program.commands.map(cmd => cmd.name()));
|
|
1183
62
|
const firstArg = process.argv[2];
|