@moreih29/nexus-core 0.15.2 → 0.16.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.
Files changed (98) hide show
  1. package/dist/claude/.claude-plugin/marketplace.json +75 -0
  2. package/dist/claude/.claude-plugin/plugin.json +67 -0
  3. package/dist/claude/agents/architect.md +172 -0
  4. package/dist/claude/agents/designer.md +120 -0
  5. package/dist/claude/agents/engineer.md +98 -0
  6. package/dist/claude/agents/lead.md +59 -0
  7. package/dist/claude/agents/postdoc.md +117 -0
  8. package/dist/claude/agents/researcher.md +132 -0
  9. package/dist/claude/agents/reviewer.md +133 -0
  10. package/dist/claude/agents/strategist.md +111 -0
  11. package/dist/claude/agents/tester.md +190 -0
  12. package/dist/claude/agents/writer.md +114 -0
  13. package/dist/claude/dist/hooks/agent-bootstrap.js +121 -0
  14. package/dist/claude/dist/hooks/agent-finalize.js +180 -0
  15. package/dist/claude/dist/hooks/prompt-router.js +7316 -0
  16. package/dist/claude/dist/hooks/session-init.js +37 -0
  17. package/dist/claude/hooks/hooks.json +52 -0
  18. package/dist/claude/settings.json +3 -0
  19. package/dist/claude/skills/nx-init/SKILL.md +189 -0
  20. package/dist/claude/skills/nx-plan/SKILL.md +353 -0
  21. package/dist/claude/skills/nx-run/SKILL.md +154 -0
  22. package/dist/claude/skills/nx-sync/SKILL.md +87 -0
  23. package/dist/codex/agents/architect.toml +172 -0
  24. package/dist/codex/agents/designer.toml +120 -0
  25. package/dist/codex/agents/engineer.toml +102 -0
  26. package/dist/codex/agents/lead.toml +64 -0
  27. package/dist/codex/agents/postdoc.toml +117 -0
  28. package/dist/codex/agents/researcher.toml +133 -0
  29. package/dist/codex/agents/reviewer.toml +134 -0
  30. package/dist/codex/agents/strategist.toml +111 -0
  31. package/dist/codex/agents/tester.toml +191 -0
  32. package/dist/codex/agents/writer.toml +118 -0
  33. package/dist/codex/dist/hooks/agent-bootstrap.js +121 -0
  34. package/dist/codex/dist/hooks/agent-finalize.js +180 -0
  35. package/dist/codex/dist/hooks/prompt-router.js +7316 -0
  36. package/dist/codex/dist/hooks/session-init.js +37 -0
  37. package/dist/codex/hooks/hooks.json +28 -0
  38. package/dist/codex/install/AGENTS.fragment.md +60 -0
  39. package/dist/codex/install/config.fragment.toml +5 -0
  40. package/dist/codex/install/install.sh +60 -0
  41. package/dist/codex/package.json +20 -0
  42. package/dist/codex/plugin/.codex-plugin/plugin.json +57 -0
  43. package/dist/codex/plugin/skills/nx-init/SKILL.md +189 -0
  44. package/dist/codex/plugin/skills/nx-plan/SKILL.md +353 -0
  45. package/dist/codex/plugin/skills/nx-run/SKILL.md +154 -0
  46. package/dist/codex/plugin/skills/nx-sync/SKILL.md +87 -0
  47. package/dist/codex/prompts/architect.md +166 -0
  48. package/dist/codex/prompts/designer.md +114 -0
  49. package/dist/codex/prompts/engineer.md +97 -0
  50. package/dist/codex/prompts/lead.md +60 -0
  51. package/dist/codex/prompts/postdoc.md +111 -0
  52. package/dist/codex/prompts/researcher.md +127 -0
  53. package/dist/codex/prompts/reviewer.md +128 -0
  54. package/dist/codex/prompts/strategist.md +105 -0
  55. package/dist/codex/prompts/tester.md +185 -0
  56. package/dist/codex/prompts/writer.md +113 -0
  57. package/dist/hooks/agent-bootstrap.js +1 -1
  58. package/dist/hooks/agent-finalize.js +1 -1
  59. package/dist/hooks/prompt-router.js +1 -1
  60. package/dist/hooks/session-init.js +1 -1
  61. package/dist/manifests/opencode-manifest.json +4 -4
  62. package/dist/opencode/.opencode/skills/nx-init/SKILL.md +189 -0
  63. package/dist/opencode/.opencode/skills/nx-plan/SKILL.md +353 -0
  64. package/dist/opencode/.opencode/skills/nx-run/SKILL.md +154 -0
  65. package/dist/opencode/.opencode/skills/nx-sync/SKILL.md +87 -0
  66. package/dist/opencode/package.json +23 -0
  67. package/dist/opencode/src/agents/architect.ts +176 -0
  68. package/dist/opencode/src/agents/designer.ts +124 -0
  69. package/dist/opencode/src/agents/engineer.ts +105 -0
  70. package/dist/opencode/src/agents/lead.ts +66 -0
  71. package/dist/opencode/src/agents/postdoc.ts +121 -0
  72. package/dist/opencode/src/agents/researcher.ts +136 -0
  73. package/dist/opencode/src/agents/reviewer.ts +137 -0
  74. package/dist/opencode/src/agents/strategist.ts +115 -0
  75. package/dist/opencode/src/agents/tester.ts +194 -0
  76. package/dist/opencode/src/agents/writer.ts +121 -0
  77. package/dist/opencode/src/index.ts +25 -0
  78. package/dist/opencode/src/plugin.ts +6 -0
  79. package/dist/scripts/build-agents.d.ts +0 -1
  80. package/dist/scripts/build-agents.d.ts.map +1 -1
  81. package/dist/scripts/build-agents.js +3 -15
  82. package/dist/scripts/build-agents.js.map +1 -1
  83. package/dist/scripts/build-hooks.js +1 -1
  84. package/dist/scripts/build-hooks.js.map +1 -1
  85. package/dist/scripts/smoke/smoke-claude.d.ts +2 -0
  86. package/dist/scripts/smoke/smoke-claude.d.ts.map +1 -0
  87. package/dist/scripts/smoke/smoke-claude.js +58 -0
  88. package/dist/scripts/smoke/smoke-claude.js.map +1 -0
  89. package/dist/scripts/smoke/smoke-codex.d.ts +2 -0
  90. package/dist/scripts/smoke/smoke-codex.d.ts.map +1 -0
  91. package/dist/scripts/smoke/smoke-codex.js +50 -0
  92. package/dist/scripts/smoke/smoke-codex.js.map +1 -0
  93. package/dist/scripts/smoke/smoke-opencode.d.ts +2 -0
  94. package/dist/scripts/smoke/smoke-opencode.d.ts.map +1 -0
  95. package/dist/scripts/smoke/smoke-opencode.js +99 -0
  96. package/dist/scripts/smoke/smoke-opencode.js.map +1 -0
  97. package/docs/contract/harness-io.md +51 -6
  98. package/package.json +7 -3
