@cohortapp/agent-sdk 2.11.15 → 2.13.0
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/.env.example +37 -22
- package/README.md +2 -0
- package/bin/maestro.mjs +117 -39
- package/bin/maestro.test.mjs +175 -5
- package/docs/guides/front-door-session.md +313 -0
- package/docs/guides/mac-mini.md +100 -28
- package/docs/guides/org-onboarding.md +1 -1
- package/docs/guides/setup-wizard.md +9 -5
- package/docs/runbooks/cohort-cutover.md +11 -1
- package/docs/runbooks/mac-mini-bootstrap.md +38 -63
- package/lib/cadence-bus-requeue.test.mjs +83 -0
- package/lib/cadence-bus.mjs +43 -7
- package/lib/channels/inbox-item.mjs +59 -2
- package/lib/cli/board.mjs +285 -0
- package/lib/cli/board.test.mjs +227 -0
- package/lib/cli/design.mjs +185 -0
- package/lib/cli/design.test.mjs +270 -0
- package/lib/cli/doctor-checks.mjs +441 -0
- package/lib/cli/doctor-checks.test.mjs +336 -0
- package/lib/cli/global-setup-extras.mjs +454 -0
- package/lib/cli/global-setup-extras.test.mjs +462 -0
- package/lib/cli/inbox.mjs +304 -0
- package/lib/cli/inbox.test.mjs +230 -0
- package/lib/cli/session-ack.mjs +63 -0
- package/lib/cli/session-ack.test.mjs +63 -0
- package/lib/cli/session.mjs +760 -0
- package/lib/cli/session.test.mjs +613 -0
- package/lib/collective/global-config.mjs +209 -6
- package/lib/collective/global-config.test.mjs +145 -0
- package/lib/collective/global-skills.mjs +145 -0
- package/lib/collective/global-skills.test.mjs +126 -0
- package/lib/collective/presence.mjs +4 -3
- package/lib/collective/vendor-skills.mjs +305 -0
- package/lib/collective/vendor-skills.test.mjs +306 -0
- package/lib/comms/send-gate.mjs +115 -0
- package/lib/comms/send-gate.test.mjs +113 -0
- package/lib/design/design-md.mjs +793 -0
- package/lib/design/design-md.test.mjs +318 -0
- package/lib/design/fixtures/DESIGN.golden.md +238 -0
- package/lib/design/fixtures/PRODUCT.golden.md +67 -0
- package/lib/design/fixtures/foundation.json +133 -0
- package/lib/design/refresh-gate.mjs +154 -0
- package/lib/design/refresh-gate.test.mjs +144 -0
- package/lib/design/write.mjs +275 -0
- package/lib/design/write.test.mjs +241 -0
- package/lib/feature-init.mjs +2 -2
- package/lib/mcp/server.test.mjs +9 -4
- package/lib/model-router/spawn.test.mjs +21 -0
- package/lib/org/board-mine-cache.mjs +99 -0
- package/lib/org/board-mine-cache.test.mjs +53 -0
- package/lib/org/board.mjs +11 -0
- package/lib/org/board.test.mjs +11 -1
- package/lib/org/client.mjs +36 -0
- package/lib/org/client.test.mjs +46 -0
- package/lib/org/inbound/directedness.mjs +18 -2
- package/lib/org/inbound/directedness.test.mjs +58 -0
- package/lib/org/inbound/index.mjs +8 -1
- package/lib/org/inbound/index.test.mjs +22 -0
- package/lib/org/mesh-directives.test.mjs +110 -0
- package/lib/org/mesh.mjs +61 -1
- package/lib/org/protocol.checksum +1 -1
- package/lib/org/protocol.mjs +52 -0
- package/lib/org/protocol.test.mjs +12 -1
- package/lib/org/registry.mjs +3 -2
- package/lib/org/tool-surface.mjs +120 -0
- package/lib/org/tool-surface.test.mjs +118 -5
- package/lib/prompts/parallelism.mjs +79 -0
- package/lib/prompts/parallelism.test.mjs +177 -0
- package/lib/security/external-content.mjs +1 -1
- package/lib/security/external-content.test.mjs +17 -0
- package/lib/session/config.mjs +137 -0
- package/lib/session/config.test.mjs +92 -0
- package/lib/session/feed-core.mjs +229 -0
- package/lib/session/feed-core.test.mjs +198 -0
- package/lib/session/first-run.mjs +126 -0
- package/lib/session/first-run.test.mjs +121 -0
- package/lib/session/frontdoor.mjs +266 -0
- package/lib/session/frontdoor.test.mjs +205 -0
- package/lib/session/handoffs.mjs +295 -0
- package/lib/session/handoffs.test.mjs +183 -0
- package/lib/session/identity.mjs +220 -0
- package/lib/session/identity.test.mjs +180 -0
- package/lib/session/inbox-claims.mjs +434 -0
- package/lib/session/inbox-claims.test.mjs +286 -0
- package/lib/session/launch-args.mjs +161 -0
- package/lib/session/launch-args.test.mjs +157 -0
- package/lib/session/liveness.mjs +174 -0
- package/lib/session/liveness.test.mjs +100 -0
- package/lib/session/status-summary.mjs +172 -0
- package/lib/session/status-summary.test.mjs +118 -0
- package/lib/session-permissions.mjs +39 -3
- package/lib/session-permissions.test.mjs +20 -0
- package/lib/setup/claude-probe.mjs +161 -24
- package/lib/setup/claude-probe.test.mjs +187 -0
- package/lib/setup/sections/learning.mjs +2 -1
- package/lib/setup/sections/model.mjs +104 -24
- package/lib/setup/sections/model.test.mjs +240 -0
- package/lib/setup/sections/org.mjs +27 -2
- package/lib/setup/sections/org.test.mjs +35 -2
- package/lib/setup/sections/verify.mjs +5 -0
- package/lib/setup/state.mjs +30 -10
- package/lib/setup/state.test.mjs +24 -1
- package/lib/singleton.js +11 -3
- package/lib/singleton.test.mjs +16 -0
- package/lib/subagents/lock.mjs +1 -1
- package/lib/telemetry/collect.mjs +270 -6
- package/lib/telemetry/collect.test.mjs +196 -1
- package/lib/upgrade/global-refresh.mjs +108 -0
- package/lib/upgrade/global-refresh.test.mjs +65 -0
- package/lib/upgrade/launchd-reconcile.mjs +327 -0
- package/lib/upgrade/launchd-reconcile.test.mjs +272 -0
- package/lib/upgrade/post-steps.mjs +151 -0
- package/lib/upgrade/post-steps.test.mjs +200 -0
- package/lib/upgrade/verify.mjs +215 -0
- package/lib/upgrade/verify.test.mjs +164 -0
- package/lib/voice/outbound.mjs +3 -2
- package/lib/voice/post-call-brief.mjs +2 -1
- package/lib/voice/session-rotation.mjs +6 -1
- package/lib/voice/session-rotation.test.mjs +114 -0
- package/package.json +3 -3
- package/plugins/maestro-skills/plugin.json +25 -1
- package/plugins/maestro-skills/skills/board-work.md +63 -0
- package/plugins/maestro-skills/skills/cohort-design.md +153 -0
- package/plugins/maestro-skills/skills/inbound-triage.md +80 -0
- package/plugins/maestro-skills/skills/main-session.md +102 -0
- package/plugins/maestro-skills/skills/peer-sessions.md +65 -0
- package/plugins/maestro-skills/skills/persona-discipline.md +75 -0
- package/plugins/maestro-skills/vendor/emilkowalski/LICENSE +21 -0
- package/plugins/maestro-skills/vendor/emilkowalski/UPSTREAM.json +70 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/animate/RECIPES.md +324 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/animate/SKILL.md +199 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/animation-vocabulary/SKILL.md +173 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/apple-design/SKILL.md +282 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/emil-design-eng/SKILL.md +674 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/find-animation-opportunities/SKILL.md +132 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/improve-animations/AUDIT.md +115 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/improve-animations/PLAN-TEMPLATE.md +73 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/improve-animations/SKILL.md +101 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/prototype/PICKER.md +197 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/prototype/SKILL.md +90 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/review-animations/SKILL.md +112 -0
- package/plugins/maestro-skills/vendor/emilkowalski/skills/review-animations/STANDARDS.md +187 -0
- package/plugins/maestro-skills/vendor/impeccable/LICENSE +191 -0
- package/plugins/maestro-skills/vendor/impeccable/NOTICE.md +11 -0
- package/plugins/maestro-skills/vendor/impeccable/SKILL.md +86 -0
- package/plugins/maestro-skills/vendor/impeccable/UPSTREAM.json +201 -0
- package/plugins/maestro-skills/vendor/impeccable/agents/impeccable-asset-producer.md +42 -0
- package/plugins/maestro-skills/vendor/impeccable/agents/impeccable-documenter.md +29 -0
- package/plugins/maestro-skills/vendor/impeccable/agents/impeccable-finish-reviewer.md +43 -0
- package/plugins/maestro-skills/vendor/impeccable/agents/impeccable-manual-edit-applier.md +97 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/adapt.md +312 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/adapt.native.md +58 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/android.md +46 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/animate.md +89 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/audit.md +136 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/audit.native.md +139 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/bolder.md +33 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/clarify.md +94 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/colorize.md +86 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/craft-floor.md +44 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/craft.md +5 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/critique.md +806 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/degraded/asset-producer.md +37 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/degraded/documenter.md +24 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/degraded/finish-reviewer.md +38 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/degraded/manual-edit-applier.md +92 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/delight.md +70 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/distill.md +111 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/doctor.md +54 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/document.md +416 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/extract.md +69 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/harden.md +336 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/hooks.md +111 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/init.md +131 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/ios.md +51 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/layout.md +84 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/live-setup.md +104 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/live.md +325 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/new-work.md +147 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/onboard.md +234 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/operate.md +61 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/optimize.md +258 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/overdrive.md +127 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/polish.md +105 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/quieter.md +99 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/routing.md +24 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/shape.md +59 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/typeset.md +80 -0
- package/plugins/maestro-skills/vendor/impeccable/reference/visualize.md +46 -0
- package/plugins/maestro-skills/vendor/taste-skill/LICENSE +21 -0
- package/plugins/maestro-skills/vendor/taste-skill/UPSTREAM.json +37 -0
- package/plugins/maestro-skills/vendor/taste-skill/skills/minimalist-skill/SKILL.md +85 -0
- package/plugins/maestro-skills/vendor/taste-skill/skills/redesign-skill/SKILL.md +178 -0
- package/plugins/maestro-skills/vendor/taste-skill/skills/soft-skill/SKILL.md +98 -0
- package/plugins/maestro-skills/vendor/taste-skill/skills/taste-skill/SKILL.md +1206 -0
- package/plugins/maestro-skills/vendor/unlazy/LICENSE +21 -0
- package/plugins/maestro-skills/vendor/unlazy/SECURITY.md +72 -0
- package/plugins/maestro-skills/vendor/unlazy/SKILL.md +104 -0
- package/plugins/maestro-skills/vendor/unlazy/UPSTREAM.json +94 -0
- package/plugins/maestro-skills/vendor/unlazy/references/dispatch.md +82 -0
- package/plugins/maestro-skills/vendor/unlazy/references/gates.md +149 -0
- package/plugins/maestro-skills/vendor/unlazy/references/method.md +49 -0
- package/plugins/maestro-skills/vendor/unlazy/references/orchestration.md +107 -0
- package/plugins/maestro-skills/vendor/unlazy/references/parallel.md +133 -0
- package/plugins/maestro-skills/vendor/unlazy/references/token-economy.md +48 -0
- package/plugins/maestro-skills/vendor/unlazy/scripts/dispatch-check.mjs +139 -0
- package/plugins/maestro-skills/vendor/unlazy/scripts/gate-check.mjs +960 -0
- package/plugins/maestro-skills/vendor/unlazy/scripts/gate-lint.mjs +245 -0
- package/plugins/maestro-skills/vendor/unlazy/scripts/lib/check-supervisor.mjs +46 -0
- package/plugins/maestro-skills/vendor/unlazy/scripts/lib/dispatch.mjs +293 -0
- package/plugins/maestro-skills/vendor/unlazy/scripts/lib/gates.mjs +953 -0
- package/plugins/maestro-skills/vendor/unlazy/scripts/lib/process-tree.mjs +161 -0
- package/plugins/maestro-skills/vendor/unlazy/scripts/lib/regex-worker.mjs +9 -0
- package/plugins/maestro-skills/vendor/unlazy/templates/PLAN.md +116 -0
- package/plugins/maestro-skills/vendor/unlazy/templates/gates-leaf.md +51 -0
- package/plugins/maestro-skills/vendor/unlazy/templates/gates-node.md +51 -0
- package/scaffold/CLAUDE.md +24 -0
- package/scripts/ci/check-durable-write-seam.mjs +147 -0
- package/scripts/ci/check-durable-write-seam.test.mjs +90 -0
- package/scripts/ci/check-skill-packs.mjs +388 -0
- package/scripts/ci/check-skill-packs.test.mjs +495 -0
- package/scripts/ci/check.mjs +6 -0
- package/scripts/collective/hook-runner.mjs +39 -4
- package/scripts/collective/hook-runner.test.mjs +85 -2
- package/scripts/daemon/agent-daemon-board-mine.test.mjs +96 -0
- package/scripts/daemon/agent-daemon-design.test.mjs +238 -0
- package/scripts/daemon/agent-daemon-frontdoor.test.mjs +60 -0
- package/scripts/daemon/agent-daemon.mjs +249 -10
- package/scripts/daemon/agent-daemon.test.mjs +73 -0
- package/scripts/daemon/assurance-e2e.test.mjs +141 -6
- package/scripts/daemon/assurance.mjs +461 -37
- package/scripts/daemon/assurance.test.mjs +408 -43
- package/scripts/daemon/cadence-consumer-frontdoor.test.mjs +393 -0
- package/scripts/daemon/cadence-consumer.mjs +289 -89
- package/scripts/daemon/cadence-handlers.mjs +53 -0
- package/scripts/daemon/classifier.mjs +1 -1
- package/scripts/daemon/dispatcher-resume.test.mjs +166 -0
- package/scripts/daemon/dispatcher.mjs +127 -19
- package/scripts/daemon/health.mjs +12 -1
- package/scripts/daemon/inbox-deferral-session.test.mjs +49 -0
- package/scripts/daemon/inbox-deferral.mjs +6 -0
- package/scripts/daemon/lib/self-echo.mjs +201 -0
- package/scripts/daemon/lib/self-echo.test.mjs +153 -0
- package/scripts/daemon/maestro-daemon.mjs +3 -0
- package/scripts/daemon/prompt-builder.mjs +19 -3
- package/scripts/daemon/responder.mjs +51 -40
- package/scripts/daemon/sdk-version.mjs +51 -0
- package/scripts/daemon/sdk-version.test.mjs +31 -0
- package/scripts/hooks/pre-send-audit.sh +97 -4
- package/scripts/hooks/pre-send-audit.test.mjs +140 -1
- package/scripts/local-triggers/autoupdate.sh +243 -19
- package/scripts/local-triggers/autoupdate.test.mjs +518 -0
- package/scripts/local-triggers/generate-plists.sh +24 -1
- package/scripts/local-triggers/generate-plists.test.mjs +49 -11
- package/scripts/org/send-orgmail.first-contact.test.mjs +102 -0
- package/scripts/org/send-orgmail.mjs +27 -3
- package/scripts/poller/inbox-privilege-injection.test.mjs +167 -0
- package/scripts/poller/slack-poller.mjs +13 -1
- package/scripts/poller/utils.mjs +46 -1
- package/scripts/poller-launchd/install.sh +19 -11
- package/scripts/poller-launchd/install.test.mjs +243 -0
- package/scripts/poller-launchd/launchd-poller-wrapper.sh +92 -0
- package/scripts/poller-launchd/migrate.sh +66 -0
- package/scripts/poller-launchd/poller.plist.template +4 -2
- package/scripts/session/feed.mjs +237 -0
- package/scripts/session/feed.test.mjs +196 -0
- package/scripts/session/supervisor-sh.test.mjs +218 -0
- package/scripts/session/supervisor.mjs +328 -0
- package/scripts/session/supervisor.sh +141 -0
- package/scripts/session/supervisor.test.mjs +482 -0
- package/scripts/setup/configure-macos.sh +250 -55
- package/scripts/setup/configure-macos.test.mjs +306 -0
- package/scripts/setup/init-agent.sh +112 -7
- package/scripts/setup/init-agent.test.mjs +220 -1
- package/scripts/vendor/skill-packs.mjs +354 -0
- package/scripts/vendor/sync-skill-packs.mjs +242 -0
- package/scripts/vendor/sync-skill-packs.test.mjs +103 -0
- package/scripts/watchdog/memory-watchdog.sh +37 -1
- package/scripts/watchdog/memory-watchdog.test.mjs +64 -0
- package/scripts/setup/boot-claude-session.sh +0 -94
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/cli/board.mjs — `maestro board mine|track|claim|complete`.
|
|
3
|
+
*
|
|
4
|
+
* The session-side CLI over the board client (design spec 2026-09-08 §3.5):
|
|
5
|
+
*
|
|
6
|
+
* maestro board mine [--json] my items across every board
|
|
7
|
+
* maestro board track <inbox-id> --stage <s> [--title …] [--why …] [--note …]
|
|
8
|
+
* file/advance an inbound ask on its board
|
|
9
|
+
* maestro board claim <itemId> claim a ready item (server resolves races)
|
|
10
|
+
* maestro board complete <itemId> [--note …] close a claimed item
|
|
11
|
+
*
|
|
12
|
+
* `track` reads the inbox item under state/inbox/cohort/ by id (live,
|
|
13
|
+
* .dispatched or .processed) and lets the SERVER derive the board from the
|
|
14
|
+
* message identity — the same seam the daemon's work-ledger uses, so the
|
|
15
|
+
* session and the daemon land on the same row. `mine` reads live and falls
|
|
16
|
+
* back to the daemon's 5-minute cache (state/org/board-mine.json) when the
|
|
17
|
+
* live read is empty or the org is off.
|
|
18
|
+
*
|
|
19
|
+
* `runBoard(argv, deps)` is the testable core (every I/O injectable);
|
|
20
|
+
* `boardCmd(argv)` is the bin entry that resolves the agent root and config.
|
|
21
|
+
* Expected failures are printed and become exit 1; nothing throws.
|
|
22
|
+
*
|
|
23
|
+
* @module lib/cli/board
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
"use strict";
|
|
27
|
+
|
|
28
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
29
|
+
import { join } from "node:path";
|
|
30
|
+
import { loadOrgConfig, configFromAgent, isEnabled, listMine, trackWork, claimItem, completeItem } from "../org/client.mjs";
|
|
31
|
+
import { WORK_STAGES, cohortChannelId, cohortMessageId } from "../org/work-ledger.mjs";
|
|
32
|
+
|
|
33
|
+
/** The ladder `track` accepts on the command line (the ledger's, minus nothing). */
|
|
34
|
+
export const TRACK_STAGES = WORK_STAGES;
|
|
35
|
+
|
|
36
|
+
export function usage() {
|
|
37
|
+
return [
|
|
38
|
+
"Usage:",
|
|
39
|
+
" maestro board mine [--json] Items assigned to you (or awaiting your review) across every board",
|
|
40
|
+
" maestro board track <inbox-id> --stage <stage> [--title T] [--why W] [--note N]",
|
|
41
|
+
` File or advance an inbound ask on its board. stage: ${TRACK_STAGES.join("|")}`,
|
|
42
|
+
" maestro board claim <itemId> Claim a ready board item",
|
|
43
|
+
" maestro board complete <itemId> [--note N] Close a claimed item (note becomes proof.note)",
|
|
44
|
+
"",
|
|
45
|
+
"The inbox id is the `id` of the item under state/inbox/cohort/ (e.g. cohort-<messageId>),",
|
|
46
|
+
"as printed by `maestro inbox list`. The board itself is derived server-side from the message.",
|
|
47
|
+
].join("\n");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Parse argv → {sub, id, json, stage, title, why, note, help, error}. Pure. */
|
|
51
|
+
export function parseBoardArgs(argv) {
|
|
52
|
+
const args = Array.isArray(argv) ? argv.map(String) : [];
|
|
53
|
+
const out = { sub: null, id: null, json: false, stage: null, title: null, why: null, note: null, help: false, error: null };
|
|
54
|
+
if (args.length === 0 || args.includes("--help") || args.includes("-h")) { out.help = true; return out; }
|
|
55
|
+
out.sub = args[0];
|
|
56
|
+
const rest = args.slice(1);
|
|
57
|
+
const positional = [];
|
|
58
|
+
for (let i = 0; i < rest.length; i++) {
|
|
59
|
+
const a = rest[i];
|
|
60
|
+
const eq = a.indexOf("=");
|
|
61
|
+
const key = a.startsWith("--") && eq > 0 ? a.slice(0, eq) : a;
|
|
62
|
+
const inline = a.startsWith("--") && eq > 0 ? a.slice(eq + 1) : undefined;
|
|
63
|
+
const take = () => (inline !== undefined ? inline : rest[++i]);
|
|
64
|
+
if (key === "--json") out.json = true;
|
|
65
|
+
else if (key === "--stage") out.stage = take() ?? null;
|
|
66
|
+
else if (key === "--title") out.title = take() ?? null;
|
|
67
|
+
else if (key === "--why") out.why = take() ?? null;
|
|
68
|
+
else if (key === "--note") out.note = take() ?? null;
|
|
69
|
+
else if (a.startsWith("-")) { out.error = `unknown flag ${a}`; return out; }
|
|
70
|
+
else positional.push(a);
|
|
71
|
+
}
|
|
72
|
+
out.id = positional[0] || null;
|
|
73
|
+
switch (out.sub) {
|
|
74
|
+
case "mine":
|
|
75
|
+
break;
|
|
76
|
+
case "track":
|
|
77
|
+
if (!out.id) out.error = "track needs an <inbox-id>";
|
|
78
|
+
else if (!out.stage) out.error = "track needs --stage";
|
|
79
|
+
else if (!TRACK_STAGES.includes(out.stage)) out.error = `--stage must be one of ${TRACK_STAGES.join("|")}`;
|
|
80
|
+
break;
|
|
81
|
+
case "claim":
|
|
82
|
+
case "complete":
|
|
83
|
+
if (!out.id) out.error = `${out.sub} needs an <itemId>`;
|
|
84
|
+
break;
|
|
85
|
+
default:
|
|
86
|
+
out.error = `unknown board command: ${out.sub}`;
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Pick the inbox file that carries `id` from a directory listing. Prefers the
|
|
93
|
+
* live `.yaml`, then `.dispatched` (in flight), then `.processed` (done — a
|
|
94
|
+
* `track --stage done` after the reply is the common case). The id must match
|
|
95
|
+
* as a whole token (`-<id>.yaml`), so `cohort-m1` never picks `cohort-m10`.
|
|
96
|
+
* @param {string[]} files
|
|
97
|
+
* @param {string} id
|
|
98
|
+
* @returns {string|null}
|
|
99
|
+
*/
|
|
100
|
+
export function findInboxItemFile(files, id) {
|
|
101
|
+
const needle = String(id || "");
|
|
102
|
+
if (!needle) return null;
|
|
103
|
+
const list = Array.isArray(files) ? files : [];
|
|
104
|
+
const hit = (suffix) => list.find((f) => f.endsWith(`-${needle}.yaml${suffix}`) || f === `${needle}.yaml${suffix}`) || null;
|
|
105
|
+
return hit("") || hit(".dispatched") || hit(".deferred") || hit(".processed") || hit(".processed-bundled");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The board.track params for an inbox item. Identity (channel + message id)
|
|
110
|
+
* comes from the item exactly as the daemon's ledger derives it, so the
|
|
111
|
+
* session and the daemon compute the same server-side row key. Pure.
|
|
112
|
+
* @returns {{ok:true, params:object, idempotencyKey:string}|{ok:false, error:string}}
|
|
113
|
+
*/
|
|
114
|
+
export function buildTrackParams(item, o = {}) {
|
|
115
|
+
const stage = String(o.stage || "");
|
|
116
|
+
if (!TRACK_STAGES.includes(stage)) return { ok: false, error: `stage must be one of ${TRACK_STAGES.join("|")}` };
|
|
117
|
+
const channelId = cohortChannelId(item);
|
|
118
|
+
if (!channelId) return { ok: false, error: "not a Cohort conversation — only Cohort asks have a board to land on" };
|
|
119
|
+
const messageId = cohortMessageId(item);
|
|
120
|
+
if (!messageId) return { ok: false, error: "inbox item carries no message id" };
|
|
121
|
+
const params = { service: "cohort", channelId, messageId, stage };
|
|
122
|
+
const body = item && (item.content || item.text || item.subject);
|
|
123
|
+
if (body) params.body = String(body).slice(0, 20000);
|
|
124
|
+
if (item && item.priority_signals && item.priority_signals.mentions_agent) params.directed = true;
|
|
125
|
+
if (o.title) params.title = String(o.title).slice(0, 200);
|
|
126
|
+
if (o.why) params.why = String(o.why).slice(0, 1000);
|
|
127
|
+
if (o.note) params.note = String(o.note).slice(0, 4000);
|
|
128
|
+
return { ok: true, params, idempotencyKey: `board.track:${channelId}:${messageId}:${stage}` };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** One line per item for a terminal. */
|
|
132
|
+
export function formatMine(items, o = {}) {
|
|
133
|
+
const list = Array.isArray(items) ? items : [];
|
|
134
|
+
if (list.length === 0) return o.cached ? "Nothing assigned to you (cached)." : "Nothing assigned to you across any board.";
|
|
135
|
+
const lines = list.map((it) => {
|
|
136
|
+
const pri = it.priority ? String(it.priority).padEnd(2) : " ";
|
|
137
|
+
const col = it.col || it.stage || "?";
|
|
138
|
+
const board = it.boardName || it.boardId || "";
|
|
139
|
+
const due = it.dueAt ? ` due ${String(it.dueAt).slice(0, 10)}` : "";
|
|
140
|
+
return `${pri} ${it.itemId || it.id || "?"} [${col}] ${it.title || "(untitled)"}${board ? ` — ${board}` : ""}${due}`;
|
|
141
|
+
});
|
|
142
|
+
if (o.cached) lines.push(`(cached ${o.fetchedAt || "earlier"} by the daemon; the live read was empty)`);
|
|
143
|
+
return lines.join("\n");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function readBoardMineCache(agentRoot) {
|
|
147
|
+
try {
|
|
148
|
+
const p = join(String(agentRoot || ""), "state", "org", "board-mine.json");
|
|
149
|
+
if (!existsSync(p)) return null;
|
|
150
|
+
const doc = JSON.parse(readFileSync(p, "utf8"));
|
|
151
|
+
const items = Array.isArray(doc) ? doc : doc && Array.isArray(doc.items) ? doc.items : null;
|
|
152
|
+
if (!items) return null;
|
|
153
|
+
// The daemon writes {ts, items} (lib/org/board-mine-cache.mjs); fetchedAt is the earlier spelling.
|
|
154
|
+
const fetchedAt = doc && typeof doc.fetchedAt === "string" ? doc.fetchedAt : doc && typeof doc.ts === "string" ? doc.ts : null;
|
|
155
|
+
return { items, fetchedAt };
|
|
156
|
+
} catch {
|
|
157
|
+
return null; // a corrupt cache is the same as no cache
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Load + parse an inbox item by id. Uses the poller's own YAML reader.
|
|
163
|
+
*
|
|
164
|
+
* The daemon retires items by RENAME (.yaml → .yaml.dispatched → .processed),
|
|
165
|
+
* and `board track --stage done` right after a reply is exactly when that
|
|
166
|
+
* happens — so a listing can name a file the read no longer finds. An ENOENT
|
|
167
|
+
* on the read re-lists (a few times) instead of surfacing as an error; an item
|
|
168
|
+
* that is gone for good is the ordinary "not found".
|
|
169
|
+
*/
|
|
170
|
+
async function loadInboxItem(agentRoot, id, deps) {
|
|
171
|
+
const dir = join(String(agentRoot || ""), "state", "inbox", "cohort");
|
|
172
|
+
const list = deps.readdirImpl || ((d) => (existsSync(d) ? readdirSync(d) : []));
|
|
173
|
+
const read = deps.readFileImpl || ((p) => readFileSync(p, "utf8"));
|
|
174
|
+
const parse = deps.parseInboxItem || (await import("../../scripts/poller/inbox-scan-poller.mjs")).parseInboxItemYaml;
|
|
175
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
176
|
+
let files = [];
|
|
177
|
+
try {
|
|
178
|
+
files = list(dir) || [];
|
|
179
|
+
} catch {
|
|
180
|
+
files = []; // unreadable inbox dir → "not found" below
|
|
181
|
+
}
|
|
182
|
+
const file = findInboxItemFile(files, id);
|
|
183
|
+
if (!file) return null;
|
|
184
|
+
let text;
|
|
185
|
+
try {
|
|
186
|
+
text = read(join(dir, file));
|
|
187
|
+
} catch (err) {
|
|
188
|
+
if (err && err.code === "ENOENT") continue; // renamed under us: re-list
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
const item = parse(text);
|
|
192
|
+
if (item && !item.id) item.id = id;
|
|
193
|
+
return item;
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function fmtErr(frame) {
|
|
199
|
+
const e = frame && frame.error ? frame.error : null;
|
|
200
|
+
return e ? `${e.code || "error"}: ${e.message || ""}`.trim() : "no response";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The testable core. deps: { agentRoot, cfg, write, listMineImpl, trackImpl,
|
|
205
|
+
* claimImpl, completeImpl, fetchImpl, parseInboxItem, readdirImpl, readFileImpl }.
|
|
206
|
+
* @returns {Promise<{code:number}>}
|
|
207
|
+
*/
|
|
208
|
+
export async function runBoard(argv, deps = {}) {
|
|
209
|
+
const write = typeof deps.write === "function" ? deps.write : (s) => process.stdout.write(`${s}\n`);
|
|
210
|
+
const p = parseBoardArgs(argv);
|
|
211
|
+
if (p.help) { write(usage()); return { code: 0 }; }
|
|
212
|
+
if (p.error) { write(`error: ${p.error}\n\n${usage()}`); return { code: 1 }; }
|
|
213
|
+
const agentRoot = deps.agentRoot || process.cwd();
|
|
214
|
+
const cfg = deps.cfg || loadOrgConfig(agentRoot);
|
|
215
|
+
const enabled = isEnabled(cfg);
|
|
216
|
+
const conn = enabled ? configFromAgent(cfg) : { base: "", token: "", orgId: "" };
|
|
217
|
+
const callOpts = { base: conn.base, token: conn.token, orgId: conn.orgId, fetchImpl: deps.fetchImpl };
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
if (p.sub === "mine") {
|
|
221
|
+
let items = [];
|
|
222
|
+
if (enabled) items = await (deps.listMineImpl || listMine)(callOpts);
|
|
223
|
+
let cached = false;
|
|
224
|
+
let fetchedAt = null;
|
|
225
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
226
|
+
const cache = readBoardMineCache(agentRoot);
|
|
227
|
+
if (cache && cache.items.length > 0) { items = cache.items; cached = true; fetchedAt = cache.fetchedAt; }
|
|
228
|
+
else items = [];
|
|
229
|
+
}
|
|
230
|
+
write(p.json ? JSON.stringify(items, null, 2) : formatMine(items, { cached, fetchedAt }));
|
|
231
|
+
return { code: 0 };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (!enabled) { write("error: the org (Cohort) is not enabled for this agent — run `maestro setup --only org`."); return { code: 1 }; }
|
|
235
|
+
|
|
236
|
+
if (p.sub === "track") {
|
|
237
|
+
const item = await loadInboxItem(agentRoot, p.id, deps);
|
|
238
|
+
if (!item) { write(`error: no inbox item ${p.id} under state/inbox/cohort/ (see \`maestro inbox list\`)`); return { code: 1 }; }
|
|
239
|
+
const built = buildTrackParams(item, { stage: p.stage, title: p.title, why: p.why, note: p.note });
|
|
240
|
+
if (!built.ok) { write(`error: ${built.error}`); return { code: 1 }; }
|
|
241
|
+
const frame = await (deps.trackImpl || trackWork)(built.params, { ...callOpts, idempotencyKey: built.idempotencyKey });
|
|
242
|
+
if (!frame || !frame.ok) { write(`error: board.track failed — ${fmtErr(frame)}`); return { code: 1 }; }
|
|
243
|
+
const r = frame.result || {};
|
|
244
|
+
write(p.json ? JSON.stringify(r, null, 2) : `tracked ${p.stage}: task ${r.taskId || "?"}${r.col ? ` [${r.col}]` : ""}${r.created ? " (opened)" : ""}${r.moved ? " (moved)" : ""}`);
|
|
245
|
+
return { code: 0 };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (p.sub === "claim") {
|
|
249
|
+
const frame = await (deps.claimImpl || claimItem)({ itemId: p.id }, { ...callOpts, idempotencyKey: `board.claim:${p.id}` });
|
|
250
|
+
if (!frame || !frame.ok) { write(`error: board.claim failed — ${fmtErr(frame)}`); return { code: 1 }; }
|
|
251
|
+
write(p.json ? JSON.stringify(frame.result || {}, null, 2) : `claimed ${p.id}`);
|
|
252
|
+
return { code: 0 };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (p.sub === "complete") {
|
|
256
|
+
const params = { itemId: p.id };
|
|
257
|
+
if (p.note) params.proof = { note: String(p.note) };
|
|
258
|
+
const frame = await (deps.completeImpl || completeItem)(params, { ...callOpts, idempotencyKey: `board.complete:${p.id}` });
|
|
259
|
+
if (!frame || !frame.ok) { write(`error: board.complete failed — ${fmtErr(frame)}`); return { code: 1 }; }
|
|
260
|
+
write(p.json ? JSON.stringify(frame.result || {}, null, 2) : `completed ${p.id}`);
|
|
261
|
+
return { code: 0 };
|
|
262
|
+
}
|
|
263
|
+
} catch (err) {
|
|
264
|
+
write(`error: ${err && err.message ? err.message : String(err)}`);
|
|
265
|
+
return { code: 1 };
|
|
266
|
+
}
|
|
267
|
+
write(usage());
|
|
268
|
+
return { code: 1 };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** bin entry: resolve the agent root (env → walk → machine pointer) and run. */
|
|
272
|
+
export async function boardCmd(argv) {
|
|
273
|
+
let agentRoot = null;
|
|
274
|
+
try {
|
|
275
|
+
const { resolveAgentRoot } = await import("../collective/config.mjs");
|
|
276
|
+
agentRoot = resolveAgentRoot(process.cwd());
|
|
277
|
+
} catch {
|
|
278
|
+
agentRoot = null; // fall through to cwd
|
|
279
|
+
}
|
|
280
|
+
const r = await runBoard(argv, { agentRoot: agentRoot || process.cwd() });
|
|
281
|
+
process.exitCode = r.code;
|
|
282
|
+
return r;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export default { runBoard, boardCmd, parseBoardArgs, findInboxItemFile, buildTrackParams, formatMine, usage, TRACK_STAGES };
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* board.test.mjs — `maestro board mine|track|claim|complete`.
|
|
3
|
+
* Run: node --test lib/cli/board.test.mjs
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
import { test } from "node:test";
|
|
8
|
+
import assert from "node:assert/strict";
|
|
9
|
+
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
|
|
14
|
+
import { parseBoardArgs, findInboxItemFile, buildTrackParams, runBoard, formatMine, usage } from "./board.mjs";
|
|
15
|
+
|
|
16
|
+
const CFG = { org: { cohort: { enabled: true, base: "https://org.example", orgId: "acme", token: "nlk_secret" } } };
|
|
17
|
+
|
|
18
|
+
test("parseBoardArgs: subcommands, flags, errors", () => {
|
|
19
|
+
assert.deepEqual(parseBoardArgs(["mine"]).sub, "mine");
|
|
20
|
+
assert.equal(parseBoardArgs(["mine", "--json"]).json, true);
|
|
21
|
+
const t = parseBoardArgs(["track", "cohort-m1", "--stage", "accepted", "--title", "Build the deck", "--why", "asked in DM"]);
|
|
22
|
+
assert.equal(t.sub, "track");
|
|
23
|
+
assert.equal(t.id, "cohort-m1");
|
|
24
|
+
assert.equal(t.stage, "accepted");
|
|
25
|
+
assert.equal(t.title, "Build the deck");
|
|
26
|
+
assert.equal(t.why, "asked in DM");
|
|
27
|
+
assert.equal(parseBoardArgs(["track", "cohort-m1", "--stage=done"]).stage, "done");
|
|
28
|
+
assert.equal(parseBoardArgs(["claim", "item_1"]).id, "item_1");
|
|
29
|
+
const c = parseBoardArgs(["complete", "item_1", "--note", "shipped"]);
|
|
30
|
+
assert.equal(c.sub, "complete");
|
|
31
|
+
assert.equal(c.note, "shipped");
|
|
32
|
+
assert.equal(parseBoardArgs([]).help, true);
|
|
33
|
+
assert.equal(parseBoardArgs(["--help"]).help, true);
|
|
34
|
+
assert.match(parseBoardArgs(["track"]).error, /inbox-id/);
|
|
35
|
+
assert.match(parseBoardArgs(["track", "x"]).error, /--stage/);
|
|
36
|
+
assert.match(parseBoardArgs(["track", "x", "--stage", "later"]).error, /accepted\|working\|blocked\|review\|done/);
|
|
37
|
+
assert.match(parseBoardArgs(["claim"]).error, /itemId/);
|
|
38
|
+
assert.match(parseBoardArgs(["frobnicate"]).error, /unknown/i);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("findInboxItemFile: prefers live .yaml, then .dispatched, then .processed; null when absent", () => {
|
|
42
|
+
const files = ["2026-09-08T10-00-00-cohort-m1.yaml.processed", "2026-09-08T10-00-00-cohort-m1.yaml.dispatched", "2026-09-08T10-00-00-cohort-m2.yaml"];
|
|
43
|
+
assert.equal(findInboxItemFile(files, "cohort-m1"), "2026-09-08T10-00-00-cohort-m1.yaml.dispatched");
|
|
44
|
+
assert.equal(findInboxItemFile(files, "cohort-m2"), "2026-09-08T10-00-00-cohort-m2.yaml");
|
|
45
|
+
assert.equal(findInboxItemFile(["2026-09-08T10-00-00-cohort-m1.yaml.processed"], "cohort-m1"), "2026-09-08T10-00-00-cohort-m1.yaml.processed");
|
|
46
|
+
assert.equal(findInboxItemFile(files, "cohort-m9"), null);
|
|
47
|
+
assert.equal(findInboxItemFile(files, ""), null);
|
|
48
|
+
// Does not match a longer id by substring (m1 vs m10).
|
|
49
|
+
assert.equal(findInboxItemFile(["x-cohort-m10.yaml"], "cohort-m1"), null);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("buildTrackParams: identity from the inbox item, stage/title/why passthrough, non-cohort rejected", () => {
|
|
53
|
+
const item = { id: "cohort-m1", service: "cohort", cohort_channel_id: "C1", raw_ref: "cohort:messaging:m1:7", content: "please build the deck" };
|
|
54
|
+
const r = buildTrackParams(item, { stage: "accepted", title: "Build the deck", why: "asked in DM" });
|
|
55
|
+
assert.equal(r.ok, true);
|
|
56
|
+
assert.equal(r.params.service, "cohort");
|
|
57
|
+
assert.equal(r.params.channelId, "C1");
|
|
58
|
+
assert.equal(r.params.messageId, "m1");
|
|
59
|
+
assert.equal(r.params.stage, "accepted");
|
|
60
|
+
assert.equal(r.params.title, "Build the deck");
|
|
61
|
+
assert.equal(r.params.why, "asked in DM");
|
|
62
|
+
assert.equal(r.params.body, "please build the deck");
|
|
63
|
+
assert.equal(r.idempotencyKey, "board.track:C1:m1:accepted");
|
|
64
|
+
const slack = buildTrackParams({ id: "slack-1", service: "slack", channel_id: "C9" }, { stage: "accepted" });
|
|
65
|
+
assert.equal(slack.ok, false);
|
|
66
|
+
assert.match(slack.error, /cohort/i);
|
|
67
|
+
const noStage = buildTrackParams(item, { stage: "later" });
|
|
68
|
+
assert.equal(noStage.ok, false);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("formatMine: one line per item, priority/board/col visible; empty → a plain sentence", () => {
|
|
72
|
+
const out = formatMine([
|
|
73
|
+
{ itemId: "i1", title: "Build the deck", boardName: "Sales", col: "doing", priority: "P1", dueAt: "2026-09-10T00:00:00Z" },
|
|
74
|
+
{ itemId: "i2", title: "Reply to Marc", boardName: "DM: Marc", col: "todo", priority: "P2" },
|
|
75
|
+
]);
|
|
76
|
+
const lines = out.split("\n");
|
|
77
|
+
assert.equal(lines.length, 2);
|
|
78
|
+
assert.match(lines[0], /P1/);
|
|
79
|
+
assert.match(lines[0], /Build the deck/);
|
|
80
|
+
assert.match(lines[0], /Sales/);
|
|
81
|
+
assert.match(lines[0], /doing/);
|
|
82
|
+
assert.match(lines[0], /i1/);
|
|
83
|
+
assert.match(formatMine([]), /nothing assigned|no items/i);
|
|
84
|
+
assert.match(usage(), /maestro board mine/);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("runBoard mine: live read via listMineImpl; --json prints the array; falls back to the cache when the read is empty and the cache exists", async () => {
|
|
88
|
+
const root = mkdtempSync(join(tmpdir(), "board-cli-"));
|
|
89
|
+
try {
|
|
90
|
+
const out = [];
|
|
91
|
+
const deps = { agentRoot: root, cfg: CFG, listMineImpl: async () => [{ itemId: "i1", title: "Deck", col: "doing", priority: "P1" }], write: (s) => out.push(s) };
|
|
92
|
+
const r = await runBoard(["mine"], deps);
|
|
93
|
+
assert.equal(r.code, 0);
|
|
94
|
+
assert.match(out.join("\n"), /Deck/);
|
|
95
|
+
out.length = 0;
|
|
96
|
+
const rj = await runBoard(["mine", "--json"], deps);
|
|
97
|
+
assert.equal(rj.code, 0);
|
|
98
|
+
assert.deepEqual(JSON.parse(out.join("")), [{ itemId: "i1", title: "Deck", col: "doing", priority: "P1" }]);
|
|
99
|
+
// Empty live read + a daemon cache → the cache (marked as such).
|
|
100
|
+
mkdirSync(join(root, "state", "org"), { recursive: true });
|
|
101
|
+
writeFileSync(join(root, "state", "org", "board-mine.json"), JSON.stringify({ items: [{ itemId: "c1", title: "Cached item" }], fetchedAt: "2026-09-08T11:00:00Z" }));
|
|
102
|
+
out.length = 0;
|
|
103
|
+
const rc = await runBoard(["mine"], { ...deps, listMineImpl: async () => [] });
|
|
104
|
+
assert.equal(rc.code, 0);
|
|
105
|
+
assert.match(out.join("\n"), /Cached item/);
|
|
106
|
+
assert.match(out.join("\n"), /cached/i);
|
|
107
|
+
// Org disabled → [] and exit 0 (fail-open), never a crash.
|
|
108
|
+
out.length = 0;
|
|
109
|
+
const off = await runBoard(["mine", "--json"], { ...deps, cfg: { org: { cohort: { enabled: false } } }, listMineImpl: async () => { throw new Error("must not be called"); } });
|
|
110
|
+
assert.equal(off.code, 0);
|
|
111
|
+
assert.deepEqual(JSON.parse(out.join("")), [{ itemId: "c1", title: "Cached item" }], "cache still served when the org is off");
|
|
112
|
+
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("runBoard track: reads the inbox item by id from state/inbox/cohort, calls board.track with stage/title/why", async () => {
|
|
116
|
+
const root = mkdtempSync(join(tmpdir(), "board-cli-"));
|
|
117
|
+
try {
|
|
118
|
+
const dir = join(root, "state", "inbox", "cohort");
|
|
119
|
+
mkdirSync(dir, { recursive: true });
|
|
120
|
+
writeFileSync(join(dir, "2026-09-08T10-00-00-cohort-m1.yaml.dispatched"), [
|
|
121
|
+
"id: cohort-m1",
|
|
122
|
+
"service: cohort",
|
|
123
|
+
"channel_id: C1",
|
|
124
|
+
"raw_ref: cohort:messaging:m1:7",
|
|
125
|
+
"sender: Marc",
|
|
126
|
+
"content: |",
|
|
127
|
+
" please build the deck",
|
|
128
|
+
"",
|
|
129
|
+
].join("\n"));
|
|
130
|
+
const calls = [];
|
|
131
|
+
const out = [];
|
|
132
|
+
const deps = {
|
|
133
|
+
agentRoot: root, cfg: CFG, write: (s) => out.push(s),
|
|
134
|
+
trackImpl: async (params, o) => { calls.push({ params, o }); return { ok: true, result: { tracked: true, taskId: "t1", col: "todo", created: true } }; },
|
|
135
|
+
};
|
|
136
|
+
const r = await runBoard(["track", "cohort-m1", "--stage", "accepted", "--title", "Build the deck", "--why", "asked in DM"], deps);
|
|
137
|
+
assert.equal(r.code, 0, out.join("\n"));
|
|
138
|
+
assert.equal(calls.length, 1);
|
|
139
|
+
assert.equal(calls[0].params.channelId, "C1");
|
|
140
|
+
assert.equal(calls[0].params.messageId, "m1");
|
|
141
|
+
assert.equal(calls[0].params.stage, "accepted");
|
|
142
|
+
assert.equal(calls[0].params.title, "Build the deck");
|
|
143
|
+
assert.equal(calls[0].params.why, "asked in DM");
|
|
144
|
+
assert.equal(calls[0].o.idempotencyKey, "board.track:C1:m1:accepted");
|
|
145
|
+
assert.equal(calls[0].o.base, "https://org.example");
|
|
146
|
+
assert.match(out.join("\n"), /t1/);
|
|
147
|
+
// Unknown id → exit 1 with a clear message, no call.
|
|
148
|
+
out.length = 0;
|
|
149
|
+
const miss = await runBoard(["track", "cohort-nope", "--stage", "done"], deps);
|
|
150
|
+
assert.equal(miss.code, 1);
|
|
151
|
+
assert.match(out.join("\n"), /cohort-nope/);
|
|
152
|
+
assert.equal(calls.length, 1);
|
|
153
|
+
// Server error frame → exit 1, message shown.
|
|
154
|
+
const err = await runBoard(["track", "cohort-m1", "--stage", "done"], { ...deps, trackImpl: async () => ({ ok: false, error: { code: "FORBIDDEN_SCOPE", message: "nope" } }) });
|
|
155
|
+
assert.equal(err.code, 1);
|
|
156
|
+
assert.match(out.join("\n"), /FORBIDDEN_SCOPE/);
|
|
157
|
+
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("runBoard claim/complete: route to the client with a stable idempotency key; --note wraps into proof.note", async () => {
|
|
161
|
+
const calls = [];
|
|
162
|
+
const out = [];
|
|
163
|
+
const deps = {
|
|
164
|
+
agentRoot: "/tmp/none", cfg: CFG, write: (s) => out.push(s),
|
|
165
|
+
claimImpl: async (params, o) => { calls.push({ name: "claim", params, o }); return { ok: true, result: { itemId: params.itemId, leaseToken: "L" } }; },
|
|
166
|
+
completeImpl: async (params, o) => { calls.push({ name: "complete", params, o }); return { ok: true, result: { itemId: params.itemId, status: "done" } }; },
|
|
167
|
+
};
|
|
168
|
+
assert.equal((await runBoard(["claim", "item_1"], deps)).code, 0);
|
|
169
|
+
assert.equal(calls[0].params.itemId, "item_1");
|
|
170
|
+
assert.equal(calls[0].o.idempotencyKey, "board.claim:item_1");
|
|
171
|
+
assert.equal((await runBoard(["complete", "item_1", "--note", "shipped v2"], deps)).code, 0);
|
|
172
|
+
assert.deepEqual(calls[1].params, { itemId: "item_1", proof: { note: "shipped v2" } });
|
|
173
|
+
assert.equal((await runBoard(["complete", "item_2"], deps)).code, 0);
|
|
174
|
+
assert.deepEqual(calls[2].params, { itemId: "item_2" });
|
|
175
|
+
// A CONFLICT (someone else won the race) is exit 1 and says so.
|
|
176
|
+
const lost = await runBoard(["claim", "item_1"], { ...deps, claimImpl: async () => ({ ok: false, error: { code: "CONFLICT", message: "already claimed" } }) });
|
|
177
|
+
assert.equal(lost.code, 1);
|
|
178
|
+
assert.match(out.join("\n"), /CONFLICT/);
|
|
179
|
+
// Org disabled → exit 1 with a reason, never a throw.
|
|
180
|
+
const off = await runBoard(["claim", "item_1"], { ...deps, cfg: { org: { cohort: { enabled: false } } } });
|
|
181
|
+
assert.equal(off.code, 1);
|
|
182
|
+
assert.match(out.join("\n"), /org|cohort/i);
|
|
183
|
+
// --help → exit 0 + usage.
|
|
184
|
+
out.length = 0;
|
|
185
|
+
assert.equal((await runBoard(["--help"], deps)).code, 0);
|
|
186
|
+
assert.match(out.join("\n"), /maestro board/);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("bin: `maestro board --help` dispatches to lib/cli/board and exits 0", () => {
|
|
190
|
+
const cli = new URL("../../bin/maestro.mjs", import.meta.url).pathname;
|
|
191
|
+
const r = spawnSync(process.execPath, [cli, "board", "--help"], { encoding: "utf8" });
|
|
192
|
+
assert.equal(r.status, 0, r.stderr);
|
|
193
|
+
assert.match(r.stdout, /maestro board mine/);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("runBoard track: an inbox item renamed by the daemon between the directory listing and the read (.yaml → .dispatched) is re-listed, not reported as ENOENT", async () => {
|
|
197
|
+
const yaml = ["id: cohort-m9", "service: cohort", "channel_id: C9", "raw_ref: cohort:messaging:m9:1", "content: hi", ""].join("\n");
|
|
198
|
+
let listings = 0;
|
|
199
|
+
let reads = 0;
|
|
200
|
+
const calls = [];
|
|
201
|
+
const out = [];
|
|
202
|
+
const deps = {
|
|
203
|
+
agentRoot: "/virtual", cfg: CFG, write: (s) => out.push(s),
|
|
204
|
+
readdirImpl: () => { listings += 1; return listings === 1 ? ["2026-09-08T10-00-00-cohort-m9.yaml"] : ["2026-09-08T10-00-00-cohort-m9.yaml.dispatched"]; },
|
|
205
|
+
readFileImpl: (p) => {
|
|
206
|
+
reads += 1;
|
|
207
|
+
if (String(p).endsWith(".yaml")) { const e = new Error("ENOENT: no such file"); e.code = "ENOENT"; throw e; }
|
|
208
|
+
return yaml;
|
|
209
|
+
},
|
|
210
|
+
trackImpl: async (params, o) => { calls.push({ params, o }); return { ok: true, result: { tracked: true, taskId: "t9", col: "done" } }; },
|
|
211
|
+
};
|
|
212
|
+
const r = await runBoard(["track", "cohort-m9", "--stage", "done"], deps);
|
|
213
|
+
assert.equal(r.code, 0, out.join("\n"));
|
|
214
|
+
assert.equal(listings, 2, "re-listed once after the rename");
|
|
215
|
+
assert.equal(reads, 2);
|
|
216
|
+
assert.equal(calls[0].params.messageId, "m9");
|
|
217
|
+
// Gone for good (retired between listings) → the documented "not found" exit, never a raw ENOENT.
|
|
218
|
+
out.length = 0;
|
|
219
|
+
const gone = await runBoard(["track", "cohort-m9", "--stage", "done"], {
|
|
220
|
+
...deps,
|
|
221
|
+
readdirImpl: () => ["2026-09-08T10-00-00-cohort-m9.yaml"],
|
|
222
|
+
readFileImpl: () => { const e = new Error("ENOENT"); e.code = "ENOENT"; throw e; },
|
|
223
|
+
});
|
|
224
|
+
assert.equal(gone.code, 1);
|
|
225
|
+
assert.match(out.join("\n"), /no inbox item cohort-m9/);
|
|
226
|
+
assert.ok(!/ENOENT/.test(out.join("\n")));
|
|
227
|
+
});
|