@moreih29/nexus-core 0.11.0 → 0.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.
Files changed (210) hide show
  1. package/README.md +48 -63
  2. package/assets/agents/architect/body.ko.md +177 -0
  3. package/{agents → assets/agents}/architect/body.md +16 -0
  4. package/assets/agents/designer/body.ko.md +125 -0
  5. package/{agents → assets/agents}/designer/body.md +16 -0
  6. package/assets/agents/engineer/body.ko.md +106 -0
  7. package/{agents → assets/agents}/engineer/body.md +14 -0
  8. package/assets/agents/lead/body.ko.md +70 -0
  9. package/assets/agents/lead/body.md +70 -0
  10. package/assets/agents/postdoc/body.ko.md +122 -0
  11. package/{agents → assets/agents}/postdoc/body.md +16 -0
  12. package/assets/agents/researcher/body.ko.md +137 -0
  13. package/{agents → assets/agents}/researcher/body.md +15 -0
  14. package/assets/agents/reviewer/body.ko.md +138 -0
  15. package/{agents → assets/agents}/reviewer/body.md +15 -0
  16. package/assets/agents/strategist/body.ko.md +116 -0
  17. package/{agents → assets/agents}/strategist/body.md +16 -0
  18. package/assets/agents/tester/body.ko.md +195 -0
  19. package/{agents → assets/agents}/tester/body.md +15 -0
  20. package/assets/agents/writer/body.ko.md +122 -0
  21. package/{agents → assets/agents}/writer/body.md +14 -0
  22. package/assets/capability-matrix.yml +198 -0
  23. package/assets/hooks/agent-bootstrap/handler.test.ts +368 -0
  24. package/assets/hooks/agent-bootstrap/handler.ts +119 -0
  25. package/assets/hooks/agent-bootstrap/meta.yml +10 -0
  26. package/assets/hooks/agent-finalize/handler.test.ts +368 -0
  27. package/assets/hooks/agent-finalize/handler.ts +76 -0
  28. package/assets/hooks/agent-finalize/meta.yml +10 -0
  29. package/assets/hooks/capability-matrix.yml +313 -0
  30. package/assets/hooks/post-tool-telemetry/handler.test.ts +302 -0
  31. package/assets/hooks/post-tool-telemetry/handler.ts +49 -0
  32. package/assets/hooks/post-tool-telemetry/meta.yml +11 -0
  33. package/assets/hooks/prompt-router/handler.test.ts +801 -0
  34. package/assets/hooks/prompt-router/handler.ts +261 -0
  35. package/assets/hooks/prompt-router/meta.yml +11 -0
  36. package/assets/hooks/session-init/handler.test.ts +274 -0
  37. package/assets/hooks/session-init/handler.ts +30 -0
  38. package/assets/hooks/session-init/meta.yml +9 -0
  39. package/assets/lsp-servers.json +55 -0
  40. package/assets/schema/lsp-servers.schema.json +67 -0
  41. package/assets/skills/nx-init/body.ko.md +197 -0
  42. package/{skills → assets/skills}/nx-init/body.md +11 -0
  43. package/assets/skills/nx-plan/body.ko.md +361 -0
  44. package/{skills → assets/skills}/nx-plan/body.md +13 -0
  45. package/assets/skills/nx-run/body.ko.md +161 -0
  46. package/{skills → assets/skills}/nx-run/body.md +11 -0
  47. package/assets/skills/nx-sync/body.ko.md +92 -0
  48. package/{skills → assets/skills}/nx-sync/body.md +10 -0
  49. package/assets/tools/tool-name-map.yml +353 -0
  50. package/dist/hooks/opencode-mount.d.ts +35 -0
  51. package/dist/hooks/opencode-mount.d.ts.map +1 -0
  52. package/dist/hooks/opencode-mount.js +332 -0
  53. package/dist/hooks/opencode-mount.js.map +1 -0
  54. package/dist/hooks/runtime.d.ts +37 -0
  55. package/dist/hooks/runtime.d.ts.map +1 -0
  56. package/dist/hooks/runtime.js +274 -0
  57. package/dist/hooks/runtime.js.map +1 -0
  58. package/dist/hooks/types.d.ts +196 -0
  59. package/dist/hooks/types.d.ts.map +1 -0
  60. package/dist/hooks/types.js +85 -0
  61. package/dist/hooks/types.js.map +1 -0
  62. package/dist/lsp/cache.d.ts +9 -0
  63. package/dist/lsp/cache.d.ts.map +1 -0
  64. package/dist/lsp/cache.js +216 -0
  65. package/dist/lsp/cache.js.map +1 -0
  66. package/dist/lsp/client.d.ts +24 -0
  67. package/dist/lsp/client.d.ts.map +1 -0
  68. package/dist/lsp/client.js +166 -0
  69. package/dist/lsp/client.js.map +1 -0
  70. package/dist/lsp/detect.d.ts +77 -0
  71. package/dist/lsp/detect.d.ts.map +1 -0
  72. package/dist/lsp/detect.js +116 -0
  73. package/dist/lsp/detect.js.map +1 -0
  74. package/dist/mcp/server.d.ts +5 -0
  75. package/dist/mcp/server.d.ts.map +1 -0
  76. package/dist/mcp/server.js +34 -0
  77. package/dist/mcp/server.js.map +1 -0
  78. package/dist/mcp/tools/artifact.d.ts +4 -0
  79. package/dist/mcp/tools/artifact.d.ts.map +1 -0
  80. package/dist/mcp/tools/artifact.js +36 -0
  81. package/dist/mcp/tools/artifact.js.map +1 -0
  82. package/dist/mcp/tools/history.d.ts +3 -0
  83. package/dist/mcp/tools/history.d.ts.map +1 -0
  84. package/dist/mcp/tools/history.js +29 -0
  85. package/dist/mcp/tools/history.js.map +1 -0
  86. package/dist/mcp/tools/lsp.d.ts +13 -0
  87. package/dist/mcp/tools/lsp.d.ts.map +1 -0
  88. package/dist/mcp/tools/lsp.js +225 -0
  89. package/dist/mcp/tools/lsp.js.map +1 -0
  90. package/dist/mcp/tools/plan.d.ts +3 -0
  91. package/dist/mcp/tools/plan.d.ts.map +1 -0
  92. package/dist/mcp/tools/plan.js +317 -0
  93. package/dist/mcp/tools/plan.js.map +1 -0
  94. package/dist/mcp/tools/task.d.ts +3 -0
  95. package/dist/mcp/tools/task.d.ts.map +1 -0
  96. package/dist/mcp/tools/task.js +252 -0
  97. package/dist/mcp/tools/task.js.map +1 -0
  98. package/dist/shared/invocations.d.ts +74 -0
  99. package/dist/shared/invocations.d.ts.map +1 -0
  100. package/dist/shared/invocations.js +247 -0
  101. package/dist/shared/invocations.js.map +1 -0
  102. package/dist/shared/json-store.d.ts +37 -0
  103. package/dist/shared/json-store.d.ts.map +1 -0
  104. package/dist/shared/json-store.js +163 -0
  105. package/dist/shared/json-store.js.map +1 -0
  106. package/dist/shared/mcp-utils.d.ts +3 -0
  107. package/dist/shared/mcp-utils.d.ts.map +1 -0
  108. package/dist/shared/mcp-utils.js +6 -0
  109. package/dist/shared/mcp-utils.js.map +1 -0
  110. package/dist/shared/paths.d.ts +21 -0
  111. package/dist/shared/paths.d.ts.map +1 -0
  112. package/dist/shared/paths.js +81 -0
  113. package/dist/shared/paths.js.map +1 -0
  114. package/dist/shared/tool-log.d.ts +8 -0
  115. package/dist/shared/tool-log.d.ts.map +1 -0
  116. package/dist/shared/tool-log.js +22 -0
  117. package/dist/shared/tool-log.js.map +1 -0
  118. package/dist/types/state.d.ts +862 -0
  119. package/dist/types/state.d.ts.map +1 -0
  120. package/dist/types/state.js +66 -0
  121. package/dist/types/state.js.map +1 -0
  122. package/docs/consuming/codex-lead-merge.md +106 -0
  123. package/docs/plugin-guide.md +360 -0
  124. package/docs/plugin-template/claude/.github/workflows/build.yml +60 -0
  125. package/docs/plugin-template/claude/README.md +110 -0
  126. package/docs/plugin-template/claude/package.json +16 -0
  127. package/docs/plugin-template/codex/.github/workflows/build.yml +51 -0
  128. package/docs/plugin-template/codex/README.md +147 -0
  129. package/docs/plugin-template/codex/package.json +17 -0
  130. package/docs/plugin-template/opencode/.github/workflows/build.yml +61 -0
  131. package/docs/plugin-template/opencode/README.md +121 -0
  132. package/docs/plugin-template/opencode/package.json +25 -0
  133. package/package.json +21 -21
  134. package/scripts/build-agents.test.ts +1279 -0
  135. package/scripts/build-agents.ts +978 -0
  136. package/scripts/build-hooks.test.ts +1385 -0
  137. package/scripts/build-hooks.ts +584 -0
  138. package/scripts/cli.test.ts +367 -0
  139. package/scripts/cli.ts +547 -0
  140. package/agents/architect/meta.yml +0 -13
  141. package/agents/designer/meta.yml +0 -13
  142. package/agents/engineer/meta.yml +0 -11
  143. package/agents/postdoc/meta.yml +0 -13
  144. package/agents/researcher/meta.yml +0 -12
  145. package/agents/reviewer/meta.yml +0 -12
  146. package/agents/strategist/meta.yml +0 -13
  147. package/agents/tester/meta.yml +0 -12
  148. package/agents/writer/meta.yml +0 -11
  149. package/conformance/README.md +0 -311
  150. package/conformance/examples/plan.extension.schema.example.json +0 -25
  151. package/conformance/lifecycle/README.md +0 -48
  152. package/conformance/lifecycle/agent-complete.json +0 -44
  153. package/conformance/lifecycle/agent-resume.json +0 -43
  154. package/conformance/lifecycle/agent-spawn.json +0 -36
  155. package/conformance/lifecycle/memory-access-record.json +0 -27
  156. package/conformance/lifecycle/session-end.json +0 -48
  157. package/conformance/scenarios/full-plan-cycle.json +0 -147
  158. package/conformance/scenarios/task-deps-ordering.json +0 -95
  159. package/conformance/schema/fixture.schema.json +0 -354
  160. package/conformance/state-schemas/agent-tracker.schema.json +0 -63
  161. package/conformance/state-schemas/history.schema.json +0 -134
  162. package/conformance/state-schemas/memory-access.schema.json +0 -36
  163. package/conformance/state-schemas/plan.schema.json +0 -77
  164. package/conformance/state-schemas/tasks.schema.json +0 -98
  165. package/conformance/tools/artifact-write.json +0 -97
  166. package/conformance/tools/context.json +0 -172
  167. package/conformance/tools/history-search.json +0 -219
  168. package/conformance/tools/plan-decide.json +0 -139
  169. package/conformance/tools/plan-start.json +0 -81
  170. package/conformance/tools/plan-status.json +0 -127
  171. package/conformance/tools/plan-update.json +0 -341
  172. package/conformance/tools/task-add.json +0 -156
  173. package/conformance/tools/task-close.json +0 -161
  174. package/conformance/tools/task-list.json +0 -177
  175. package/conformance/tools/task-update.json +0 -167
  176. package/docs/behavioral-contracts.md +0 -145
  177. package/docs/consumer-implementation-guide.md +0 -852
  178. package/docs/memory-lifecycle-contract.md +0 -119
  179. package/docs/nexus-layout.md +0 -224
  180. package/docs/nexus-outputs-contract.md +0 -344
  181. package/docs/nexus-state-overview.md +0 -170
  182. package/docs/nexus-tools-contract.md +0 -438
  183. package/manifest.json +0 -449
  184. package/schema/README.md +0 -69
  185. package/schema/agent.schema.json +0 -23
  186. package/schema/common.schema.json +0 -17
  187. package/schema/manifest.schema.json +0 -78
  188. package/schema/memory-policy.schema.json +0 -98
  189. package/schema/skill.schema.json +0 -54
  190. package/schema/task-exceptions.schema.json +0 -40
  191. package/schema/vocabulary.schema.json +0 -167
  192. package/scripts/.gitkeep +0 -0
  193. package/scripts/conformance-coverage.ts +0 -466
  194. package/scripts/import-from-claude-nexus.ts +0 -403
  195. package/scripts/lib/frontmatter.ts +0 -71
  196. package/scripts/lib/lint.ts +0 -348
  197. package/scripts/lib/structure.ts +0 -159
  198. package/scripts/lib/validate.ts +0 -794
  199. package/scripts/validate.ts +0 -90
  200. package/skills/nx-init/meta.yml +0 -8
  201. package/skills/nx-plan/meta.yml +0 -10
  202. package/skills/nx-run/meta.yml +0 -9
  203. package/skills/nx-sync/meta.yml +0 -7
  204. package/vocabulary/capabilities.yml +0 -65
  205. package/vocabulary/categories.yml +0 -11
  206. package/vocabulary/invocations.yml +0 -147
  207. package/vocabulary/memory_policy.yml +0 -88
  208. package/vocabulary/resume-tiers.yml +0 -11
  209. package/vocabulary/tags.yml +0 -60
  210. package/vocabulary/task-exceptions.yml +0 -29