@@ -0,0 +1,37 @@
1
+ // assets/hooks/session-init/handler.ts
2
+ import { mkdirSync, writeFileSync } from "node:fs";
3
+ import { join, basename } from "node:path";
4
+ var handler = async (input) => {
5
+ if (input.hook_event_name !== "SessionStart")
6
+ return;
7
+ const safeSid = basename(input.session_id);
8
+ if (!safeSid || safeSid.startsWith(".") || safeSid.includes("/")) {
9
+ process.stderr.write(`[session-init] invalid session_id: ${input.session_id}
10
+ `);
11
+ return;
12
+ }
13
+ const sessionDir = join(input.cwd, ".nexus/state", safeSid);
14
+ mkdirSync(sessionDir, { recursive: true });
15
+ writeFileSync(join(sessionDir, "agent-tracker.json"), "[]");
16
+ writeFileSync(join(sessionDir, "tool-log.jsonl"), "");
17
+ };
18
+ var handler_default = handler;
19
+
20
+ // ../../../../../tmp/nexus-hook-entry-session-init-1776671215218/session-init-entry.ts
21
+ import { readFileSync } from "node:fs";
22
+ async function main() {
23
+ let raw = "";
24
+ try {
25
+ raw = readFileSync(0, "utf-8");
26
+ } catch {}
27
+ const input = raw ? JSON.parse(raw) : {};
28
+ const result = await handler_default(input);
29
+ if (result != null && result !== undefined) {
30
+ process.stdout.write(JSON.stringify(result));
31
+ }
32
+ }
33
+ main().then(() => process.exit(0), (err) => {
34
+ process.stderr.write(String(err?.stack ?? err) + `
35
+ `);
36
+ process.exit(1);
37
+ });
@@ -0,0 +1,52 @@
1
+ {
2
+ "hooks": {
3
+ "SessionStart": [
4
+ {
5
+ "matcher": "*",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/dist/hooks/session-init.js",
10
+ "timeout": 10
11
+ }
12
+ ]
13
+ }
14
+ ],
15
+ "UserPromptSubmit": [
16
+ {
17
+ "matcher": "*",
18
+ "hooks": [
19
+ {
20
+ "type": "command",
21
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/dist/hooks/prompt-router.js",
22
+ "timeout": 10
23
+ }
24
+ ]
25
+ }
26
+ ],
27
+ "SubagentStop": [
28
+ {
29
+ "matcher": "*",
30
+ "hooks": [
31
+ {
32
+ "type": "command",
33
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/dist/hooks/agent-finalize.js",
34
+ "timeout": 10
35
+ }
36
+ ]
37
+ }
38
+ ],
39
+ "SubagentStart": [
40
+ {
41
+ "matcher": "*",
42
+ "hooks": [
43
+ {
44
+ "type": "command",
45
+ "command": "node ${CLAUDE_PLUGIN_ROOT}/dist/hooks/agent-bootstrap.js",
46
+ "timeout": 10
47
+ }
48
+ ]
49
+ }
50
+ ]
51
+ }
52
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "agent": "lead"
3
+ }
@@ -0,0 +1,189 @@
1
+ ---
2
+ description: "Project onboarding — scan, mission, essentials, context generation"
3
+ ---
4
+ ## Role
5
+
6
+ Scans the project and builds Nexus knowledge in the flat .nexus/ structure. On first run, performs a 5-step full onboarding sequence.
7
+
8
+ ## Constraints
9
+
10
+ - NEVER modify source code. Slimming down the instruction file beyond the project section is not this skill's responsibility.
11
+ - NEVER infer or guess information that cannot be confirmed from code — do not write it to context/.
12
+ - NEVER store secrets (API keys, credentials, etc.) in knowledge files.
13
+ - NEVER overwrite existing files without `--reset`. On resume, preserve existing files intact.
14
+ - Project section in the instruction file MUST go through user confirmation before writing.
15
+ - NEVER reference or create identity/, codebase/, reference/, or core/ paths.
16
+ - Essentials section MUST NOT exceed 10 lines. If more items are needed, move lower-priority ones to .nexus/context/.
17
+
18
+ ## Guidelines
19
+
20
+ ## Trigger
21
+
22
+ - Manual trigger — full onboarding (or resume). See harness docs: slash_command_display.
23
+ - Manual trigger with `--reset` flag — back up existing `.nexus/` knowledge and re-onboard. See harness docs: slash_command_display.
24
+ - Manual trigger with `--reset --cleanup` flags — show backup list + selective deletion. See harness docs: slash_command_display.
25
+
26
+ ---
27
+
28
+ ## Modes
29
+
30
+ ### First Run (no `.nexus/` flat structure)
31
+
32
+ Automatically runs the 5-step full onboarding.
33
+
34
+ Detection: `.nexus/context/`, `.nexus/memory/`, `.nexus/state/`, `.nexus/rules/` do not exist.
35
+
36
+ ### Resume (`.nexus/` partially exists)
37
+
38
+ Check existing state and resume from the first incomplete step.
39
+
40
+ ### Reset (`--reset`)
41
+
42
+ Back up existing `.nexus/` knowledge directories to `.nexus/bak.{timestamp}/`, then enter First Run.
43
+
44
+ ### Cleanup (`--reset --cleanup`)
45
+
46
+ Show backup directory list, let user select backups to delete.
47
+
48
+ ---
49
+
50
+ ## Process
51
+
52
+ ### Phase 0: Mode Detection
53
+
54
+ ```
55
+ IF --reset --cleanup flag:
56
+ Show list of .nexus/bak.*/ directories
57
+ Prompt user with options via `AskUserQuestion({ questions: [{ question: "Select a backup to delete (or cancel)", options: [<backup list...>, {label: Cancel, description: "Exit without changes"}] }] })`.
58
+ Delete selected backup and exit
59
+
60
+ ELSE IF --reset flag:
61
+ Move .nexus/{memory,context,state,rules}/ → .nexus/bak.{timestamp}/
62
+ Inform: "Existing knowledge has been backed up to .nexus/bak.{timestamp}/. Starting re-onboarding."
63
+ → Enter First Run
64
+
65
+ ELSE IF .nexus/context/ exists:
66
+ → Enter Resume (check existing steps and resume)
67
+
68
+ ELSE:
69
+ → Enter First Run (from Step 1)
70
+ ```
71
+
72
+ ---
73
+
74
+ ## Steps
75
+
76
+ ### Step 1: Project Scan
77
+
78
+ Auto-detect code structure and tech stack. Create the flat `.nexus/` directory structure if it does not exist.
79
+
80
+ Create directories (using shell command execution):
81
+ - `.nexus/memory/`
82
+ - `.nexus/context/`
83
+ - `.nexus/state/`
84
+ - `.nexus/rules/`
85
+
86
+ Collected items:
87
+ - **Directory structure**: top-level layout, major modules/packages
88
+ - **Tech stack**: language, framework, runtime (package.json, Cargo.toml, pyproject.toml, go.mod, build.gradle, etc.)
89
+ - **Build/test system**: scripts, CI configuration
90
+ - **Existing docs**: CLAUDE.md, README.md, docs/, .cursorrules, etc.
91
+ - **git context**: recent commits, branch structure, contributors
92
+
93
+ Output: scan summary (language, framework, structure overview)
94
+
95
+ For large projects (10+ top-level directories or 100+ files), consider spawning an Explore subagent for parallel scanning to reduce Lead context usage.
96
+
97
+ ### Step 2: Mission + Essentials (Interactive)
98
+
99
+ Using the Step 1 scan results, draft a Mission statement (1–2 lines) and an Essentials list, then present both to the user for confirmation in a single pass.
100
+
101
+ #### Essentials Guidelines
102
+
103
+ Essentials are agent-critical facts — things an agent would get wrong if it didn't know them. Apply this judgment criterion: **"Would an agent produce wrong results without knowing this?"** Yes → Essentials. No → .nexus/context/.
104
+
105
+ Draft from these five categories (include only what applies to this project):
106
+
107
+ - **Tech stack** — runtime, language, package manager, core framework. Flag non-default tools (e.g. bun instead of npm, deno instead of node).
108
+ - **Workflow** — build, test, deploy commands. Must-follow procedures such as required lint or type-check steps before committing.
109
+ - **Constraints** — forbidden tools, patterns, or approaches. Directories or files that must not be modified.
110
+ - **Domain** — target audience, required terminology or tone, compliance or regulatory constraints, methodology for research projects.
111
+ - **Conventions** — naming, structure, or style that deviate from general defaults. Project-specific patterns an agent would not infer.
112
+
113
+ Do not include items that are standard defaults for the detected tech stack. Do not exceed 10 lines total in the Essentials section.
114
+
115
+ #### Draft Presentation
116
+
117
+ Present the full draft to the user in this format:
118
+
119
+ ```
120
+ The following will be added to the instruction file (see harness docs: instruction_file) (existing content will not be changed):
121
+
122
+ <!-- PROJECT:START -->
123
+ ## {project-name}
124
+
125
+ {mission 1-2 lines}
126
+
127
+ ### Essentials
128
+ - {auto-detected item}
129
+ - {auto-detected item}
130
+ <!-- PROJECT:END -->
131
+
132
+ Any changes?
133
+ ```
134
+
135
+ Wait for the user to confirm or provide edits. Apply all changes in one pass — do not ask about Mission and Essentials separately.
136
+
137
+ After confirmation, write the section into the instruction file inside markers using the harness's file-editing primitive. If the instruction file already contains `<!-- PROJECT:START -->` markers, replace the content between them. If the instruction file does not exist, create it with the markers.
138
+
139
+ ### Step 3: Context Knowledge Auto-Generation
140
+
141
+ Analyze Step 1 scan results to generate context knowledge documents in `.nexus/context/`.
142
+
143
+ Principles:
144
+ - File names and content are decided freely based on project characteristics. No fixed templates.
145
+ - Existing docs are information sources only — do not replicate their structure verbatim.
146
+ - Do not guess content that cannot be confirmed from code.
147
+ - Typically 1-3 files are sufficient. More files are not better.
148
+ - **Generate abstract-level content only** — design patterns, architecture direction, module relationships, conventions. Do NOT include code-level details such as file listings, function signatures, or import maps. Those can be read directly from code.
149
+
150
+ Generation targets (select and name based on what the project actually needs):
151
+ - Development stack (languages, frameworks, runtimes, key dependencies, build/test/deploy workflow)
152
+ - Design and architecture (module relationships, data flow, core entry points, conventions)
153
+ - Implementation specifics (pipeline details, configuration patterns, file structure conventions, tool restrictions — anything too specific for the instruction file but not readable from code alone)
154
+
155
+ Use the harness's file-creation primitive to create files at `.nexus/context/{chosen-name}.md`.
156
+
157
+ For large projects, spawn Writer subagents per topic to generate context knowledge in parallel. Lead coordinates and reviews outputs.
158
+
159
+ On completion: "context knowledge N files generated"
160
+
161
+ ### Step 4: Rules Initial Setup (Optional)
162
+
163
+ Check whether team custom rules are needed.
164
+
165
+ ```
166
+ AskUserQuestion({ questions: [{ question: "Do you want to set up development rules now?", options: [{label: "Set up", description: "Coding conventions, test policy, commit rules, etc."}, {label: Skip, description: "Can be added later via [rule] tag"}] }] })
167
+ ```
168
+
169
+ If "Set up": present a draft based on scan results → user confirms → save via the harness's file-creation primitive to `.nexus/rules/{topic}.md`.
170
+
171
+ If "Skip": inform and proceed to Step 5.
172
+
173
+ ### Step 5: Completion Summary
174
+
175
+ Output a summary of the onboarding results.
176
+
177
+ ```
178
+ ## Nexus Initialization Complete
179
+
180
+ ### Generated Files
181
+ - instruction file: project section — mission and essentials (<!-- PROJECT:START/END -->)
182
+ - .nexus/context/: {list of generated files}
183
+ - .nexus/rules/: {generated files or "none (skipped)"}
184
+
185
+ ### Next Steps
186
+ - [plan] — research, analyze, and plan before execution
187
+ - [run] — execute from a plan
188
+ - Manual re-run trigger with `--reset` flag — re-run onboarding (existing knowledge will be backed up). See harness docs: slash_command_display.
189
+ ```
@@ -0,0 +1,353 @@
1
+ ---
2
+ description: "Structured multi-perspective analysis to decompose issues, align on decisions, and produce an enriched plan before execution. Plan only — does not execute."
3
+ triggers:
4
+ - plan
5
+ ---
6
+ ## Role
7
+
8
+ Facilitate structured multi-perspective analysis using subagents to decompose issues, deliberate on options, and align on decisions. Lead acts as synthesizer AND active participant — orchestrates subagent research/analysis AND contributes its own position. Does not execute — planning only. Transition to execution is the user's decision.
9
+
10
+ ## Constraints
11
+
12
+ - NEVER execute — this skill is planning only; transition to execution is the user's decision
13
+ - NEVER call `nx_plan_start` before research is complete (research_summary is required)
14
+ - NEVER present multiple issues at once — one issue at a time only
15
+ - NEVER ask groundless questions — always research code/knowledge/decisions first
16
+ - NEVER use the harness's team creation primitive. Inter-agent messaging for resume is permitted ONLY for resuming completed subagents whose `resume_tier` is `persistent` or `bounded`, and ONLY within the constraints of the Resume Policy section below. Direct inter-agent communication to running teammates remains forbidden in plan sessions.
17
+ - MUST record all decisions with `[d]` tag so they are not scattered across turns
18
+ - MUST call `nx_plan_decide` when recording `[d]`
19
+ - MUST check for existing plan.json before starting a new session
20
+ - `[d]` without an active plan.json is BLOCKED — "[d]는 plan 세션 안에서만 유효합니다."
21
+ - MUST present a comparison table before asking for a decision — never present options as prose only. Format:
22
+
23
+ ```
24
+ | | A: {title} | B: {title} |
25
+ |---|---|---|
26
+ | Pros | ... | ... |
27
+ | Cons | ... | ... |
28
+ | Pick | | **(Recommended)** |
29
+ ```
30
+
31
+ ## Guidelines
32
+
33
+ ## Trigger
34
+
35
+ - Explicit tag: `[plan]` — continue existing session if plan.json exists, otherwise start new
36
+ - Additional analysis needed mid-session: spawn HOW subagents independently via the harness's subagent spawn primitive
37
+ - Continuing conversation without a tag → continue existing session
38
+
39
+ ---
40
+
41
+ ## Auto Mode (`[plan:auto]`)
42
+
43
+ When triggered with `[plan:auto]` or invoked via `Skill({ command: "nx-plan" })`, run the full planning process **without user interaction**:
44
+
45
+ 1. **Research** — spawn researcher+Explore subagents (same as interactive)
46
+ 2. **Issue derivation** — Lead identifies issues from research
47
+ 3. **Auto-decide** — for each issue, Lead selects the recommended option without presenting choices. Each `nx_plan_decide(summary)` MUST include: selected approach + reason, AND rejected alternatives + why they were dismissed. No comparison table needed, but internal deliberation is mandatory.
48
+ 4. **Decision briefing** — output a concise summary of all decisions before generating tasks:
49
+ ```
50
+ [auto-plan complete] N issues, N decisions:
51
+ - #1: {selected} ({rejected alternative} — reason)
52
+ - #2: ...
53
+ ```
54
+ Do not wait for user response — proceed immediately to task generation.
55
+ 5. **Plan document** — generate tasks.json following Step 7 rules (including HOW-assisted decomposition if `how_agents` present in plan.json issues). Apply owner table and verification auto-pairing.
56
+
57
+ Key differences from interactive mode:
58
+ - No user prompts or comparison tables — Lead decides autonomously
59
+ - No dynamic agenda proposals — Lead handles all derived issues internally
60
+ - Output: tasks.json ready for `[run]` execution
61
+
62
+ **Scope by invocation context:**
63
+ - `[plan:auto]` standalone → auto-plan + briefing + tasks.json generation. Stops here.
64
+ - Invoked by `[run]` (tasks.json absent) → auto-plan + briefing + tasks.json generation + seamless execution transition. No pause between plan and run.
65
+
66
+ This mode is invoked internally by `[run]` when no tasks.json exists, or explicitly by the user with `[plan:auto]`.
67
+
68
+ ---
69
+
70
+ ## Procedure (Interactive Mode)
71
+
72
+ ### Step 1: Intent Discovery
73
+
74
+ Determine planning depth and identify which HOW subagents to delegate analysis to, based on Progressive Depth.
75
+
76
+ | Level | Signal | Exploration Scope |
77
+ |-------|--------|-------------------|
78
+ | **Specific** | File path, function name, error message, or concrete target named | Focused on the relevant file/module |
79
+ | **Direction-setting** | Open-ended question, "it would be nice if ~", choice needed among approaches | Related area + external case research |
80
+ | **Abstract** | "I don't know how to approach this", goal itself unclear, fundamental direction | Full codebase + external research + comparable project comparison |
81
+
82
+ - Specific request → confirm intent with 1–2 questions, derive issues immediately
83
+ - Direction-setting → use hypothesis-based questions to understand intent
84
+ - Abstract/fundamental → actively interview to uncover root goals the user hasn't clarified
85
+
86
+ **HOW subagent selection rule:**
87
+ - User explicitly names agents → use as-is, propose additions if gaps detected
88
+ - User does not name agents → Lead proposes based on issue scope, confirm with user
89
+ - Additional HOW subagents can be spawned at any time during analysis (Lead's or user's discretion)
90
+
91
+ ### Step 2: Research
92
+
93
+ Understand code, core knowledge, and prior decisions before forming a planning agenda.
94
+
95
+ **Start by checking existing knowledge**: before spawning any subagent, use file pattern search and file reading to scan `.nexus/memory/` and `.nexus/context/` for relevant memos and context files, and use `nx_history_search` to check for prior decisions on this topic. If the needed information is already there, use it directly and skip or narrow the subagent spawn. Only spawn subagents to fill gaps not covered by existing knowledge.
96
+
97
+ **Approach selection:**
98
+
99
+ | Scenario | Approach |
100
+ |----------|----------|
101
+ | Codebase orientation | `Agent({ subagent_type: "explore", prompt: "<file/code search task>" })` for codebase exploration |
102
+ | External research needed | `Agent({ subagent_type: "researcher", prompt: "<research question>" })` for web search |
103
+ | Both codebase and external | Spawn Explore + Researcher in parallel |
104
+
105
+ - NEVER call `nx_plan_start` before research is complete.
106
+ - `research_summary` parameter in `nx_plan_start` is required — forces research completion before session creation.
107
+ - Researcher subagents are spawned via the harness's subagent spawn primitive and return findings to Lead. They do not join the plan session.
108
+
109
+ **Existing session (plan.json present):**
110
+ - Check current state with `nx_plan_status`.
111
+ - If new topic or additional research needed → spawn researcher subagent accordingly.
112
+ - Do not proceed to next issue before research is complete.
113
+
114
+ ### Step 3: Session Setup
115
+
116
+ Register the planning session.
117
+
118
+ 1. **`nx_plan_start(topic, issues, research_summary)`** — register plan in plan.json; auto-archives any existing plan.json.
119
+ 2. Show the issue list to the user and confirm before proceeding.
120
+
121
+ ### Step 4: Analysis
122
+
123
+ **Always proceed one issue at a time.** Never present multiple issues simultaneously.
124
+
125
+ For each issue:
126
+
127
+ 1. **Current State Analysis** — Lead summarizes the current state and problems, drawing on research.
128
+ 2. **Subagent Analysis** — for complex issues, spawn HOW subagents (architect, strategist, etc.) in parallel via the harness's subagent spawn primitive. Each subagent independently analyzes the issue and returns findings.
129
+ - **Domain-Agent mapping** — match issue keywords to recommended HOW subagents:
130
+
131
+ | Domain keywords | Recommended HOW |
132
+ |----------------|-----------------|
133
+ | UI, UX, 디자인, 인터페이스, 사용자 경험, 레이아웃 | Designer |
134
+ | 아키텍처, 시스템 설계, 성능, 구조 변경, API, 스키마 | Architect |
135
+ | 비즈니스, 시장, 전략, 포지셔닝, 경쟁, 수익 | Strategist |
136
+ | 연구 방법론, 근거 평가, 문헌, 실험 설계 | Postdoc |
137
+
138
+ - **Opt-out default**: if the issue matches a domain in the mapping, spawning is the default. Multiple matches → multiple spawns. To skip, state "{Agent} not needed — reason: ..." in the analysis text.
139
+ - **No mapping match**: if no domain matches, Lead analyzes directly. When uncertain, spawn — the cost of an unnecessary spawn is lower than the cost of a shallow analysis.
140
+ - **Record HOW findings**: after HOW subagents return, include their agent names and key findings when recording the decision via `nx_plan_decide(how_agents=[...], how_summary={...})`. This data is stored in plan.json for Step 7 task generation.
141
+ 3. **Present Options** — after synthesis, Lead presents a comparison:
142
+
143
+ ```
144
+ | Item | A: {title} | B: {title} | C: {title} |
145
+ |------|-----------|-----------|-----------|
146
+ | Pros | ... | ... | ... |
147
+ | Cons | ... | ... | ... |
148
+ | Trade-offs | ... | ... | ... |
149
+ | Best for | ... | ... | ... |
150
+
151
+ **Recommendation: {X} ({title})**
152
+
153
+ - Option A falls short because {reason}
154
+ - Option B falls short because {reason}
155
+ - Option X overcomes {A/B limitations} → {core benefit}
156
+ ```
157
+
158
+ 4. **Await user response** — receive free-form responses. Users may combine options, push back, or ask follow-up questions.
159
+
160
+ ## Resume Policy
161
+
162
+ When the harness's resume mechanism is unavailable, ALL resume paths are disabled — force fresh spawn. Otherwise:
163
+
164
+ | resume_tier | Same-issue default | Cross-issue | Disqualifiers |
165
+ |---|---|---|---|
166
+ | persistent | resume by default | Lead opt-in only | counter-evidence / reversal / re-review issue → fresh |
167
+ | bounded | conditional (same artifact only) | forbidden | loop 3x / feedback cycle (REVISION_REQUIRED) → fresh |
168
+ | ephemeral | forbidden | forbidden | N/A (always fresh) |
169
+
170
+ Before resuming a `bounded` agent: include a "re-read target files before any modification" instruction in the prompt. Bounded resume without re-read is BLOCKED.
171
+
172
+ `resume_tier` is read from each agent's frontmatter (`agents/*.md`). If absent, treat as `ephemeral` (most conservative).
173
+
174
+ ### Step 5: Record Decision
175
+
176
+ When the user decides, record with the `[d]` tag.
177
+
178
+ - gate.ts detects `[d]` and routes to `nx_plan_decide`.
179
+ - `nx_plan_decide(issue_id, summary)` — marks issue as `decided`, writes `decision` inline in plan.json.
180
+ - Decisions are NOT written to decisions.json — plan.json is the single source of truth.
181
+ - `[d]` without plan.json is blocked.
182
+ - **Progress anchoring**: immediately after recording, output one line: "Issue #N decided (M of K complete). Next: #X — {title}." This keeps the user oriented in multi-issue sessions.
183
+
184
+ **Immediately after each decision**, Lead checks: "Does this decision create follow-up questions or new issues?" If yes, propose adding via `nx_plan_update(action='add')` before moving to the next issue.
185
+
186
+ **Decision reversal**: if the user wants to reconsider a prior decision ("아까 결정 다시 생각해보자", "issue #N 번복"), Lead calls `nx_plan_update(action='reopen', issue_id=N)` to reopen the issue and returns to Step 4 analysis for that issue.
187
+
188
+ ### Step 6: Dynamic Agenda + Wrap-up
189
+
190
+ After each decision, Lead automatically checks for derived issues.
191
+
192
+ - **Dynamic agenda proposal**: after a decision is recorded, Lead examines whether the decision implies follow-on questions or unresolved sub-issues. If found, propose adding them with `nx_plan_update(action='add', ...)` and confirm with the user before adding.
193
+ - Pending issues remain → naturally transition to the next issue.
194
+ - All issues decided → **Gap check**: compare original question/topic against the issue list.
195
+ - Gap found → register additional issues with `nx_plan_update(action='add', ...)`, return to Step 4.
196
+ - No gap → signal planning complete.
197
+ - Wrap-up: confirm all analysis threads have reported conclusions to Lead.
198
+ - Proceed to Step 7 automatically — do not ask whether to generate the plan document.
199
+
200
+ ### Step 7: Plan Document Generation
201
+
202
+ All issues decided → generate the plan document (tasks.json) immediately:
203
+
204
+ 1. **Collect decisions** — gather all `decided` issues from plan.json
205
+ 2. **Derive tasks** — decompose decisions into concrete, actionable tasks
206
+
207
+ **HOW-assisted task decomposition**: check plan.json issues for `how_agents` field.
208
+ - If HOW agents participated in analysis → re-spawn those HOWs with the decided approach + their prior `how_summary` as context. Ask them to propose task decomposition and owner assignment for their domain.
209
+ - If no HOW agents participated → Lead decomposes alone using the owner table and auto-pairing rules above.
210
+ - This ensures task generation depth is proportional to plan analysis depth.
211
+
212
+ 3. **Enrich each task** with:
213
+ - `approach` — implementation strategy derived from the decision rationale
214
+ - `acceptance` — definition of done, verifiable criteria
215
+ - `risk` — known risks or caveats from the analysis
216
+ - `deps` — task dependencies based on execution order
217
+ - `owner` — assign based on delegation analysis:
218
+
219
+ | Work type | owner | Criteria |
220
+ |-----------|-------|----------|
221
+ | Single file, small change | **lead** | Subagent overhead > task effort |
222
+ | Code implementation (.ts, .js, .py, etc.) | **engineer** | Source code creation/modification |
223
+ | Documentation/content (.md, non-code) | **writer** | .md files, README, docs, non-code content |
224
+ | Web research / external investigation | **researcher** | External information gathering needed |
225
+ | Design analysis / review | **architect** etc. HOW | Technical trade-off judgment |
226
+ | Sequential edits to same file | **lead** | Parallel subagents risk conflict |
227
+
228
+ **Primary metric — artifact-coherence**: a well-scoped task targets a single artifact or a tightly coupled artifact cluster and makes a single coherent change. A change is coherent when (a) it can be described in one sentence, (b) reverting it leaves all other artifacts consistent, and (c) its acceptance can be verified by inspecting its outputs alone.
229
+
230
+ **Verification auto-pairing (conditional)** — create a CHECK task only when the DO task's acceptance includes the appropriate verification trigger:
231
+ - `owner: "engineer"` + acceptance contains a runtime-behavior criterion → pair a **tester** task.
232
+ - `owner: "writer"` + acceptance contains a verifiable deliverable criterion → pair a **reviewer** task.
233
+ - Exclusions: pure refactor (behavior-preserving), type-only changes, docs-adjacent tasks (.md or frontmatter-only, classified under `docs_only` entries in `vocabulary/task-exceptions.yml`), and researcher tasks. Researcher tasks never receive an auto-paired CHECK — research outputs feed Lead or HOW agents directly, not tester or reviewer.
234
+ - Paired verification tasks are linked via `deps` to the original task.
235
+
236
+ **Exception catalog**: task decomposition exceptions are defined in `vocabulary/task-exceptions.yml` (`docs_only.coherent`, `docs_only.independent`, `same_file_bundle`, `generated_artifacts`). When an exception applies to a task, record its id in the task's `context` field so downstream tooling can trace the classification.
237
+
238
+ **Dedup Layer 1 (plan-time static merge)**: before finalizing the task list, scan draft tasks for overlapping target_files. Overlapping tasks are merged into a single owner task via the `same_file_bundle` exception from `vocabulary/task-exceptions.yml` to prevent parallel write conflicts during execution.
239
+
240
+ **DO/CHECK decomposition principle**: DO agents (engineer, writer, researcher) and CHECK agents (tester, reviewer) accumulate less per-task context than HOW agents. When a task involves multiple independent artifacts, decompose across multiple parallel DO/CHECK subagents rather than bundling. HOW agents benefit from consolidated context and should generally remain as single sessions. Parallel decomposition is worthwhile when there are at least three independent artifacts; below that, bundling under one owner is preferable to avoid parallelization overhead.
241
+
242
+ **HOW decomposition rule**: split HOW analysis across multiple subagents only when the issue crosses different rows of the domain-agent mapping table (architect vs designer vs strategist vs postdoc). Sub-concerns within a single domain row belong in one HOW session.
243
+
244
+ 4. **Populate tasks.json** via `nx_task_add`:
245
+ - Set `goal` from the plan topic
246
+ - Set `decisions` from plan.json decided summaries
247
+ - Call `nx_task_add(plan_issue=N, approach, acceptance, risk, owner)` for each task
248
+ - If any decisions involve design or architecture changes, include a task (owner: `writer` or `lead`) to update the relevant files in `.nexus/context/` to reflect those decisions
249
+ 5. **Present plan document** — show the user the generated tasks.json summary for review
250
+ 6. **Present transition**: "Proceed with `[run]` to execute."
251
+
252
+ **Incremental mode**: if tasks.json already exists (e.g., after adding follow-up issues), only add tasks for new decisions. Check `plan_issue` field to avoid duplicating tasks for already-covered issues.
253
+
254
+ ---
255
+
256
+ ## plan → run Transition
257
+
258
+ tasks.json is already generated in Step 7. Plan's role ends here.
259
+ Proceed with `[run]` to execute.
260
+
261
+ ---
262
+
263
+ ## Principles
264
+
265
+ 1. **Active intent discovery** — actively uncover what the user hasn't clarified. Use interviewing to surface the root goal behind the words.
266
+ 2. **Lead as synthesizer AND participant** — Lead does not merely relay subagent findings. Lead forms its own position, makes recommendations, and pushes back with evidence. Not a yes-man.
267
+ 3. **Exploration first + proactive expansion** — research code/knowledge/external sources before planning starts. Never ask groundless questions.
268
+ 4. **Hypothesis-based questions** — instead of empty questions, form hypotheses grounded in research and confirm with the user.
269
+ 5. **Progressive Depth** — automatically adjust planning depth and HOW subagent composition based on request complexity.
270
+ 6. **One at a time** — never present multiple issues at once. Reduce the user's cognitive load.
271
+ 7. **Options must include pros/cons/trade-offs/recommendation** — when recommending, explain why other options fall short.
272
+ 8. **Objective pushback** — even when the user arrives with strong conviction, Lead MUST independently analyze all viable options and present trade-offs the user may not have considered. The comparison table exists to surface what the user doesn't know, not to confirm what they already believe. Counter with evidence when better alternatives exist.
273
+ 9. **Prose conversation by default** — free-form user responses (combinations, pushback, follow-up questions) are the core of planning quality.
274
+ 10. **Dynamic agenda** — decisions create new questions. Lead proactively surfaces derived issues rather than waiting for the user to notice gaps.
275
+
276
+ ---
277
+
278
+ ## State Management
279
+
280
+ ### plan.json
281
+
282
+ `.nexus/state/plan.json` — managed via MCP tools.
283
+
284
+ ```json
285
+ {
286
+ "id": 1,
287
+ "topic": "topic name",
288
+ "issues": [
289
+ {
290
+ "id": 1,
291
+ "title": "issue title",
292
+ "status": "pending"
293
+ },
294
+ {
295
+ "id": 2,
296
+ "title": "issue title",
297
+ "status": "decided",
298
+ "decision": "decision summary",
299
+ "how_agents": ["architect", "designer"],
300
+ "how_summary": {
301
+ "architect": "key findings...",
302
+ "designer": "key findings..."
303
+ }
304
+ }
305
+ ],
306
+ "research_summary": "...",
307
+ "created_at": "2026-01-01T00:00:00Z"
308
+ }
309
+ ```
310
+
311
+ - **Create**: `nx_plan_start(topic, issues, research_summary)` — called in Step 3; auto-archives any existing plan.json
312
+ - **Status**: `nx_plan_status()` — check current issue state + decisions
313
+ - **Update**: `nx_plan_update(action, ...)` — add/remove/modify/reopen issues
314
+ - **Decide**: `nx_plan_decide(issue_id, summary)` — marks issue as `decided`, writes decision inline
315
+ - **File presence = session in progress**
316
+
317
+ ### Topic Switching
318
+
319
+ - `[plan]` → continue existing plan.json if present; start new session if not
320
+ - Continue conversation without tag → continue existing session
321
+ - New `nx_plan_start` call → auto-archives current plan.json before creating new one
322
+
323
+ ### Session Abort
324
+
325
+ To abort a session, archive current state via `nx_task_close`. Incomplete issues/tasks are recorded in history.json for future reference.
326
+
327
+ ---
328
+
329
+ ## Self-Reinforcing Loop
330
+
331
+ ```
332
+ [plan] start → check/continue existing plan.json (start new if none)
333
+
334
+ Intent discovery → research (parallel subagents) → nx_plan_start (register issues)
335
+
336
+ Per-issue: HOW subagent analysis (parallel, independent) → Lead synthesis
337
+ → options comparison → [d] → nx_plan_decide
338
+ → dynamic agenda check → propose derived issues if found
339
+
340
+ Next issue → ... → gap check → planning complete
341
+
342
+ Proceed with `[run]` to execute.
343
+
344
+ [run]: execution skill handles the full pipeline
345
+
346
+ All done → nx_task_close (handled by run skill)
347
+ ```
348
+
349
+ gate.ts detects `[d]` and routes to `nx_plan_decide` if plan.json exists; blocks otherwise.
350
+
351
+ ## Deactivation
352
+
353
+ When transitioning to `[run]`, Plan's role ends. Execution is handled by the run skill.