somora 2026.930.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/LICENSE +21 -0
- package/README.md +364 -0
- package/bin/node-version.d.mts +3 -0
- package/bin/node-version.mjs +45 -0
- package/bin/somora.mjs +77 -0
- package/config.example.yaml +896 -0
- package/docs/agents.md +677 -0
- package/docs/api.md +3194 -0
- package/docs/browser.md +317 -0
- package/docs/builder.md +331 -0
- package/docs/cache-strategy.md +373 -0
- package/docs/compaction.md +253 -0
- package/docs/display.md +154 -0
- package/docs/dream-phases.md +891 -0
- package/docs/files.md +387 -0
- package/docs/imagegen.md +366 -0
- package/docs/images/somora-hero.png +0 -0
- package/docs/images/somora-mobile-2026-05-23.png +0 -0
- package/docs/images/somora-tui-2026-05-23.png +0 -0
- package/docs/images/somora-web-2026-05-23.png +0 -0
- package/docs/index.md +178 -0
- package/docs/lsp.md +93 -0
- package/docs/mcp.md +332 -0
- package/docs/memory.md +407 -0
- package/docs/mobile.md +310 -0
- package/docs/models.md +379 -0
- package/docs/projects.md +425 -0
- package/docs/realtime-voice.md +293 -0
- package/docs/resources.md +230 -0
- package/docs/sampling.md +128 -0
- package/docs/security.md +189 -0
- package/docs/sentinel.md +295 -0
- package/docs/setup.md +1217 -0
- package/docs/skills.md +501 -0
- package/docs/team.md +189 -0
- package/docs/thinking.md +463 -0
- package/docs/tmux.md +399 -0
- package/docs/tools.md +117 -0
- package/docs/videogen.md +191 -0
- package/docs/voice.md +288 -0
- package/docs/web.md +893 -0
- package/docs/wiki.md +583 -0
- package/npm-shrinkwrap.json +5670 -0
- package/package.json +116 -0
- package/src/attachments/store.ts +196 -0
- package/src/browser/change-stream.ts +31 -0
- package/src/browser/display.ts +108 -0
- package/src/browser/policy.ts +121 -0
- package/src/browser/screencast.ts +374 -0
- package/src/browser/service.ts +1337 -0
- package/src/browser/session.ts +15 -0
- package/src/browser/snapshot.ts +40 -0
- package/src/cli/auth.ts +117 -0
- package/src/cli/codex.ts +41 -0
- package/src/cli/lsp.ts +71 -0
- package/src/cli/resolvers/clawhub.ts +400 -0
- package/src/cli/setup.ts +835 -0
- package/src/cli/skill.ts +619 -0
- package/src/cli/somora.ts +548 -0
- package/src/cli/systemd-unit.ts +72 -0
- package/src/cli/team.ts +148 -0
- package/src/cli/tui/activity-stream.ts +121 -0
- package/src/cli/tui/api.ts +479 -0
- package/src/cli/tui/app.tsx +1169 -0
- package/src/cli/tui/autocomplete.tsx +55 -0
- package/src/cli/tui/commands.ts +913 -0
- package/src/cli/tui/dream-glyphs.ts +22 -0
- package/src/cli/tui/footer.tsx +15 -0
- package/src/cli/tui/format.ts +28 -0
- package/src/cli/tui/header.tsx +279 -0
- package/src/cli/tui/index.tsx +120 -0
- package/src/cli/tui/markdown.tsx +63 -0
- package/src/cli/tui/sampling.ts +162 -0
- package/src/cli/tui/separator.tsx +13 -0
- package/src/cli/tui/state.ts +42 -0
- package/src/cli/tui/stream.ts +330 -0
- package/src/cli/tui/thinking-text.ts +54 -0
- package/src/cli/tui/turn-views.tsx +499 -0
- package/src/cli/tui/types.ts +410 -0
- package/src/cli/tui/work-queue.ts +161 -0
- package/src/cli/update-args.ts +55 -0
- package/src/cli/wiki.ts +406 -0
- package/src/compaction/index.ts +28 -0
- package/src/compaction/midturn.ts +210 -0
- package/src/compaction/policy.ts +154 -0
- package/src/compaction/summarize.ts +691 -0
- package/src/compaction/template.ts +90 -0
- package/src/compaction/types.ts +148 -0
- package/src/config/loader.ts +276 -0
- package/src/config/reload.ts +43 -0
- package/src/config/types.ts +2292 -0
- package/src/dream/deep-actions.ts +324 -0
- package/src/dream/deep-dispatcher.ts +237 -0
- package/src/dream/deep-llm.ts +388 -0
- package/src/dream/deep-prompts.ts +106 -0
- package/src/dream/deep-runner.ts +757 -0
- package/src/dream/deep-skip-cache.ts +199 -0
- package/src/dream/deep-worker.ts +229 -0
- package/src/dream/json-salvage.ts +34 -0
- package/src/dream/judge.ts +188 -0
- package/src/dream/loop-state.ts +286 -0
- package/src/dream/lucid-actions.ts +303 -0
- package/src/dream/lucid-batches.ts +94 -0
- package/src/dream/lucid-prompt.ts +82 -0
- package/src/dream/lucid-runner.ts +744 -0
- package/src/dream/lucid-storage.ts +277 -0
- package/src/dream/lucid-structure.ts +102 -0
- package/src/dream/lucid-types.ts +137 -0
- package/src/dream/lucid-worker.ts +224 -0
- package/src/dream/rem-dedup.ts +502 -0
- package/src/dream/rem-extract.ts +782 -0
- package/src/dream/rem-reset-run.ts +67 -0
- package/src/dream/rem-runner.ts +696 -0
- package/src/dream/rem-worker.ts +527 -0
- package/src/dream/review-window.ts +71 -0
- package/src/dream/scheduler-state.ts +129 -0
- package/src/dream/storage.ts +497 -0
- package/src/dream/types.ts +133 -0
- package/src/dream/wiki-context.ts +133 -0
- package/src/engine/a2a.ts +33 -0
- package/src/engine/availability.ts +63 -0
- package/src/engine/claude-cli.ts +969 -0
- package/src/engine/codex-app-server-client.ts +294 -0
- package/src/engine/codex-bin.ts +49 -0
- package/src/engine/codex-cli.ts +1014 -0
- package/src/engine/codex-dynamic-tools.ts +239 -0
- package/src/engine/codex-home.ts +63 -0
- package/src/engine/codex-thread-config.ts +74 -0
- package/src/engine/context-budget.ts +257 -0
- package/src/engine/engine-meta-labels.ts +211 -0
- package/src/engine/grok-cli.ts +941 -0
- package/src/engine/inline-think.ts +59 -0
- package/src/engine/model-availability.ts +105 -0
- package/src/engine/openai-compatible.ts +2464 -0
- package/src/engine/reasoning-retry.ts +83 -0
- package/src/engine/registry.ts +13 -0
- package/src/engine/replay.ts +195 -0
- package/src/engine/sampling.ts +90 -0
- package/src/engine/thinking-params.ts +264 -0
- package/src/engine/types.ts +269 -0
- package/src/engine/user-tag.ts +24 -0
- package/src/imagegen/aspect.ts +128 -0
- package/src/imagegen/generate.ts +642 -0
- package/src/imagegen/references.ts +75 -0
- package/src/imagegen/types.ts +154 -0
- package/src/lsp/client.ts +183 -0
- package/src/lsp/fake-server.helper.mjs +42 -0
- package/src/lsp/format.ts +29 -0
- package/src/lsp/index.ts +21 -0
- package/src/lsp/manager.ts +238 -0
- package/src/lsp/registry.ts +151 -0
- package/src/mcp/config.ts +117 -0
- package/src/mcp/hub/audit.ts +55 -0
- package/src/mcp/hub/bridge.ts +115 -0
- package/src/mcp/hub/catalog.ts +69 -0
- package/src/mcp/hub/credentials.ts +406 -0
- package/src/mcp/hub/env-expand.ts +14 -0
- package/src/mcp/hub/manager.ts +770 -0
- package/src/mcp/hub/normalize.ts +213 -0
- package/src/mcp/server.ts +368 -0
- package/src/mcp/tool-schema.ts +20 -0
- package/src/media/capabilities.ts +392 -0
- package/src/media/records.ts +175 -0
- package/src/media/store.ts +217 -0
- package/src/media/types.ts +69 -0
- package/src/memory/chunking.ts +168 -0
- package/src/memory/embeddings.ts +262 -0
- package/src/memory/index.ts +15 -0
- package/src/memory/inject.ts +197 -0
- package/src/memory/manager.ts +996 -0
- package/src/memory/registry.ts +176 -0
- package/src/memory/rescan.ts +101 -0
- package/src/memory/retrieval.ts +586 -0
- package/src/memory/shared-index.ts +372 -0
- package/src/memory/slug.ts +39 -0
- package/src/memory/storage.ts +385 -0
- package/src/memory/watcher.ts +134 -0
- package/src/multimodal/blocks.ts +101 -0
- package/src/multimodal/dimensions.ts +214 -0
- package/src/multimodal/load.ts +86 -0
- package/src/multimodal/mime.ts +135 -0
- package/src/multimodal/pdf-render.ts +80 -0
- package/src/multimodal/user-content.ts +266 -0
- package/src/persona/files.ts +144 -0
- package/src/persona/loader.ts +598 -0
- package/src/persona/skill-gating-store.ts +59 -0
- package/src/persona/tool-gating-store.ts +113 -0
- package/src/projects/focus.ts +186 -0
- package/src/projects/prompt-block.ts +106 -0
- package/src/projects/scheme.ts +107 -0
- package/src/projects/store.ts +144 -0
- package/src/projects/types.ts +73 -0
- package/src/sentinel/dispatcher.ts +97 -0
- package/src/sentinel/schedule.ts +271 -0
- package/src/sentinel/scheduler.ts +840 -0
- package/src/sentinel/store.ts +259 -0
- package/src/sentinel/types.ts +221 -0
- package/src/server/activity-stream.ts +160 -0
- package/src/server/ask-calls.ts +137 -0
- package/src/server/ask-wait-graph.ts +171 -0
- package/src/server/async-tasks.ts +199 -0
- package/src/server/builder-busy.ts +86 -0
- package/src/server/builder-prompt.ts +204 -0
- package/src/server/builder-questions.ts +117 -0
- package/src/server/builder-session.ts +249 -0
- package/src/server/chat-aborts.ts +83 -0
- package/src/server/claude-config-dir.ts +71 -0
- package/src/server/claude-credential-sync.ts +454 -0
- package/src/server/env-file.ts +100 -0
- package/src/server/env.ts +115 -0
- package/src/server/heal-session.ts +151 -0
- package/src/server/history-page.ts +46 -0
- package/src/server/index.ts +7244 -0
- package/src/server/lockfile.ts +89 -0
- package/src/server/logger.ts +67 -0
- package/src/server/logs.ts +187 -0
- package/src/server/loopback-fetch.ts +130 -0
- package/src/server/openai-client.ts +89 -0
- package/src/server/prompt-assembly.ts +334 -0
- package/src/server/restart-reconcile.ts +139 -0
- package/src/server/run-turn-fallback.ts +275 -0
- package/src/server/run-turn-types.ts +91 -0
- package/src/server/run-turn.ts +1474 -0
- package/src/server/sanitize-assistant-text.ts +112 -0
- package/src/server/session-export.ts +220 -0
- package/src/server/session-queue.ts +376 -0
- package/src/server/session-workdir.ts +49 -0
- package/src/server/sse-h2-safe.ts +61 -0
- package/src/server/sse-liveness.ts +162 -0
- package/src/server/sse-serializer.ts +161 -0
- package/src/server/start-turn.ts +249 -0
- package/src/server/steer-inbox.ts +107 -0
- package/src/server/tls-keeper.ts +153 -0
- package/src/server/tool-format.ts +167 -0
- package/src/server/turn-framing.ts +52 -0
- package/src/server/turn-origin-kind.ts +74 -0
- package/src/server/turn-origin.ts +40 -0
- package/src/server/work-ledger.ts +975 -0
- package/src/server/workspace.ts +114 -0
- package/src/setup/config-edit.ts +201 -0
- package/src/setup/presets.ts +71 -0
- package/src/setup/prompt.ts +163 -0
- package/src/setup/tailscale.ts +44 -0
- package/src/skills/bin-checks.ts +227 -0
- package/src/skills/bootstrap.ts +347 -0
- package/src/skills/env-scope.ts +175 -0
- package/src/skills/gating.ts +71 -0
- package/src/skills/lint.ts +202 -0
- package/src/skills/load.ts +368 -0
- package/src/skills/path-helpers.ts +102 -0
- package/src/skills/registry.ts +178 -0
- package/src/ssh/exec.ts +142 -0
- package/src/ssh/index.ts +12 -0
- package/src/ssh/known-hosts.ts +109 -0
- package/src/ssh/pool.ts +307 -0
- package/src/storage/sessions.ts +602 -0
- package/src/team/render.ts +149 -0
- package/src/team/resolve.ts +122 -0
- package/src/team/store.ts +124 -0
- package/src/team/types.ts +111 -0
- package/src/team/write.ts +95 -0
- package/src/testing/isolated-home.mts +46 -0
- package/src/tmux/attention-watcher.ts +272 -0
- package/src/tmux/attention.ts +336 -0
- package/src/tmux/list.ts +91 -0
- package/src/tmux/origin-store.ts +102 -0
- package/src/tmux/tui-markers.ts +267 -0
- package/src/tools/agents/ask-cancel.ts +94 -0
- package/src/tools/agents/ask-result.ts +235 -0
- package/src/tools/agents/ask.ts +704 -0
- package/src/tools/agents/builder-dispatch.ts +217 -0
- package/src/tools/agents/images.ts +104 -0
- package/src/tools/agents/index.ts +42 -0
- package/src/tools/agents/long-task-timeouts.ts +39 -0
- package/src/tools/agents/session-list.ts +136 -0
- package/src/tools/agents/session-model.ts +106 -0
- package/src/tools/agents/spawn.ts +845 -0
- package/src/tools/agents/status.ts +589 -0
- package/src/tools/browser/index.ts +6 -0
- package/src/tools/browser/ops.ts +145 -0
- package/src/tools/browser/tools.ts +184 -0
- package/src/tools/builder/short-descriptions.ts +80 -0
- package/src/tools/builder/tools.ts +222 -0
- package/src/tools/docs/index.ts +1 -0
- package/src/tools/docs/tools.ts +228 -0
- package/src/tools/dream/index.ts +11 -0
- package/src/tools/dream/tools.ts +1002 -0
- package/src/tools/exec/allowlist.ts +233 -0
- package/src/tools/exec/background-detach.helper.mts +27 -0
- package/src/tools/exec/blacklist.ts +336 -0
- package/src/tools/exec/concurrency.ts +150 -0
- package/src/tools/exec/fit-output.ts +82 -0
- package/src/tools/exec/index.ts +7 -0
- package/src/tools/exec/internal-env.ts +89 -0
- package/src/tools/exec/job-store.ts +403 -0
- package/src/tools/exec/local.ts +649 -0
- package/src/tools/exec/remote.ts +399 -0
- package/src/tools/exec/tools.ts +934 -0
- package/src/tools/file/analyze.ts +378 -0
- package/src/tools/file/index.ts +2 -0
- package/src/tools/file/local.ts +707 -0
- package/src/tools/file/lsp-hook.ts +72 -0
- package/src/tools/file/persona-guard.ts +61 -0
- package/src/tools/file/policy.ts +292 -0
- package/src/tools/file/read-format.ts +129 -0
- package/src/tools/file/remote.ts +680 -0
- package/src/tools/file/replace.ts +507 -0
- package/src/tools/file/search-window.ts +224 -0
- package/src/tools/file/tools.ts +658 -0
- package/src/tools/file/write-scope.ts +182 -0
- package/src/tools/gating.ts +106 -0
- package/src/tools/image/budget.ts +82 -0
- package/src/tools/image/index.ts +7 -0
- package/src/tools/image/tools.ts +601 -0
- package/src/tools/index.ts +99 -0
- package/src/tools/memory/index.ts +12 -0
- package/src/tools/memory/tools.ts +399 -0
- package/src/tools/projects/index.ts +1 -0
- package/src/tools/projects/tools.ts +643 -0
- package/src/tools/registry.ts +427 -0
- package/src/tools/resources/index.ts +8 -0
- package/src/tools/resources/tools.ts +176 -0
- package/src/tools/resources/visibility.ts +60 -0
- package/src/tools/sentinel/index.ts +1 -0
- package/src/tools/sentinel/tools.ts +592 -0
- package/src/tools/skill/index.ts +4 -0
- package/src/tools/skill/tools.ts +285 -0
- package/src/tools/time/index.ts +5 -0
- package/src/tools/time/tools.ts +123 -0
- package/src/tools/tmux/index.ts +1 -0
- package/src/tools/tmux/local.ts +277 -0
- package/src/tools/tmux/remote.ts +168 -0
- package/src/tools/tmux/tools.ts +1064 -0
- package/src/tools/tool-output.ts +97 -0
- package/src/tools/types.ts +227 -0
- package/src/tools/video/index.ts +1 -0
- package/src/tools/video/tools.ts +425 -0
- package/src/tools/web/fetch.ts +337 -0
- package/src/tools/web/index.ts +4 -0
- package/src/tools/web/tools.ts +186 -0
- package/src/tools/wiki/index.ts +1 -0
- package/src/tools/wiki/tools.ts +445 -0
- package/src/tts/cache-gc.ts +128 -0
- package/src/tts/prepare-for-tts.ts +114 -0
- package/src/tts/service.ts +332 -0
- package/src/types/events.ts +695 -0
- package/src/types/turn-origin.ts +53 -0
- package/src/version.ts +21 -0
- package/src/videogen/dialects.ts +222 -0
- package/src/videogen/generate.ts +484 -0
- package/src/videogen/jobs.ts +178 -0
- package/src/videogen/runner.ts +125 -0
- package/src/videogen/wake.ts +119 -0
- package/src/voice/realtime/call.ts +948 -0
- package/src/voice/realtime/consult.ts +293 -0
- package/src/voice/realtime/fake-provider.ts +134 -0
- package/src/voice/realtime/manager.ts +384 -0
- package/src/voice/realtime/openai-provider.ts +471 -0
- package/src/voice/realtime/persona.ts +227 -0
- package/src/voice/realtime/session-match.ts +116 -0
- package/src/voice/realtime/types.ts +182 -0
- package/src/wiki/conflict.ts +113 -0
- package/src/wiki/explorer.ts +578 -0
- package/src/wiki/index-builder.ts +172 -0
- package/src/wiki/language.ts +134 -0
- package/src/wiki/log-builder.ts +150 -0
- package/src/wiki/map.ts +258 -0
- package/src/wiki/migration/analyze.ts +304 -0
- package/src/wiki/migration/execute.ts +689 -0
- package/src/wiki/migration/refine.ts +402 -0
- package/src/wiki/migration/store.ts +100 -0
- package/src/wiki/move-page.ts +57 -0
- package/src/wiki/structure-file.ts +192 -0
- package/src/wiki/taxonomy.ts +140 -0
- package/src/wiki/templates.ts +163 -0
- package/src/wiki/types.ts +133 -0
- package/templates/skills/README.md +24 -0
- package/templates/skills/_templates/api-wrapper/SKILL.md +26 -0
- package/templates/skills/_templates/cli-wrapper/BOOTSTRAP.md +32 -0
- package/templates/skills/_templates/cli-wrapper/SKILL.md +24 -0
- package/templates/skills/_templates/default/SKILL.md +25 -0
- package/templates/skills/builder-handover/SKILL.md +96 -0
- package/templates/skills/builder-handover/assets/ORDER.md +12 -0
- package/templates/skills/skill-author/SKILL.md +110 -0
- package/tsconfig.json +22 -0
- package/web/dist/assets/index-BaVv6pB2.js +631 -0
- package/web/dist/assets/index-BaVv6pB2.js.map +1 -0
- package/web/dist/assets/index-V3FV3Z25.css +32 -0
- package/web/dist/favicon.svg +8 -0
- package/web/dist/index.html +20 -0
- package/web/package.json +36 -0
- package/web/tsconfig.json +25 -0
- package/web-mobile/dist/apple-touch-icon.png +0 -0
- package/web-mobile/dist/assets/index-BqKt7IMx.css +1 -0
- package/web-mobile/dist/assets/index-X_vRr6cd.js +88 -0
- package/web-mobile/dist/assets/index-X_vRr6cd.js.map +1 -0
- package/web-mobile/dist/favicon.svg +8 -0
- package/web-mobile/dist/icon-192.png +0 -0
- package/web-mobile/dist/icon-512.png +0 -0
- package/web-mobile/dist/index.html +27 -0
- package/web-mobile/dist/manifest.webmanifest +32 -0
- package/web-mobile/dist/service-worker.js +90 -0
- package/web-mobile/package.json +28 -0
- package/web-mobile/tsconfig.json +25 -0
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
// Project tools — six tools that let an agent manage the project
|
|
2
|
+
// pointer-file index (~/.somora/projects/<slug>.md) and pin/unpin a
|
|
3
|
+
// project to the current session.
|
|
4
|
+
//
|
|
5
|
+
// All six are gated on `config.projects.enabled` via the `available`
|
|
6
|
+
// probe — when projects are disabled in config.yaml, the tools are
|
|
7
|
+
// completely invisible to the model (filtered out by the registry
|
|
8
|
+
// before it builds the model-facing tool list).
|
|
9
|
+
//
|
|
10
|
+
// Why all in one file: six small tools with shared validation helpers
|
|
11
|
+
// (entity-cross-check, scheme inference) read better together than
|
|
12
|
+
// split into six files with import-chains. If this grows past ~10 tools
|
|
13
|
+
// we can re-split by responsibility (read tools vs. write tools).
|
|
14
|
+
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import { logger } from '../../server/logger.ts';
|
|
17
|
+
import { sessionMetaStore } from '../../storage/sessions.ts';
|
|
18
|
+
import { focusProject } from '../../projects/focus.ts';
|
|
19
|
+
import { validatePathRef, inferPathType } from '../../projects/scheme.ts';
|
|
20
|
+
import {
|
|
21
|
+
deleteProjectFile,
|
|
22
|
+
listProjects,
|
|
23
|
+
projectExists,
|
|
24
|
+
readProject,
|
|
25
|
+
writeProject,
|
|
26
|
+
} from '../../projects/store.ts';
|
|
27
|
+
import {
|
|
28
|
+
PROJECT_SLUG_RE,
|
|
29
|
+
ProjectFrontmatterSchema,
|
|
30
|
+
ProjectPathSchema,
|
|
31
|
+
type ProjectFrontmatter,
|
|
32
|
+
type ProjectPath,
|
|
33
|
+
} from '../../projects/types.ts';
|
|
34
|
+
import type { ToolContext, ToolDefinition } from '../types.ts';
|
|
35
|
+
|
|
36
|
+
// ─── shared helpers ─────────────────────────────────────────────────
|
|
37
|
+
|
|
38
|
+
function ensureEnabled(ctx: ToolContext): void {
|
|
39
|
+
if (!ctx.config.projects?.enabled) {
|
|
40
|
+
throw new Error('projects.enabled is false in config.yaml — project tools are inactive');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function validateEntity(ctx: ToolContext, entitySlug: string): void {
|
|
45
|
+
const entities = ctx.config.projects?.entities ?? [];
|
|
46
|
+
if (entities.length === 0) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
'no entities configured in config.projects.entities — add at least one before creating projects',
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
const known = entities.map((e) => e.slug);
|
|
52
|
+
if (!known.includes(entitySlug)) {
|
|
53
|
+
throw new Error(`unknown entity '${entitySlug}' — available: ${known.join(', ')}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function validatePathsArray(paths: ProjectPath[], ctx: ToolContext): void {
|
|
58
|
+
const errors: string[] = [];
|
|
59
|
+
for (const p of paths) {
|
|
60
|
+
const result = validatePathRef(p.ref, ctx.config);
|
|
61
|
+
if (!result.ok) errors.push(result.error);
|
|
62
|
+
}
|
|
63
|
+
if (errors.length > 0) {
|
|
64
|
+
throw new Error(`path validation failed: ${errors.join('; ')}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function nowIso(): string {
|
|
69
|
+
return new Date().toISOString();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Compact projection of a project for `project_list` — strips the
|
|
73
|
+
* paths array so the list result stays small. Callers fetch full
|
|
74
|
+
* details via project_get when they need the pointers. */
|
|
75
|
+
interface ProjectSummary {
|
|
76
|
+
slug: string;
|
|
77
|
+
name: string;
|
|
78
|
+
entity: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
color?: string;
|
|
81
|
+
tags: string[];
|
|
82
|
+
created: string;
|
|
83
|
+
updated: string;
|
|
84
|
+
expires?: string | null;
|
|
85
|
+
archived: boolean;
|
|
86
|
+
pathCount: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function toSummary(p: ProjectFrontmatter): ProjectSummary {
|
|
90
|
+
const summary: ProjectSummary = {
|
|
91
|
+
slug: p.slug,
|
|
92
|
+
name: p.name,
|
|
93
|
+
entity: p.entity,
|
|
94
|
+
tags: p.tags,
|
|
95
|
+
created: p.created,
|
|
96
|
+
updated: p.updated,
|
|
97
|
+
archived: p.archived,
|
|
98
|
+
pathCount: p.paths.length,
|
|
99
|
+
};
|
|
100
|
+
if (p.description !== undefined) summary.description = p.description;
|
|
101
|
+
if (p.color !== undefined) summary.color = p.color;
|
|
102
|
+
if (p.expires !== undefined) summary.expires = p.expires;
|
|
103
|
+
return summary;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ─── entity_list ─────────────────────────────────────────────────────
|
|
107
|
+
|
|
108
|
+
const EntityListInput = z.object({}).strict();
|
|
109
|
+
|
|
110
|
+
export const entityList: ToolDefinition<z.infer<typeof EntityListInput>> = {
|
|
111
|
+
name: 'entity_list',
|
|
112
|
+
toolset: 'projects',
|
|
113
|
+
description:
|
|
114
|
+
'List the entities configured in config.projects.entities — the controlled vocabulary for ' +
|
|
115
|
+
'project-creation. Call this BEFORE project_create if you are unsure which entity slug ' +
|
|
116
|
+
'matches the user\'s intent (e.g. you heard a fuzzy STT transcript). Entities are CURATED ' +
|
|
117
|
+
'by the user in config.yaml; you cannot extend the list via tools.',
|
|
118
|
+
inputSchema: EntityListInput,
|
|
119
|
+
jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
120
|
+
available: (ctx) => Boolean(ctx.config.projects?.enabled),
|
|
121
|
+
async handler(_input, ctx) {
|
|
122
|
+
ensureEnabled(ctx);
|
|
123
|
+
return { entities: ctx.config.projects?.entities ?? [] };
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// ─── project_list ────────────────────────────────────────────────────
|
|
128
|
+
|
|
129
|
+
const ProjectListInput = z
|
|
130
|
+
.object({
|
|
131
|
+
entity: z.string().optional().describe('Filter to projects matching this entity slug.'),
|
|
132
|
+
tag: z.string().optional().describe('Filter to projects whose tags include this string.'),
|
|
133
|
+
includeArchived: z.boolean().default(false).describe('Include soft-deleted projects.'),
|
|
134
|
+
})
|
|
135
|
+
.strict();
|
|
136
|
+
|
|
137
|
+
export const projectList: ToolDefinition<z.infer<typeof ProjectListInput>> = {
|
|
138
|
+
name: 'project_list',
|
|
139
|
+
toolset: 'projects',
|
|
140
|
+
description:
|
|
141
|
+
'List configured projects with light metadata. Returns slug, name, entity, description, ' +
|
|
142
|
+
'color, tags, timestamps, archived state, and path count — but NOT the full paths array. ' +
|
|
143
|
+
'Use project_get to fetch a single project\'s full pointer-list. Filters: `entity` and ' +
|
|
144
|
+
'`tag` are AND-combined. Archived projects are hidden by default — pass ' +
|
|
145
|
+
'includeArchived:true to see them.',
|
|
146
|
+
inputSchema: ProjectListInput,
|
|
147
|
+
jsonSchema: {
|
|
148
|
+
type: 'object',
|
|
149
|
+
properties: {
|
|
150
|
+
entity: { type: 'string', description: 'Filter to projects matching this entity slug.' },
|
|
151
|
+
tag: { type: 'string', description: 'Filter to projects whose tags include this string.' },
|
|
152
|
+
includeArchived: {
|
|
153
|
+
type: 'boolean',
|
|
154
|
+
description: 'Include soft-deleted projects (default false).',
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
additionalProperties: false,
|
|
158
|
+
},
|
|
159
|
+
available: (ctx) => Boolean(ctx.config.projects?.enabled),
|
|
160
|
+
async handler(input, ctx) {
|
|
161
|
+
ensureEnabled(ctx);
|
|
162
|
+
const all = await listProjects();
|
|
163
|
+
const filtered = all.filter((p) => {
|
|
164
|
+
if (!input.includeArchived && p.archived) return false;
|
|
165
|
+
if (input.entity && p.entity !== input.entity) return false;
|
|
166
|
+
if (input.tag && !p.tags.includes(input.tag)) return false;
|
|
167
|
+
return true;
|
|
168
|
+
});
|
|
169
|
+
return { projects: filtered.map(toSummary), total: filtered.length };
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// ─── project_get ─────────────────────────────────────────────────────
|
|
174
|
+
|
|
175
|
+
const ProjectGetInput = z
|
|
176
|
+
.object({
|
|
177
|
+
slug: z.string().regex(PROJECT_SLUG_RE).describe('Project slug to fetch.'),
|
|
178
|
+
})
|
|
179
|
+
.strict();
|
|
180
|
+
|
|
181
|
+
export const projectGet: ToolDefinition<z.infer<typeof ProjectGetInput>> = {
|
|
182
|
+
name: 'project_get',
|
|
183
|
+
toolset: 'projects',
|
|
184
|
+
description:
|
|
185
|
+
'Fetch a single project\'s full frontmatter — all fields including the paths array with ' +
|
|
186
|
+
'per-path scheme inference (`local` / `url` / `resource`). Returns 404-style error if the ' +
|
|
187
|
+
'slug does not exist.',
|
|
188
|
+
inputSchema: ProjectGetInput,
|
|
189
|
+
jsonSchema: {
|
|
190
|
+
type: 'object',
|
|
191
|
+
properties: {
|
|
192
|
+
slug: { type: 'string', description: 'Project slug to fetch.' },
|
|
193
|
+
},
|
|
194
|
+
required: ['slug'],
|
|
195
|
+
additionalProperties: false,
|
|
196
|
+
},
|
|
197
|
+
available: (ctx) => Boolean(ctx.config.projects?.enabled),
|
|
198
|
+
async handler(input, ctx) {
|
|
199
|
+
ensureEnabled(ctx);
|
|
200
|
+
const project = await readProject(input.slug);
|
|
201
|
+
if (!project) {
|
|
202
|
+
throw new Error(`project '${input.slug}' does not exist`);
|
|
203
|
+
}
|
|
204
|
+
// Decorate paths with inferred type for the agent's convenience.
|
|
205
|
+
const decoratedPaths = project.paths.map((p) => {
|
|
206
|
+
const inferred = inferPathType(p.ref);
|
|
207
|
+
return {
|
|
208
|
+
ref: p.ref,
|
|
209
|
+
...(p.label ? { label: p.label } : {}),
|
|
210
|
+
type: inferred?.type ?? 'unknown',
|
|
211
|
+
...(inferred?.resource ? { resource: inferred.resource } : {}),
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
return { project: { ...project, paths: decoratedPaths } };
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// ─── project_create ──────────────────────────────────────────────────
|
|
219
|
+
|
|
220
|
+
const CreateInput = z
|
|
221
|
+
.object({
|
|
222
|
+
slug: z.string().regex(PROJECT_SLUG_RE).describe('New unique project slug (lowercase kebab-case).'),
|
|
223
|
+
name: z.string().min(1).describe('Display name.'),
|
|
224
|
+
entity: z
|
|
225
|
+
.string()
|
|
226
|
+
.min(1)
|
|
227
|
+
.describe('Entity slug — MUST match one of config.projects.entities. Call entity_list first if unsure.'),
|
|
228
|
+
description: z.string().optional(),
|
|
229
|
+
color: z.string().optional().describe('CSS color (hex like "#4f46e5" or name).'),
|
|
230
|
+
tags: z.array(z.string().min(1)).default([]),
|
|
231
|
+
expires: z.string().nullable().optional().describe('ISO date string for soft-expiry, or null.'),
|
|
232
|
+
paths: z.array(ProjectPathSchema).default([]).describe('Initial pointer list (can be empty).'),
|
|
233
|
+
workdir: z
|
|
234
|
+
.string()
|
|
235
|
+
.min(1)
|
|
236
|
+
.optional()
|
|
237
|
+
.describe('The project\'s working directory (its repository), absolute or ~/…. Pinning the project to a session makes it the session\'s working directory: relative file paths and exec\'s default cwd resolve there; a builder agent works in it.'),
|
|
238
|
+
})
|
|
239
|
+
.strict();
|
|
240
|
+
|
|
241
|
+
export const projectCreate: ToolDefinition<z.infer<typeof CreateInput>> = {
|
|
242
|
+
name: 'project_create',
|
|
243
|
+
toolset: 'projects',
|
|
244
|
+
description:
|
|
245
|
+
'Create a new project pointer file under ~/.somora/projects/<slug>.md with frontmatter ' +
|
|
246
|
+
'metadata + an initial pointer list. Slug must be unique (kebab-case). Entity is ' +
|
|
247
|
+
'validated against config.projects.entities — use entity_list first if uncertain. Paths ' +
|
|
248
|
+
'use scheme inference: `~/path` or `/path` → local, `https://...` etc. → url, ' +
|
|
249
|
+
'`<resource-slug>:/path` → resource (cross-checked against config.resources). Multiple ' +
|
|
250
|
+
'paths in one call: pass them all in `paths`.',
|
|
251
|
+
inputSchema: CreateInput,
|
|
252
|
+
jsonSchema: {
|
|
253
|
+
type: 'object',
|
|
254
|
+
properties: {
|
|
255
|
+
slug: { type: 'string', description: 'New unique project slug (lowercase kebab-case).' },
|
|
256
|
+
name: { type: 'string', description: 'Display name.' },
|
|
257
|
+
entity: {
|
|
258
|
+
type: 'string',
|
|
259
|
+
description: 'Entity slug — MUST match one of config.projects.entities.',
|
|
260
|
+
},
|
|
261
|
+
description: { type: 'string' },
|
|
262
|
+
color: { type: 'string', description: 'CSS color (hex like "#4f46e5" or name).' },
|
|
263
|
+
tags: { type: 'array', items: { type: 'string' } },
|
|
264
|
+
expires: { type: ['string', 'null'], description: 'ISO date for soft-expiry, or null.' },
|
|
265
|
+
paths: {
|
|
266
|
+
type: 'array',
|
|
267
|
+
items: {
|
|
268
|
+
type: 'object',
|
|
269
|
+
properties: {
|
|
270
|
+
ref: { type: 'string' },
|
|
271
|
+
label: { type: 'string' },
|
|
272
|
+
},
|
|
273
|
+
required: ['ref'],
|
|
274
|
+
additionalProperties: false,
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
workdir: { type: 'string', description: 'Working directory (repository) of the project, absolute or ~/…; becomes the session working directory when pinned.' },
|
|
278
|
+
},
|
|
279
|
+
required: ['slug', 'name', 'entity'],
|
|
280
|
+
additionalProperties: false,
|
|
281
|
+
},
|
|
282
|
+
available: (ctx) => Boolean(ctx.config.projects?.enabled),
|
|
283
|
+
async handler(input, ctx) {
|
|
284
|
+
ensureEnabled(ctx);
|
|
285
|
+
validateEntity(ctx, input.entity);
|
|
286
|
+
if (await projectExists(input.slug)) {
|
|
287
|
+
throw new Error(`project '${input.slug}' already exists`);
|
|
288
|
+
}
|
|
289
|
+
validatePathsArray(input.paths, ctx);
|
|
290
|
+
|
|
291
|
+
const now = nowIso();
|
|
292
|
+
const project: ProjectFrontmatter = ProjectFrontmatterSchema.parse({
|
|
293
|
+
slug: input.slug,
|
|
294
|
+
name: input.name,
|
|
295
|
+
entity: input.entity,
|
|
296
|
+
...(input.description !== undefined ? { description: input.description } : {}),
|
|
297
|
+
...(input.color !== undefined ? { color: input.color } : {}),
|
|
298
|
+
tags: input.tags,
|
|
299
|
+
created: now,
|
|
300
|
+
updated: now,
|
|
301
|
+
...(input.expires !== undefined ? { expires: input.expires } : {}),
|
|
302
|
+
archived: false,
|
|
303
|
+
paths: input.paths,
|
|
304
|
+
...(input.workdir !== undefined ? { workdir: input.workdir } : {}),
|
|
305
|
+
});
|
|
306
|
+
await writeProject(project);
|
|
307
|
+
logger.info({
|
|
308
|
+
msg: 'project.created',
|
|
309
|
+
slug: project.slug,
|
|
310
|
+
entity: project.entity,
|
|
311
|
+
pathCount: project.paths.length,
|
|
312
|
+
agent: ctx.agent,
|
|
313
|
+
session: ctx.session,
|
|
314
|
+
});
|
|
315
|
+
return { project };
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
// ─── project_update ──────────────────────────────────────────────────
|
|
320
|
+
|
|
321
|
+
// UpdateOp union. Lives only in this file because it's tool-API surface,
|
|
322
|
+
// not stored — the on-disk shape is always the frontmatter snapshot.
|
|
323
|
+
const SetFieldOp = z.object({
|
|
324
|
+
op: z.literal('set_field'),
|
|
325
|
+
field: z.enum(['name', 'description', 'color', 'expires', 'workdir']),
|
|
326
|
+
value: z.string().nullable(),
|
|
327
|
+
});
|
|
328
|
+
const AddPathOp = z.object({
|
|
329
|
+
op: z.literal('add_path'),
|
|
330
|
+
ref: z.string().min(1),
|
|
331
|
+
label: z.string().min(1).optional(),
|
|
332
|
+
});
|
|
333
|
+
const RemovePathOp = z.object({
|
|
334
|
+
op: z.literal('remove_path'),
|
|
335
|
+
ref: z.string().min(1),
|
|
336
|
+
});
|
|
337
|
+
const SetTagsOp = z.object({
|
|
338
|
+
op: z.literal('set_tags'),
|
|
339
|
+
tags: z.array(z.string().min(1)),
|
|
340
|
+
});
|
|
341
|
+
const ArchiveOp = z.object({
|
|
342
|
+
op: z.literal('archive'),
|
|
343
|
+
reason: z.string().optional(),
|
|
344
|
+
});
|
|
345
|
+
const UnarchiveOp = z.object({
|
|
346
|
+
op: z.literal('unarchive'),
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
const UpdateOpSchema = z.discriminatedUnion('op', [
|
|
350
|
+
SetFieldOp,
|
|
351
|
+
AddPathOp,
|
|
352
|
+
RemovePathOp,
|
|
353
|
+
SetTagsOp,
|
|
354
|
+
ArchiveOp,
|
|
355
|
+
UnarchiveOp,
|
|
356
|
+
]);
|
|
357
|
+
type UpdateOp = z.infer<typeof UpdateOpSchema>;
|
|
358
|
+
|
|
359
|
+
const UpdateInput = z
|
|
360
|
+
.object({
|
|
361
|
+
slug: z.string().regex(PROJECT_SLUG_RE),
|
|
362
|
+
ops: z.array(UpdateOpSchema).min(1).describe('Mutations to apply, in order. Transactional.'),
|
|
363
|
+
})
|
|
364
|
+
.strict();
|
|
365
|
+
|
|
366
|
+
function applyOps(
|
|
367
|
+
current: ProjectFrontmatter,
|
|
368
|
+
ops: UpdateOp[],
|
|
369
|
+
ctx: ToolContext,
|
|
370
|
+
): ProjectFrontmatter {
|
|
371
|
+
// Work on a shallow clone so a mid-op failure leaves the caller's
|
|
372
|
+
// copy untouched (we re-throw and skip the write).
|
|
373
|
+
const next: ProjectFrontmatter = {
|
|
374
|
+
...current,
|
|
375
|
+
tags: [...current.tags],
|
|
376
|
+
paths: current.paths.map((p) => ({ ...p })),
|
|
377
|
+
};
|
|
378
|
+
for (const op of ops) {
|
|
379
|
+
switch (op.op) {
|
|
380
|
+
case 'set_field': {
|
|
381
|
+
if (op.field === 'name') {
|
|
382
|
+
if (op.value === null || op.value.trim().length === 0) {
|
|
383
|
+
throw new Error("set_field name: value must be a non-empty string");
|
|
384
|
+
}
|
|
385
|
+
next.name = op.value;
|
|
386
|
+
} else if (op.field === 'description') {
|
|
387
|
+
if (op.value === null) {
|
|
388
|
+
delete next.description;
|
|
389
|
+
} else {
|
|
390
|
+
next.description = op.value;
|
|
391
|
+
}
|
|
392
|
+
} else if (op.field === 'workdir') {
|
|
393
|
+
if (op.value === null || op.value.trim().length === 0) {
|
|
394
|
+
delete next.workdir;
|
|
395
|
+
} else {
|
|
396
|
+
next.workdir = op.value.trim();
|
|
397
|
+
}
|
|
398
|
+
} else if (op.field === 'color') {
|
|
399
|
+
if (op.value === null) {
|
|
400
|
+
delete next.color;
|
|
401
|
+
} else {
|
|
402
|
+
next.color = op.value;
|
|
403
|
+
}
|
|
404
|
+
} else if (op.field === 'expires') {
|
|
405
|
+
next.expires = op.value;
|
|
406
|
+
}
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
case 'add_path': {
|
|
410
|
+
const result = validatePathRef(op.ref, ctx.config);
|
|
411
|
+
if (!result.ok) throw new Error(`add_path '${op.ref}': ${result.error}`);
|
|
412
|
+
if (next.paths.some((p) => p.ref === op.ref)) {
|
|
413
|
+
throw new Error(`add_path: ref '${op.ref}' already in paths`);
|
|
414
|
+
}
|
|
415
|
+
next.paths.push({ ref: op.ref, ...(op.label ? { label: op.label } : {}) });
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
case 'remove_path': {
|
|
419
|
+
const idx = next.paths.findIndex((p) => p.ref === op.ref);
|
|
420
|
+
if (idx < 0) {
|
|
421
|
+
const known = next.paths.map((p) => p.ref).join(', ') || '(none)';
|
|
422
|
+
throw new Error(`remove_path: no path with ref '${op.ref}' to remove (available: ${known})`);
|
|
423
|
+
}
|
|
424
|
+
next.paths.splice(idx, 1);
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
case 'set_tags': {
|
|
428
|
+
// Replaces the full tags array — semantic equivalent to a set
|
|
429
|
+
// operation. Per-tag add/remove ops would be possible but the
|
|
430
|
+
// common use-case is "update the tag list to X" so a single
|
|
431
|
+
// replace covers it cleaner.
|
|
432
|
+
next.tags = [...op.tags];
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
case 'archive': {
|
|
436
|
+
next.archived = true;
|
|
437
|
+
next.archivedAt = nowIso();
|
|
438
|
+
if (op.reason !== undefined) next.archiveReason = op.reason;
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
case 'unarchive': {
|
|
442
|
+
next.archived = false;
|
|
443
|
+
delete next.archivedAt;
|
|
444
|
+
delete next.archiveReason;
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return next;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export const projectUpdate: ToolDefinition<z.infer<typeof UpdateInput>> = {
|
|
453
|
+
name: 'project_update',
|
|
454
|
+
toolset: 'projects',
|
|
455
|
+
description:
|
|
456
|
+
'Apply one or more mutations to a project transactionally. Each entry in `ops` is an ' +
|
|
457
|
+
'OBJECT with an `op` discriminator plus op-specific fields. All ops validate first, ' +
|
|
458
|
+
'then a single write happens; if any op fails, nothing is written.\n' +
|
|
459
|
+
'\n' +
|
|
460
|
+
'Example — add a path AND change the description in one call:\n' +
|
|
461
|
+
' { "slug": "heimkino", "ops": [\n' +
|
|
462
|
+
' { "op": "add_path", "ref": "~/code/foo", "label": "Sourcecode" },\n' +
|
|
463
|
+
' { "op": "set_field", "field": "description", "value": "Updated" }\n' +
|
|
464
|
+
' ] }\n' +
|
|
465
|
+
'\n' +
|
|
466
|
+
'Supported ops (each `op` value has its own required fields — see the input schema):\n' +
|
|
467
|
+
' - set_field { field: name|description|color|expires, value: string|null }\n' +
|
|
468
|
+
' value=null clears optional fields (cannot clear name).\n' +
|
|
469
|
+
' - add_path { ref: string, label?: string }\n' +
|
|
470
|
+
' `ref` is scheme-inferred: `https://…` / `~/abs` or `/abs` / `<resource>:/path`.\n' +
|
|
471
|
+
' - remove_path { ref: string } — removes by ref match.\n' +
|
|
472
|
+
' - set_tags { tags: string[] } — replaces the full tag array.\n' +
|
|
473
|
+
' - archive { reason?: string } — soft-delete.\n' +
|
|
474
|
+
' - unarchive { } — restore.\n' +
|
|
475
|
+
'\n' +
|
|
476
|
+
'Entity cannot be mutated (delete and recreate to move between entities). ' +
|
|
477
|
+
'Slug cannot be renamed in v1 (would break session links).',
|
|
478
|
+
inputSchema: UpdateInput,
|
|
479
|
+
jsonSchema: {
|
|
480
|
+
type: 'object',
|
|
481
|
+
properties: {
|
|
482
|
+
slug: { type: 'string' },
|
|
483
|
+
ops: {
|
|
484
|
+
type: 'array',
|
|
485
|
+
minItems: 1,
|
|
486
|
+
description:
|
|
487
|
+
'Array of UpdateOp objects. Each entry is an object — NOT a string. The shape ' +
|
|
488
|
+
'depends on the `op` discriminator; see the per-variant entries in items.oneOf.',
|
|
489
|
+
items: {
|
|
490
|
+
oneOf: [
|
|
491
|
+
{
|
|
492
|
+
type: 'object',
|
|
493
|
+
description: 'Replace a top-level frontmatter field. `value: null` clears optional fields (cannot clear name).',
|
|
494
|
+
properties: {
|
|
495
|
+
op: { const: 'set_field' },
|
|
496
|
+
field: { enum: ['name', 'description', 'color', 'expires', 'workdir'] },
|
|
497
|
+
value: { type: ['string', 'null'] },
|
|
498
|
+
},
|
|
499
|
+
required: ['op', 'field', 'value'],
|
|
500
|
+
additionalProperties: false,
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
type: 'object',
|
|
504
|
+
description: 'Append a pointer to the paths array. `ref` is scheme-inferred (URL / local / resource).',
|
|
505
|
+
properties: {
|
|
506
|
+
op: { const: 'add_path' },
|
|
507
|
+
ref: { type: 'string', description: 'https://… or ~/abs or /abs or <resource>:/path' },
|
|
508
|
+
label: { type: 'string' },
|
|
509
|
+
},
|
|
510
|
+
required: ['op', 'ref'],
|
|
511
|
+
additionalProperties: false,
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
type: 'object',
|
|
515
|
+
description: 'Remove a path by exact ref match.',
|
|
516
|
+
properties: {
|
|
517
|
+
op: { const: 'remove_path' },
|
|
518
|
+
ref: { type: 'string' },
|
|
519
|
+
},
|
|
520
|
+
required: ['op', 'ref'],
|
|
521
|
+
additionalProperties: false,
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
type: 'object',
|
|
525
|
+
description: 'Replace the entire tags array.',
|
|
526
|
+
properties: {
|
|
527
|
+
op: { const: 'set_tags' },
|
|
528
|
+
tags: { type: 'array', items: { type: 'string' } },
|
|
529
|
+
},
|
|
530
|
+
required: ['op', 'tags'],
|
|
531
|
+
additionalProperties: false,
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
type: 'object',
|
|
535
|
+
description: 'Soft-delete with optional reason; project_list hides archived by default.',
|
|
536
|
+
properties: {
|
|
537
|
+
op: { const: 'archive' },
|
|
538
|
+
reason: { type: 'string' },
|
|
539
|
+
},
|
|
540
|
+
required: ['op'],
|
|
541
|
+
additionalProperties: false,
|
|
542
|
+
},
|
|
543
|
+
{
|
|
544
|
+
type: 'object',
|
|
545
|
+
description: 'Restore an archived project.',
|
|
546
|
+
properties: {
|
|
547
|
+
op: { const: 'unarchive' },
|
|
548
|
+
},
|
|
549
|
+
required: ['op'],
|
|
550
|
+
additionalProperties: false,
|
|
551
|
+
},
|
|
552
|
+
],
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
},
|
|
556
|
+
required: ['slug', 'ops'],
|
|
557
|
+
additionalProperties: false,
|
|
558
|
+
},
|
|
559
|
+
available: (ctx) => Boolean(ctx.config.projects?.enabled),
|
|
560
|
+
async handler(input, ctx) {
|
|
561
|
+
ensureEnabled(ctx);
|
|
562
|
+
const current = await readProject(input.slug);
|
|
563
|
+
if (!current) {
|
|
564
|
+
throw new Error(`project '${input.slug}' does not exist`);
|
|
565
|
+
}
|
|
566
|
+
const next = applyOps(current, input.ops, ctx);
|
|
567
|
+
next.updated = nowIso();
|
|
568
|
+
await writeProject(next);
|
|
569
|
+
logger.info({
|
|
570
|
+
msg: 'project.updated',
|
|
571
|
+
slug: next.slug,
|
|
572
|
+
opCount: input.ops.length,
|
|
573
|
+
opTypes: input.ops.map((o) => o.op),
|
|
574
|
+
agent: ctx.agent,
|
|
575
|
+
session: ctx.session,
|
|
576
|
+
});
|
|
577
|
+
return { project: next };
|
|
578
|
+
},
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
// ─── project_focus ───────────────────────────────────────────────────
|
|
582
|
+
|
|
583
|
+
const FocusInput = z
|
|
584
|
+
.object({
|
|
585
|
+
slug: z
|
|
586
|
+
.string()
|
|
587
|
+
.regex(PROJECT_SLUG_RE)
|
|
588
|
+
.nullable()
|
|
589
|
+
.describe('Project slug to pin, or null to clear focus.'),
|
|
590
|
+
})
|
|
591
|
+
.strict();
|
|
592
|
+
|
|
593
|
+
export const projectFocus: ToolDefinition<z.infer<typeof FocusInput>> = {
|
|
594
|
+
name: 'project_focus',
|
|
595
|
+
toolset: 'projects',
|
|
596
|
+
description:
|
|
597
|
+
'Pin a project to the current session, or clear the current pin. When pinned, the project ' +
|
|
598
|
+
'name + pointer list lands in the system prompt tail for every subsequent turn of this ' +
|
|
599
|
+
'session, so the agent knows which paths matter. Pass `slug: null` (or omit handling) to ' +
|
|
600
|
+
'unpin and remove project context. Idempotent — re-pinning the same project is a noop.',
|
|
601
|
+
inputSchema: FocusInput,
|
|
602
|
+
jsonSchema: {
|
|
603
|
+
type: 'object',
|
|
604
|
+
properties: {
|
|
605
|
+
slug: { type: ['string', 'null'], description: 'Project slug to pin, or null to clear focus.' },
|
|
606
|
+
},
|
|
607
|
+
required: ['slug'],
|
|
608
|
+
additionalProperties: false,
|
|
609
|
+
},
|
|
610
|
+
available: (ctx) => Boolean(ctx.config.projects?.enabled),
|
|
611
|
+
async handler(input, ctx) {
|
|
612
|
+
ensureEnabled(ctx);
|
|
613
|
+
if (!ctx.session) {
|
|
614
|
+
throw new Error('project_focus requires a session context — no session id available');
|
|
615
|
+
}
|
|
616
|
+
const result = await focusProject({
|
|
617
|
+
agent: ctx.agent,
|
|
618
|
+
session: ctx.session,
|
|
619
|
+
slug: input.slug,
|
|
620
|
+
via: 'tool',
|
|
621
|
+
metaStore: sessionMetaStore,
|
|
622
|
+
});
|
|
623
|
+
return result;
|
|
624
|
+
},
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
// ─── bundle export ──────────────────────────────────────────────────
|
|
628
|
+
|
|
629
|
+
export function projectTools(): ToolDefinition[] {
|
|
630
|
+
return [
|
|
631
|
+
entityList,
|
|
632
|
+
projectList,
|
|
633
|
+
projectGet,
|
|
634
|
+
projectCreate,
|
|
635
|
+
projectUpdate,
|
|
636
|
+
projectFocus,
|
|
637
|
+
] as ToolDefinition[];
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// Re-export deleteProjectFile so admin / future tools can use it
|
|
641
|
+
// without reaching into the store module. Currently unused — kept for
|
|
642
|
+
// the eventual `project_purge` admin path.
|
|
643
|
+
export { deleteProjectFile };
|