elanous 0.2.12 → 0.2.13
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/apps/pwa/out/404/index.html +1 -1
- package/apps/pwa/out/404.html +1 -1
- package/apps/pwa/out/_next/static/chunks/{1394-ee3795b112907122.js → 1394-931c9827067b2276.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/{3992-2e522a8ac5f2afde.js → 3992-fe5c06d6b31f8b25.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/5250-c78ca295585bbf95.js +1 -0
- package/apps/pwa/out/_next/static/chunks/6511-ff8360be3d65aaa4.js +1 -0
- package/apps/pwa/out/_next/static/chunks/6588-ba380869b67c4fa7.js +1 -0
- package/apps/pwa/out/_next/static/chunks/{7758-0b018a9e4fc56200.js → 7758-85c2b53f731da024.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/{8605-0259994816604c49.js → 8605-9da4678f8a310d18.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/9906-e7b8b5310a169dfe.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/approvals/{page-cb169620945d1952.js → page-e5b4e1b256f41076.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/autopilot/{page-cefe8169e36cf62a.js → page-e49b9b76c565a0b1.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/board/page-b4f032c893b21cc9.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/botlab/page-f14987d5850a31e0.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/bots/page-b433308aad13ceb6.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/chat/{page-813c4a52c9d05ca8.js → page-4c1dbb21861beab2.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/consult/{page-4731f2c215358937.js → page-c85b816e3b269dbb.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/control/{page-a022b257950f39e6.js → page-f6bc66b919b2ea7d.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/design-check/{page-a2ffc717e04b8b0a.js → page-60603c1e056c9b25.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/editor/{page-b59ee4e70fc18fcf.js → page-a0ea8f5a2341ee6b.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/exec/page-45c5bf04b4a605e6.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/field/{page-c172dabd796eb7a3.js → page-36c6c4183353ac9e.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/inside/{page-1efd0cb9e0ed9d13.js → page-cb2eb0fd809980da.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/intake/{page-d5dc7ff69a37b4cf.js → page-31012264da8a341f.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/layout-50309aeb0bdd554a.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/live/page-bc00e964e855f4df.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/market/{page-dfca9b7d2de0b135.js → page-0696ee3fac9fe56c.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/missions/[id]/{page-793fa536b3a6ef37.js → page-66c27608f651b866.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/morning/{page-6dd3bfbbde2a5c2c.js → page-6ddd2109b7fc3a80.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/not-found-4e50b7298c1f69a5.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/observatory/{page-77447356baad75d2.js → page-7a2bf830038a2264.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/ops/checklist/page-1f327f18694fabca.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/ops/release/page-e5cef2fe6e4028df.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/ops/seats/page-cf596128d2b420ba.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/outputs/{page-6d604227e1664b71.js → page-f672536f14f0969f.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/page-b52365662232db89.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/reflection/{page-4048543b4b7ad5e0.js → page-e7a6c80f288b1948.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/scheduler/{page-4c3a3126abed551a.js → page-29a709616df9b050.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/sessions/{page-64b0aecb1ca75e75.js → page-fee842d7c2151129.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/settings/devices/page-78b40a344ed22f24.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/settings/page-75d199f448171014.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/setup/done/page-a011dd5b0bff29c5.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/setup/{page-9547b5cec7cf76bf.js → page-d92e32d51ab5157e.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/share/page-5f21aed6932ef375.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/showroom/page-1e1a53946804debf.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/tasks/{page-2cddeb9e2aeedc55.js → page-a1833cd43d832601.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/term/{page-e297866051595d81.js → page-63d14a4d8fe1e1c1.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/today/{page-baba2e047872fb0f.js → page-2a511d320f762e06.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/trace/{page-e895da4ec9cac345.js → page-1c3e03f88dac1e21.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/vault/page-c4d5289c2ea97a89.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/workflows/chat-ui/page-b91f8952deaeaf27.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/workflows/page-71b43a2588489987.js +1 -0
- package/apps/pwa/out/_next/static/chunks/app/workspace/{page-2e9e2fb01c9da1c9.js → page-2b256feed331546f.js} +1 -1
- package/apps/pwa/out/_next/static/chunks/app/worktrees/{page-d62ceb13411ebba4.js → page-505bb96d69a8622c.js} +1 -1
- package/apps/pwa/out/approvals/index.html +1 -1
- package/apps/pwa/out/approvals/index.txt +13 -13
- package/apps/pwa/out/autopilot/index.html +1 -1
- package/apps/pwa/out/autopilot/index.txt +13 -13
- package/apps/pwa/out/board/index.html +1 -1
- package/apps/pwa/out/board/index.txt +13 -13
- package/apps/pwa/out/botlab/index.html +1 -1
- package/apps/pwa/out/botlab/index.txt +13 -13
- package/apps/pwa/out/bots/index.html +1 -1
- package/apps/pwa/out/bots/index.txt +13 -13
- package/apps/pwa/out/chat/index.html +1 -1
- package/apps/pwa/out/chat/index.txt +13 -13
- package/apps/pwa/out/consult/index.html +1 -1
- package/apps/pwa/out/consult/index.txt +13 -13
- package/apps/pwa/out/control/index.html +1 -1
- package/apps/pwa/out/control/index.txt +13 -13
- package/apps/pwa/out/design-check/index.html +1 -1
- package/apps/pwa/out/design-check/index.txt +13 -13
- package/apps/pwa/out/editor/index.html +1 -1
- package/apps/pwa/out/editor/index.txt +13 -13
- package/apps/pwa/out/exec/index.html +1 -1
- package/apps/pwa/out/exec/index.txt +13 -13
- package/apps/pwa/out/field/index.html +1 -1
- package/apps/pwa/out/field/index.txt +13 -13
- package/apps/pwa/out/healthz +1 -1
- package/apps/pwa/out/index.html +1 -1
- package/apps/pwa/out/index.txt +13 -13
- package/apps/pwa/out/inside/index.html +1 -1
- package/apps/pwa/out/inside/index.txt +13 -13
- package/apps/pwa/out/intake/index.html +1 -1
- package/apps/pwa/out/intake/index.txt +13 -13
- package/apps/pwa/out/live/index.html +1 -1
- package/apps/pwa/out/live/index.txt +13 -13
- package/apps/pwa/out/market/index.html +1 -1
- package/apps/pwa/out/market/index.txt +13 -13
- package/apps/pwa/out/missions/placeholder/index.html +1 -1
- package/apps/pwa/out/missions/placeholder/index.txt +13 -13
- package/apps/pwa/out/morning/index.html +1 -1
- package/apps/pwa/out/morning/index.txt +13 -13
- package/apps/pwa/out/observatory/index.html +1 -1
- package/apps/pwa/out/observatory/index.txt +13 -13
- package/apps/pwa/out/ops/checklist/index.html +1 -1
- package/apps/pwa/out/ops/checklist/index.txt +13 -13
- package/apps/pwa/out/ops/release/index.html +1 -1
- package/apps/pwa/out/ops/release/index.txt +13 -13
- package/apps/pwa/out/ops/seats/index.html +1 -1
- package/apps/pwa/out/ops/seats/index.txt +13 -13
- package/apps/pwa/out/outputs/index.html +1 -1
- package/apps/pwa/out/outputs/index.txt +13 -13
- package/apps/pwa/out/reflection/index.html +1 -1
- package/apps/pwa/out/reflection/index.txt +14 -14
- package/apps/pwa/out/scheduler/index.html +1 -1
- package/apps/pwa/out/scheduler/index.txt +13 -13
- package/apps/pwa/out/sessions/index.html +1 -1
- package/apps/pwa/out/sessions/index.txt +13 -13
- package/apps/pwa/out/settings/devices/index.html +1 -1
- package/apps/pwa/out/settings/devices/index.txt +13 -13
- package/apps/pwa/out/settings/index.html +1 -1
- package/apps/pwa/out/settings/index.txt +13 -13
- package/apps/pwa/out/setup/done/index.html +1 -1
- package/apps/pwa/out/setup/done/index.txt +13 -13
- package/apps/pwa/out/setup/index.html +1 -1
- package/apps/pwa/out/setup/index.txt +13 -13
- package/apps/pwa/out/share/index.html +1 -1
- package/apps/pwa/out/share/index.txt +13 -13
- package/apps/pwa/out/showroom/index.html +1 -1
- package/apps/pwa/out/showroom/index.txt +13 -13
- package/apps/pwa/out/tasks/index.html +1 -1
- package/apps/pwa/out/tasks/index.txt +13 -13
- package/apps/pwa/out/term/index.html +1 -1
- package/apps/pwa/out/term/index.txt +13 -13
- package/apps/pwa/out/today/index.html +1 -1
- package/apps/pwa/out/today/index.txt +13 -13
- package/apps/pwa/out/trace/index.html +1 -1
- package/apps/pwa/out/trace/index.txt +13 -13
- package/apps/pwa/out/vault/index.html +1 -1
- package/apps/pwa/out/vault/index.txt +13 -13
- package/apps/pwa/out/workflows/chat-ui/index.html +1 -1
- package/apps/pwa/out/workflows/chat-ui/index.txt +13 -13
- package/apps/pwa/out/workflows/index.html +1 -1
- package/apps/pwa/out/workflows/index.txt +13 -13
- package/apps/pwa/out/workspace/index.html +1 -1
- package/apps/pwa/out/workspace/index.txt +13 -13
- package/apps/pwa/out/worktrees/index.html +1 -1
- package/apps/pwa/out/worktrees/index.txt +13 -13
- package/examples/teams/personas/backend.yaml +4 -0
- package/examples/teams/personas/pm.yaml +4 -0
- package/examples/teams/personas/qa.yaml +4 -0
- package/examples/teams/small-product.yaml +20 -0
- package/graphs/lecture/lecture-note.yaml +28 -0
- package/graphs/lecture/recipes.yaml +17 -0
- package/package.json +2 -1
- package/scripts/context-hooks/emit.ts +36 -14
- package/scripts/coord-channel-watch.sh +1 -0
- package/scripts/discord-seat-probe.ts +144 -0
- package/scripts/hq/hq-standby.sh +65 -0
- package/scripts/hq/standby-promote.ts +173 -0
- package/scripts/hq/standby-role.ts +59 -0
- package/scripts/hq/standby-snapshot.ts +226 -0
- package/scripts/hq/standby-verify.ts +219 -0
- package/scripts/lecture-note/node.ts +256 -0
- package/scripts/release-loop/gate-node.ts +53 -15
- package/scripts/release-loop/ops-upgrade-node.ts +17 -5
- package/scripts/test-deterministic.ts +53 -3
- package/skills/omni-crawl/SKILL.md +16 -16
- package/skills/omni-crawl/package-lock.json +1 -544
- package/skills/omni-crawl/package.json +3 -4
- package/skills/omni-crawl/scripts/main.ts +13 -13
- package/skills/omni-crawl/scripts/monitor.ts +8 -8
- package/skills/omni-crawl/src/apify.ts +13 -2
- package/skills/omni-crawl/src/capture.ts +6 -0
- package/skills/omni-crawl/src/registry.ts +2 -2
- package/skills/omni-crawl/src/stdout-json.ts +4 -0
- package/skills/omni-digest/SKILL.md +10 -11
- package/skills/omni-digest/package-lock.json +0 -545
- package/skills/omni-digest/package.json +2 -5
- package/skills/omni-digest/scripts/main.ts +3 -3
- package/skills/omni-digest/src/delegate.ts +5 -5
- package/skills/omni-digest/src/fetch.ts +2 -2
- package/skills/omni-digest/src/media.ts +25 -11
- package/skills/omni-digest/src/visual.ts +3 -2
- package/skills/omni-market/scripts/main.ts +1 -1
- package/skills/omni-market/scripts/stdout-json.ts +4 -0
- package/src/agent/identity-env.ts +11 -0
- package/src/agent-mission/driver.ts +12 -7
- package/src/agent-mission/duo.ts +94 -0
- package/src/agent-mission/pty-decision.ts +1 -1
- package/src/autopilot/track-agent-shadow.ts +2 -1
- package/src/autopilot/track-agent.ts +4 -1
- package/src/boot/daemon-prompt-request.ts +3 -0
- package/src/boot/daemon-prompt-turn.ts +6 -2
- package/src/boot/daemon-runtime.ts +48 -16
- package/src/cli/decisions-cli.ts +51 -19
- package/src/cli/outputs-cli.ts +92 -0
- package/src/cli/persona-cli.ts +29 -0
- package/src/cli/pod-cli.ts +10 -3
- package/src/cli/pr-cli.ts +15 -1
- package/src/cli/release-cli.ts +108 -28
- package/src/context-bus/condense.ts +194 -0
- package/src/context-bus/context-day.ts +82 -0
- package/src/context-bus/context-now-surfaces.ts +15 -2
- package/src/context-bus/long-term-memory.ts +118 -22
- package/src/context-bus/nightly-condense.ts +1 -1
- package/src/decisions/decision-cards.ts +13 -7
- package/src/decisions/decision-ledger.ts +43 -17
- package/src/graph-kinds/registry.ts +2 -2
- package/src/graph-runner/graph-approval-card.ts +2 -2
- package/src/graph-runner/graph-grow.ts +64 -11
- package/src/graph-runner/graph-tick.ts +9 -2
- package/src/graph-runner/runner.ts +81 -17
- package/src/harness/harness-cli-command.ts +27 -1
- package/src/harness/harness-queue-child.ts +37 -0
- package/src/harness/harness-queue.ts +306 -0
- package/src/hooks/github-shadow.ts +72 -2
- package/src/hooks/receiver.ts +4 -2
- package/src/hq/hq.ts +318 -0
- package/src/hq/lease.ts +210 -0
- package/src/hq/ledger-write-target.ts +41 -0
- package/src/index.ts +199 -7
- package/src/intake-plane/discord-seat-work.ts +13 -6
- package/src/intake-plane/linear-wish.ts +44 -0
- package/src/intake-plane/persona-answer.ts +5 -0
- package/src/intake-plane/telegram-seat-work.ts +13 -6
- package/src/intake-plane/wish-card.ts +1 -1
- package/src/loops/checker.ts +178 -0
- package/src/loops/loop-cli.ts +37 -3
- package/src/loops/observe.ts +49 -0
- package/src/loops/orchestrator/overlap.ts +141 -0
- package/src/loops/orchestrator/traffic.ts +150 -0
- package/src/loops/package/verify.ts +125 -0
- package/src/loops/verdict.ts +22 -0
- package/src/maturity/feature-maturity.ts +3 -3
- package/src/memory.ts +37 -4
- package/src/nexus/api/card-followup-route.ts +118 -0
- package/src/nexus/api/decisions-route.ts +68 -0
- package/src/nexus/api/http-server.ts +47 -0
- package/src/nexus/api/personas.ts +2 -1
- package/src/nexus/api/skill-exec-route.ts +97 -0
- package/src/persona/loader.ts +18 -0
- package/src/persona/persona-todo.ts +14 -9
- package/src/persona/presets.ts +2 -1
- package/src/persona/team.ts +105 -0
- package/src/persona/types.ts +4 -0
- package/src/pod-lease/host-lease.ts +130 -20
- package/src/release-loop/landed-but-yellow.ts +12 -0
- package/src/seat-dispatch/seat-ask.ts +57 -12
- package/src/seat-loop/seat-loop.ts +90 -16
- package/src/seat-loop/seat-pack.ts +127 -0
- package/src/self-dev/ask-launch-flow.ts +3 -0
- package/src/self-implement/l8-merge-queue.ts +157 -1
- package/src/steward/launch.ts +5 -1
- package/src/steward/readiness.ts +125 -0
- package/src/steward/rescue.ts +75 -0
- package/src/steward/triage.ts +48 -9
- package/src/task-cards/card-cli.ts +78 -0
- package/src/task-orchestrator/surfaces/pod-lease.ts +18 -6
- package/src/task-orchestrator/surfaces/pod-pool.ts +27 -10
- package/src/task-orchestrator/surfaces/self-implement-pod.ts +38 -8
- package/src/telegram-dispatch-forward.ts +1 -1
- package/src/telegram-fabric-plan.ts +90 -0
- package/src/telegram-project-command.ts +10 -4
- package/src/telegram.ts +5 -0
- package/src/tool-runtime/elanous-control-runtimes.ts +2 -1
- package/src/user-config.ts +94 -10
- package/src/version/packed-revision.json +1 -1
- package/src/workflow-runtime/executor.ts +4 -0
- package/src/workflow-runtime/node-catalog.ts +13 -0
- package/src/workflow-runtime/nodes/knowledge.ts +38 -0
- package/src/workflow-runtime/schema.ts +17 -1
- package/src/workflow-runtime/types.ts +13 -1
- package/apps/pwa/out/_next/static/chunks/1147-466ec15afacc1a65.js +0 -1
- package/apps/pwa/out/_next/static/chunks/7277-0b2fc7c16ba2d64b.js +0 -1
- package/apps/pwa/out/_next/static/chunks/9906-482c6619b3fdda20.js +0 -1
- package/apps/pwa/out/_next/static/chunks/9920-5cfdc5e8fd209825.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/board/page-d2e35228bc497119.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/botlab/page-5c05b0da4bc1392c.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/bots/page-e0ccdb576812b523.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/exec/page-a67e11ba962337b5.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/layout-e71c84189e8c683e.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/live/page-1d6a533ce5a6efcb.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/not-found-490653e8d4cc8852.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/ops/checklist/page-29e961191f6057df.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/ops/release/page-c822f55b884d9104.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/ops/seats/page-fa4ccfc432424e52.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/page-9c7e8f744a765daf.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/settings/devices/page-4292d0149020e8a7.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/settings/page-db14d0be7f1c460c.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/setup/done/page-e5d8072cd7cfef73.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/share/page-e6dcb83265530636.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/showroom/page-45248f08d6aecae5.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/vault/page-4344faf20216233b.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/workflows/chat-ui/page-698bb29f11864b89.js +0 -1
- package/apps/pwa/out/_next/static/chunks/app/workflows/page-bd6a6dc1ddc273f2.js +0 -1
- /package/apps/pwa/out/_next/static/{-6XrAoD3eU7NyMHAE4xPS → D51l8jUBplJrIpWvENsDK}/_buildManifest.js +0 -0
- /package/apps/pwa/out/_next/static/{-6XrAoD3eU7NyMHAE4xPS → D51l8jUBplJrIpWvENsDK}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { parseDocument } from 'yaml';
|
|
4
|
+
import { parsePersonaYaml } from './loader.js';
|
|
5
|
+
|
|
6
|
+
export interface TeamMember {
|
|
7
|
+
persona: string;
|
|
8
|
+
title: string;
|
|
9
|
+
checklistTemplate: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface TeamHandoff {
|
|
13
|
+
from: string;
|
|
14
|
+
to: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TeamDefinition {
|
|
18
|
+
name: string;
|
|
19
|
+
members: TeamMember[];
|
|
20
|
+
handoffs: TeamHandoff[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function mapping(value: unknown): value is Record<string, unknown> {
|
|
24
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function fields(value: Record<string, unknown>, required: readonly string[], label: string): void {
|
|
28
|
+
for (const key of required) {
|
|
29
|
+
if (!Object.hasOwn(value, key)) throw new Error(`${label}.${key} is required`);
|
|
30
|
+
}
|
|
31
|
+
for (const key of Object.keys(value)) {
|
|
32
|
+
if (!required.includes(key)) throw new Error(`${label}.${key} is not a team schema field`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function text(value: unknown, label: string): string {
|
|
37
|
+
if (typeof value !== 'string' || !value.trim()) throw new Error(`${label} must be a non-empty string`);
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Read-only validation: resolve persona paths relative to the team file, not the caller's cwd. */
|
|
42
|
+
export function validateTeamFile(file: string): TeamDefinition {
|
|
43
|
+
const document = parseDocument(readFileSync(file, 'utf8'), { uniqueKeys: true });
|
|
44
|
+
if (document.errors.length) throw new Error(`invalid team YAML: ${document.errors[0]!.message}`);
|
|
45
|
+
const raw: unknown = document.toJS();
|
|
46
|
+
if (!mapping(raw)) throw new Error('team must be a YAML mapping');
|
|
47
|
+
fields(raw, ['name', 'members', 'handoffs'], 'team');
|
|
48
|
+
const name = text(raw.name, 'team.name');
|
|
49
|
+
if (!Array.isArray(raw.members) || raw.members.length === 0) {
|
|
50
|
+
throw new Error('team.members must be a non-empty list');
|
|
51
|
+
}
|
|
52
|
+
const titles = new Set<string>();
|
|
53
|
+
const personaIds = new Set<string>();
|
|
54
|
+
const members: TeamMember[] = raw.members.map((item: unknown, index: number) => {
|
|
55
|
+
const label = `team.members[${index}]`;
|
|
56
|
+
if (!mapping(item)) throw new Error(`${label} must be a mapping`);
|
|
57
|
+
fields(item, ['persona', 'title', 'checklistTemplate'], label);
|
|
58
|
+
const persona = text(item.persona, `${label}.persona`);
|
|
59
|
+
const title = text(item.title, `${label}.title`);
|
|
60
|
+
if (titles.has(title)) throw new Error(`duplicate team title: ${title}`);
|
|
61
|
+
titles.add(title);
|
|
62
|
+
if (!Array.isArray(item.checklistTemplate) || item.checklistTemplate.length === 0) {
|
|
63
|
+
throw new Error(`${label}.checklistTemplate must be a non-empty list of strings`);
|
|
64
|
+
}
|
|
65
|
+
const checklistTemplate = item.checklistTemplate.map((entry: unknown) => text(entry, `${label}.checklistTemplate item`));
|
|
66
|
+
const personaPath = resolve(dirname(file), persona);
|
|
67
|
+
let yaml: string;
|
|
68
|
+
try {
|
|
69
|
+
yaml = readFileSync(personaPath, 'utf8');
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') throw new Error(`persona not found: ${persona} (${title})`);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
const parsed = parsePersonaYaml(yaml, personaPath);
|
|
75
|
+
if (!parsed.ok) throw new Error(`invalid persona ${persona}: ${parsed.error.message}`);
|
|
76
|
+
if (parsed.profile.seat !== title) throw new Error(`persona seat mismatch: ${persona} requires seat ${title}`);
|
|
77
|
+
if (personaIds.has(parsed.profile.personaId)) throw new Error(`duplicate personaId: ${parsed.profile.personaId}`);
|
|
78
|
+
personaIds.add(parsed.profile.personaId);
|
|
79
|
+
return { persona, title, checklistTemplate };
|
|
80
|
+
});
|
|
81
|
+
if (!Array.isArray(raw.handoffs)) throw new Error('team.handoffs must be a list');
|
|
82
|
+
const handoffs: TeamHandoff[] = raw.handoffs.map((item: unknown, index: number) => {
|
|
83
|
+
const label = `team.handoffs[${index}]`;
|
|
84
|
+
if (!mapping(item)) throw new Error(`${label} must be a mapping`);
|
|
85
|
+
fields(item, ['from', 'to'], label);
|
|
86
|
+
const from = text(item.from, `${label}.from`);
|
|
87
|
+
const to = text(item.to, `${label}.to`);
|
|
88
|
+
if (!titles.has(from) || !titles.has(to)) throw new Error(`handoff references missing title: ${from} -> ${to}`);
|
|
89
|
+
return { from, to };
|
|
90
|
+
});
|
|
91
|
+
const edges = new Map([...titles].map((title) => [title, [] as string[]]));
|
|
92
|
+
for (const { from, to } of handoffs) edges.get(from)!.push(to);
|
|
93
|
+
const visiting = new Set<string>();
|
|
94
|
+
const visited = new Set<string>();
|
|
95
|
+
const visit = (title: string): void => {
|
|
96
|
+
if (visiting.has(title)) throw new Error(`handoff cycle at ${title}`);
|
|
97
|
+
if (visited.has(title)) return;
|
|
98
|
+
visiting.add(title);
|
|
99
|
+
for (const next of edges.get(title)!) visit(next);
|
|
100
|
+
visiting.delete(title);
|
|
101
|
+
visited.add(title);
|
|
102
|
+
};
|
|
103
|
+
for (const title of titles) visit(title);
|
|
104
|
+
return { name, members, handoffs };
|
|
105
|
+
}
|
package/src/persona/types.ts
CHANGED
|
@@ -19,6 +19,10 @@ export type PersonaBrand =
|
|
|
19
19
|
export interface PersonaProfile {
|
|
20
20
|
readonly personaId: string;
|
|
21
21
|
readonly displayName: string;
|
|
22
|
+
/** Seat address (title, id or alias) represented by this persona. */
|
|
23
|
+
readonly seat?: string;
|
|
24
|
+
/** Per-persona JSONL todo filename in the state persona directory. */
|
|
25
|
+
readonly todo?: string;
|
|
22
26
|
readonly description?: string;
|
|
23
27
|
|
|
24
28
|
/** System prompt to prepend in LLM calls. Markdown text. May
|
|
@@ -2,12 +2,32 @@
|
|
|
2
2
|
// in a per-user directory; a launch is admitted only while live leases stay under the pool's measured total.
|
|
3
3
|
// Without this, independent CLI processes each measured an empty pool and all launched (review round 2 of #23212).
|
|
4
4
|
import { spawnSync } from 'node:child_process';
|
|
5
|
-
import { mkdirSync, readdirSync, readFileSync, rmSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
6
6
|
import { tmpdir, userInfo } from 'node:os';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
8
|
import { debug } from '../debug/log.js';
|
|
9
9
|
|
|
10
|
-
export interface HostLeaseRecord { pid: number; startedAt: string; at: string }
|
|
10
|
+
export interface HostLeaseRecord { pid: number; startedAt: string; at: string; stage?: 'authoring' | 'job'; claimed?: boolean; job?: string; context?: string; namespace?: string }
|
|
11
|
+
|
|
12
|
+
export interface PendingJobIdentity { context: string; namespace: string; job: string }
|
|
13
|
+
|
|
14
|
+
/** Only the same cluster, namespace and Job can account for an existing host lease. */
|
|
15
|
+
export function leaseHasPendingPod(lease: HostLeaseRecord, pending: readonly PendingJobIdentity[]): boolean {
|
|
16
|
+
return lease.stage === 'job' && !!lease.context && !!lease.namespace && !!lease.job &&
|
|
17
|
+
pending.some((pod) => pod.context === lease.context && pod.namespace === lease.namespace && pod.job === lease.job);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface HostLeaseHandle {
|
|
21
|
+
(): void;
|
|
22
|
+
readonly id: string;
|
|
23
|
+
/** Job creation is not release: retain the lease until its Pod is observed Running or terminal. */
|
|
24
|
+
applied: (job: string, context: string, namespace: string) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A Job without a Running/terminal Pod still occupies a host reservation. */
|
|
28
|
+
export function hostLeaseCounts(records: readonly HostLeaseRecord[]): { reserved: number; waitingJobs: number } {
|
|
29
|
+
return { reserved: records.filter((r) => r.stage !== 'job').length, waitingJobs: records.filter((r) => r.stage === 'job').length };
|
|
30
|
+
}
|
|
11
31
|
|
|
12
32
|
export interface HostPoolLeaseOptions {
|
|
13
33
|
/** Base directory — default `$TMPDIR/elanous-pod-leases-<uid>` (0700). */
|
|
@@ -53,8 +73,42 @@ export class HostPoolLease {
|
|
|
53
73
|
this.staleLockMs = options.staleLockMs ?? 10_000;
|
|
54
74
|
}
|
|
55
75
|
|
|
76
|
+
reservationIsOther(id: string): boolean {
|
|
77
|
+
if (!/^[A-Za-z0-9._-]+\.json$/.test(id)) return false;
|
|
78
|
+
try {
|
|
79
|
+
const record = JSON.parse(readFileSync(join(this.dir, id), 'utf8')) as HostLeaseRecord;
|
|
80
|
+
return record.stage === 'authoring' && Number.isSafeInteger(record.pid) && record.pid > 0 &&
|
|
81
|
+
typeof record.startedAt === 'string' && this.processStart(record.pid) === record.startedAt &&
|
|
82
|
+
(record.pid !== this.pid || record.startedAt !== this.selfStart());
|
|
83
|
+
} catch { return false; }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Transfer a reservation across the authoring → orchestrator process boundary. */
|
|
87
|
+
claim(id: string): HostLeaseHandle | null {
|
|
88
|
+
if (!/^[A-Za-z0-9._-]+\.json$/.test(id)) return null;
|
|
89
|
+
const file = join(this.dir, id);
|
|
90
|
+
const deadline = Date.now() + this.staleLockMs;
|
|
91
|
+
while (!this.lock()) {
|
|
92
|
+
if (Date.now() >= deadline) return null;
|
|
93
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
if (this.ownStart === undefined) this.ownStart = this.processStart(this.pid);
|
|
97
|
+
if (!this.ownStart) return null;
|
|
98
|
+
const original = JSON.parse(readFileSync(file, 'utf8')) as HostLeaseRecord;
|
|
99
|
+
if (original.stage !== 'authoring' || original.claimed || !Number.isSafeInteger(original.pid) || original.pid <= 0 ||
|
|
100
|
+
typeof original.startedAt !== 'string' || this.processStart(original.pid) !== original.startedAt) return null;
|
|
101
|
+
const record: HostLeaseRecord = { ...original, pid: this.pid, startedAt: this.ownStart, claimed: true };
|
|
102
|
+
this.replaceRecord(file, record);
|
|
103
|
+
return this.handle(file, record, id);
|
|
104
|
+
} catch { return null; }
|
|
105
|
+
finally { this.unlock(); }
|
|
106
|
+
}
|
|
107
|
+
|
|
56
108
|
/** Live leases after removing stale ones (dead pid or a recycled pid whose start time differs). */
|
|
57
|
-
live(): HostLeaseRecord[] {
|
|
109
|
+
live(): HostLeaseRecord[] { return this.readLive(false); }
|
|
110
|
+
|
|
111
|
+
private readLive(lockHeld: boolean): HostLeaseRecord[] {
|
|
58
112
|
const out: HostLeaseRecord[] = [];
|
|
59
113
|
let names: string[] = [];
|
|
60
114
|
try { names = readdirSync(this.dir).filter((name) => name.endsWith('.json')); } catch { return out; }
|
|
@@ -62,50 +116,106 @@ export class HostPoolLease {
|
|
|
62
116
|
const file = join(this.dir, name);
|
|
63
117
|
let record: HostLeaseRecord | null = null;
|
|
64
118
|
try { record = JSON.parse(readFileSync(file, 'utf8')) as HostLeaseRecord; } catch { record = null; }
|
|
65
|
-
const alive = record &&
|
|
119
|
+
const alive = record && Number.isSafeInteger(record.pid) && record.pid > 0 && typeof record.startedAt === 'string'
|
|
120
|
+
&& this.processStart(record.pid) === record.startedAt;
|
|
66
121
|
if (record && alive) { out.push(record); continue; }
|
|
67
|
-
|
|
68
|
-
|
|
122
|
+
// A concurrent claim can replace the record while we check the original PID.
|
|
123
|
+
if (!lockHeld && !this.lock()) { if (record) out.push(record); continue; }
|
|
124
|
+
try {
|
|
125
|
+
let current: HostLeaseRecord | null;
|
|
126
|
+
try { current = JSON.parse(readFileSync(file, 'utf8')) as HostLeaseRecord; } catch { current = null; }
|
|
127
|
+
if (current && Number.isSafeInteger(current.pid) && current.pid > 0 && typeof current.startedAt === 'string' &&
|
|
128
|
+
this.processStart(current.pid) === current.startedAt) { out.push(current); continue; }
|
|
129
|
+
try { unlinkSync(file); } catch { /* already cleaned */ }
|
|
130
|
+
debug.log('pod.lease', 'host-lease-stale-cleared', { file: name, pid: current?.pid ?? null });
|
|
131
|
+
} finally { if (!lockHeld) this.unlock(); }
|
|
69
132
|
}
|
|
70
133
|
return out;
|
|
71
134
|
}
|
|
72
135
|
|
|
73
|
-
|
|
74
|
-
othersPending(): number {
|
|
136
|
+
selfStart(): string | null {
|
|
75
137
|
if (this.ownStart === undefined) this.ownStart = this.processStart(this.pid);
|
|
76
|
-
return this.
|
|
138
|
+
return this.ownStart;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Reservations held by other processes while the cluster cannot yet observe them. */
|
|
142
|
+
othersPending(): number {
|
|
143
|
+
return this.live().filter((r) => !(r.pid === this.pid && r.startedAt === this.selfStart())).length;
|
|
77
144
|
}
|
|
78
145
|
|
|
79
146
|
/**
|
|
80
|
-
* Under the host lock, take a lease only if `allowed(
|
|
81
|
-
*
|
|
147
|
+
* Under the host lock, take a lease only if `allowed(pending)` holds — the check and the write are one step.
|
|
148
|
+
* By default pending excludes this process's permits (the local admission gate owns them); includeOwn
|
|
149
|
+
* counts every reservation for independent authoring launches from the same process.
|
|
150
|
+
* Null = refused or lock busy (retry later).
|
|
82
151
|
*/
|
|
83
|
-
tryReserve(allowed: (othersPending: number) => boolean
|
|
152
|
+
tryReserve(allowed: (othersPending: number) => boolean, includeOwn = false): HostLeaseHandle | null {
|
|
84
153
|
try { mkdirSync(this.dir, { recursive: true, mode: 0o700 }); } catch { return null; }
|
|
85
154
|
if (!this.lock()) return null;
|
|
86
155
|
try {
|
|
87
156
|
if (this.ownStart === undefined) this.ownStart = this.processStart(this.pid);
|
|
88
157
|
if (!this.ownStart) return null;
|
|
89
|
-
const others = this.
|
|
158
|
+
const others = this.readLive(true).filter((r) => includeOwn || !(r.pid === this.pid && r.startedAt === this.ownStart)).length;
|
|
90
159
|
if (!allowed(others)) {
|
|
91
160
|
debug.log('pod.lease', 'host-lease-refused', { othersPending: others });
|
|
92
161
|
return null;
|
|
93
162
|
}
|
|
94
163
|
const file = join(this.dir, `${this.pid}-${this.now()}-${Math.random().toString(36).slice(2, 8)}.json`);
|
|
95
|
-
const record: HostLeaseRecord = { pid: this.pid, startedAt: this.ownStart, at: new Date(this.now()).toISOString() };
|
|
164
|
+
const record: HostLeaseRecord = { pid: this.pid, startedAt: this.ownStart, at: new Date(this.now()).toISOString(), stage: 'authoring' };
|
|
96
165
|
writeFileSync(file, JSON.stringify(record), { flag: 'wx', mode: 0o600 });
|
|
97
166
|
debug.log('pod.lease', 'host-lease-acquired', { othersPending: others });
|
|
98
|
-
|
|
99
|
-
return () => {
|
|
100
|
-
if (released) return;
|
|
101
|
-
released = true;
|
|
102
|
-
try { unlinkSync(file); } catch { /* already cleaned */ }
|
|
103
|
-
};
|
|
167
|
+
return this.handle(file, record, file.slice(this.dir.length + 1));
|
|
104
168
|
} finally {
|
|
105
169
|
this.unlock();
|
|
106
170
|
}
|
|
107
171
|
}
|
|
108
172
|
|
|
173
|
+
private replaceRecord(file: string, record: HostLeaseRecord): void {
|
|
174
|
+
const temp = `${file}.${this.pid}-${Math.random().toString(36).slice(2)}.tmp`;
|
|
175
|
+
try {
|
|
176
|
+
writeFileSync(temp, JSON.stringify(record), { flag: 'wx', mode: 0o600 });
|
|
177
|
+
renameSync(temp, file);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
try { unlinkSync(temp); } catch { /* already gone */ }
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private handle(file: string, record: HostLeaseRecord, id: string): HostLeaseHandle {
|
|
185
|
+
let released = false;
|
|
186
|
+
const release = (() => {
|
|
187
|
+
if (released) return;
|
|
188
|
+
// Claim replaces the same file under this lock. An old owner must not unlink a
|
|
189
|
+
// newly transferred reservation between reading and removing its record.
|
|
190
|
+
const deadline = Date.now() + this.staleLockMs;
|
|
191
|
+
while (!this.lock()) {
|
|
192
|
+
if (Date.now() >= deadline) return;
|
|
193
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
const current = JSON.parse(readFileSync(file, 'utf8')) as HostLeaseRecord;
|
|
197
|
+
if (current.pid === record.pid && current.startedAt === record.startedAt && current.claimed === record.claimed) unlinkSync(file);
|
|
198
|
+
} catch { /* transferred or already cleaned */ }
|
|
199
|
+
finally { released = true; this.unlock(); }
|
|
200
|
+
}) as HostLeaseHandle;
|
|
201
|
+
Object.defineProperty(release, 'id', { value: id });
|
|
202
|
+
release.applied = (job, context, namespace) => {
|
|
203
|
+
if (released) return;
|
|
204
|
+
const deadline = Date.now() + this.staleLockMs;
|
|
205
|
+
while (!this.lock()) {
|
|
206
|
+
if (Date.now() >= deadline) throw new Error('pod lease: cannot update Job reservation');
|
|
207
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
const current = JSON.parse(readFileSync(file, 'utf8')) as HostLeaseRecord;
|
|
211
|
+
if (current.pid !== record.pid || current.startedAt !== record.startedAt || current.claimed !== record.claimed) throw new Error('pod lease: reservation owner changed');
|
|
212
|
+
if (!job || !context || !namespace) throw new Error('pod lease: Job identity requires context, namespace and name');
|
|
213
|
+
this.replaceRecord(file, { ...record, stage: 'job', job, context, namespace });
|
|
214
|
+
} finally { this.unlock(); }
|
|
215
|
+
};
|
|
216
|
+
return release;
|
|
217
|
+
}
|
|
218
|
+
|
|
109
219
|
private lockDir(): string { return join(this.dir, '.lock'); }
|
|
110
220
|
|
|
111
221
|
private lock(): boolean {
|
|
@@ -11,6 +11,18 @@ export interface LandedButYellowRow {
|
|
|
11
11
|
newer: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export function evidencePlan(rows: readonly LandedButYellowRow[]): Array<{ id: string; ref: string }> {
|
|
15
|
+
const seen = new Set<string>();
|
|
16
|
+
return rows.flatMap((row) => row.prs.flatMap((pr, index) => {
|
|
17
|
+
if (pr.basis === 'mention' || row.alreadyInEvidence[index]) return [];
|
|
18
|
+
const ref = `#${pr.number}`;
|
|
19
|
+
const key = JSON.stringify([row.id, ref]);
|
|
20
|
+
if (seen.has(key)) return [];
|
|
21
|
+
seen.add(key);
|
|
22
|
+
return [{ id: row.id, ref }];
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
|
|
14
26
|
/** Prefer a dedicated body cell line over title evidence; incidental mentions only qualify for long ids. */
|
|
15
27
|
export function landedButYellow(items: readonly ChecklistItem[], prs: readonly MergedChecklistPr[], { owner }: { owner?: string } = {}): LandedButYellowRow[] {
|
|
16
28
|
const rows: LandedButYellowRow[] = [];
|
|
@@ -1,31 +1,58 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { join } from 'node:path';
|
|
2
3
|
import { debug } from '../debug/log.js';
|
|
3
4
|
import { openMsgStore, type MsgStore } from '../msg/msg-store.js';
|
|
4
5
|
import { dispatchCeoTask, type CeoCommandDeps } from './ceo-commands.js';
|
|
6
|
+
import type { SeatId } from './seat-questions.js';
|
|
5
7
|
|
|
6
8
|
export type AskOrigin =
|
|
7
9
|
| { channel: 'telegram'; chatId: number | string; messageId: number; threadId?: number; botId?: string }
|
|
8
10
|
| { channel: 'discord'; channelId: string; messageId: string; threadId?: string }
|
|
9
11
|
| { channel: 'pwa'; clientId: string };
|
|
10
12
|
|
|
11
|
-
export const DEFAULT_ASK_TIMEOUT_MS =
|
|
13
|
+
export const DEFAULT_ASK_TIMEOUT_MS = 2 * 60 * 60 * 1000;
|
|
12
14
|
export const parseSeatAsk = (text: string): string | null => /^\s*CTO\s*에게\s*물어봐\s*[::]\s*(\S[\s\S]*)$/i.exec(text)?.[1]?.trim() ?? null;
|
|
13
15
|
|
|
14
|
-
interface AskRow { id: string; seat: string; origin: string; deadline: number; timeout_minutes: number }
|
|
16
|
+
interface AskRow { id: string; seat: string; origin: string; deadline: number; timeout_minutes: number; answer: string | null; answered_at: number | null }
|
|
15
17
|
|
|
16
18
|
function createTable(store: MsgStore): void {
|
|
17
19
|
store.db.exec(`CREATE TABLE IF NOT EXISTS seat_asks (
|
|
18
20
|
id TEXT PRIMARY KEY, seat TEXT NOT NULL, origin TEXT NOT NULL,
|
|
19
|
-
deadline INTEGER NOT NULL, timeout_minutes INTEGER NOT NULL DEFAULT
|
|
21
|
+
deadline INTEGER NOT NULL, timeout_minutes INTEGER NOT NULL DEFAULT 120, status TEXT NOT NULL DEFAULT 'pending',
|
|
22
|
+
answer TEXT, answered_at INTEGER
|
|
20
23
|
); CREATE TABLE IF NOT EXISTS seat_ask_outbox (
|
|
21
24
|
id TEXT PRIMARY KEY, origin TEXT NOT NULL, text TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending',
|
|
22
25
|
claim_until INTEGER NOT NULL DEFAULT 0, claim_token TEXT
|
|
23
26
|
)`);
|
|
27
|
+
const askColumns = store.db.query('PRAGMA table_info(seat_asks)').all() as Array<{ name: string }>;
|
|
28
|
+
if (!askColumns.some(({ name }) => name === 'answer')) store.db.exec('ALTER TABLE seat_asks ADD COLUMN answer TEXT');
|
|
29
|
+
if (!askColumns.some(({ name }) => name === 'answered_at')) store.db.exec('ALTER TABLE seat_asks ADD COLUMN answered_at INTEGER');
|
|
24
30
|
const columns = store.db.query('PRAGMA table_info(seat_ask_outbox)').all() as Array<{ name: string }>;
|
|
25
31
|
if (!columns.some(({ name }) => name === 'claim_until')) store.db.exec('ALTER TABLE seat_ask_outbox ADD COLUMN claim_until INTEGER NOT NULL DEFAULT 0');
|
|
26
32
|
if (!columns.some(({ name }) => name === 'claim_token')) store.db.exec('ALTER TABLE seat_ask_outbox ADD COLUMN claim_token TEXT');
|
|
27
33
|
}
|
|
28
34
|
|
|
35
|
+
export interface SeatAskShadow {
|
|
36
|
+
from: SeatId;
|
|
37
|
+
to: SeatId;
|
|
38
|
+
itemId: string;
|
|
39
|
+
version: string;
|
|
40
|
+
question: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Keep an internal seat-to-seat question in the existing ask ledger, without dispatching or queuing an outbox message. */
|
|
44
|
+
export function recordSeatAskShadow(root: string, ask: SeatAskShadow, now: number): boolean {
|
|
45
|
+
if (ask.from === ask.to || !ask.itemId || !ask.question.trim() || !Number.isFinite(now)) throw new Error('invalid shadow seat ask');
|
|
46
|
+
const id = `seat-loop:${createHash('sha256').update(JSON.stringify([ask.from, ask.to, ask.version, ask.itemId])).digest('hex')}`;
|
|
47
|
+
const store = openMsgStore(join(root, 'msg', 'messages.db'));
|
|
48
|
+
try {
|
|
49
|
+
createTable(store);
|
|
50
|
+
const origin = JSON.stringify({ channel: 'seat-loop', from: ask.from, itemId: ask.itemId, version: ask.version, question: ask.question.trim() });
|
|
51
|
+
return store.db.query("INSERT OR IGNORE INTO seat_asks (id, seat, origin, deadline, timeout_minutes, status) VALUES (?, ?, ?, ?, ?, 'shadow')")
|
|
52
|
+
.run(id, ask.to, origin, now + DEFAULT_ASK_TIMEOUT_MS, Math.ceil(DEFAULT_ASK_TIMEOUT_MS / 60000)).changes === 1;
|
|
53
|
+
} finally { store.close(); }
|
|
54
|
+
}
|
|
55
|
+
|
|
29
56
|
export interface SeatAskDeps {
|
|
30
57
|
open?: () => MsgStore;
|
|
31
58
|
now?: () => number;
|
|
@@ -52,7 +79,7 @@ export async function askSeat(text: string, origin: AskOrigin, command: CeoComma
|
|
|
52
79
|
.run(id, 'TC', JSON.stringify(origin), (deps.now ?? Date.now)() + timeout, minutes, 'pending');
|
|
53
80
|
} finally { store.close(); }
|
|
54
81
|
try {
|
|
55
|
-
const result = await (deps.dispatch ?? dispatchCeoTask)('TC', `질문: ${body}\n답장 요청: ${id}\n회신: elanous
|
|
82
|
+
const result = await (deps.dispatch ?? dispatchCeoTask)('TC', `질문: ${body}\n답장 요청: ${id}\n회신: elanous seat answer ${id} "<답>"`, command,
|
|
56
83
|
{ via: origin.channel, ref: `ask:${id}` });
|
|
57
84
|
debug.log('seat.ask', 'sent', { seat: 'TC', id, via: origin.channel, channel: result.channel });
|
|
58
85
|
return `CTO에게 물었습니다. 답을 기다립니다 (최대 ${minutes}분). 요청: ${id}${result.channel === 'failed' ? ` · 조율 채널 전송 실패: ${result.channelError}` : ''}`;
|
|
@@ -64,22 +91,40 @@ export async function askSeat(text: string, origin: AskOrigin, command: CeoComma
|
|
|
64
91
|
}
|
|
65
92
|
}
|
|
66
93
|
|
|
67
|
-
/**
|
|
94
|
+
/** Record a seat reply in its original request row; delivery stays with the originating surface's worker. */
|
|
95
|
+
export function answerSeatAsk(id: string, text: string, deps: Pick<SeatAskDeps, 'open' | 'now'> = {}): void {
|
|
96
|
+
const answer = text.trim();
|
|
97
|
+
if (!answer) throw new Error('seat answer must not be empty');
|
|
98
|
+
const store = (deps.open ?? openMsgStore)();
|
|
99
|
+
try {
|
|
100
|
+
createTable(store);
|
|
101
|
+
const now = (deps.now ?? Date.now)();
|
|
102
|
+
const updated = store.db.query(`UPDATE seat_asks SET answer = ?, answered_at = ?
|
|
103
|
+
WHERE id = ? AND seat = 'TC' AND status = 'pending' AND answer IS NULL AND deadline > ?`)
|
|
104
|
+
.run(answer, now, id, now);
|
|
105
|
+
if (updated.changes !== 1) throw new Error(`seat ask not pending or deadline passed: ${id}`);
|
|
106
|
+
debug.log('seat.ask', 'reply-recorded', { seat: 'TC', id });
|
|
107
|
+
} finally { store.close(); }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Deliver recorded seat answers or expiration notices via the original surface. */
|
|
68
111
|
export async function deliverSeatAnswers(deps: SeatAskDeps): Promise<void> {
|
|
69
112
|
const store = (deps.open ?? openMsgStore)();
|
|
70
113
|
try {
|
|
71
114
|
createTable(store);
|
|
72
|
-
const pending = store.db.query("SELECT id, seat, origin, deadline, timeout_minutes FROM seat_asks WHERE status = 'pending'").all() as AskRow[];
|
|
115
|
+
const pending = store.db.query("SELECT id, seat, origin, deadline, timeout_minutes, answer, answered_at FROM seat_asks WHERE status = 'pending'").all() as AskRow[];
|
|
73
116
|
const decide = store.db.transaction((id: string, now: number): 'answered' | 'expired' | null => {
|
|
74
|
-
const ask = store.db.query("SELECT id, seat, origin, deadline, timeout_minutes FROM seat_asks WHERE id = ? AND status = 'pending'").get(id) as AskRow | null;
|
|
117
|
+
const ask = store.db.query("SELECT id, seat, origin, deadline, timeout_minutes, answer, answered_at FROM seat_asks WHERE id = ? AND status = 'pending'").get(id) as AskRow | null;
|
|
75
118
|
if (!ask) return null;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
119
|
+
// Retain compatibility with replies already posted to the existing seat mailbox.
|
|
120
|
+
const reply = ask.answer === null ? store.db.query("SELECT id, body, created_at FROM msg_messages WHERE recipient = 'CEO' AND kind = 'seat-ask-reply' AND substr(body, 1, ?) = ? AND sender = ? ORDER BY id LIMIT 1")
|
|
121
|
+
.get(id.length + 2, `${id}: `, ask.seat) as { id: number; body: string; created_at: string } | null : null;
|
|
122
|
+
const answer = ask.answer !== null && ask.answered_at !== null && ask.answered_at < ask.deadline ? ask.answer
|
|
123
|
+
: reply && Date.parse(reply.created_at) < ask.deadline ? reply.body.slice(id.length + 2).trim() : '';
|
|
79
124
|
const status = answer ? 'answered' : now >= ask.deadline ? 'expired' : null;
|
|
80
125
|
if (!status) return null;
|
|
81
126
|
const text = status === 'answered' ? `CTO 답변 (${id}): ${answer}`
|
|
82
|
-
: `CTO 미답 (${id}): ${ask.timeout_minutes}분
|
|
127
|
+
: `CTO 미답 (${id}): 아직 답 없음 (${ask.timeout_minutes}분 경과).`;
|
|
83
128
|
const updated = store.db.query("UPDATE seat_asks SET status = ? WHERE id = ? AND status = 'pending'").run(status, id);
|
|
84
129
|
if (updated.changes !== 1) return null;
|
|
85
130
|
store.db.query('INSERT INTO seat_ask_outbox (id, origin, text) VALUES (?, ?, ?)').run(id, ask.origin, text);
|