@@ -1,852 +0,0 @@
1
- # Nexus Consumer Implementation Guide
2
-
3
- **Version:** nexus-core 0.2.0
4
- **Audience:** Developers building a Nexus consumer harness from scratch.
5
-
6
- ---
7
-
8
- ## Table of Contents
9
-
10
- 1. [Overview](#1-overview)
11
- 2. [Prerequisites](#2-prerequisites)
12
- 3. [Component Map and Build Order](#3-component-map-and-build-order)
13
- 4. [State File Management](#4-state-file-management)
14
- 5. [MCP Tool Implementation](#5-mcp-tool-implementation)
15
- 6. [Capability Handling](#6-capability-handling)
16
- 7. [Agent Catalog Construction](#7-agent-catalog-construction)
17
- 8. [Skill Activation Architecture](#8-skill-activation-architecture)
18
- 9. [Hook Event Lifecycle](#9-hook-event-lifecycle)
19
- 10. [Subagent Orchestration Model](#10-subagent-orchestration-model)
20
- 11. [Conformance Verification](#11-conformance-verification)
21
- 12. [Minimum Viable Consumer](#12-minimum-viable-consumer)
22
-
23
- ---
24
-
25
- ## 1. Overview
26
-
27
- A **Nexus consumer** is an execution-layer harness that reads nexus-core and orchestrates agents on behalf of the user. nexus-core is the authoring layer: it defines prompts, metadata, vocabulary, schemas, conformance fixtures, and documentation. The consumer is the runtime layer: it implements tool execution, spawns agents, enforces capability gates, and manages session state.
28
-
29
- ### What nexus-core provides
30
-
31
- - **Agent prompts** — `agents/{id}/body.md`, harness-neutral behavioral specifications for each agent role
32
- - **Skill prompts** — `skills/{id}/body.md`, full behavioral specifications for each skill
33
- - **Metadata** — `agents/{id}/meta.yml` and `skills/{id}/meta.yml`, structured descriptions of each agent and skill
34
- - **Manifest** — `manifest.json`, a single-file snapshot of all agents, skills, and vocabulary for the current version
35
- - **Vocabulary** — `vocabulary/capabilities.yml`, `tags.yml`, `resume-tiers.yml`, `categories.yml`, abstract definitions of the Nexus semantic model
36
- - **Schemas** — `schema/*.json`, JSON Schema definitions for all data structures
37
- - **Conformance fixtures** — `conformance/tools/*.json` and `conformance/scenarios/*.json`, declarative behavioral tests
38
- - **Documentation** — `docs/`, normative specifications for tools, state files, layout, and behavioral contracts
39
-
40
- ### What the consumer builds
41
-
42
- - **Runtime orchestration** — session start/end logic, cycle management, state file creation and cleanup
43
- - **Tool implementation** — concrete implementations of the 11 abstract Nexus tools
44
- - **Hook system** — lifecycle event handlers that fire at well-defined points in the session
45
- - **Capability mapping** — a local file that translates abstract capability IDs to concrete disallowed tools in your harness
46
- - **Agent catalog** — your harness's agent registration, populated from nexus-core agent definitions
47
- - **Skill dispatcher** — tag detection and skill body injection
48
- - **Subagent orchestration** — spawn, context injection, resume evaluation, result collection
49
- - **UI integration** — your harness's plugin registration, command system, and inter-process communication
50
-
51
- ### How to use this guide
52
-
53
- Read this guide cover to cover before writing any code. The sections are ordered by build dependency: later sections assume the structures established by earlier ones. Jumping ahead and implementing subagent orchestration before state file management or tool implementation is defined will produce integration failures that are difficult to diagnose.
54
-
55
- Cross-reference the normative specifications linked throughout. This guide describes what to build and in what order; the linked documents define the precise contracts your implementation must satisfy.
56
-
57
- ---
58
-
59
- ## 2. Prerequisites
60
-
61
- ### Package installation
62
-
63
- Install nexus-core as a development dependency. It is not shipped to end users — it is consumed at build time by your harness.
64
-
65
- ```
66
- npm install --save-dev @moreih29/nexus-core
67
- ```
68
-
69
- After installation, the package is available at `node_modules/@moreih29/nexus-core/`. All paths in this guide referencing nexus-core files resolve from that root.
70
-
71
- ### Knowledge prerequisites
72
-
73
- Before building a consumer, you must be familiar with:
74
-
75
- 1. **Your harness's plugin system** — how to register tools that the LLM can call, how hooks are declared and fire, and how to inject content into the LLM's context (system prompt, tool response, or user message prefix).
76
- 2. **Your harness's agent/subprocess model** — how to spawn an isolated LLM session, how to pass initial context, and how to receive the result.
77
- 3. **JSON and YAML** — all nexus-core metadata files are YAML or JSON; all state files are JSON.
78
-
79
- ### Primary entry points
80
-
81
- Begin your implementation by reading these files in order:
82
-
83
- 1. `manifest.json` — the complete catalog of agents, skills, and vocabulary for the installed version. This is your primary lookup source; most implementation tasks start here.
84
- 2. `docs/nexus-tools-contract.md` — normative specifications for all 11 tools: parameters, return values, side effects, and error conditions. Read this before implementing any tool.
85
- 3. `docs/nexus-state-overview.md` — lifecycle and tool access table for every state file.
86
- 4. `docs/nexus-layout.md` — the canonical `.nexus/` directory structure your harness must create.
87
- 5. `docs/behavioral-contracts.md` — state machines, permission model, resume tier semantics, and the `manual_only` contract.
88
-
89
- ---
90
-
91
- ## 3. Component Map and Build Order
92
-
93
- A complete Nexus consumer comprises nine components. They have hard dependencies: some components cannot be implemented until others are in place. Build them in the order shown.
94
-
95
- ### Components
96
-
97
- | # | Component | Description |
98
- |---|-----------|-------------|
99
- | 1 | `.nexus/` Directory Initialization | Create the required directory tree and `.gitignore` at session start |
100
- | 2 | State File Management | Read/write plan.json, tasks.json, history.json, agent-tracker.json |
101
- | 3 | MCP Tool Implementation | Concrete implementations of the 11 abstract Nexus tools |
102
- | 4 | Capability Mapping | Local file translating abstract capability IDs to concrete disallowed tools |
103
- | 5 | Agent Catalog | Load nexus-core agents, apply capability-map, register with harness |
104
- | 6 | Skill Dispatcher | Detect bracket tags, load skill body.md, inject into LLM context |
105
- | 7 | Hook/Gate System | Lifecycle event handlers: session_start, user_message, pre_tool_use, etc. |
106
- | 8 | Subagent Orchestration | Spawn isolated LLM sessions, pass context, collect results, evaluate resume |
107
- | 9 | Conformance Verification | Run fixtures against your tool implementations to verify interoperability |
108
-
109
- ### Dependency graph
110
-
111
- ```
112
- Directory Init → State File Mgmt → MCP Tools → Capability Mapping
113
- → Agent Catalog → Skill Dispatcher
114
- → Hook/Gate System → Subagent Orchestration
115
- → Conformance Verification
116
- ```
117
-
118
- **Directory Init** must precede everything: state files cannot be written if the directory does not exist.
119
-
120
- **State File Management** must precede tool implementation: tools read and write specific files at specific paths. Without knowing the file layout, tool implementation cannot be completed.
121
-
122
- **MCP Tools** must precede Capability Mapping, Agent Catalog, and Hook/Gate: the capability-map is only useful once the tools it restricts are implemented; the agent catalog is validated against the tool set; hooks reference both.
123
-
124
- **Capability Mapping** must precede Agent Catalog: effective capabilities are computed by merging canonical capabilities with consumer additions, and that merge requires the capability-map to be defined.
125
-
126
- **Agent Catalog** must precede Skill Dispatcher: the dispatcher injects skill body alongside agent context; the agent registration format must exist first.
127
-
128
- **Hook/Gate System** must precede Subagent Orchestration: hooks fire during agent spawn and completion; the hook contracts must be defined before the orchestration logic can reference them.
129
-
130
- **Subagent Orchestration** must precede Conformance Verification: end-to-end scenario fixtures test the full lifecycle, including agent spawning.
131
-
132
- ### Build order within components
133
-
134
- Within MCP Tools, implement in this recommended order:
135
-
136
- 1. `plan_start`, `plan_decide` — the core planning pair; all planning workflows depend on them
137
- 2. `plan_status`, `plan_update` — planning query and mutation
138
- 3. `task_add`, `task_list`, `task_update`, `task_close` — execution lifecycle
139
- 4. `history_search`, `context`, `artifact_write` — support and reporting
140
-
141
- This order matches the dependency chain within the planning/execution lifecycle. Implement and test each tool against its conformance fixtures before moving to the next.
142
-
143
- ---
144
-
145
- ## 4. State File Management
146
-
147
- Nexus state is split into two categories with different scopes, persistence, and git-tracking rules. Your implementation must respect these boundaries exactly.
148
-
149
- ### Two-category model
150
-
151
- **Session-scoped state** lives in `.nexus/state/`. It is created at session start, updated throughout the session, and deleted at session end or cycle close. It must never be git-tracked. Your `.nexus/.gitignore` must contain `state/` to enforce this.
152
-
153
- **Project-scoped content** lives directly under `.nexus/` (outside `state/`). It persists across sessions and git branches. It is git-tracked and committed to the repository.
154
-
155
- ### Directory tree
156
-
157
- ```
158
- .nexus/
159
- ├── state/ ← session-scoped (not git-tracked)
160
- │ ├── plan.json
161
- │ ├── tasks.json
162
- │ ├── tool-log.jsonl
163
- │ ├── artifacts/
164
- │ └── {harness-id}/ ← harness namespace (see §Harness-local State Extension)
165
- │ └── agent-tracker.json
166
- ├── history.json ← project-scoped (git-tracked, append-only)
167
- ├── memory/ ← project-scoped (git-tracked)
168
- │ └── *.md
169
- ├── context/ ← project-scoped (git-tracked, nx-sync managed)
170
- │ └── *.md
171
- ├── rules/ ← project-scoped (git-tracked, user-defined)
172
- │ └── *.md
173
- └── .gitignore
174
- ```
175
-
176
- ### Initialization sequence
177
-
178
- At session start, your harness must:
179
-
180
- 1. Create `.nexus/` if it does not exist.
181
- 2. Create `.nexus/state/` if it does not exist.
182
- 3. Write `.nexus/.gitignore` with content `state/` if the file does not exist.
183
- 4. Create `.nexus/state/{harness-id}/` if it does not exist, then initialize `.nexus/state/{harness-id}/agent-tracker.json` as an empty array `[]`. (`{harness-id}` is the last segment of your npm package name; see [nexus-outputs-contract.md §Shared filename convention](./nexus-outputs-contract.md) for the namespace convention.)
184
- 5. Check for stale state files from a prior crashed session. If `plan.json` or `tasks.json` exist without a running session, warn the user that a previous session may not have closed cleanly.
185
-
186
- ### Key state files
187
-
188
- | File | Scope | Git-tracked | Created by | Deleted by |
189
- |------|-------|------------|------------|------------|
190
- | `state/plan.json` | Session | No | `plan_start` tool | `task_close` tool |
191
- | `state/tasks.json` | Session | No | `task_add` tool (first call) | `task_close` tool |
192
- | `state/{harness-id}/agent-tracker.json` | Session | No | session_start hook | session_end hook |
193
- | `state/tool-log.jsonl` | Session | No | post_tool_use hook | session_end hook |
194
- | `history.json` | Project | Yes | `plan_start` or `task_close` (first archive) | Never |
195
-
196
- ### Schema validation
197
-
198
- JSON Schema definitions for all state files are available in `conformance/state-schemas/`. The schemas cover `plan.json`, `tasks.json`, `history.json`, and `agent-tracker.json`. Validate state files against these schemas in your test suite.
199
-
200
- For full lifecycle and tool access details, see [nexus-state-overview.md](./nexus-state-overview.md) and [nexus-layout.md](./nexus-layout.md).
201
-
202
- ---
203
-
204
- ## 5. MCP Tool Implementation
205
-
206
- The 11 Nexus abstract tools are the interface between the LLM and Nexus state. Your harness implements each one concretely. nexus-core specifies behavior; you choose the registration name, prefix, and implementation mechanism.
207
-
208
- ### The 11 abstract tool names
209
-
210
- | Abstract name | Function |
211
- |---------------|----------|
212
- | `plan_start` | Create a new planning session |
213
- | `plan_status` | Query the current plan state |
214
- | `plan_update` | Add, remove, edit, or reopen plan issues |
215
- | `plan_decide` | Record a decision on a plan issue |
216
- | `task_add` | Add a task to the active task list |
217
- | `task_list` | List tasks with dependency-aware ready set |
218
- | `task_update` | Update a task's status |
219
- | `task_close` | Archive the current cycle to history.json and delete session state files |
220
- | `history_search` | Search past cycles in history.json |
221
- | `context` | Read active session context (branch, task summary, decisions) |
222
- | `artifact_write` | Write a named artifact file to the session artifact directory |
223
-
224
- ### Tool naming
225
-
226
- nexus-core uses abstract names only. Your harness chooses its own registration names. For example, a harness might register `plan_start` as `nx_plan_start`, or a plugin system might prefix it as `mcp__plugin_name_nx__plan_start`. The name you use internally is your decision. The behavioral contract — parameters, return values, side effects, error conditions — is fixed by nexus-core and must not vary.
227
-
228
- ### Implementation contract
229
-
230
- For every tool, implement exactly the parameter schema, return shape, and side effects documented in [nexus-tools-contract.md](./nexus-tools-contract.md). Do not add undocumented parameters or return fields that callers may depend on. Do not omit required return fields.
231
-
232
- Specific requirements to enforce:
233
-
234
- - `plan_start`: when a prior `plan.json` exists, archive it to `history.json` before creating the new session. Failure to archive on replace will cause data loss.
235
- - `task_close`: delete `plan.json` and `tasks.json` after archiving. Leaving these files causes stale state on next session. Files such as `edit-tracker.json` and `reopen-tracker.json` are harness-local concerns and are not managed by `task_close`; delete them in your session_end hook if your harness maintains them.
236
- - `artifact_write`: create `.nexus/state/artifacts/` on demand if it does not exist. Do not require the directory to pre-exist.
237
- - `context`: return `{ active: false }` (for plan_status) or `{ exists: false }` (for task_list) when the relevant state file is absent. Do not return an error.
238
-
239
- ### Implementation order
240
-
241
- Implement in this sequence:
242
-
243
- 1. `plan_start`, `plan_decide` — validates state file management; these are the most frequently tested tools
244
- 2. `plan_status`, `plan_update` — complete the planning surface
245
- 3. `task_add`, `task_list`, `task_update`, `task_close` — execution lifecycle; `task_close` is the cleanup path
246
- 4. `history_search`, `context`, `artifact_write` — support tools; implement after the core tools are passing conformance
247
-
248
- After each tool pair, run the relevant fixtures from `conformance/tools/` before continuing.
249
-
250
- For full parameter schemas, return value shapes, and error conditions, see [nexus-tools-contract.md](./nexus-tools-contract.md).
251
-
252
- ---
253
-
254
- ## 6. Capability Handling
255
-
256
- Capabilities restrict which tools a subagent may call. nexus-core defines capabilities in abstract semantic terms. Your harness translates them into concrete tool blocklists.
257
-
258
- ### Canonical capability definitions
259
-
260
- Read `vocabulary/capabilities.yml`. Each capability has:
261
-
262
- - `id` — the canonical identifier (e.g., `no_file_edit`)
263
- - `intent` — a machine-readable semantic class (e.g., `workspace_write_denial`)
264
- - `blocks_semantic_classes` — the list of semantic operation classes this capability forbids
265
- - `prose_guidance` — a human-readable description of exactly which tool behaviors are blocked and which are not
266
-
267
- The four canonical capabilities in nexus-core 0.2.0:
268
-
269
- | ID | Intent | Blocks |
270
- |----|--------|--------|
271
- | `no_file_edit` | `workspace_write_denial` | `file_creation`, `file_modification`, `file_deletion`, `partial_file_edit`, `structured_document_edit` |
272
- | `no_task_create` | `task_pipeline_append_denial` | `nexus_task_creation` |
273
- | `no_task_update` | `task_pipeline_mutate_denial` | `nexus_task_state_transition`, `nexus_task_metadata_modification` |
274
- | `no_shell_exec` | `shell_execution_denial` | `shell_command_exec`, `subprocess_spawn`, `interactive_shell_session` |
275
-
276
- ### Local capability-map
277
-
278
- Create a consumer-owned capability-map file that translates each capability ID and semantic class to the concrete tool names in your harness. The format is your choice; the following YAML structure is a workable pattern:
279
-
280
- ```yaml
281
- # capability-map.yml (consumer-owned, not part of nexus-core)
282
- no_file_edit:
283
- disallowed_tools:
284
- - YourEditTool
285
- - YourWriteTool
286
- - YourDeleteTool
287
- - YourPatchTool
288
- - YourNotebookCellEditTool
289
- mapped_classes:
290
- - file_creation
291
- - file_modification
292
- - file_deletion
293
- - partial_file_edit
294
- - structured_document_edit
295
-
296
- no_task_create:
297
- disallowed_tools:
298
- - YourTaskAddTool # your harness's concrete registration name for task_add
299
- mapped_classes:
300
- - nexus_task_creation
301
-
302
- no_task_update:
303
- disallowed_tools:
304
- - YourTaskUpdateTool # your harness's concrete registration name for task_update
305
- - YourTaskCloseTool # your harness's concrete registration name for task_close
306
- mapped_classes:
307
- - nexus_task_state_transition
308
- - nexus_task_metadata_modification
309
-
310
- no_shell_exec:
311
- disallowed_tools:
312
- - YourShellTool
313
- - YourSubprocessTool
314
- mapped_classes:
315
- - shell_command_exec
316
- - subprocess_spawn
317
- - interactive_shell_session
318
- ```
319
-
320
- ### Effective capability computation
321
-
322
- When building an agent's effective restriction set, apply the additive-only merge rule defined in [behavioral-contracts.md §4](./behavioral-contracts.md):
323
-
324
- ```
325
- effective_capabilities(agent) = canonical_capabilities(agent) ∪ consumer_additions(agent)
326
- ```
327
-
328
- - `canonical_capabilities` is the `capabilities` array in `agents/{id}/meta.yml` (the nexus-core definition).
329
- - `consumer_additions` is a harness-local set you define for agents where you want stricter restrictions.
330
-
331
- **You may add capabilities. You must not remove canonical capabilities.** Removing `no_file_edit` from an agent that carries it canonically violates the nexus-core design intent. If nexus-core later adds a capability that your consumer already applies locally, the overlap is harmless — the union is idempotent.
332
-
333
- ### Applying the capability-map
334
-
335
- When registering an agent for a subagent session:
336
-
337
- 1. Read the agent's `capabilities` array from `manifest.json` or `agents/{id}/meta.yml`.
338
- 2. Merge with any consumer additions for that agent ID.
339
- 3. For each capability in the merged set, look up `disallowed_tools` in your capability-map.
340
- 4. Build the union of all disallowed tools across all capabilities.
341
- 5. Pass this union to your harness's agent-registration mechanism as the set of tools the agent may not call.
342
-
343
- ### CI coverage assertion
344
-
345
- In your test suite, verify that every `blocks_semantic_classes` value across all entries in `vocabulary/capabilities.yml` has at least one mapped tool in your capability-map. This catches omissions when nexus-core adds new semantic classes in a future version.
346
-
347
- ---
348
-
349
- ## 7. Agent Catalog Construction
350
-
351
- The agent catalog is your harness's internal registry of all Nexus agent roles, populated from nexus-core agent definitions and augmented with harness-specific context.
352
-
353
- ### Reading agent definitions
354
-
355
- Start with `manifest.json`. The `agents` array contains one entry per agent role with these fields:
356
-
357
- | Field | Type | Description |
358
- |-------|------|-------------|
359
- | `id` | string | Canonical agent identifier (e.g., `engineer`) |
360
- | `name` | string | Display name |
361
- | `description` | string | One-line role description |
362
- | `category` | `"how" \| "do" \| "check"` | Role category |
363
- | `resume_tier` | `"persistent" \| "bounded" \| "ephemeral"` | Session persistence behavior |
364
- | `model_tier` | `"high" \| "standard"` | Abstract model selection signal |
365
- | `capabilities` | `string[]` | Canonical capability IDs |
366
- | `body_hash` | string | SHA-256 hash of body.md for integrity verification |
367
-
368
- For full metadata, read `agents/{id}/meta.yml`. For the agent's prompt content, read `agents/{id}/body.md`.
369
-
370
- ### Transformation pipeline
371
-
372
- For each agent in `manifest.json`:
373
-
374
- 1. **Read body.md** from `agents/{id}/body.md`. This is the prompt you will inject into the agent's LLM context.
375
- 2. **Compute effective_capabilities** by merging canonical capabilities with your consumer additions (see §6).
376
- 3. **Resolve disallowed tools** by applying your capability-map to `effective_capabilities`.
377
- 4. **Map model_tier** to a concrete model identifier: `high` → your harness's high-capability model, `standard` → your harness's standard model. This mapping is consumer-owned.
378
- 5. **Register** the agent in your harness's agent system with the resolved prompt, model, and tool restrictions.
379
-
380
- ### Neutral body + harness context synthesis
381
-
382
- `body.md` is deliberately harness-neutral. It says things like "report to Lead" without specifying the concrete mechanism. This is intentional: the same body works across claude-nexus and opencode-nexus because each harness injects the mechanism alongside the body.
383
-
384
- Your harness must inject harness-specific tool awareness when activating an agent. Concretely:
385
-
386
- - body.md says: "report to Lead"
387
- - Your harness injects alongside it: "To report to Lead, use [your harness's inter-agent communication tool]."
388
-
389
- - body.md says: "save your output using the artifact tool"
390
- - Your harness injects alongside it: "The artifact tool in this harness is registered as [your concrete tool name]."
391
-
392
- The `harness_docs_refs` field in `skills/{id}/meta.yml` signals which harness-specific topics should be surfaced when injecting context for that skill. For example, `nx-plan` and `nx-run` both declare `harness_docs_refs: [resume_invocation]` — meaning your harness should inject documentation about how agent resume works in your specific system when those skills are active.
393
-
394
- ### Nine agent roles
395
-
396
- nexus-core 0.2.0 defines these nine agents:
397
-
398
- | ID | Category | Resume tier | Canonical capabilities |
399
- |----|----------|-------------|------------------------|
400
- | `architect` | how | persistent | no_file_edit, no_task_create, no_task_update |
401
- | `designer` | how | persistent | no_file_edit, no_task_create, no_task_update |
402
- | `postdoc` | how | persistent | no_file_edit, no_task_create, no_task_update |
403
- | `strategist` | how | persistent | no_file_edit, no_task_create, no_task_update |
404
- | `engineer` | do | bounded | no_task_create |
405
- | `writer` | do | bounded | no_task_create |
406
- | `researcher` | do | persistent | no_file_edit, no_task_create |
407
- | `tester` | check | ephemeral | no_file_edit, no_task_create |
408
- | `reviewer` | check | ephemeral | no_file_edit, no_task_create |
409
-
410
- All nine roles must be registered in your catalog. A consumer that omits an agent prevents Lead from using that role in plans and run cycles.
411
-
412
- ---
413
-
414
- ## 8. Skill Activation Architecture
415
-
416
- Skills are behavioral specifications that change how Lead operates. Skill activation transforms the LLM's operating mode by injecting a new body.md as its primary instruction set. The activation flow has six stages.
417
-
418
- ### Full activation flow
419
-
420
- ```
421
- User types "[plan] analyze the architecture"
422
- |
423
- v
424
- 1. Tag Detection
425
- - The consumer's user_message hook (or equivalent) intercepts the message
426
- - Scan the message text for bracket tag patterns defined in vocabulary/tags.yml
427
- - "[plan]" matches: id=plan, type=skill, skill=nx-plan
428
- |
429
- v
430
- 2. Routing by type
431
- - type=skill → proceed to skill body loading (step 3)
432
- - type=inline_action → call the handler tool directly; do not load a skill body
433
- Example: "[d]" → call plan_decide tool immediately
434
- |
435
- v
436
- 3. Skill Body Loading
437
- - Read skills/{skill_id}/body.md from the nexus-core package
438
- - This file is the skill's complete behavioral specification
439
- - Also read skills/{skill_id}/meta.yml to check for harness_docs_refs
440
- |
441
- v
442
- 4. LLM Context Injection
443
- - Inject the body.md content into the LLM's operating context
444
- - HOW to inject is consumer's decision:
445
- a. System prompt injection — most common; replaces or appends to the system prompt
446
- b. Tool-response injection — return body.md as a tool response the LLM reads
447
- c. User-message prefix — prepend body.md to the next user message
448
- - Also inject harness-specific context for any harness_docs_refs declared in meta.yml
449
- - The body.md content BECOMES the LLM's operating instructions for this skill
450
- |
451
- v
452
- 5. Skill Active State
453
- - Skill remains active until one of:
454
- a. Session ends — all skills deactivate
455
- b. Another skill is activated — replacement (e.g., [plan] → [run] transition)
456
- c. The skill's own deactivation condition is met
457
- Example: nx-plan completes (all issues decided) → user types [run] to transition
458
- - While active, the skill's body governs Lead's behavior
459
- |
460
- v
461
- 6. manual_only Handling
462
- - Before exposing skills to LLM natural-language detection, check meta.yml
463
- - If manual_only=true: NEVER include in auto-detection candidate list
464
- - Only activate on explicit user trigger: slash command or bracket tag typed by user
465
- - Applies to: nx-init, nx-setup in nexus-core 0.2.0
466
- - See: behavioral-contracts.md §6
467
- ```
468
-
469
- ### Tag variants
470
-
471
- Tags may include variant suffixes. The `variants` field in `vocabulary/tags.yml` lists valid variant tokens for each tag.
472
-
473
- Example: `plan` has `variants: ["auto"]`. This means `[plan:auto]` is a valid trigger that activates the same `nx-plan` skill but passes `auto` as a mode flag. Your consumer must:
474
-
475
- 1. Detect `[plan:auto]` as a variant of the `plan` tag.
476
- 2. Activate the same `nx-plan` skill body.
477
- 3. Pass the variant string (`auto`) to the skill activation logic as an argument or injected parameter.
478
-
479
- The `rule` tag has `variants: ["*"]`, meaning any suffix is valid: `[rule:frontend]`, `[rule:testing]`, etc. Capture the suffix and pass it to the `rule_store` handler.
480
-
481
- ### Inline actions
482
-
483
- Tags with `type=inline_action` do not load a skill body. They trigger a direct tool call.
484
-
485
- | Tag | Handler | Effect |
486
- |-----|---------|--------|
487
- | `[d]` | `nx_plan_decide` | Immediately calls plan_decide with the user's decision text |
488
- | `[m]` | `memory_store` | Stores the current lesson to `.nexus/memory/` |
489
- | `[m:gc]` | `memory_gc` | Garbage-collects `.nexus/memory/` |
490
- | `[rule]` | `rule_store` | Stores a rule to `.nexus/rules/` |
491
-
492
- For inline actions, extract the relevant content from the user's message (the text following the tag) and pass it as the tool parameter. No skill body is loaded; no LLM mode change occurs.
493
-
494
- ### Natural-language trigger detection
495
-
496
- Natural-language trigger detection — recognizing that a user's message implies a skill activation even without a bracket tag — is **consumer-owned**. nexus-core does not define, distribute, or maintain natural-language pattern lists.
497
-
498
- The canonical trigger for every tag is the explicit bracket form in `vocabulary/tags.yml`. Any other activation form (recognizing "let's plan this" as equivalent to `[plan]`) is a consumer extension. Different consumers may implement different patterns. This divergence is explicitly acceptable per [behavioral-contracts.md §7](./behavioral-contracts.md).
499
-
500
- ---
501
-
502
- ## 9. Hook Event Lifecycle
503
-
504
- Hooks are the consumer's mechanism for responding to lifecycle events. nexus-core defines 8 abstract events. The names are harness-neutral; each harness maps them to its own event API.
505
-
506
- ### Relationship to harness-native knowledge surfaces
507
-
508
- Consumer harnesses typically maintain a harness-native primary knowledge surface — for example, a system-prompt layer, a persistent session notice, or a harness banner injected before every LLM call. The hook events and their guidance in §9 are **complementary to** this harness-native surface, not a replacement for it. When §9 says "inject X at hook Y", the concrete injection path may live in the harness-native surface if that produces an equivalent effect. What matters is that the described information reaches the agent at the described moment — the delivery mechanism is consumer-local.
509
-
510
- ### Event mapping examples
511
-
512
- Different harnesses expose these events under different names:
513
-
514
- - **(illustrative, non-normative)** **Claude Code**: `SessionStart`, `UserPromptSubmit`, `SubagentStart`, `SubagentStop`, `PreToolUse`, `PostToolUse`, `Stop`, `PostCompact`
515
- - **OpenCode**: its own hook API names — map accordingly when building an OpenCode consumer
516
-
517
- Identify the equivalent events in your harness's plugin system and implement the expected behaviors below.
518
-
519
- ### 8 lifecycle events
520
-
521
- #### `session_start`
522
-
523
- **When it fires:** A new agent session begins (harness runtime may expose this as `SessionStart`, `session.created`, an init hook, or equivalent).
524
-
525
- **Expected consumer behavior:**
526
- - **SHOULD** create `.nexus/` and `.nexus/state/` directories if they do not exist.
527
- - **SHOULD** write `.nexus/.gitignore` with `state/` if it does not exist.
528
- - **MUST** create `.nexus/state/{harness-id}/` if it does not exist, then initialize `.nexus/state/{harness-id}/agent-tracker.json` as `[]`. `agent-tracker.json` is a shared-purpose session file whose path is namespaced per harness to prevent cross-harness collisions (see [nexus-outputs-contract.md §Shared filename convention](./nexus-outputs-contract.md)).
529
- - On v0.7.0+, harnesses **SHOULD** silently remove any legacy `.nexus/state/agent-tracker.json` (root) at session start. The file is session-scoped and legacy records are safely discarded.
530
-
531
- ---
532
-
533
- #### `user_message`
534
-
535
- **When it fires:** The user submits a message and it is about to be processed (harness runtime may expose this as `UserPromptSubmit`, `message.received`, an on-input hook, or equivalent).
536
-
537
- **Expected consumer behavior:**
538
- - **SHOULD** scan the message text for bracket tags. Match against all triggers defined in `vocabulary/tags.yml`.
539
- - For each matched tag:
540
- - **SHOULD** activate the skill if `type=skill` (see §8, steps 3–5). Do not proceed with normal message handling for that tag.
541
- - **SHOULD** inject contextual guidance into Lead's available context before LLM inference begins:
542
- - Current plan status: if `plan.json` exists, summarize pending vs. decided issues.
543
- - Task progress: if `tasks.json` exists, summarize total/completed/pending counts and the ready-task set.
544
- - **SHOULD** pass the message to Lead without modification if no tags are matched.
545
-
546
- ---
547
-
548
- #### `subagent_spawn`
549
-
550
- **When it fires:** A subagent is created and about to begin execution (harness runtime may expose this as `SubagentStart`, `agent.spawned`, a subagent-init hook, or equivalent).
551
-
552
- **Expected consumer behavior:**
553
- - **MUST** record the new agent entry in `.nexus/state/{harness-id}/agent-tracker.json`: `{ harness_id, agent_name, agent_id, started_at }`.
554
- - **SHOULD** inject the knowledge index into the subagent's initial context: the list of files in `.nexus/memory/`, `.nexus/context/`, and `.nexus/rules/` so the agent knows what project knowledge is available.
555
- - **SHOULD** apply capability restrictions: resolve `effective_capabilities` for this agent type and configure the subagent's tool access accordingly (see §6).
556
- - **SHOULD** apply the resume evaluation: check `owner_reuse_policy` on the task and the agent's `resume_tier` to determine whether to spawn fresh or resume a prior session (see §10).
557
-
558
- ---
559
-
560
- #### `subagent_complete`
561
-
562
- **When it fires:** A subagent finishes its assigned work and returns control (harness runtime may expose this as `SubagentStop`, `agent.completed`, a subagent-exit hook, or equivalent).
563
-
564
- **Expected consumer behavior:**
565
- - **MUST** update `.nexus/state/{harness-id}/agent-tracker.json`: set `status=completed`, record `stopped_at` timestamp.
566
- - **MUST** compute `files_touched` from your tool-log or the subagent's tool usage record. Record which files were created or modified in the `files_touched` array of the agent's `agent-tracker.json` entry. This field is the authoritative source for bounded-tier resume evaluation.
567
- - **MAY** maintain a separate `edit-tracker.json` for cross-session file-touch history, updating it here. This is not a nexus-core requirement; it is a harness-local optimization.
568
- - **SHOULD** surface an unfinished-task warning when the stopping agent has tasks left in `pending` or `in_progress` state. This pattern is observed across consumers and aids recovery; the warning may be injected into Lead's context or surfaced as a reminder.
569
- - **MAY** update the task status in `tasks.json` when the agent was assigned a specific task. Note: this responsibility may alternatively be fulfilled at the Lead or tool-contract layer rather than the hook surface.
570
-
571
- ---
572
-
573
- #### `pre_tool_use`
574
-
575
- **When it fires:** A tool call has been issued and is about to execute (harness runtime may expose this as `PreToolUse`, `tool.before`, a pre-call interceptor, or equivalent).
576
-
577
- **Expected consumer behavior:**
578
- - **SHOULD** enforce a gate for unplanned file edits: if `tasks.json` does not exist and the tool is a file-editing tool, block the call and return an error explaining that edits outside of a planned task cycle are disallowed. This prevents unplanned workspace changes.
579
- - **Capability invariant (MUST)**: disallowed tools MUST NOT execute. **Enforcement layer (consumer choice)**: The abstract invariant holds regardless of enforcement layer. Consumers may enforce at the hook, in static agent config (frontmatter/TOML/disallowedTools), at a framework-level gate, or any combination — the choice is consumer-local. What nexus-core requires is the invariant, not the enforcement mechanism.
580
- - **MAY** apply any other pre-condition checks your harness requires (rate limits, sandbox policies, etc.).
581
-
582
- > **SHOULD note on block reason**: When a tool call is blocked, the `reason` field returned to the LLM is consumed as operational guidance for the next action. Consumers SHOULD compose the `reason` as actionable, directive text rather than a generic error message.
583
-
584
- Read-only tools (query tools, status reads) are never blocked by capability gates. Only tools with primary write effects are subject to capability restrictions.
585
-
586
- ---
587
-
588
- #### `post_tool_use`
589
-
590
- **When it fires:** A tool call has completed and a result is available (harness runtime may expose this as `PostToolUse`, `tool.after`, a post-call interceptor, or equivalent).
591
-
592
- **Expected consumer behavior:**
593
- - **SHOULD** append a log entry to `.nexus/state/tool-log.jsonl`: timestamp, agent_id, tool name, file path (if a file was touched), result status. (This practice is observed across all consumers; nexus-core does not yet define a schema for this file — tracked for v0.11.0.)
594
- - **MAY** record the file path and agent_id in `edit-tracker.json` if your harness maintains it for cross-session file-touch history. This is a harness-local optimization and is not required by nexus-core. The `files_touched` array in `agent-tracker.json` is the nexus-core-defined record of which files an agent touched.
595
- - **MAY** record the error in the log for diagnostic purposes if the tool result indicates an error. Do not suppress error results.
596
-
597
- ---
598
-
599
- #### `session_end`
600
-
601
- **When it fires:** The session is terminating (harness runtime may expose this as `Stop`, `session.end`, a shutdown hook, or equivalent).
602
-
603
- **Expected consumer behavior:**
604
- - **SHOULD** warn the user if `tasks.json` exists and contains incomplete tasks (status `pending` or `in_progress`), that the session is ending with unfinished work and suggest calling `task_close` to archive before exiting.
605
- - **SHOULD** delete `.nexus/state/{harness-id}/agent-tracker.json` (a session-scoped file that has no value beyond the session).
606
- - **MAY** rotate or archive `tool-log.jsonl` if your harness supports log retention.
607
- - **MUST NOT** delete `history.json`, `memory/`, `context/`, or `rules/` — these are project-scoped and must persist across sessions.
608
- - **SHOULD** prompt or block with an "all tasks completed — call `task_close` to archive" reminder when `tasks.json` shows all tasks completed but the cycle has not been archived via `task_close`. Run-cycle closure is a recoverability boundary.
609
-
610
- ---
611
-
612
- #### `context_compact`
613
-
614
- **When it fires:** The runtime compresses the context window (harness runtime may expose this as `PostCompact`, `context.compacted`, a post-compact hook, or equivalent).
615
-
616
- **Expected consumer behavior:**
617
- - **SHOULD** re-inject the critical session snapshot that was lost in compression:
618
- - Active skill/mode: which skill is currently active (plan, run, sync, or none).
619
- - Plan status: if `plan.json` exists, re-inject the issue list with pending/decided status.
620
- - Task progress: if `tasks.json` exists, re-inject the task list with status and ready-task set.
621
- - Knowledge file index: re-inject the list of files in `.nexus/memory/`, `.nexus/context/`, `.nexus/rules/`.
622
- - Active agent list: re-inject which subagents are currently tracked in `.nexus/state/{harness-id}/agent-tracker.json`.
623
- - **SHOULD** restore state from the state files on disk. Context compaction is a context loss event; the LLM cannot reconstruct session state from its compressed context alone.
624
- - **SHOULD** read state files fresh from disk — do not rely on in-memory caches that may also have been cleared.
625
-
626
- ---
627
-
628
- ### 9.X Appendix: Hook Event Runtime Mapping (consumer-owned)
629
-
630
- Each consumer harness MUST publish a mapping document at `harness-content/nexus-hook-mapping.md` in its own repository, listing how its runtime hook surface maps to the 8 conceptual events in §9.
631
-
632
- nexus-core does not mirror these mappings — they are owned and maintained per consumer. This appendix is a registry pointer, not a copy.
633
-
634
- - **harness_docs_refs token**: `nexus_hook_mapping`
635
- - **Expected location in consumer repo**: `harness-content/nexus-hook-mapping.md`
636
- - **Descriptive, not normative**: the consumer mapping document reflects current harness implementation. Verify against the consumer repo for the current mapping — this appendix does not guarantee specific contents.
637
-
638
- ---
639
-
640
- ## 10. Subagent Orchestration Model
641
-
642
- Subagent orchestration is the mechanism by which Lead delegates work to specialized agents. nexus-core specifies the behavioral contracts; the implementation mechanism is consumer-decided.
643
-
644
- ### Spawn model
645
-
646
- When Lead assigns a task to an agent, the consumer:
647
-
648
- 1. Creates an isolated LLM session for the agent. The isolation mechanism is implementation-specific: a subprocess, an API call to a sandboxed session, a parallel conversation thread, or any other approach your harness supports.
649
- 2. Injects the agent's `body.md` as the agent's system prompt or initial context. This is the agent's identity and behavioral specification.
650
- 3. Applies tool restrictions derived from `effective_capabilities` (see §6). The agent session must not have access to tools in its disallowed set.
651
- 4. Passes the task's structured context as the agent's working prompt.
652
- 5. Waits for the agent to complete and collects the result.
653
-
654
- ### Context passing
655
-
656
- Pass task context to the agent in this structured format:
657
-
658
- ```
659
- TASK: {task.title}
660
-
661
- CONTEXT:
662
- {task.context}
663
-
664
- APPROACH:
665
- {task.approach}
666
-
667
- ACCEPTANCE:
668
- {task.acceptance}
669
- ```
670
-
671
- Omit sections whose fields are absent (not all tasks have `approach` or `acceptance` defined). The `task_list` tool returns the full task structure including all optional fields.
672
-
673
- Also inject:
674
- - The knowledge index: file paths in `.nexus/memory/`, `.nexus/context/`, `.nexus/rules/`
675
- - Harness-specific tool name mapping: which of your harness's concrete tool names correspond to the abstract nexus operations the agent's body.md may reference
676
- - Any `harness_docs_refs` from the active skill's meta.yml
677
-
678
- ### Result collection
679
-
680
- The agent produces output: file changes, artifact files, reports, or analysis. How the result is returned to Lead is consumer-decided. Common patterns:
681
-
682
- - **Return value** — the subagent session's final message is returned as a string; Lead reads it directly.
683
- - **Shared filesystem** — the agent writes to `.nexus/state/artifacts/` via the `artifact_write` tool; Lead reads the file.
684
- - **Message passing** — the agent sends a structured message to Lead via your harness's inter-agent communication mechanism; Lead receives and acts on it.
685
-
686
- The body.md of each agent specifies that it should "report to Lead" — whatever concrete mechanism you implement, ensure that the agent's output reaches Lead before the subagent session closes.
687
-
688
- Lead is the only coordinator. Subagents do not communicate directly with each other. All inter-agent communication flows through Lead.
689
-
690
- ### Resume model
691
-
692
- Before spawning an agent, evaluate whether to spawn fresh or resume a prior session. The evaluation follows three inputs:
693
-
694
- **1. `owner_reuse_policy` from `tasks.json`** (per-task override, highest priority):
695
-
696
- | Value | Effect |
697
- |-------|--------|
698
- | `fresh` | Always spawn fresh; ignore resume_tier |
699
- | `resume_if_same_artifact` | Resume only if same agent, same target files, no intervening edits |
700
- | `resume` | Always resume if a prior session is available |
701
- | absent | Fall back to the agent's default resume_tier |
702
-
703
- **2. Agent `resume_tier` from `manifest.json`** (default behavior):
704
-
705
- | Tier | Behavior |
706
- |------|----------|
707
- | `ephemeral` | Always spawn fresh. Independent verification requires no prior context. Applies to: tester, reviewer. |
708
- | `bounded` | Resume only when: same owner identity, same target files, no intervening edits by others. Re-read target files at session start. Applies to: engineer, writer. |
709
- | `persistent` | Resume by default within the same run session. Cross-task reuse allowed. Applies to: architect, designer, postdoc, strategist, researcher. |
710
-
711
- **3. Resume gating**:
712
-
713
- Before attempting to resume, verify that your harness supports the resume mechanism for the current context. If the mechanism is unavailable (the harness cannot reopen a prior session, or no session ID was recorded for this agent), fall back to a fresh spawn silently. Do not surface a resume failure as an error to the user.
714
-
715
- For `bounded` agents evaluating resume eligibility:
716
- - Check `.nexus/state/{harness-id}/agent-tracker.json` for the prior agent ID assigned to this task.
717
- - Scan the `files_touched` arrays of all other completed agents in `agent-tracker.json`. If any other agent has touched the same target files since the last session, treat that as an intervening edit and use a fresh spawn regardless of `owner_reuse_policy`. The `files_touched` field is defined in `state-schemas/agent-tracker.schema.json` and is the nexus-core-defined source for this check.
718
- - If your harness additionally maintains `edit-tracker.json` for finer-grained cross-session tracking, you may consult it as a supplemental heuristic, but it is not required by nexus-core.
719
-
720
- Full resume tier definitions are in [behavioral-contracts.md §3](./behavioral-contracts.md).
721
-
722
- ### Inter-agent communication boundary
723
-
724
- Subagents communicate results to Lead. Lead is responsible for all coordination. No direct subagent-to-subagent communication is defined or permitted by the nexus-core model.
725
-
726
- If your harness exposes an inter-agent communication tool, it must be available to Lead and may be made available to subagents for the purpose of reporting back to Lead. Subagents must not use it to route work to other subagents — that is Lead's responsibility.
727
-
728
- ---
729
-
730
- ## 11. Conformance Verification (Required)
731
-
732
- Consumers MUST pass all conformance fixtures to claim nexus-core compatibility. This is not optional — it is the mechanism by which cross-harness interoperability is guaranteed. Non-conforming implementations may produce state files that other Nexus ecosystem components cannot read, or exhibit behavioral divergence that breaks plan/task lifecycle assumptions.
733
-
734
- ### Fixture types
735
-
736
- **Tool fixtures** (`conformance/tools/*.json`) — single-action tests for individual tools. Each fixture specifies:
737
- - `precondition` — which state files must exist or must not exist before the test
738
- - `action` — the tool name and parameters to call
739
- - `postcondition` — assertions on the return value and state file contents after the call
740
-
741
- **Scenario fixtures** (`conformance/scenarios/*.json`) — multi-step tests for end-to-end lifecycle flows. Each fixture specifies a sequence of steps, each with an action and assertions. Scenarios cover flows such as a full plan cycle and dependency-ordered task execution.
742
-
743
- Available fixture files in nexus-core 0.2.0:
744
-
745
- | File | Coverage |
746
- |------|----------|
747
- | `conformance/tools/plan-start.json` | `plan_start` happy path and edge cases |
748
- | `conformance/tools/plan-decide.json` | `plan_decide` decision recording |
749
- | `conformance/tools/task-add.json` | `task_add` creation and first-time initialization |
750
- | `conformance/tools/task-close.json` | `task_close` archiving and state file deletion |
751
- | `conformance/scenarios/full-plan-cycle.json` | Complete plan → decide → task → close lifecycle |
752
- | `conformance/scenarios/task-deps-ordering.json` | Dependency-ordered task readiness computation |
753
-
754
- ### Writing a test runner
755
-
756
- A conformance test runner:
757
-
758
- 1. Loads a fixture JSON file.
759
- 2. Establishes the precondition: writes or deletes state files as specified.
760
- 3. Calls your harness's implementation of the named tool with the fixture's parameters.
761
- 4. Evaluates postconditions using JSONPath assertions against the return value and state files.
762
- 5. Reports pass/fail per `test_id`.
763
-
764
- Assertion keys in postconditions are JSONPath expressions. A `null` value at a file path key means the file must not exist. A `null` value at a JSONPath key means that field must be `null`.
765
-
766
- The fixture format schema is at `conformance/schema/fixture.schema.json`.
767
-
768
- For runner implementation patterns and a TypeScript sketch, see [conformance/README.md](../conformance/README.md).
769
-
770
- ### CI integration
771
-
772
- Add the conformance test runner to your CI pipeline. Conformance failures MUST block release. Do not merge harness changes that break conformance — a conformance failure means your implementation diverges from the Nexus ecosystem contract.
773
-
774
- Conformance verification is distinct from your harness's own unit tests. Run both.
775
-
776
- ---
777
-
778
- ## 12. Minimum Viable Consumer
779
-
780
- The smallest working Nexus session requires exactly these components. Build this first, verify it works end to end, then expand incrementally.
781
-
782
- ### Tools (4 minimum)
783
-
784
- | Abstract name | Purpose |
785
- |---------------|---------|
786
- | `plan_start` | Create a planning session |
787
- | `plan_decide` | Record decisions on plan issues |
788
- | `task_add` | Add tasks to the execution list |
789
- | `task_close` | Archive the cycle and clean up session state |
790
-
791
- This set covers the complete plan → decide → add tasks → close cycle. Implement these four tools first, run their conformance fixtures, and verify the full cycle before adding more tools.
792
-
793
- ### Agent (1 minimum)
794
-
795
- Register the `engineer` agent:
796
-
797
- - **body.md**: `agents/engineer/body.md`
798
- - **resume_tier**: `bounded`
799
- - **capabilities**: `no_task_create`
800
- - **model_tier**: `standard`
801
-
802
- Engineer is the execution agent. With engineer alone, Lead can delegate implementation tasks and collect results.
803
-
804
- ### Skill (1 minimum)
805
-
806
- Activate `nx-plan` when the user types `[plan]`:
807
-
808
- - **body.md**: `skills/nx-plan/body.md`
809
- - **trigger**: `[plan]` (from `vocabulary/tags.yml`)
810
- - **type**: `skill`
811
-
812
- Implement tag detection in your `user_message` hook. When `[plan]` is detected, load `skills/nx-plan/body.md` and inject it into Lead's context.
813
-
814
- ### Hook events (3 minimum)
815
-
816
- | Event | Minimum required behavior |
817
- |-------|--------------------------|
818
- | `session_start` | Create `.nexus/state/{harness-id}/` directory; initialize `agent-tracker.json` as `[]` |
819
- | `user_message` | Detect `[plan]` tag; load `skills/nx-plan/body.md`; inject into Lead's context |
820
- | `session_end` | Check for `tasks.json`; if present with incomplete tasks, warn the user. If the harness maintains local tracker files (e.g. `edit-tracker.json`, `reopen-tracker.json`), delete them here — see the `session_end` subsection in §9 for full details. |
821
-
822
- ### State files (3 minimum)
823
-
824
- | File | Why it is required |
825
- |------|--------------------|
826
- | `plan.json` | Written by `plan_start`; read by `plan_decide` |
827
- | `tasks.json` | Written by `task_add`; archived by `task_close` |
828
- | `history.json` | Written by `task_close`; the permanent project record |
829
-
830
- ### What this gives you
831
-
832
- A minimum viable consumer supports this complete cycle:
833
-
834
- 1. User types `[plan] let's plan the feature` → `nx-plan` skill activates
835
- 2. Lead runs a planning session, calls `plan_start`, calls `plan_decide` for each issue
836
- 3. Lead calls `task_add` to create implementation tasks
837
- 4. Lead spawns engineer subagent with task context
838
- 5. Engineer completes the work
839
- 6. Lead calls `task_close` to archive the cycle
840
-
841
- ### Incremental expansion path
842
-
843
- Add components in this order after verifying the MVC:
844
-
845
- 1. **`[run]` skill + `nx-run` body** — adds structured execution orchestration; Lead gets the full delegation protocol for parallel task assignment
846
- 2. **Remaining 7 agents** — researcher, architect, postdoc, strategist, designer, writer, tester, reviewer; adds parallel analysis and verification roles
847
- 3. **Remaining 7 tools** — `plan_status`, `plan_update`, `task_list`, `task_update`, `history_search`, `context`, `artifact_write`; completes the full tool surface
848
- 4. **All 8 hook events** — adds `subagent_spawn`, `subagent_complete`, `pre_tool_use`, `post_tool_use`, `context_compact` for full lifecycle management
849
- 5. **Conformance suite** — run all fixtures in `conformance/tools/` and `conformance/scenarios/` before marking the harness production-ready
850
- 6. **`[sync]` skill** — adds `nx-sync` for keeping `.nexus/context/` synchronized with project state
851
-
852
- Do not add the `[sync]`, `nx-init`, or `nx-setup` skills until the core planning and execution lifecycle is verified. These skills depend on the project state infrastructure built by the earlier components.