oh-my-opencode 4.11.1 → 4.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/codex-qa/scripts/lib/app-server-client.mjs +132 -82
- package/.agents/skills/codex-qa/scripts/lib/app-server-client.test.js +48 -0
- package/.agents/skills/opencode-qa/scripts/serve-wake-split-probe.sh +361 -84
- package/.agents/skills/work-with-pr/SKILL.md +19 -5
- package/.opencode/skills/work-with-pr/SKILL.md +19 -5
- package/dist/agents/types.d.ts +7 -6
- package/dist/cli/index.js +460 -309
- package/dist/cli-node/index.js +460 -309
- package/dist/features/background-agent/parent-wake-flush-runner.d.ts +1 -0
- package/dist/features/background-agent/parent-wake-history-state.d.ts +1 -0
- package/dist/features/background-agent/parent-wake-session-history.d.ts +1 -47
- package/dist/features/background-agent/parent-wake-session-message.d.ts +47 -0
- package/dist/index.js +593 -310
- package/dist/plugin/tool-execute-before.d.ts +2 -0
- package/dist/plugin-handlers/plugin-components-loader.d.ts +1 -0
- package/dist/skills/ultraresearch/SKILL.md +11 -2
- package/dist/skills/ulw-plan/SKILL.md +2 -1
- package/dist/skills/ulw-plan/references/full-workflow.md +1 -1
- package/dist/skills/ulw-plan/references/intent-clear.md +2 -2
- package/dist/tools/background-task/constants.d.ts +1 -1
- package/dist/tools/delegate-task/sync-session-poller.d.ts +1 -2
- package/dist/tools/delegate-task/sync-session-turns.d.ts +3 -0
- package/dist/tui.js +25 -10
- package/package.json +13 -13
- package/packages/omo-codex/plugin/.codex-plugin/plugin.json +24 -2
- package/packages/omo-codex/plugin/components/bootstrap/dist/cli.js +25 -9
- package/packages/omo-codex/plugin/components/bootstrap/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/bootstrap/package.json +1 -1
- package/packages/omo-codex/plugin/components/codegraph/dist/cli.js +336 -173
- package/packages/omo-codex/plugin/components/codegraph/dist/serve.js +284 -33
- package/packages/omo-codex/plugin/components/codegraph/package.json +1 -1
- package/packages/omo-codex/plugin/components/codegraph/src/cli.ts +11 -0
- package/packages/omo-codex/plugin/components/codegraph/src/hook-types.ts +12 -0
- package/packages/omo-codex/plugin/components/codegraph/src/hook.ts +34 -0
- package/packages/omo-codex/plugin/components/codegraph/src/serve.ts +47 -5
- package/packages/omo-codex/plugin/components/codegraph/src/session-start-worker.ts +7 -5
- package/packages/omo-codex/plugin/components/codegraph/test/hook.test.ts +58 -96
- package/packages/omo-codex/plugin/components/codegraph/test/provisioned-node-guard.test.ts +94 -0
- package/packages/omo-codex/plugin/components/codegraph/test/serve-node-support.test.ts +33 -0
- package/packages/omo-codex/plugin/components/codegraph/test/serve-provision.test.ts +48 -0
- package/packages/omo-codex/plugin/components/codegraph/test/serve.test.ts +1 -0
- package/packages/omo-codex/plugin/components/codegraph/test/session-start-node-support.test.ts +142 -0
- package/packages/omo-codex/plugin/components/comment-checker/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/comment-checker/package.json +1 -1
- package/packages/omo-codex/plugin/components/comment-checker/test/package-smoke.test.ts +2 -71
- package/packages/omo-codex/plugin/components/git-bash/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/git-bash/package.json +1 -1
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/package.json +1 -1
- package/packages/omo-codex/plugin/components/lsp/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/lsp/package.json +2 -2
- package/packages/omo-codex/plugin/components/lsp/test/package-smoke.test.ts +26 -104
- package/packages/omo-codex/plugin/components/rules/hooks/hooks.json +4 -4
- package/packages/omo-codex/plugin/components/rules/package.json +1 -1
- package/packages/omo-codex/plugin/components/rules/test/package-smoke.test.ts +12 -92
- package/packages/omo-codex/plugin/components/start-work-continuation/dist/cli.js +157 -234
- package/packages/omo-codex/plugin/components/start-work-continuation/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/start-work-continuation/package.json +1 -2
- package/packages/omo-codex/plugin/components/start-work-continuation/src/boulder-reader.ts +227 -15
- package/packages/omo-codex/plugin/components/start-work-continuation/test/boulder-reader.test.ts +62 -2
- package/packages/omo-codex/plugin/components/start-work-continuation/test/cli.test.ts +34 -3
- package/packages/omo-codex/plugin/components/teammode/dist/cli.js +94 -0
- package/packages/omo-codex/plugin/components/teammode/hooks/hooks.json +17 -0
- package/packages/omo-codex/plugin/components/teammode/package.json +26 -0
- package/packages/omo-codex/plugin/components/teammode/skills/teammode/SKILL.md +139 -0
- package/packages/omo-codex/plugin/components/teammode/skills/teammode/scripts/team-guide.mjs +111 -0
- package/packages/omo-codex/plugin/components/teammode/skills/teammode/scripts/team-state.mjs +250 -0
- package/packages/omo-codex/plugin/components/teammode/skills/teammode/scripts/team.mjs +220 -0
- package/packages/omo-codex/plugin/components/teammode/src/cli.ts +12 -0
- package/packages/omo-codex/plugin/components/teammode/src/codex-hook.ts +125 -0
- package/packages/omo-codex/plugin/components/teammode/test/thread-title-hook.test.ts +116 -0
- package/packages/omo-codex/plugin/components/teammode/tsconfig.json +25 -0
- package/packages/omo-codex/plugin/components/telemetry/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/telemetry/package.json +1 -1
- package/packages/omo-codex/plugin/components/test-support/package-smoke-fixture.ts +158 -0
- package/packages/omo-codex/plugin/components/ultrawork/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/package.json +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/SKILL.md +2 -1
- package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/agents/openai.yaml +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/references/full-workflow.md +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/references/intent-clear.md +2 -2
- package/packages/omo-codex/plugin/components/ultrawork/test/package-smoke.test.ts +76 -49
- package/packages/omo-codex/plugin/components/ulw-loop/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/ulw-loop/package.json +1 -1
- package/packages/omo-codex/plugin/components/ulw-loop/skills/ulw-loop/agents/openai.yaml +1 -1
- package/packages/omo-codex/plugin/components/ulw-loop/test/package-smoke.test.ts +1 -1
- package/packages/omo-codex/plugin/hooks/post-compact-resetting-git-bash-mcp-reminder.json +17 -0
- package/packages/omo-codex/plugin/hooks/post-compact-resetting-lsp-diagnostics-cache.json +17 -0
- package/packages/omo-codex/plugin/hooks/post-compact-resetting-project-rule-cache.json +17 -0
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-codegraph-init-guidance.json +17 -0
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-comments.json +17 -0
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-lsp-diagnostics.json +17 -0
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-thread-title-hygiene.json +17 -0
- package/packages/omo-codex/plugin/hooks/post-tool-use-matching-project-rules.json +17 -0
- package/packages/omo-codex/plugin/hooks/pre-tool-use-enforcing-unlimited-goal-budget.json +17 -0
- package/packages/omo-codex/plugin/hooks/pre-tool-use-recommending-git-bash-mcp.json +17 -0
- package/packages/omo-codex/plugin/hooks/session-start-checking-auto-update.json +17 -0
- package/packages/omo-codex/plugin/hooks/session-start-checking-bootstrap-provisioning.json +17 -0
- package/packages/omo-codex/plugin/hooks/session-start-checking-codegraph-bootstrap.json +16 -0
- package/packages/omo-codex/plugin/hooks/session-start-loading-project-rules.json +16 -0
- package/packages/omo-codex/plugin/hooks/session-start-recording-session-telemetry.json +16 -0
- package/packages/omo-codex/plugin/hooks/stop-checking-start-work-continuation.json +16 -0
- package/packages/omo-codex/plugin/hooks/subagent-stop-checking-start-work-continuation.json +16 -0
- package/packages/omo-codex/plugin/hooks/subagent-stop-verifying-lazycodex-executor-evidence.json +17 -0
- package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ultrawork-trigger.json +16 -0
- package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ulw-loop-steering.json +16 -0
- package/packages/omo-codex/plugin/hooks/user-prompt-submit-loading-project-rules.json +16 -0
- package/packages/omo-codex/plugin/package-lock.json +30 -22
- package/packages/omo-codex/plugin/package.json +2 -1
- package/packages/omo-codex/plugin/scripts/hook-status-message.mjs +15 -11
- package/packages/omo-codex/plugin/scripts/sync-hook-status-messages.mjs +15 -4
- package/packages/omo-codex/plugin/scripts/sync-skills.mjs +37 -0
- package/packages/omo-codex/plugin/skills/ast-grep/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/comment-checker/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/debugging/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/frontend/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/git-master/agents/openai.yaml +1 -1
- package/packages/omo-codex/plugin/skills/init-deep/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/lcx-contribute-bug-fix/agents/openai.yaml +1 -1
- package/packages/omo-codex/plugin/skills/lcx-doctor/agents/openai.yaml +1 -1
- package/packages/omo-codex/plugin/skills/lcx-report-bug/agents/openai.yaml +1 -1
- package/packages/omo-codex/plugin/skills/lsp/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/lsp-setup/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/programming/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/refactor/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/remove-ai-slops/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/review-work/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/rules/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/start-work/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/teammode/SKILL.md +139 -0
- package/packages/omo-codex/plugin/skills/teammode/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/teammode/scripts/team-guide.mjs +111 -0
- package/packages/omo-codex/plugin/skills/teammode/scripts/team-state.mjs +250 -0
- package/packages/omo-codex/plugin/skills/teammode/scripts/team.mjs +220 -0
- package/packages/omo-codex/plugin/skills/ultraresearch/SKILL.md +11 -2
- package/packages/omo-codex/plugin/skills/ultraresearch/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/ulw-loop/agents/openai.yaml +1 -1
- package/packages/omo-codex/plugin/skills/ulw-plan/SKILL.md +2 -1
- package/packages/omo-codex/plugin/skills/ulw-plan/agents/openai.yaml +1 -1
- package/packages/omo-codex/plugin/skills/ulw-plan/references/full-workflow.md +1 -1
- package/packages/omo-codex/plugin/skills/ulw-plan/references/intent-clear.md +2 -2
- package/packages/omo-codex/plugin/skills/visual-qa/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/test/aggregate-hooks.test.mjs +70 -33
- package/packages/omo-codex/plugin/test/aggregate-manifest.test.mjs +6 -2
- package/packages/omo-codex/plugin/test/aggregate-plugin-fixture.mjs +14 -1
- package/packages/omo-codex/plugin/test/bootstrap-binlinks.test.mjs +1 -1
- package/packages/omo-codex/plugin/test/bootstrap-hooks.test.mjs +14 -6
- package/packages/omo-codex/plugin/test/bootstrap-ps-guard.test.mjs +7 -3
- package/packages/omo-codex/plugin/test/component-bundled-cli.test.mjs +4 -3
- package/packages/omo-codex/plugin/test/component-hook-contract-cases.mjs +24 -0
- package/packages/omo-codex/plugin/test/display-metadata.test.mjs +83 -0
- package/packages/omo-codex/plugin/test/hook-status-message.test.mjs +31 -19
- package/packages/omo-codex/plugin/test/lcx-bug-skills.test.mjs +3 -3
- package/packages/omo-codex/plugin/test/sync-hook-status-messages.test.mjs +6 -6
- package/packages/omo-codex/plugin/test/sync-skills-test-support.mjs +2 -0
- package/packages/omo-codex/plugin/test/sync-skills.test.mjs +9 -4
- package/packages/omo-codex/plugin/test/teammode-safety-fixture.mjs +88 -0
- package/packages/omo-codex/plugin/test/teammode-safety.test.mjs +240 -0
- package/packages/omo-codex/plugin/test/ultraresearch-skill-contract.test.mjs +48 -0
- package/packages/omo-codex/scripts/install-dist/install-local.mjs +398 -206
- package/packages/omo-codex/scripts/install-hook-targets.test.mjs +93 -0
- package/packages/omo-codex/scripts/install-lazycodex-version-stamp.test.mjs +2 -2
- package/packages/omo-codex/scripts/install-local-bun-global-update.test.mjs +63 -0
- package/packages/omo-codex/scripts/install-local-entrypoint.test.mjs +109 -1
- package/packages/omo-codex/scripts/install-local.mjs +1 -0
- package/packages/shared-skills/skills/ultraresearch/SKILL.md +11 -2
- package/packages/shared-skills/skills/ulw-plan/SKILL.md +2 -1
- package/packages/shared-skills/skills/ulw-plan/references/full-workflow.md +1 -1
- package/packages/shared-skills/skills/ulw-plan/references/intent-clear.md +2 -2
- package/packages/omo-codex/plugin/hooks/hooks.json +0 -214
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: teammode
|
|
3
|
+
description: "Codex-only team orchestration: run a named team of cooperating Codex threads with durable, script-managed state. MUST USE when the user asks Codex to create, run, coordinate, inspect, archive, or delete a team of threads/sessions, or to work on something as a team in parallel. The main session is always the leader; members are defined by a concrete part, ownership area, or perspective - never a vague job role; a bundled cross-platform script writes the .omo/teams state plus an auto-generated member field manual. Use a team when the work is not perfectly isolated but parallelizing helps, or when a task still needs exploration under a clear goal; use plain subagents when scope is perfectly isolated or the goal is ambiguous. Triggers: team mode, teammode, make a team, run as a team, team of agents, coordinate threads, parallel Codex threads, archive the team, delete the team."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Teammode
|
|
7
|
+
|
|
8
|
+
Run a named team of cooperating Codex threads under one leader, with durable state on disk.
|
|
9
|
+
This is a Codex-only workflow. It is inspired by the lifecycle concerns in the
|
|
10
|
+
Yeachan-Heo/oh-my-codex team skill, but it does not copy that runtime model and never depends
|
|
11
|
+
on an external terminal runner - it coordinates through Codex's own thread tools plus a bundled
|
|
12
|
+
state script.
|
|
13
|
+
|
|
14
|
+
## When to use a team (and when to use plain subagents instead)
|
|
15
|
+
|
|
16
|
+
Use a TEAM when EITHER holds:
|
|
17
|
+
- the work does NOT split into perfectly isolated pieces, but doing it in parallel is clearly
|
|
18
|
+
more convenient - members will need to see and react to each other's findings; or
|
|
19
|
+
- one task still needs exploration, yet its GOAL is already clear - parallel investigation under
|
|
20
|
+
a fixed objective.
|
|
21
|
+
|
|
22
|
+
Use plain subagents (`$ulw` / `multi_agent_v1.spawn_agent`) - NOT a team - when EITHER holds:
|
|
23
|
+
- the work IS perfectly isolated, so there is no coordination cost worth paying; or
|
|
24
|
+
- the GOAL is still ambiguous, where one mind should resolve direction before any fan-out.
|
|
25
|
+
|
|
26
|
+
A team buys cross-member coordination at a real overhead cost; only spend it when coordination
|
|
27
|
+
is the thing you actually need.
|
|
28
|
+
|
|
29
|
+
## You are the leader
|
|
30
|
+
|
|
31
|
+
The main session is ALWAYS the team leader. Do NOT create a separate leader thread - you
|
|
32
|
+
orchestrate directly. Members are the threads you create; they report to you, and you own the
|
|
33
|
+
final synthesis and any integration.
|
|
34
|
+
|
|
35
|
+
## Compose by part, ownership, or perspective - not by job title
|
|
36
|
+
|
|
37
|
+
A team is ALWAYS two or more members - never a single-member team. One worker on an isolated
|
|
38
|
+
job is a subagent (`multi_agent_v1.spawn_agent`), not a team; if you end up with a single member,
|
|
39
|
+
either split off a second distinct slice or drop the team and use a subagent.
|
|
40
|
+
|
|
41
|
+
Compose the team from what you actually KNOW about the work. Ground the split in real knowledge
|
|
42
|
+
of the problem, then divide it into clear, non-overlapping responsibilities - one per aspect of
|
|
43
|
+
the work - and give each member exactly one. No two members may own the same thing. Define each
|
|
44
|
+
member by a concrete slice: a specific part of the codebase, an ownership area, or a distinct
|
|
45
|
+
perspective/lens. Assigning a vague role ("backend dev", "release analyst", "the tester") is an
|
|
46
|
+
anti-pattern - it gives the member no real boundary and invites overlap. Each member's `focus`
|
|
47
|
+
names what they own concretely; the `lens` is one of `area`, `ownership`, or `perspective`.
|
|
48
|
+
|
|
49
|
+
## Run the script - never hand-write team state
|
|
50
|
+
|
|
51
|
+
A bundled, dependency-free Node script owns all team state so you never author `team.json` or
|
|
52
|
+
the member manual by hand. Run it with `node` (or `bun`); it works on macOS, Linux, and Windows.
|
|
53
|
+
Replace `<skill-root>` with this skill's own directory.
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
node "<skill-root>/scripts/team.mjs" init --name "<team>" --session-name "<session>" [--session <leader_session_id>] [--worktree] [--base-branch dev]
|
|
57
|
+
node "<skill-root>/scripts/team.mjs" add-member --team <session_id> --id A --focus "<part/ownership/perspective>" --lens area|ownership|perspective --deliverable "<...>" [--branch <branch>]
|
|
58
|
+
node "<skill-root>/scripts/team.mjs" bind-thread --team <session_id> --id A --thread <thread_id> [--cwd <path>]
|
|
59
|
+
node "<skill-root>/scripts/team.mjs" member-prompt --team <session_id> --id A
|
|
60
|
+
node "<skill-root>/scripts/team.mjs" set-status --team <session_id> --id A --status reported|blocked|active|archived [--note "<...>"]
|
|
61
|
+
node "<skill-root>/scripts/team.mjs" archive --team <session_id> [--id A]
|
|
62
|
+
node "<skill-root>/scripts/team.mjs" delete --team <session_id> [--force]
|
|
63
|
+
node "<skill-root>/scripts/team.mjs" status --team <session_id>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`init` creates `.omo/teams/{session_id}/` containing `team.json` (the single durable state file:
|
|
67
|
+
team id, the main-session leader, the member roster, status, worktree config, and a lifecycle
|
|
68
|
+
log), `guide.md` (the auto-generated member field manual), and `artifacts/` (a shared exchange
|
|
69
|
+
space). `{session_id}` is the leader's Codex session id when you can pass it via `--session`;
|
|
70
|
+
otherwise the script generates a stable handle. Re-running `init` is a safe no-op. Every mutating
|
|
71
|
+
subcommand rewrites `guide.md`, so the manual always matches the current team.
|
|
72
|
+
|
|
73
|
+
## Create the team and its threads
|
|
74
|
+
|
|
75
|
+
1. `init` the team, then `add-member` once per member.
|
|
76
|
+
2. Create a durable thread per member with `codex_app.create_thread` - ALWAYS this tool for every
|
|
77
|
+
member, never a spawned agent - titled EXACTLY
|
|
78
|
+
`[team name] {session name}` (keep this convention strictly). If `codex_app.create_thread`
|
|
79
|
+
accepts a working directory / cwd argument, set it to that member's worktree; otherwise the
|
|
80
|
+
member's manual tells it to `cd` there first. Use `codex_app.set_thread_title` if the title
|
|
81
|
+
did not land at creation.
|
|
82
|
+
3. `bind-thread` to record each thread id (and `--cwd`), then send that member's bootstrap
|
|
83
|
+
trigger (printed by `add-member` / `member-prompt`) as the thread's first message. The trigger
|
|
84
|
+
is short on purpose: it tells the new thread to READ its `guide.md` and `team.json` rather than
|
|
85
|
+
carrying the whole protocol inline.
|
|
86
|
+
|
|
87
|
+
Every team member is a real Codex thread created with `codex_app.create_thread` - this is strict,
|
|
88
|
+
not a preference. NEVER substitute `multi_agent_v1.spawn_agent`, or any other in-process subagent,
|
|
89
|
+
for a team member: a spawned agent is an ephemeral helper that does not show up as a team thread,
|
|
90
|
+
cannot carry the `[team name] {session name}` title, and cannot be inspected, titled, archived, or
|
|
91
|
+
re-opened with the `codex_app.*` thread tools - which defeats the entire point of a durable team.
|
|
92
|
+
A member only counts once you have `bind-thread`-ed it to a real `codex_app.create_thread` thread
|
|
93
|
+
id. If the thread-creation tool is unavailable, STOP and say so (see Stop rules); do not quietly
|
|
94
|
+
fall back to a spawned agent.
|
|
95
|
+
|
|
96
|
+
## Communication
|
|
97
|
+
|
|
98
|
+
Coordinate with `codex_app.send_message_to_thread` (leader-to-member and peer digests) and inspect
|
|
99
|
+
status with `codex_app.read_thread`. The generated manual already binds members to the hard rules,
|
|
100
|
+
so you mostly enforce them: all member-to-member and member-to-leader communication is in English;
|
|
101
|
+
when the END user addresses a member, that member replies in the user's own language. Members
|
|
102
|
+
over-communicate relentlessly - constant, small, lean updates that report every finding, hand-off,
|
|
103
|
+
and even the smallest or most trivial step as it happens rather than one final dump - and send
|
|
104
|
+
`WORKING:`/`BLOCKED:` markers so the leader always knows their state; stale, stuck, or
|
|
105
|
+
silently-blocked members are not acceptable, and a finished
|
|
106
|
+
member reports to the leader immediately. Members hand off files and
|
|
107
|
+
memos through the team `artifacts/` directory and reference them by path instead of pasting large
|
|
108
|
+
content. Wait for every required member's final report before you declare the team done.
|
|
109
|
+
|
|
110
|
+
## Worktrees (optional isolation)
|
|
111
|
+
|
|
112
|
+
When parallel members would edit overlapping files, enable isolation with `init --worktree`. Create
|
|
113
|
+
one git worktree per member off the base branch, `bind-thread --cwd <worktree>` so each member's
|
|
114
|
+
worktree is recorded in `team.json`, and rely on the manual to direct each member into its own
|
|
115
|
+
worktree. Each member commits inside its worktree so you can integrate.
|
|
116
|
+
|
|
117
|
+
## Archive, delete, and cleanup
|
|
118
|
+
|
|
119
|
+
DISBAND the team the moment it is no longer needed. A team exists only to do its work; once that
|
|
120
|
+
work is done, or the user no longer wants it, do not leave it lying around - archive every member,
|
|
121
|
+
then delete the team state. A finished team that is never disbanded is a leak.
|
|
122
|
+
|
|
123
|
+
- `archive` closes the team: notify each active member, copy anything useful into `artifacts/`,
|
|
124
|
+
archive each member thread with `codex_app.set_thread_archived`, then `archive` flips the team
|
|
125
|
+
and all members to archived. If a thread-archive tool is unavailable, record that in the team log
|
|
126
|
+
and tell the user - never pretend a member was archived.
|
|
127
|
+
- `delete` removes `.omo/teams/{session_id}` and refuses while the team is unarchived or any member
|
|
128
|
+
is still active unless `--force`.
|
|
129
|
+
- When the work wraps up, integrate each member's worktree the way the user asked - merge directly,
|
|
130
|
+
or open a fresh PR and merge it - then archive and delete. Cleanup is real work; respect the
|
|
131
|
+
user's instruction on how to land it.
|
|
132
|
+
|
|
133
|
+
## Stop rules
|
|
134
|
+
|
|
135
|
+
- Stop and ask before deleting an unarchived team while any member is still active.
|
|
136
|
+
- Member communication stays English unless the user explicitly requests otherwise; user-facing
|
|
137
|
+
replies follow the user's language.
|
|
138
|
+
- Stop if the requested operation needs Codex thread tools (create/read/send/title/archive) and
|
|
139
|
+
they are unavailable; say so instead of faking it.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// team-guide.mjs - render the member-facing field manual (guide.md) and the short
|
|
2
|
+
// bootstrap trigger a new thread reads on startup. Pure string builders, no I/O.
|
|
3
|
+
//
|
|
4
|
+
// The manual is the durable, two-channel replacement for per-prompt guidance: the leader
|
|
5
|
+
// writes it once at team creation, and every member thread is told to READ it instead of
|
|
6
|
+
// receiving the rules inline each turn.
|
|
7
|
+
|
|
8
|
+
function memberLine(member) {
|
|
9
|
+
const thread = member.threadId ? ` | thread ${member.threadId}` : " | thread not created yet";
|
|
10
|
+
const wt = member.worktree?.path ? ` | worktree ${member.worktree.path}` : "";
|
|
11
|
+
return `- **${member.id}** (${member.lens}) - ${member.focus}${member.deliverable ? ` -> ${member.deliverable}` : ""}${thread}${wt} [${member.status}]`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function worktreeSection(team) {
|
|
15
|
+
if (!team.worktree?.enabled) {
|
|
16
|
+
return `## Worktrees
|
|
17
|
+
|
|
18
|
+
This team does not use isolated git worktrees. Work in the shared repository checkout
|
|
19
|
+
the leader is running from. If your changes would collide with another member's files,
|
|
20
|
+
that is a coordination signal: mark yourself \`blocked\` and tell the leader at once.`;
|
|
21
|
+
}
|
|
22
|
+
const lines = team.members
|
|
23
|
+
.filter((m) => m.worktree?.path || m.worktree?.branch)
|
|
24
|
+
.map((m) => `- **${m.id}**: worktree \`${m.worktree.path ?? "(assign with bind-thread --cwd)"}\` on branch \`${m.worktree.branch ?? team.worktree.baseBranch}\``);
|
|
25
|
+
return `## Worktrees (ISOLATION IS ON - this is not optional for you)
|
|
26
|
+
|
|
27
|
+
This team runs each member in its own git worktree branched off \`${team.worktree.baseBranch}\`.
|
|
28
|
+
**You MUST work only inside your own worktree.** The very first thing you do is \`cd\` into it;
|
|
29
|
+
every edit, command, and commit happens there. Never touch another member's worktree, and
|
|
30
|
+
never edit files outside your assigned scope. Commit your work so the leader can integrate it.
|
|
31
|
+
|
|
32
|
+
${lines.length ? lines.join("\n") : "- (worktree paths are assigned as threads are bound; read team.json for yours)"}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function buildGuide(team) {
|
|
36
|
+
const artifacts = team.paths?.artifacts ?? ".omo/teams/<session_id>/artifacts";
|
|
37
|
+
const teamJson = team.paths?.team ?? ".omo/teams/<session_id>/team.json";
|
|
38
|
+
const roster = team.members.length ? team.members.map(memberLine).join("\n") : "- (no members yet)";
|
|
39
|
+
return `# Team ${team.teamName} - Member Field Manual
|
|
40
|
+
|
|
41
|
+
> Auto-generated by the teammode script. This file is the single source of truth for how
|
|
42
|
+
> this team works. Re-read it whenever you are unsure - do not improvise the protocol.
|
|
43
|
+
|
|
44
|
+
- Team: **${team.teamName}** (id \`${team.teamId}\`)
|
|
45
|
+
- Team state: \`${teamJson}\`
|
|
46
|
+
- Thread/session title convention (use it EXACTLY): \`${team.threadTitleConvention}\`
|
|
47
|
+
|
|
48
|
+
## Who you are (your identity is fixed)
|
|
49
|
+
|
|
50
|
+
**You are a member of team ${team.teamName}, not a generic assistant.** You own exactly one
|
|
51
|
+
slice of this team's work - the focus and deliverable assigned to your id below - and you are
|
|
52
|
+
accountable for it end to end. Read your row, internalize it, and act as that owner for the
|
|
53
|
+
whole session. Do not drift into other members' scope.
|
|
54
|
+
|
|
55
|
+
${roster}
|
|
56
|
+
|
|
57
|
+
## Leader
|
|
58
|
+
|
|
59
|
+
**The main session is the leader. There is no other leader, and you are not it.** You report
|
|
60
|
+
to the leader, take direction from the leader, and send your results to the leader. Peers
|
|
61
|
+
coordinate with each other, but the leader owns the final decision and integration.
|
|
62
|
+
|
|
63
|
+
## Communication rules (hard rules)
|
|
64
|
+
|
|
65
|
+
- **All communication between team members, and from you to the leader, is in English.** This
|
|
66
|
+
is mandatory regardless of the language the task was given in.
|
|
67
|
+
- **Exception: when the END USER addresses you directly, reply in the user's own language.**
|
|
68
|
+
Team-internal traffic stays English; user-facing replies match the user.
|
|
69
|
+
- **Report to the leader the moment your work is complete.** A finished task that was never
|
|
70
|
+
reported does not count as done.
|
|
71
|
+
- **Over-communicate relentlessly - report even the trivial.** Message constantly and
|
|
72
|
+
proactively: every finding, decision, hand-off, and even the smallest or most trivial step, the
|
|
73
|
+
moment it happens, in short lean notes. Never save it up for one final report. When in doubt,
|
|
74
|
+
send the message - far more and far smaller updates always beats going quiet. The instant
|
|
75
|
+
anything changes a peer's assumption, push it to them. Too many messages is correct here; the
|
|
76
|
+
only failure is going quiet.
|
|
77
|
+
- **Stale, stuck, and silently-blocked states are NOT acceptable.** During long work send
|
|
78
|
+
\`WORKING: <your focus> - <phase>\` so the leader can see you are alive. If you truly cannot
|
|
79
|
+
proceed, send \`BLOCKED: <reason>\` immediately and propose the smallest unblock - never sit
|
|
80
|
+
idle and never disappear. Being quiet is a failure, not a pause.
|
|
81
|
+
|
|
82
|
+
## Artifacts (how you hand work off)
|
|
83
|
+
|
|
84
|
+
Exchange files and memos through the team artifacts directory:
|
|
85
|
+
|
|
86
|
+
\`${artifacts}\`
|
|
87
|
+
|
|
88
|
+
Drop deliverables, notes, diffs, and findings there as files, and reference them by path in
|
|
89
|
+
your messages instead of pasting large content into a thread. Treat it as the team's shared
|
|
90
|
+
desk: if a peer or the leader needs something from you, leave it in artifacts and point them to it.
|
|
91
|
+
|
|
92
|
+
${worktreeSection(team)}
|
|
93
|
+
|
|
94
|
+
## Done means reported and verified
|
|
95
|
+
|
|
96
|
+
Your slice is done only when (1) the deliverable exists, (2) you have evidence it works, and
|
|
97
|
+
(3) you have reported it to the leader. Until all three are true, keep going.`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function buildMemberPrompt(team, id) {
|
|
101
|
+
const member = team.members.find((m) => m.id === id);
|
|
102
|
+
if (!member) throw new Error(`no member with id "${id}"`);
|
|
103
|
+
const guide = team.paths?.guide ?? ".omo/teams/<session_id>/guide.md";
|
|
104
|
+
const teamJson = team.paths?.team ?? ".omo/teams/<session_id>/team.json";
|
|
105
|
+
const where = member.cwd ? `Work inside \`${member.cwd}\`.` : "Work from the repository root unless your manual assigns a worktree.";
|
|
106
|
+
return `You are member ${member.id} of team ${team.teamName} - owner of: ${member.focus}.
|
|
107
|
+
FIRST read your field manual at \`${guide}\`, then the team state at \`${teamJson}\`; they define your scope, deliverable, the leader, the artifacts directory, and the communication rules.
|
|
108
|
+
${where}
|
|
109
|
+
Communicate with the team and leader in English; reply to the end user in the user's own language.
|
|
110
|
+
Start now, send WORKING/BLOCKED updates so you never look stale, and report to the leader the moment you are done.`;
|
|
111
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// team-state.mjs - the teammode state model + atomic, symlink-guarded persistence.
|
|
2
|
+
//
|
|
3
|
+
// Zero external dependencies (node builtins only) so it runs byte-identically under
|
|
4
|
+
// `node` and `bun` on macOS, Linux, and Windows with no install step, no POSIX shell,
|
|
5
|
+
// and no python3 precondition. This is the SINGLE source of the team-state shape: the
|
|
6
|
+
// model never hand-writes team.json - it calls these helpers through scripts/team.mjs.
|
|
7
|
+
//
|
|
8
|
+
// Rendering (the member field manual + bootstrap trigger) lives in team-guide.mjs so
|
|
9
|
+
// this file stays the state concern only.
|
|
10
|
+
|
|
11
|
+
import { randomUUID } from "node:crypto";
|
|
12
|
+
import { lstat, mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
13
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
14
|
+
|
|
15
|
+
export const LENSES = ["area", "ownership", "perspective"];
|
|
16
|
+
export const MEMBER_STATUSES = ["pending", "active", "reported", "blocked", "archived"];
|
|
17
|
+
// A team is never a single member: two or more distinct slices is the minimum. One isolated
|
|
18
|
+
// job is a subagent, not a team.
|
|
19
|
+
export const MIN_MEMBERS = 2;
|
|
20
|
+
|
|
21
|
+
export function isUnderstaffed(team) {
|
|
22
|
+
return team.members.length < MIN_MEMBERS;
|
|
23
|
+
}
|
|
24
|
+
// A team dir is a single child of .omo/teams. This pattern alone blocks "/", "\", and a
|
|
25
|
+
// leading "." so ".." and "a/b" can never name a team dir (the escape guard).
|
|
26
|
+
const SESSION_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
27
|
+
|
|
28
|
+
function isoNow(now) {
|
|
29
|
+
return now ?? new Date().toISOString();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function buildTeam({ teamName, sessionName, sessionId = null, dir = null, worktreeEnabled = false, baseBranch = "dev", now }) {
|
|
33
|
+
if (!teamName?.trim()) throw new Error("team name is required");
|
|
34
|
+
if (!sessionName?.trim()) throw new Error("session name is required");
|
|
35
|
+
const ts = isoNow(now);
|
|
36
|
+
return {
|
|
37
|
+
schemaVersion: 2,
|
|
38
|
+
teamId: randomUUID(),
|
|
39
|
+
teamName: teamName.trim(),
|
|
40
|
+
sessionName: sessionName.trim(),
|
|
41
|
+
sessionId,
|
|
42
|
+
threadTitleConvention: `[${teamName.trim()}] ${sessionName.trim()}`,
|
|
43
|
+
status: "active",
|
|
44
|
+
createdAt: ts,
|
|
45
|
+
updatedAt: ts,
|
|
46
|
+
archivedAt: null,
|
|
47
|
+
leader: { kind: "main-session", sessionId },
|
|
48
|
+
communication: { memberLanguage: "english", replyToUserInUserLanguage: true },
|
|
49
|
+
worktree: { enabled: Boolean(worktreeEnabled), baseBranch, root: dir ? join(dir, "worktrees") : null },
|
|
50
|
+
paths: dir
|
|
51
|
+
? { dir, team: join(dir, "team.json"), guide: join(dir, "guide.md"), artifacts: join(dir, "artifacts") }
|
|
52
|
+
: null,
|
|
53
|
+
members: [],
|
|
54
|
+
log: [{ ts, event: "created", detail: `team ${teamName.trim()}` }],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function touch(team, event, detail) {
|
|
59
|
+
const ts = isoNow();
|
|
60
|
+
team.updatedAt = ts;
|
|
61
|
+
team.log.push({ ts, event, detail });
|
|
62
|
+
return team;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function memberById(team, id) {
|
|
66
|
+
const found = team.members.find((m) => m.id === id);
|
|
67
|
+
if (!found) throw new Error(`no member with id "${id}"`);
|
|
68
|
+
return found;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function normalizedFocus(focus) {
|
|
72
|
+
return focus.trim().replace(/\s+/g, " ").toLowerCase();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function assertUniqueMemberFocus(team) {
|
|
76
|
+
const seen = new Map();
|
|
77
|
+
for (const member of team.members) {
|
|
78
|
+
const key = normalizedFocus(member.focus ?? "");
|
|
79
|
+
const previous = seen.get(key);
|
|
80
|
+
if (previous) {
|
|
81
|
+
throw new Error(`member focus "${member.focus}" duplicates "${previous.focus}" (no two members may own the same thing)`);
|
|
82
|
+
}
|
|
83
|
+
seen.set(key, member);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function assertTeamReadyForThreadBinding(team) {
|
|
88
|
+
if (isUnderstaffed(team)) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`cannot bind member threads until the team has at least ${MIN_MEMBERS} distinct members; current count is ${team.members.length}`,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
assertUniqueMemberFocus(team);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function addMember(team, { id, focus, lens, deliverable = "", branch = null }) {
|
|
97
|
+
if (!id?.trim()) throw new Error("member id is required");
|
|
98
|
+
if (!focus?.trim()) throw new Error("member focus is required - a concrete part, ownership area, or perspective");
|
|
99
|
+
if (!LENSES.includes(lens)) throw new Error(`invalid lens "${lens}" - use one of: ${LENSES.join(", ")}`);
|
|
100
|
+
const memberId = id.trim();
|
|
101
|
+
const memberFocus = focus.trim();
|
|
102
|
+
if (team.members.some((m) => m.id === memberId)) throw new Error(`member id "${memberId}" already exists (duplicate)`);
|
|
103
|
+
const duplicate = team.members.find((m) => normalizedFocus(m.focus) === normalizedFocus(memberFocus));
|
|
104
|
+
if (duplicate) throw new Error(`member focus "${memberFocus}" duplicates "${duplicate.focus}" (no two members may own the same thing)`);
|
|
105
|
+
team.members.push({
|
|
106
|
+
id: memberId,
|
|
107
|
+
focus: memberFocus,
|
|
108
|
+
lens,
|
|
109
|
+
deliverable: deliverable.trim(),
|
|
110
|
+
threadId: null,
|
|
111
|
+
threadTitle: team.threadTitleConvention,
|
|
112
|
+
cwd: null,
|
|
113
|
+
worktree: { path: null, branch: branch ?? null },
|
|
114
|
+
status: "pending",
|
|
115
|
+
});
|
|
116
|
+
return touch(team, "add-member", `member ${memberId} (${lens}): ${memberFocus}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function bindThread(team, { id, threadId, cwd = null, worktreePath = null }) {
|
|
120
|
+
if (!threadId?.trim()) throw new Error("thread id is required");
|
|
121
|
+
assertTeamReadyForThreadBinding(team);
|
|
122
|
+
const m = memberById(team, id);
|
|
123
|
+
m.threadId = threadId.trim();
|
|
124
|
+
m.status = "active";
|
|
125
|
+
if (cwd) m.cwd = cwd;
|
|
126
|
+
if (team.worktree.enabled) m.worktree.path = worktreePath ?? cwd ?? m.worktree.path;
|
|
127
|
+
return touch(team, "bind-thread", `member ${id} -> thread ${threadId.trim()}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function setMemberStatus(team, { id, status, note = "" }) {
|
|
131
|
+
if (!MEMBER_STATUSES.includes(status)) throw new Error(`invalid status "${status}" - use one of: ${MEMBER_STATUSES.join(", ")}`);
|
|
132
|
+
memberById(team, id).status = status;
|
|
133
|
+
return touch(team, "set-status", `member ${id} -> ${status}${note ? `: ${note}` : ""}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function archive(team, { id = null, note = "" } = {}) {
|
|
137
|
+
if (id) {
|
|
138
|
+
memberById(team, id).status = "archived";
|
|
139
|
+
return touch(team, "archive-member", `member ${id}${note ? `: ${note}` : ""}`);
|
|
140
|
+
}
|
|
141
|
+
for (const m of team.members) m.status = "archived";
|
|
142
|
+
team.status = "archived";
|
|
143
|
+
team.archivedAt = isoNow();
|
|
144
|
+
return touch(team, "archive", note || "team archived; all members closed");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function validateTeam(team) {
|
|
148
|
+
if (team?.schemaVersion !== 2) throw new Error("invalid team: schemaVersion must be 2");
|
|
149
|
+
if (!team.teamId || !team.teamName) throw new Error("invalid team: teamId and teamName are required");
|
|
150
|
+
if (team.leader?.kind !== "main-session") throw new Error("invalid team: leader.kind must be main-session");
|
|
151
|
+
if (!Array.isArray(team.members)) throw new Error("invalid team: members must be an array");
|
|
152
|
+
assertUniqueMemberFocus(team);
|
|
153
|
+
return team;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Resolve (and confine) a team dir to a single child of <cwd>/.omo/teams.
|
|
157
|
+
export function resolveTeamDir(cwd, sessionId) {
|
|
158
|
+
if (!SESSION_ID_PATTERN.test(sessionId ?? "")) throw new Error(`invalid or unsafe session id "${sessionId}"`);
|
|
159
|
+
return resolve(cwd, ".omo", "teams", sessionId);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function lstatOrNull(p) {
|
|
163
|
+
return lstat(p).catch((error) => {
|
|
164
|
+
if (error && error.code === "ENOENT") return null;
|
|
165
|
+
throw error;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Create a directory chain refusing any symlinked component, so team state can never be
|
|
170
|
+
// written through a symlink that escapes the workspace.
|
|
171
|
+
async function mkdirNoSymlink(dir, stopAt) {
|
|
172
|
+
if (dir === stopAt) return;
|
|
173
|
+
const rel = relative(stopAt, dir);
|
|
174
|
+
if (rel.startsWith("..") || isAbsolute(rel)) throw new Error(`refused: path escapes ${stopAt}: ${dir}`);
|
|
175
|
+
await mkdirNoSymlink(dirname(dir), stopAt);
|
|
176
|
+
const st = await lstatOrNull(dir);
|
|
177
|
+
if (st) {
|
|
178
|
+
if (st.isSymbolicLink()) throw new Error(`refused: path component is a symlink: ${dir}`);
|
|
179
|
+
if (!st.isDirectory()) throw new Error(`refused: path component is not a directory: ${dir}`);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
await mkdir(dir);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async function assertNoSymlinkComponents(dir, stopAt) {
|
|
186
|
+
if (dir === stopAt) return;
|
|
187
|
+
const rel = relative(stopAt, dir);
|
|
188
|
+
if (rel.startsWith("..") || isAbsolute(rel)) throw new Error(`refused: path escapes ${stopAt}: ${dir}`);
|
|
189
|
+
await assertNoSymlinkComponents(dirname(dir), stopAt);
|
|
190
|
+
const st = await lstatOrNull(dir);
|
|
191
|
+
if (st?.isSymbolicLink()) throw new Error(`refused: path component is a symlink: ${dir}`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export async function ensureTeamDir(cwd, sessionId) {
|
|
195
|
+
const workspaceRoot = resolve(cwd);
|
|
196
|
+
const teamsRoot = resolve(cwd, ".omo", "teams");
|
|
197
|
+
const dir = resolveTeamDir(cwd, sessionId);
|
|
198
|
+
await mkdirNoSymlink(teamsRoot, workspaceRoot);
|
|
199
|
+
await mkdirNoSymlink(dir, teamsRoot);
|
|
200
|
+
await mkdirNoSymlink(join(dir, "artifacts"), dir);
|
|
201
|
+
return dir;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export async function assertSafeTeamDir(cwd, sessionId) {
|
|
205
|
+
const workspaceRoot = resolve(cwd);
|
|
206
|
+
const teamsRoot = resolve(cwd, ".omo", "teams");
|
|
207
|
+
const dir = resolveTeamDir(cwd, sessionId);
|
|
208
|
+
await assertNoSymlinkComponents(teamsRoot, workspaceRoot);
|
|
209
|
+
await assertNoSymlinkComponents(dir, teamsRoot);
|
|
210
|
+
return dir;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export async function readTeam(dir) {
|
|
214
|
+
return validateTeam(JSON.parse(await readFile(join(dir, "team.json"), "utf8")));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export async function teamExists(dir) {
|
|
218
|
+
return (await lstatOrNull(join(dir, "team.json"))) !== null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function persistedFileTarget(team, pathKey, fileName, expectedDir) {
|
|
222
|
+
validateTeam(team);
|
|
223
|
+
if (!team.paths?.dir || !team.paths?.[pathKey]) throw new Error(`invalid team: paths.${pathKey} is required`);
|
|
224
|
+
const dir = resolve(expectedDir);
|
|
225
|
+
if (resolve(team.paths.dir) !== dir) throw new Error(`refused: persisted team dir does not match trusted team dir: ${team.paths.dir}`);
|
|
226
|
+
const target = resolve(team.paths[pathKey]);
|
|
227
|
+
if (target !== resolve(dir, fileName)) throw new Error(`refused: ${fileName} persist target escapes team dir: ${team.paths[pathKey]}`);
|
|
228
|
+
const dirStat = await lstatOrNull(dir);
|
|
229
|
+
if (dirStat?.isSymbolicLink()) throw new Error(`refused: team dir is a symlink: ${dir}`);
|
|
230
|
+
const st = await lstatOrNull(target);
|
|
231
|
+
if (st?.isSymbolicLink()) throw new Error(`refused: ${fileName} is a symlink: ${target}`);
|
|
232
|
+
if (st && !st.isFile()) throw new Error(`refused: ${fileName} is not a file: ${target}`);
|
|
233
|
+
return target;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function writePersistedFileAtomic(team, pathKey, fileName, content, expectedDir) {
|
|
237
|
+
const target = await persistedFileTarget(team, pathKey, fileName, expectedDir);
|
|
238
|
+
const tmp = `${target}.tmp-${process.pid}-${randomUUID()}`;
|
|
239
|
+
await writeFile(tmp, content, { encoding: "utf8", flag: "wx" });
|
|
240
|
+
await rename(tmp, target);
|
|
241
|
+
return team;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export async function writeTeamAtomic(team, expectedDir) {
|
|
245
|
+
return writePersistedFileAtomic(team, "team", "team.json", `${JSON.stringify(team, null, 2)}\n`, expectedDir);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export async function writeGuideAtomic(team, content, expectedDir) {
|
|
249
|
+
return writePersistedFileAtomic(team, "guide", "guide.md", content, expectedDir);
|
|
250
|
+
}
|