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,149 @@
|
|
|
1
|
+
// Renders the per-agent `# Your team` block. Pure and deterministic:
|
|
2
|
+
// same team + same agent → byte-identical output, so the system prompt
|
|
3
|
+
// stays prefix-cache-stable until team.yaml actually changes.
|
|
4
|
+
//
|
|
5
|
+
// Lives in the SYSTEM PROMPT on purpose, never in a tool description:
|
|
6
|
+
// Claude Code measured that a mutable agent list inside the tool schema
|
|
7
|
+
// busts the whole tool cache (≈10 % of cache-creation tokens).
|
|
8
|
+
|
|
9
|
+
import type { ResolvedTeam, ResolvedTeamAgent } from './types.ts';
|
|
10
|
+
|
|
11
|
+
/** Soft cap for `somora team check` / GET /team/check — every agent
|
|
12
|
+
* carries its block in every turn. */
|
|
13
|
+
export const TEAM_BLOCK_SOFT_MAX_CHARS = 3000;
|
|
14
|
+
|
|
15
|
+
function joinPhrases(list: string[]): string {
|
|
16
|
+
return list.map((p) => p.replace(/\s+/g, ' ').trim()).filter(Boolean).join('; ');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function chartLines(team: ResolvedTeam, self: string): string[] {
|
|
20
|
+
const p = team.principal;
|
|
21
|
+
const head =
|
|
22
|
+
`${p.name} — ${p.title ?? 'Principal'} (human)` + (p.about ? `: ${p.about.replace(/\s+/g, ' ').trim()}` : '');
|
|
23
|
+
const lines: string[] = [head];
|
|
24
|
+
const walk = (parent: string, prefix: string): void => {
|
|
25
|
+
const kids = team.order.filter((n) => team.agents[n]!.reportsTo === parent);
|
|
26
|
+
kids.forEach((name, i) => {
|
|
27
|
+
const last = i === kids.length - 1;
|
|
28
|
+
const a = team.agents[name]!;
|
|
29
|
+
lines.push(
|
|
30
|
+
`${prefix}${last ? '└── ' : '├── '}${name} — ${a.title}` +
|
|
31
|
+
(a.active ? '' : ' (currently inactive)') +
|
|
32
|
+
(name === self ? ' ← you' : ''),
|
|
33
|
+
);
|
|
34
|
+
walk(name, `${prefix}${last ? ' ' : '│ '}`);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
walk('principal', '');
|
|
38
|
+
return lines;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** What every colleague is told about a builder (docs/builder.md). */
|
|
42
|
+
export const BUILDER_HANDOVER_HINT =
|
|
43
|
+
'Builder — hand over a COMPLETE order in one message (builder_dispatch: repository or project with its folder, ' +
|
|
44
|
+
'what to build, what done means, where the report goes) and wait for the report; no interim check-ins, no ' +
|
|
45
|
+
'corrections into running work — a correction is a new message into its session.';
|
|
46
|
+
|
|
47
|
+
function involveLine(a: ResolvedTeamAgent): string | null {
|
|
48
|
+
const parts: string[] = [];
|
|
49
|
+
if (a.kind === 'builder') parts.push(BUILDER_HANDOVER_HINT);
|
|
50
|
+
if (a.involveFor.length > 0) parts.push(joinPhrases(a.involveFor) + '.');
|
|
51
|
+
if (a.notFor.length > 0) parts.push(`Not for: ${joinPhrases(a.notFor)}.`);
|
|
52
|
+
if (a.notes) parts.push(a.notes.replace(/\s+/g, ' ').trim());
|
|
53
|
+
if (parts.length === 0) return null;
|
|
54
|
+
return `- ${a.name} (${a.title}): ${parts.join(' ')}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The short form a builder gets: who to consult, one line each, and the
|
|
59
|
+
* team rules. No org chart, no superior prose — a builder takes orders
|
|
60
|
+
* from whoever handed it the task and consults colleagues for their
|
|
61
|
+
* specialty (see src/server/builder-prompt.ts).
|
|
62
|
+
*/
|
|
63
|
+
export function renderTeamBlockCompact(team: ResolvedTeam, self: string): string | null {
|
|
64
|
+
const colleagues = team.order.filter((n) => n !== self && team.agents[n]!.active);
|
|
65
|
+
if (colleagues.length === 0 && team.rules.length === 0) return null;
|
|
66
|
+
const out: string[] = ['# Your team', '', `Principal (human): ${team.principal.name}${team.principal.title ? `, ${team.principal.title}` : ''}.`];
|
|
67
|
+
if (colleagues.length > 0) {
|
|
68
|
+
out.push(
|
|
69
|
+
'Colleagues you can consult with agent_ask — a question in their specialty, not a hand-off; the agent or person who gave you the task is your client:',
|
|
70
|
+
);
|
|
71
|
+
out.push(colleagues.map((n) => `${n} (${team.agents[n]!.title})`).join(', ') + '.');
|
|
72
|
+
}
|
|
73
|
+
if (team.rules.length > 0) {
|
|
74
|
+
out.push('', 'Rules:');
|
|
75
|
+
for (const r of team.rules) out.push(`- ${r}`);
|
|
76
|
+
}
|
|
77
|
+
return out.join('\n').trimEnd();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The block for `self`. Returns null only when the team is empty. An
|
|
82
|
+
* agent that exists but is not in the file still gets the full
|
|
83
|
+
* picture, plus a line saying it is not placed yet.
|
|
84
|
+
*/
|
|
85
|
+
export function renderTeamBlock(team: ResolvedTeam, self: string): string | null {
|
|
86
|
+
if (team.order.length === 0 && team.unlisted.length === 0) return null;
|
|
87
|
+
const me = team.agents[self];
|
|
88
|
+
const principal = team.principal.name;
|
|
89
|
+
const out: string[] = ['# Your team', '', 'Org chart (you are marked with ←):', ...chartLines(team, self)];
|
|
90
|
+
|
|
91
|
+
if (team.unlisted.length > 0) {
|
|
92
|
+
const list = team.unlisted.map((u) => (u.name === self ? `${u.name} (${u.title}) ← you` : `${u.name} (${u.title})`));
|
|
93
|
+
out.push(`Not in the org chart yet: ${list.join(', ')}.`);
|
|
94
|
+
for (const u of team.unlisted) {
|
|
95
|
+
if (u.kind === 'builder' && u.name !== self) out.push(`- ${u.name}: ${BUILDER_HANDOVER_HINT}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
out.push('');
|
|
99
|
+
|
|
100
|
+
if (me) {
|
|
101
|
+
if (me.reportsTo === 'principal') {
|
|
102
|
+
out.push(`Your superior: ${principal}, the principal — you report to them directly; their word is final.`);
|
|
103
|
+
} else {
|
|
104
|
+
out.push(
|
|
105
|
+
`Your superior: ${me.reportsTo} — escalate there first; ${me.reportsTo}'s briefings are authoritative ` +
|
|
106
|
+
`inside your lane. The principal (${principal}) has the final say over everyone.`,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (!me.active) {
|
|
110
|
+
out.push(
|
|
111
|
+
'You are currently marked inactive in the team — colleagues were told not to involve you. ' +
|
|
112
|
+
'You were addressed anyway, so work normally, but do not pull colleagues in unless asked.',
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
const tag = (n: string): string => (team.agents[n]!.active ? n : `${n} (inactive)`);
|
|
116
|
+
const peers = team.order.filter((n) => n !== self && team.agents[n]!.reportsTo === me.reportsTo);
|
|
117
|
+
out.push(`Your peers (same superior): ${peers.length > 0 ? peers.map(tag).join(', ') : 'none'}.`);
|
|
118
|
+
out.push(`Your reports: ${me.children.length > 0 ? me.children.map(tag).join(', ') : 'none'}.`);
|
|
119
|
+
} else {
|
|
120
|
+
out.push(
|
|
121
|
+
`You are not placed in the org chart yet — the operator maintains it in team.yaml. ` +
|
|
122
|
+
`Until then treat ${principal}, the principal, as your superior.`,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
out.push('');
|
|
126
|
+
|
|
127
|
+
const colleagues = team.order.filter((n) => n !== self && team.agents[n]!.active);
|
|
128
|
+
const inactive = team.order.filter((n) => n !== self && !team.agents[n]!.active);
|
|
129
|
+
if (colleagues.length > 0) {
|
|
130
|
+
out.push('Who to involve — via agent_ask; their reply comes back to your session:');
|
|
131
|
+
const plain: string[] = [];
|
|
132
|
+
for (const n of colleagues) {
|
|
133
|
+
const line = involveLine(team.agents[n]!);
|
|
134
|
+
if (line) out.push(line);
|
|
135
|
+
else plain.push(`${n} (${team.agents[n]!.title})`);
|
|
136
|
+
}
|
|
137
|
+
if (plain.length > 0) out.push(`- ${plain.join(', ')}.`);
|
|
138
|
+
}
|
|
139
|
+
if (inactive.length > 0) {
|
|
140
|
+
out.push(`Currently inactive — do not involve: ${inactive.join(', ')}. Go one level up instead.`);
|
|
141
|
+
}
|
|
142
|
+
if (colleagues.length > 0 || inactive.length > 0) out.push('');
|
|
143
|
+
|
|
144
|
+
if (team.rules.length > 0) {
|
|
145
|
+
out.push('Rules:');
|
|
146
|
+
for (const r of team.rules) out.push(`- ${r}`);
|
|
147
|
+
}
|
|
148
|
+
return out.join('\n').trimEnd();
|
|
149
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Validation + resolution of a parsed team file against the agents on
|
|
2
|
+
// disk. Pure — no I/O — so the CLI, the server and the tests share it.
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_TEAM_RULES,
|
|
6
|
+
TeamFileSchema,
|
|
7
|
+
type ResolvedTeam,
|
|
8
|
+
type ResolvedTeamAgent,
|
|
9
|
+
type TeamAgentInfo,
|
|
10
|
+
type TeamFile,
|
|
11
|
+
type TeamIssue,
|
|
12
|
+
} from './types.ts';
|
|
13
|
+
|
|
14
|
+
/** Parse + structural validation. Returns the file or the issues that
|
|
15
|
+
* make it unusable (schema errors, unknown reports_to, cycles). */
|
|
16
|
+
export function parseTeamFile(raw: unknown): { file: TeamFile; issues: [] } | { file: null; issues: TeamIssue[] } {
|
|
17
|
+
const parsed = TeamFileSchema.safeParse(raw);
|
|
18
|
+
if (!parsed.success) {
|
|
19
|
+
return {
|
|
20
|
+
file: null,
|
|
21
|
+
issues: parsed.error.issues.map((i) => ({ path: i.path.join('.') || '(root)', message: i.message })),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const file = parsed.data;
|
|
25
|
+
const issues: TeamIssue[] = [];
|
|
26
|
+
const names = Object.keys(file.agents);
|
|
27
|
+
for (const name of names) {
|
|
28
|
+
const target = file.agents[name]!.reports_to;
|
|
29
|
+
if (target === name) {
|
|
30
|
+
issues.push({ path: `agents.${name}.reports_to`, message: 'an agent cannot report to itself' });
|
|
31
|
+
} else if (target !== 'principal' && !(target in file.agents)) {
|
|
32
|
+
issues.push({
|
|
33
|
+
path: `agents.${name}.reports_to`,
|
|
34
|
+
message: `'${target}' is neither 'principal' nor an agent listed in this file`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (issues.length > 0) return { file: null, issues };
|
|
39
|
+
// Cycle check: every agent must reach the principal.
|
|
40
|
+
for (const name of names) {
|
|
41
|
+
const seen = new Set<string>([name]);
|
|
42
|
+
let cur = file.agents[name]!.reports_to;
|
|
43
|
+
while (cur !== 'principal') {
|
|
44
|
+
if (seen.has(cur)) {
|
|
45
|
+
issues.push({ path: `agents.${name}.reports_to`, message: `reporting cycle: ${[...seen, cur].join(' → ')}` });
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
seen.add(cur);
|
|
49
|
+
cur = file.agents[cur]!.reports_to;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (issues.length > 0) return { file: null, issues };
|
|
53
|
+
return { file, issues: [] };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Title fallback chain: file `title` → frontmatter `role` → `description` → the name. */
|
|
57
|
+
function titleFor(name: string, fileTitle: string | undefined, info: TeamAgentInfo | undefined): string {
|
|
58
|
+
return fileTitle ?? info?.role ?? info?.description ?? name;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Combine a valid file with the agents on disk. Agents in the file but
|
|
62
|
+
* not on disk are dropped (with a warning) — their children re-attach
|
|
63
|
+
* to the nearest existing ancestor so the tree stays connected. */
|
|
64
|
+
export function resolveTeam(file: TeamFile, onDisk: TeamAgentInfo[]): ResolvedTeam {
|
|
65
|
+
const infoByName = new Map(onDisk.map((a) => [a.name, a]));
|
|
66
|
+
const warnings: string[] = [];
|
|
67
|
+
const missing = Object.keys(file.agents).filter((n) => !infoByName.has(n));
|
|
68
|
+
for (const m of missing) warnings.push(`agents.${m}: no such agent directory — skipped`);
|
|
69
|
+
|
|
70
|
+
const existing = Object.keys(file.agents).filter((n) => infoByName.has(n));
|
|
71
|
+
const effectiveParent = (name: string): string => {
|
|
72
|
+
let cur = file.agents[name]!.reports_to;
|
|
73
|
+
while (cur !== 'principal' && !infoByName.has(cur)) cur = file.agents[cur]!.reports_to;
|
|
74
|
+
return cur;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const agents: Record<string, ResolvedTeamAgent> = {};
|
|
78
|
+
for (const name of existing) {
|
|
79
|
+
const a = file.agents[name]!;
|
|
80
|
+
agents[name] = {
|
|
81
|
+
name,
|
|
82
|
+
title: titleFor(name, a.title, infoByName.get(name)),
|
|
83
|
+
...(infoByName.get(name)?.kind ? { kind: infoByName.get(name)!.kind } : {}),
|
|
84
|
+
reportsTo: effectiveParent(name),
|
|
85
|
+
involveFor: a.involve_for ?? [],
|
|
86
|
+
notFor: a.not_for ?? [],
|
|
87
|
+
...(a.notes ? { notes: a.notes } : {}),
|
|
88
|
+
active: a.active !== false,
|
|
89
|
+
children: [],
|
|
90
|
+
depth: 0,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
for (const name of existing) {
|
|
94
|
+
const parent = agents[name]!.reportsTo;
|
|
95
|
+
if (parent !== 'principal') agents[parent]!.children.push(name);
|
|
96
|
+
}
|
|
97
|
+
const order: string[] = [];
|
|
98
|
+
const walk = (parent: string, depth: number): void => {
|
|
99
|
+
const kids = existing.filter((n) => agents[n]!.reportsTo === parent);
|
|
100
|
+
for (const k of kids) {
|
|
101
|
+
agents[k]!.depth = depth;
|
|
102
|
+
order.push(k);
|
|
103
|
+
walk(k, depth + 1);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
walk('principal', 1);
|
|
107
|
+
|
|
108
|
+
const unlisted = onDisk
|
|
109
|
+
.filter((a) => !(a.name in file.agents))
|
|
110
|
+
.map((a) => ({ name: a.name, title: titleFor(a.name, undefined, a), ...(a.kind ? { kind: a.kind } : {}) }));
|
|
111
|
+
for (const u of unlisted) warnings.push(`${u.name} exists but is not in team.yaml — shown under "Not in the org chart"`);
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
principal: file.principal,
|
|
115
|
+
rules: file.rules ?? [...DEFAULT_TEAM_RULES],
|
|
116
|
+
agents,
|
|
117
|
+
order,
|
|
118
|
+
unlisted,
|
|
119
|
+
missing,
|
|
120
|
+
warnings,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// team.yaml on disk → ResolvedTeam, cached by file mtime and by the
|
|
2
|
+
// agent roster. No restart needed: the next turn after a save sees the
|
|
3
|
+
// change. An invalid file keeps the last valid team in force (or the
|
|
4
|
+
// feature off when there never was one) and logs once per mtime.
|
|
5
|
+
|
|
6
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
7
|
+
import { homedir } from 'node:os';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { load as parseYaml } from 'js-yaml';
|
|
10
|
+
import { logger } from '../server/logger.ts';
|
|
11
|
+
import { listAgents } from '../persona/loader.ts';
|
|
12
|
+
import { parseTeamFile, resolveTeam } from './resolve.ts';
|
|
13
|
+
import { renderTeamBlock, renderTeamBlockCompact } from './render.ts';
|
|
14
|
+
import { TEAM_FILE_NAME, type ResolvedTeam, type TeamAgentInfo, type TeamFile, type TeamIssue } from './types.ts';
|
|
15
|
+
|
|
16
|
+
const SOMORA_HOME = process.env.SOMORA_HOME ?? join(homedir(), '.somora');
|
|
17
|
+
|
|
18
|
+
export function teamFilePath(): string {
|
|
19
|
+
return join(SOMORA_HOME, TEAM_FILE_NAME);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface TeamLoad {
|
|
23
|
+
/** null = no file, or the file is invalid (see issues). */
|
|
24
|
+
file: TeamFile | null;
|
|
25
|
+
exists: boolean;
|
|
26
|
+
issues: TeamIssue[];
|
|
27
|
+
mtimeMs: number | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Read + parse + validate. Never throws. */
|
|
31
|
+
export async function loadTeamFile(): Promise<TeamLoad> {
|
|
32
|
+
const path = teamFilePath();
|
|
33
|
+
let raw: string;
|
|
34
|
+
let mtimeMs: number;
|
|
35
|
+
try {
|
|
36
|
+
const st = await stat(path);
|
|
37
|
+
mtimeMs = st.mtimeMs;
|
|
38
|
+
raw = await readFile(path, 'utf8');
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if ((err as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
41
|
+
return { file: null, exists: false, issues: [], mtimeMs: null };
|
|
42
|
+
}
|
|
43
|
+
return { file: null, exists: true, issues: [{ path: '(file)', message: String(err) }], mtimeMs: null };
|
|
44
|
+
}
|
|
45
|
+
let doc: unknown;
|
|
46
|
+
try {
|
|
47
|
+
doc = parseYaml(raw);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
return { file: null, exists: true, issues: [{ path: '(yaml)', message: (err as Error).message }], mtimeMs };
|
|
50
|
+
}
|
|
51
|
+
const parsed = parseTeamFile(doc ?? {});
|
|
52
|
+
return { file: parsed.file, exists: true, issues: parsed.issues, mtimeMs };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ── cache ────────────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
const ROSTER_TTL_MS = 30_000;
|
|
58
|
+
|
|
59
|
+
let cached: { mtimeMs: number; rosterKey: string; team: ResolvedTeam } | null = null;
|
|
60
|
+
let lastValidTeam: ResolvedTeam | null = null;
|
|
61
|
+
let rosterCache: { at: number; agents: TeamAgentInfo[]; key: string } | null = null;
|
|
62
|
+
let warnedForMtime: number | null = null;
|
|
63
|
+
|
|
64
|
+
async function roster(): Promise<{ agents: TeamAgentInfo[]; key: string }> {
|
|
65
|
+
const now = Date.now();
|
|
66
|
+
if (rosterCache && now - rosterCache.at < ROSTER_TTL_MS) return rosterCache;
|
|
67
|
+
const list = await listAgents();
|
|
68
|
+
const agents: TeamAgentInfo[] = list.map((a) => ({ name: a.name, role: a.role, description: a.description, kind: a.kind }));
|
|
69
|
+
const key = agents.map((a) => `${a.name}:${a.role ?? ''}:${a.kind ?? ''}:${a.description}`).join('|');
|
|
70
|
+
rosterCache = { at: now, agents, key };
|
|
71
|
+
return rosterCache;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Drop caches — used by tests and after a PUT. */
|
|
75
|
+
export function resetTeamCache(): void {
|
|
76
|
+
cached = null;
|
|
77
|
+
rosterCache = null;
|
|
78
|
+
warnedForMtime = null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The team in force right now, or null when the feature is off
|
|
83
|
+
* (no file, or an invalid file with no earlier valid load).
|
|
84
|
+
*/
|
|
85
|
+
export async function getResolvedTeam(): Promise<ResolvedTeam | null> {
|
|
86
|
+
const load = await loadTeamFile();
|
|
87
|
+
if (!load.exists) {
|
|
88
|
+
cached = null;
|
|
89
|
+
lastValidTeam = null;
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
if (!load.file) {
|
|
93
|
+
if (warnedForMtime !== load.mtimeMs) {
|
|
94
|
+
warnedForMtime = load.mtimeMs;
|
|
95
|
+
logger.warn({
|
|
96
|
+
msg: 'team.invalid',
|
|
97
|
+
path: teamFilePath(),
|
|
98
|
+
issues: load.issues,
|
|
99
|
+
hint: lastValidTeam ? 'keeping the last valid team' : 'team block disabled until the file is fixed',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return lastValidTeam;
|
|
103
|
+
}
|
|
104
|
+
const r = await roster();
|
|
105
|
+
if (cached && cached.mtimeMs === load.mtimeMs && cached.rosterKey === r.key) return cached.team;
|
|
106
|
+
const team = resolveTeam(load.file, r.agents);
|
|
107
|
+
cached = { mtimeMs: load.mtimeMs ?? 0, rosterKey: r.key, team };
|
|
108
|
+
lastValidTeam = team;
|
|
109
|
+
logger.info({
|
|
110
|
+
msg: 'team.loaded',
|
|
111
|
+
agents: team.order.length,
|
|
112
|
+
unlisted: team.unlisted.map((u) => u.name),
|
|
113
|
+
missing: team.missing,
|
|
114
|
+
warnings: team.warnings.length,
|
|
115
|
+
});
|
|
116
|
+
return team;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The `# Your team` block for one agent, or '' when the feature is off. */
|
|
120
|
+
export async function buildTeamBlock(agent: string, variant: 'full' | 'compact' = 'full'): Promise<string> {
|
|
121
|
+
const team = await getResolvedTeam();
|
|
122
|
+
if (!team) return '';
|
|
123
|
+
return (variant === 'compact' ? renderTeamBlockCompact(team, agent) : renderTeamBlock(team, agent)) ?? '';
|
|
124
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Team — the organisation of an install's agents as ONE source of truth.
|
|
2
|
+
//
|
|
3
|
+
// `~/.somora/team.yaml` says who reports to whom, what each agent is
|
|
4
|
+
// for (and not for), and which rules hold across the team. somora
|
|
5
|
+
// renders that into a per-agent `# Your team` block in the system
|
|
6
|
+
// prompt (src/team/render.ts) so every agent knows the same org chart
|
|
7
|
+
// from its own seat — instead of six hand-copied "my place in the team"
|
|
8
|
+
// sections that drift (design: private/team-design.md, 2026-09-07).
|
|
9
|
+
//
|
|
10
|
+
// Operator-owned: agents read the block, they never edit the file.
|
|
11
|
+
// No file → feature off, prompt unchanged.
|
|
12
|
+
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
|
|
15
|
+
export const TEAM_FILE_NAME = 'team.yaml';
|
|
16
|
+
|
|
17
|
+
/** Agent directory names, same rule as the persona loader. */
|
|
18
|
+
const AGENT_NAME = /^[a-z0-9][a-z0-9_-]{0,63}$/i;
|
|
19
|
+
|
|
20
|
+
/** Rules rendered when the file has no `rules:` key. `somora team init`
|
|
21
|
+
* writes them out explicitly so the operator sees and can edit them. */
|
|
22
|
+
export const DEFAULT_TEAM_RULES: readonly string[] = [
|
|
23
|
+
"The principal's word is final. In any conflict with an agent, the principal wins.",
|
|
24
|
+
'Briefings from your direct superior are authoritative inside your lane.',
|
|
25
|
+
"Do not take over a colleague's lane unless the principal or your superior delegates it explicitly.",
|
|
26
|
+
'A colleague only knows what you write to them — give them the goal, the context and what a good answer looks like.',
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const Phrase = z.string().trim().min(1).max(200);
|
|
30
|
+
|
|
31
|
+
export const TeamAgentSchema = z
|
|
32
|
+
.object({
|
|
33
|
+
/** `principal` or the name of another agent listed in the file. */
|
|
34
|
+
reports_to: z.string().trim().min(1),
|
|
35
|
+
/** Display title; defaults to `role` from AGENTS.md frontmatter. */
|
|
36
|
+
title: z.string().trim().min(1).max(80).optional(),
|
|
37
|
+
/** false = temporarily out of the team: stays in the chart (greyed),
|
|
38
|
+
* colleagues are told not to involve it. Default true. */
|
|
39
|
+
active: z.boolean().optional(),
|
|
40
|
+
/** Short trigger phrases: "library docs and framework comparisons". */
|
|
41
|
+
involve_for: z.array(Phrase).max(20).optional(),
|
|
42
|
+
/** Short phrases naming what NOT to bring to this agent. */
|
|
43
|
+
not_for: z.array(Phrase).max(20).optional(),
|
|
44
|
+
/** Free text for nuance; rendered after the phrases. */
|
|
45
|
+
notes: z.string().trim().max(600).optional(),
|
|
46
|
+
})
|
|
47
|
+
.strict();
|
|
48
|
+
|
|
49
|
+
export const TeamPrincipalSchema = z
|
|
50
|
+
.object({
|
|
51
|
+
name: z.string().trim().min(1).max(80),
|
|
52
|
+
title: z.string().trim().min(1).max(80).optional(),
|
|
53
|
+
about: z.string().trim().max(600).optional(),
|
|
54
|
+
})
|
|
55
|
+
.strict();
|
|
56
|
+
|
|
57
|
+
export const TeamFileSchema = z
|
|
58
|
+
.object({
|
|
59
|
+
version: z.literal(1),
|
|
60
|
+
principal: TeamPrincipalSchema,
|
|
61
|
+
rules: z.array(z.string().trim().min(1).max(300)).max(20).optional(),
|
|
62
|
+
agents: z.record(z.string().regex(AGENT_NAME, 'invalid agent name'), TeamAgentSchema),
|
|
63
|
+
})
|
|
64
|
+
.strict();
|
|
65
|
+
|
|
66
|
+
export type TeamFile = z.infer<typeof TeamFileSchema>;
|
|
67
|
+
export type TeamAgent = z.infer<typeof TeamAgentSchema>;
|
|
68
|
+
export type TeamPrincipal = z.infer<typeof TeamPrincipalSchema>;
|
|
69
|
+
|
|
70
|
+
/** What the renderer needs to know about an agent on disk. */
|
|
71
|
+
export interface TeamAgentInfo {
|
|
72
|
+
name: string;
|
|
73
|
+
role?: string | undefined;
|
|
74
|
+
description?: string | undefined;
|
|
75
|
+
/** agent.yaml `kind` — a builder is handed complete orders, not consulted. */
|
|
76
|
+
kind?: 'chat' | 'builder' | undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface ResolvedTeamAgent {
|
|
80
|
+
name: string;
|
|
81
|
+
title: string;
|
|
82
|
+
kind?: 'chat' | 'builder' | undefined;
|
|
83
|
+
/** 'principal' or an agent name. */
|
|
84
|
+
reportsTo: string;
|
|
85
|
+
involveFor: string[];
|
|
86
|
+
notFor: string[];
|
|
87
|
+
notes?: string;
|
|
88
|
+
active: boolean;
|
|
89
|
+
/** Direct reports, in file order. */
|
|
90
|
+
children: string[];
|
|
91
|
+
/** 1 = reports to the principal. */
|
|
92
|
+
depth: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface ResolvedTeam {
|
|
96
|
+
principal: TeamPrincipal;
|
|
97
|
+
rules: string[];
|
|
98
|
+
agents: Record<string, ResolvedTeamAgent>;
|
|
99
|
+
/** Pre-order walk of the tree from the principal — the rendering order. */
|
|
100
|
+
order: string[];
|
|
101
|
+
/** Agents that exist on disk but are not in the file. */
|
|
102
|
+
unlisted: Array<{ name: string; title: string; kind?: 'chat' | 'builder' | undefined }>;
|
|
103
|
+
/** Agents in the file that do not exist on disk (skipped). */
|
|
104
|
+
missing: string[];
|
|
105
|
+
warnings: string[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface TeamIssue {
|
|
109
|
+
path: string;
|
|
110
|
+
message: string;
|
|
111
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Writing team.yaml: the web Team window (PUT /team) and the bootstrap
|
|
2
|
+
// (POST /team/init, `somora team init`) go through here. Atomic
|
|
3
|
+
// (tmp + rename), keeps the last five versions as `team.yaml.bak-<ts>`,
|
|
4
|
+
// and drops the read cache so the next turn sees the new file.
|
|
5
|
+
|
|
6
|
+
import { existsSync, readdirSync, unlinkSync } from 'node:fs';
|
|
7
|
+
import { copyFile, rename, writeFile } from 'node:fs/promises';
|
|
8
|
+
import { dirname, join } from 'node:path';
|
|
9
|
+
import { dump as dumpYaml } from 'js-yaml';
|
|
10
|
+
import { resetTeamCache, teamFilePath } from './store.ts';
|
|
11
|
+
import { DEFAULT_TEAM_RULES, TEAM_FILE_NAME, type TeamAgentInfo, type TeamFile } from './types.ts';
|
|
12
|
+
|
|
13
|
+
const KEEP_BACKUPS = 5;
|
|
14
|
+
|
|
15
|
+
const HEADER =
|
|
16
|
+
'# somora team — who is who, who reports to whom, who to involve for what.\n' +
|
|
17
|
+
'# Rendered into every agent\'s system prompt as "# Your team" (see docs/team.md).\n' +
|
|
18
|
+
'# Edit by hand or in the web Team window; agents read it, they never write it.\n';
|
|
19
|
+
|
|
20
|
+
/** Serialise a validated document. Keys in a stable, readable order. */
|
|
21
|
+
export function teamFileToYaml(file: TeamFile): string {
|
|
22
|
+
const ordered = {
|
|
23
|
+
version: file.version,
|
|
24
|
+
principal: file.principal,
|
|
25
|
+
...(file.rules ? { rules: file.rules } : {}),
|
|
26
|
+
agents: Object.fromEntries(
|
|
27
|
+
Object.entries(file.agents).map(([name, a]) => [
|
|
28
|
+
name,
|
|
29
|
+
{
|
|
30
|
+
reports_to: a.reports_to,
|
|
31
|
+
...(a.title ? { title: a.title } : {}),
|
|
32
|
+
...(a.active === false ? { active: false } : {}),
|
|
33
|
+
...(a.involve_for && a.involve_for.length > 0 ? { involve_for: a.involve_for } : {}),
|
|
34
|
+
...(a.not_for && a.not_for.length > 0 ? { not_for: a.not_for } : {}),
|
|
35
|
+
...(a.notes ? { notes: a.notes } : {}),
|
|
36
|
+
},
|
|
37
|
+
]),
|
|
38
|
+
),
|
|
39
|
+
};
|
|
40
|
+
return HEADER + dumpYaml(ordered, { lineWidth: 100, noRefs: true, quotingType: '"' });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ts(): string {
|
|
44
|
+
return new Date().toISOString().replace(/[-:]/g, '').replace(/\..+$/, '').replace('T', '-');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function rotateBackups(dir: string): void {
|
|
48
|
+
const baks = readdirSync(dir)
|
|
49
|
+
.filter((f) => f.startsWith(`${TEAM_FILE_NAME}.bak-`))
|
|
50
|
+
.sort();
|
|
51
|
+
while (baks.length > KEEP_BACKUPS) {
|
|
52
|
+
const victim = baks.shift()!;
|
|
53
|
+
try {
|
|
54
|
+
unlinkSync(join(dir, victim));
|
|
55
|
+
} catch {
|
|
56
|
+
/* best effort */
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Write the file atomically; the previous version becomes a backup. */
|
|
62
|
+
export async function writeTeamFile(file: TeamFile): Promise<{ path: string; backup: string | null }> {
|
|
63
|
+
const path = teamFilePath();
|
|
64
|
+
const dir = dirname(path);
|
|
65
|
+
let backup: string | null = null;
|
|
66
|
+
if (existsSync(path)) {
|
|
67
|
+
backup = `${path}.bak-${ts()}`;
|
|
68
|
+
await copyFile(path, backup);
|
|
69
|
+
rotateBackups(dir);
|
|
70
|
+
}
|
|
71
|
+
const tmp = `${path}.tmp-${process.pid}`;
|
|
72
|
+
await writeFile(tmp, teamFileToYaml(file), 'utf8');
|
|
73
|
+
await rename(tmp, path);
|
|
74
|
+
resetTeamCache();
|
|
75
|
+
return { path, backup };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A first document: every agent under the principal, titles from the
|
|
79
|
+
* frontmatter, the default rules spelled out so the operator can edit
|
|
80
|
+
* them. Shared by `somora team init` and POST /team/init. */
|
|
81
|
+
export function initialTeamFile(agents: TeamAgentInfo[], principalName: string): TeamFile {
|
|
82
|
+
const file: TeamFile = {
|
|
83
|
+
version: 1,
|
|
84
|
+
principal: { name: principalName, title: 'Principal' },
|
|
85
|
+
rules: [...DEFAULT_TEAM_RULES],
|
|
86
|
+
agents: {},
|
|
87
|
+
};
|
|
88
|
+
for (const a of agents) {
|
|
89
|
+
file.agents[a.name] = {
|
|
90
|
+
reports_to: 'principal',
|
|
91
|
+
...(a.role ? { title: a.role } : {}),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return file;
|
|
95
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// A home of its own, or nothing. Import FIRST in any test that writes
|
|
2
|
+
// into SOMORA_HOME.
|
|
3
|
+
//
|
|
4
|
+
// Why this exists, plainly: on 2026-09-12 a test of mine wrote fixture
|
|
5
|
+
// personas for "hans" and "lisa" into the configured home. Run through
|
|
6
|
+
// scripts/run-tests.mjs that is a throwaway directory and harmless. Run
|
|
7
|
+
// straight with `npx tsx src/…/x.test.mts` — which is what the header
|
|
8
|
+
// of every test file invites you to do — SOMORA_HOME is unset, the
|
|
9
|
+
// default is the operator's real `~/.somora`, and two live agents lost
|
|
10
|
+
// their persona and their agent.yaml. They were restored from backups;
|
|
11
|
+
// the voice block, added the day before, was younger than the newest
|
|
12
|
+
// backup and had to be reconstructed by hand.
|
|
13
|
+
//
|
|
14
|
+
// The lesson is not "remember to set the variable". It is that a test
|
|
15
|
+
// must not be able to reach the real installation at all. So:
|
|
16
|
+
//
|
|
17
|
+
// - no SOMORA_HOME → a temp one is created and used
|
|
18
|
+
// - SOMORA_HOME already set → trusted, unless it IS the real home
|
|
19
|
+
// - SOMORA_HOME = ~/.somora → refuse to run, loudly
|
|
20
|
+
//
|
|
21
|
+
// Ordering is load-bearing. `src/server/logger.ts` resolves the home and
|
|
22
|
+
// opens its log file at import time, and anything that imports it
|
|
23
|
+
// inherits that decision. ESM evaluates imports in source order, so this
|
|
24
|
+
// line has to come before every other src import — and modules that read
|
|
25
|
+
// the home at load time have to be pulled in dynamically, after it.
|
|
26
|
+
import { mkdtempSync } from 'node:fs';
|
|
27
|
+
import { homedir, tmpdir } from 'node:os';
|
|
28
|
+
import { join, resolve } from 'node:path';
|
|
29
|
+
|
|
30
|
+
const realHome = join(homedir(), '.somora');
|
|
31
|
+
const configured = process.env.SOMORA_HOME;
|
|
32
|
+
|
|
33
|
+
if (configured && resolve(configured) === realHome) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`refusing to run: SOMORA_HOME points at the live installation (${realHome}). ` +
|
|
36
|
+
'Tests write fixtures into it. Unset the variable and a throwaway home is made for you.',
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!configured) {
|
|
41
|
+
const home = mkdtempSync(join(tmpdir(), 'somora-test-'));
|
|
42
|
+
process.env.SOMORA_HOME = home;
|
|
43
|
+
process.env.CLAUDE_CONFIG_DIR = join(home, 'claude-home');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const ISOLATED_HOME = process.env.SOMORA_HOME!;
|