@inkobytes/nexus 1.0.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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +455 -0
  3. package/bin/nexus.js +108 -0
  4. package/drills/nexus-agent-protocol/README.md +65 -0
  5. package/drills/nexus-agent-protocol/cases/blocked.yaml +20 -0
  6. package/drills/nexus-agent-protocol/cases/claim-before-edit.yaml +16 -0
  7. package/drills/nexus-agent-protocol/cases/current-file-state.yaml +15 -0
  8. package/drills/nexus-agent-protocol/cases/data-boundary-table-header.yaml +21 -0
  9. package/drills/nexus-agent-protocol/cases/data-mutation-delete-rows.yaml +20 -0
  10. package/drills/nexus-agent-protocol/cases/done-claim-adversarial.yaml +18 -0
  11. package/drills/nexus-agent-protocol/cases/ghost-file-claim-loop.yaml +16 -0
  12. package/drills/nexus-agent-protocol/cases/issue-found.yaml +21 -0
  13. package/drills/nexus-agent-protocol/cases/private-path-protection.yaml +23 -0
  14. package/drills/nexus-agent-protocol/cases/queue-is-thin-index.yaml +21 -0
  15. package/drills/nexus-agent-protocol/cases/removal-scope.yaml +26 -0
  16. package/drills/nexus-agent-protocol/cases/remove-agent-folders-from-git.yaml +24 -0
  17. package/drills/nexus-agent-protocol/cases/stale-lock-after-commit.yaml +26 -0
  18. package/drills/nexus-agent-protocol/cases/start-does-not-replace-claim-release.yaml +17 -0
  19. package/drills/nexus-agent-protocol/cases/task-contract.yaml +23 -0
  20. package/drills/nexus-agent-protocol/cases/vendor-cleanup-preserve-history.yaml +24 -0
  21. package/drills/nexus-agent-protocol/cases/wrong-repo-push.yaml +23 -0
  22. package/nexus-dashboard/docs/index.html +183 -0
  23. package/nexus-dashboard/index.html +678 -0
  24. package/nexus-dashboard/logo-nexus.svg +14 -0
  25. package/nexus-dashboard/style.css +1454 -0
  26. package/package.json +42 -0
  27. package/skills/nexus/SKILL.md +62 -0
  28. package/src/commands/checkin.js +19 -0
  29. package/src/commands/checkout.js +33 -0
  30. package/src/commands/chmod.js +93 -0
  31. package/src/commands/claim.js +122 -0
  32. package/src/commands/clean.js +76 -0
  33. package/src/commands/dashboard.js +387 -0
  34. package/src/commands/db.js +256 -0
  35. package/src/commands/doctor.js +958 -0
  36. package/src/commands/drill.js +507 -0
  37. package/src/commands/help.js +8 -0
  38. package/src/commands/init.js +576 -0
  39. package/src/commands/ledger.js +215 -0
  40. package/src/commands/metrics.js +178 -0
  41. package/src/commands/next.js +317 -0
  42. package/src/commands/release.js +107 -0
  43. package/src/commands/soul.js +156 -0
  44. package/src/commands/standup.js +59 -0
  45. package/src/commands/start.js +126 -0
  46. package/src/commands/status.js +109 -0
  47. package/src/hooks/pre-migration-backup.js +35 -0
  48. package/src/lib/agentScopes.js +61 -0
  49. package/src/lib/blackboard.js +90 -0
  50. package/src/lib/config.js +38 -0
  51. package/src/lib/dump.js +63 -0
  52. package/src/lib/git.js +111 -0
  53. package/src/lib/lockManager.js +302 -0
  54. package/src/lib/pathSafety.js +41 -0
  55. package/src/lib/permissions.js +74 -0
@@ -0,0 +1,576 @@
1
+ /**
2
+ * nexus init — scaffold Nexus files into the current repo
3
+ */
4
+
5
+ import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs';
6
+ import { join } from 'path';
7
+ import { cwd } from 'process';
8
+ import { AGENT_SCOPE_ENTRIES } from '../lib/agentScopes.js';
9
+ import { DEFAULT_MATRIX } from '../lib/permissions.js';
10
+
11
+ const TEMPLATES = {
12
+ '_NEXUS.md': '',
13
+ 'DECISIONS.md': `# Decisions
14
+
15
+ Local agent work decisions live here. This file is gitignored by Nexus.
16
+ `,
17
+
18
+ '_NEXUS_STANDUP.md': `# šŸŽÆ NEXUS SWARM HQ
19
+
20
+ ## šŸ“‹ The Board
21
+ *Rules: Only work on tasks tagged with your @handle. Claim files with \`nexus claim\` before coding.*
22
+
23
+ ### Epics (High Level)
24
+
25
+ - [ ] EPIC: Build a Hello World app
26
+ - Status: Approved
27
+ - Owner: @You
28
+ - Assignments:
29
+ - @Agent-1 → src/hello.js (main entry point)
30
+ - @Agent-2 → src/utils.js (helper functions)
31
+ - Owner comment: Keep it simple. One file each, no overlap.
32
+
33
+ ## Runways
34
+
35
+ - @Agent-1: Hello World -> next assigned epic
36
+ - @Agent-2: Hello World -> next assigned epic
37
+
38
+ ## Ready Queue
39
+
40
+ - [ ] TASK/Agent-1: Create the main hello.js entry point
41
+ - Id: hello-main
42
+ - Epic: Hello World
43
+ - Status: Ready
44
+ - Depends on: none
45
+ - Files: src/hello.js
46
+ - Affinity: entry-point
47
+ - Cost: small
48
+ - Auto-flow: yes
49
+ - Review: approved
50
+ - Approved by: human
51
+
52
+ - [ ] TASK/Agent-2: Create the utils.js helper
53
+ - Id: hello-utils
54
+ - Epic: Hello World
55
+ - Status: Ready
56
+ - Depends on: none
57
+ - Files: src/utils.js
58
+ - Affinity: helpers
59
+ - Cost: small
60
+ - Auto-flow: yes
61
+ - Review: approved
62
+ - Approved by: human
63
+
64
+ ---
65
+
66
+ ### šŸ’¬ Comms Log
67
+ *Rules: Append new entries at the bottom. One line per message. Use \`YYYY-MM-DD HH:MM AM/PM @agent [STATUS]: message\` so relevance is visible. Use 🧵 for long discussions.*
68
+ *Status examples: \`[DONE]\`, \`[READY]\`, \`[BLOCKED]\`, \`[NOTE]\`, \`[ASK]\`.*
69
+
70
+ `,
71
+
72
+ '_NEXUS_REPORT.md': `# šŸ“‹ NEXUS REPORT
73
+ Repo-local release receipts and done-review notes live here.
74
+
75
+ Each \`nexus release\` appends a lightweight backup record:
76
+
77
+ \`\`\`markdown
78
+ Done claim:
79
+ - Changed:
80
+ - Validated:
81
+ - Risk:
82
+
83
+ Adversarial result:
84
+ - Pass, or:
85
+ - Finding:
86
+ \`\`\`
87
+
88
+ `,
89
+
90
+ '_NEXUS_QUEUE.md': `# šŸš€ NEXUS QUEUE
91
+
92
+ ## Runways
93
+
94
+ - @Agent-1: Hello World -> next assigned epic
95
+ - @Agent-2: Hello World -> next assigned epic
96
+
97
+ ## Ready Queue
98
+
99
+ - [ ] TASK/Agent-1: Create the main hello.js entry point
100
+ - Id: hello-main
101
+ - Epic: Hello World
102
+ - Status: Ready
103
+ - Depends on: none
104
+ - Files: src/hello.js
105
+ - Affinity: entry-point
106
+ - Cost: small
107
+ - Auto-flow: yes
108
+ - Review: approved
109
+ - Approved by: human
110
+
111
+ - [ ] TASK/Agent-2: Create the utils.js helper
112
+ - Id: hello-utils
113
+ - Epic: Hello World
114
+ - Status: Ready
115
+ - Depends on: none
116
+ - Files: src/utils.js
117
+ - Affinity: helpers
118
+ - Cost: small
119
+ - Auto-flow: yes
120
+ - Review: approved
121
+ - Approved by: human
122
+ `,
123
+
124
+ '_NEXUS_CHMOD.md': DEFAULT_MATRIX,
125
+
126
+ '_NEXUS_CONSTITUTION.md': `# Nexus Swarm: Core Operating Protocol
127
+
128
+ Nexus is mandatory coordination for agents sharing a local repository.
129
+
130
+ ## 1. Start With Doctor
131
+
132
+ When entering an existing Nexus repo, run:
133
+
134
+ \`\`\`bash
135
+ nexus doctor
136
+ \`\`\`
137
+
138
+ Use the cheap, local, idempotent report to notice missing protocol files, stale locks, missing continuity/memory scaffolds, and legacy helper references. Ask before running \`nexus doctor --fix\` unless the human already approved safe scaffold repair.
139
+
140
+ ## 2. Queue First
141
+
142
+ Before choosing follow-on work, read \`_NEXUS_QUEUE.md\`.
143
+
144
+ - \`_NEXUS_QUEUE.md\` decides executable priority, dependencies, file scope, cost, and \`Auto-flow\`.
145
+ - \`_NEXUS_STANDUP.md\` is for comms, human context, decisions, and completion notes.
146
+ - \`USER.md\`, when present, is local-only human identity and preference context.
147
+ - If queue and standup conflict, follow the queue for what to work on, then use standup to explain or ask.
148
+ - Direct user instruction can override queue order, but not claim/release, data, security, or approval gates.
149
+ - If no explicit user task is given, run \`nexus next @Agent\` and only auto-claim returned work when \`Auto-flow: yes\`.
150
+
151
+ ## 3. Approval Gate
152
+
153
+ If a queue item, standup note, or user instruction says to make a plan and get approval:
154
+
155
+ - stop before claiming implementation files
156
+ - present the plan in the terminal chat
157
+ - wait for explicit approval
158
+
159
+ ## 4. Task Contract Guardrail
160
+
161
+ If a task lacks an explicit why, tradeoff, non-goal, and unacceptable interpretation, treat it as under-specified.
162
+
163
+ Before broad or destructive work, agents must restate:
164
+
165
+ - Why this task exists.
166
+ - What tradeoff is being accepted.
167
+ - What is explicitly out of scope.
168
+ - What interpretation would be unacceptable.
169
+
170
+ If any of those are missing or ambiguous and the task is broad, destructive, irreversible, security-sensitive, architecture-changing, or dependency-related, stop and ask before implementation.
171
+
172
+ ## 5. Drill Guidance
173
+
174
+ Drills are preventive scenario guides for known agent failure modes. If a situation resembles a drill, use that drill to avoid the bad move before acting.
175
+
176
+ | Situation | Drill |
177
+ |---|---|
178
+ | Blocked or unsafe to proceed | \`drills/nexus-agent-protocol/cases/blocked.yaml\` |
179
+ | Found a bug, mismatch, suspicious behavior, or defect | \`drills/nexus-agent-protocol/cases/issue-found.yaml\` |
180
+ | Removing a dependency, service, framework, vendor, or integration | \`drills/nexus-agent-protocol/cases/removal-scope.yaml\` |
181
+ | Task is broad, destructive, irreversible, security-sensitive, architecture-changing, or dependency-related | \`drills/nexus-agent-protocol/cases/task-contract.yaml\` |
182
+ | Touching persisted data, fixtures, uploads, app caches, migrations, or ambiguous data terms | \`drills/nexus-agent-protocol/cases/data-mutation-delete-rows.yaml\` |
183
+
184
+ If no drill matches, continue with the smallest safe change.
185
+ If a referenced drill file is missing, continue from this constitution and use the smallest safe change; ask first if the task is risky.
186
+
187
+ ## 6. Claim Granularity
188
+
189
+ Nexus supports two ownership levels:
190
+
191
+ - **Directory claim**: use for a self-contained module or component folder.
192
+ - **File claim**: use for standalone files, configs, stores, commands, or docs.
193
+
194
+ If a directory is claimed, no other agent may claim a file inside it. If a child file is claimed, another agent may not claim the parent directory.
195
+
196
+ If a claim appears stale, do not edit through it. Run \`nexus status\` or \`nexus doctor\`; use \`nexus clean --stale\` only when ownership is clearly abandoned, otherwise ask or report in standup.
197
+
198
+ ## 7. Execution Loop
199
+
200
+ 1. Select work from \`_NEXUS_QUEUE.md\` or \`nexus next @Agent\`.
201
+ 2. Claim before reading or editing shared project files:
202
+
203
+ \`\`\`bash
204
+ nexus claim <path> @Agent "intent"
205
+ \`\`\`
206
+
207
+ 3. Treat \`nexus claim\` as the atomic lock-and-read boundary and claim output as current file state.
208
+ 4. Do the scoped work only inside the claimed surface.
209
+ 5. Release through Nexus:
210
+
211
+ \`\`\`bash
212
+ nexus release <path> "short commit message"
213
+ \`\`\`
214
+
215
+ 6. Add a short completion note with \`nexus standup "YYYY-MM-DD HH:MM AM/PM @agent [STATUS]: message"\` if useful.
216
+ 7. Run \`nexus next @Agent\` or stand by.
217
+
218
+ ## 8. Delegated Work
219
+
220
+ When a lead agent uses subagents, tools, or parallel workers, Nexus still treats the lead as accountable for repo state.
221
+
222
+ - Claim the full path scope before delegating work that may read or edit shared project files.
223
+ - Tell subagents the claimed path, intent, non-goals, and boundaries before they start.
224
+ - Subagents may help inspect, test, or draft changes, but they must not expand scope or touch unclaimed paths.
225
+ - After subagent work, the lead must re-read affected files before final edits, release, or claims about current state.
226
+ - The release or \`nexus standup\` note must mention delegated work when it affected repo files, tests, or risk.
227
+
228
+ Subagents can be an implementation detail; their repo effects cannot be invisible.
229
+
230
+ ## 9. Current File State
231
+
232
+ - Treat previous chat context, cached model memory, and earlier reads as stale when file contents matter.
233
+ - Before claiming what a file says, making edits, or judging current state, read the file from disk with a fresh command.
234
+ - Treat \`nexus claim\` as the atomic lock-and-read boundary and its output as fresh file state for the claimed path.
235
+ - If you read a shared file before claiming it, treat that read as stale after claim succeeds.
236
+ - If another agent or tool may have touched the file since your last read, re-read it before editing.
237
+
238
+ ## 10. Golden Rules
239
+
240
+ - Never modify shared project files without \`nexus claim\`.
241
+ - Never run \`git commit\` manually for claimed work; use \`nexus release\`.
242
+ - Never claim inside another agent's locked directory.
243
+ - Agent instruction files are shared protocol files; normal edits require claim/release, while \`nexus doctor --fix\` may update managed protocol blocks after user approval.
244
+ - Direct user instruction can override assignment, but not claim/release safety.
245
+ - Do not free-roam into \`Auto-flow: no\` work without approval.
246
+ - Agents work inside assigned work zones. If a change crosses work-zone boundaries or alters a shared contract another zone may depend on, announce it in \`_NEXUS_STANDUP.md\` before release and ask if coordination is needed.
247
+ - If no safe task remains, announce \`Standby\` with what you are waiting for, then stop until user input, queue change, or explicit assignment.
248
+ - A small safe change does not alter exported type signatures, public APIs, auth, billing, permissions, data schema, migrations, dependency graph, or cross-agent ownership boundaries.
249
+
250
+ ## 11. Root-Cause Guardrails
251
+
252
+ - Prefer root-cause fixes over workaround paths.
253
+ - When removing a dependency, service, framework, or vendor, remove only project-owned integrations that are explicitly in scope.
254
+ - Treat third-party package internals, lockfiles, generated files, build output, and dependency trees as evidence to report, not permission to remove the package.
255
+ - If removing the target would delete or disable an unported feature, stop and ask whether to port it first or remove it.
256
+ - Treat persisted data as state, not an ordinary code artifact.
257
+ - Do not write, delete, reset, reseed, migrate, or alter data without explicit operation-level approval.
258
+ - Before data mutation, state the target environment, affected data, exact command or code path, expected effect, and rollback plan.
259
+ - Clarify ambiguous terms such as table, row, header, column, clean up, reset, remove, old, stale, or unused before mutating data.
260
+ - Never rewrite historical records just to make current code cleaner.
261
+ - For every non-obvious architectural or organizational decision, add a short entry to \`DECISIONS.md\` with:
262
+ - decision
263
+ - reason
264
+ - tradeoff
265
+ - files affected
266
+ - Do not agree reflexively with Pong. Flag technical flaws, hidden costs, security risks, or simpler alternatives plainly and respectfully.
267
+ - Use \`DECISIONS.md\` for durable architecture and protocol decisions; use memory files for session handoff, not permanent system truth.
268
+ - Mention a decision in \`_NEXUS_STANDUP.md\` only when active agents need to coordinate around it.
269
+ - Do not use standup as the permanent decision ledger.
270
+
271
+ ## 12. Supply-Chain Safety
272
+
273
+ - Do not install third-party packages that have existed for less than 14 days.
274
+ - Before adding a new dependency, verify the package creation date and the specific version publish date.
275
+ - If the package or version is younger than 14 days, or either date cannot be verified, stop and ask the human.
276
+ - Treat install hooks and scripts with network commands, webhooks, raw sockets, SSH, or secret-looking variables as human-review only.
277
+
278
+ ## 13. Agent-Local Files
279
+
280
+ Continuity and memory files are agent-local handoff state. They are exempt from claim/release unless the human says otherwise.
281
+
282
+ ## 14. Legacy Helper Transition
283
+
284
+ Older repos may mention shell helpers:
285
+
286
+ \`\`\`text
287
+ ./_nexus_claim.sh -> nexus claim
288
+ ./_nexus_release.sh -> nexus release
289
+ ./_nexus_next.sh -> nexus next
290
+ \`\`\`
291
+
292
+ Prefer the \`nexus\` CLI commands. \`nexus doctor\` reports legacy references.
293
+ `,
294
+ };
295
+
296
+ const GITIGNORE_ENTRY = `
297
+ # Nexus Swarm Stack
298
+ .DS_Store
299
+ DECISIONS.md
300
+ docs-priv/
301
+ .nexus/locks/
302
+ .nexus/presence/
303
+ *.lockdir
304
+ *.flock
305
+ `;
306
+
307
+ const CONTINUITY_TEMPLATE = `# CONTINUITY
308
+ Goal: Project setup
309
+ State: Planning
310
+
311
+ Now: Initial Nexus setup
312
+ Next: Confirm first task
313
+ Blockers: None
314
+ Decisions:
315
+ - Nexus manages swarm coordination
316
+ - Continuity and memories are agent-local
317
+ Files:
318
+ - _NEXUS_QUEUE.md
319
+ - _NEXUS_STANDUP.md
320
+ `;
321
+
322
+ const MEMORY_INDEX_TEMPLATE = `# Memory Index
323
+
324
+ Newest first, max 10 visible entries.
325
+
326
+ Format:
327
+
328
+ - YYYY-Month/YYYY-MM-DD-HHMM-topic.md - short session label
329
+
330
+ Entries live in month folders from the start, for example:
331
+
332
+ - \`2026-January/2026-01-15-1030-project-setup.md\`
333
+ - \`2026-February/2026-02-01-0900-debug-session.md\`
334
+
335
+ This keeps monthly review simple: ask an agent to read one month folder and summarize the Markdown files.
336
+
337
+ `;
338
+
339
+ const MONTH_NAMES = [
340
+ 'January',
341
+ 'February',
342
+ 'March',
343
+ 'April',
344
+ 'May',
345
+ 'June',
346
+ 'July',
347
+ 'August',
348
+ 'September',
349
+ 'October',
350
+ 'November',
351
+ 'December',
352
+ ];
353
+
354
+ const START_MARKER = '<!-- NEXUS-AGENT-PROTOCOL:START -->';
355
+ const END_MARKER = '<!-- NEXUS-AGENT-PROTOCOL:END -->';
356
+
357
+ function currentMemoryMonthFolder(now = new Date()) {
358
+ return `${now.getFullYear()}-${MONTH_NAMES[now.getMonth()]}`;
359
+ }
360
+
361
+ function agentEntrypointTemplate(scaffold) {
362
+ return `# ${scaffold.label} Agent Guide
363
+
364
+ ${START_MARKER}
365
+
366
+ ## Nexus Project Protocol
367
+
368
+ This project uses Nexus for multi-agent coordination.
369
+
370
+ ### Start Here
371
+
372
+ 1. Read \`_NEXUS_CONSTITUTION.md\`.
373
+ 2. Read \`_NEXUS_QUEUE.md\` for executable priorities.
374
+ 3. Read \`_NEXUS_STANDUP.md\` for comms, decisions, and completion notes.
375
+ 4. Read \`USER.md\` if present for local human preferences.
376
+ 5. Read \`${scaffold.continuity}\` for current session state.
377
+ 6. Read \`${scaffold.memoryIndex}\` and the latest memory entry when resync is needed.
378
+
379
+ ### Nexus Rules
380
+
381
+ - Claim before editing shared project files: \`nexus claim <path> @Agent "intent"\`.
382
+ - Release finished work through Nexus: \`nexus release <path> "commit message"\`.
383
+ - Use \`nexus next @Agent\` for the next safe queue task.
384
+ - Do not free-roam into unassigned or \`Auto-flow: no\` work without user approval.
385
+ - Direct user instruction can override queue order, but not claim/release, data, security, or approval gates.
386
+ - If no safe task remains, announce \`Standby\` with what you are waiting for, then stop until user input, queue change, or explicit assignment.
387
+
388
+ ### Current File State
389
+
390
+ - Treat previous chat context, cached model memory, and earlier reads as stale when file contents matter.
391
+ - Before claiming what a file says, making edits, or judging current state, read the file from disk with a fresh command.
392
+ - Treat \`nexus claim\` as the atomic lock-and-read boundary and its output as fresh file state for the claimed path.
393
+ - If you read a shared file before claiming it, treat that read as stale after claim succeeds.
394
+ - If another agent or tool may have touched the file since your last read, re-read it before editing.
395
+ - If a claim appears stale, do not edit through it; run \`nexus status\` or \`nexus doctor\`, then clean only when ownership is clearly abandoned.
396
+
397
+ ### Drills
398
+
399
+ Drill guidance is defined in \`_NEXUS_CONSTITUTION.md\`.
400
+ If the situation resembles a drill, use that drill before acting.
401
+
402
+ ### Delegated Work
403
+
404
+ - Lead agents own the repo effects of their subagents, tools, and parallel workers.
405
+ - Claim the full path scope before delegating shared-file work.
406
+ - Give subagents the claimed path, intent, non-goals, and boundaries.
407
+ - Re-read affected files after subagent work before final edits, release, or current-state claims.
408
+ - Mention delegated work in release or \`nexus standup\` notes when it affected files, tests, or risk.
409
+
410
+ ### Git Write Safety
411
+
412
+ - Before git writes, verify \`pwd\`, repo root, branch/status, and remotes.
413
+ - Stop if they do not match the requested project.
414
+ - Never infer from similar folder names or cached context.
415
+ - Require explicit confirmation before push/force-push, main/master, remote changes, or deletes.
416
+ - To remove private agent files from git, untrack them; do not delete local folders.
417
+ - Agent instruction files are shared protocol files; normal edits require claim/release, while \`nexus doctor --fix\` may update managed protocol blocks after user approval.
418
+ - Agents work inside assigned work zones. If a change crosses work-zone boundaries or alters a shared contract another zone may depend on, announce it in \`_NEXUS_STANDUP.md\` before release and ask if coordination is needed.
419
+
420
+ ### Supply-Chain Safety
421
+
422
+ - Do not install third-party packages that have existed for less than 14 days.
423
+ - Before adding a new dependency, verify the package creation date and the specific version publish date.
424
+ - If the package or version is younger than 14 days, or either date cannot be verified, stop and ask the user.
425
+ - Run \`nexus doctor\` before installs; review any Security findings before running package scripts.
426
+ - \`nexus doctor\` is cheap, local, and idempotent.
427
+ - If \`nexus doctor\` reports Security, Package Privacy, Git Privacy, or supply-chain findings, stop and report before fixing or installing.
428
+ - Treat install hooks and scripts with network commands, webhooks, raw sockets, SSH, or secret-looking variables as human-review only.
429
+ - Prefer built-in runtime APIs and existing project dependencies when they fit.
430
+
431
+ ### Agent-Local Files
432
+
433
+ \`${scaffold.continuity}\` and \`${scaffold.memoryIndex}\` are agent-local handoff files.
434
+ They are exempt from Nexus claim/release unless the user says otherwise.
435
+
436
+ ### Memory Flow
437
+
438
+ - On session start, read \`${scaffold.memoryIndex}\`.
439
+ - If the index has entries, read the newest \`${scaffold.memoryDir}/YYYY-Month/YYYY-MM-DD-HHMM-topic.md\` entry.
440
+ - Durable architecture and protocol decisions belong in \`DECISIONS.md\`; mention them in \`_NEXUS_STANDUP.md\` only when active agents need to coordinate around them.
441
+ - Memory entries are session handoffs.
442
+ - When writing your own memory entry, create the current month folder under \`${scaffold.memoryDir}\` if it is missing.
443
+ - Do not create or repair other agents' memory folders manually; use \`nexus doctor --fix\` for broad scaffold repair.
444
+ - On session end, pause, or checkpoint request:
445
+ 1. Run \`nexus checkout @${scaffold.aliases[0]}\` to clear your presence heartbeat.
446
+ 2. Create one new memory file: \`${scaffold.memoryDir}/YYYY-Month/YYYY-MM-DD-HHMM-topic.md\`.
447
+ - Add the newest file to the top of \`${scaffold.memoryIndex}\`.
448
+ - Keep the index to the 10 newest visible entries.
449
+ - For monthly review, read one month folder such as \`${scaffold.memoryDir}/2026-January/\` and summarize the Markdown files.
450
+
451
+ Memory entry format:
452
+
453
+ \`\`\`markdown
454
+ # YYYY-MM-DD-HHMM - <topic>
455
+
456
+ ## Session Summary
457
+ - What we worked on: [<=50 words]
458
+ - What got done: [bullet list, max 5]
459
+ - Where we stopped: [exact state, <=30 words]
460
+
461
+ ## Next Session Needs
462
+ - Immediate next task: [<=20 words]
463
+ - Blockers: [None, or list]
464
+ - Open questions: [if any]
465
+
466
+ ## Context to Carry
467
+ - Key decisions made: [max 3 bullets]
468
+ - Files touched: [max 5 paths]
469
+ - Gotchas/warnings: [anything next session should watch for]
470
+ \`\`\`
471
+
472
+ ${END_MARKER}
473
+ `;
474
+ }
475
+
476
+ export default function init(args) {
477
+ const root = cwd();
478
+
479
+ // Create .nexus directory
480
+ const nexusDir = join(root, '.nexus');
481
+ const locksDir = join(nexusDir, 'locks');
482
+
483
+ if (!existsSync(nexusDir)) {
484
+ mkdirSync(nexusDir, { recursive: true });
485
+ console.log(' Created .nexus/');
486
+ }
487
+
488
+ if (!existsSync(locksDir)) {
489
+ mkdirSync(locksDir, { recursive: true });
490
+ console.log(' Created .nexus/locks/');
491
+ }
492
+
493
+ // Create agent-local continuity and memory scaffolds.
494
+ // These files are exempt from Nexus claim/release because they are session-local handoff state.
495
+ let agentFilesCreated = 0;
496
+ for (const [, scaffold] of AGENT_SCOPE_ENTRIES) {
497
+ const agentDir = scaffold.dir;
498
+ const baseDir = join(root, agentDir);
499
+ const memoryDir = join(root, scaffold.memoryDir);
500
+ const memoryMonthDir = join(memoryDir, currentMemoryMonthFolder());
501
+ const continuityPath = join(root, scaffold.continuity);
502
+ const memoryIndexPath = join(root, scaffold.memoryIndex);
503
+
504
+ if (!existsSync(baseDir)) {
505
+ mkdirSync(baseDir, { recursive: true });
506
+ console.log(` Created ${agentDir}/`);
507
+ }
508
+
509
+ if (!existsSync(memoryDir)) {
510
+ mkdirSync(memoryDir, { recursive: true });
511
+ console.log(` Created ${scaffold.memoryDir}/`);
512
+ }
513
+
514
+ if (!existsSync(memoryMonthDir)) {
515
+ mkdirSync(memoryMonthDir, { recursive: true });
516
+ console.log(` Created ${scaffold.memoryDir}/${currentMemoryMonthFolder()}/`);
517
+ }
518
+
519
+ if (existsSync(continuityPath)) {
520
+ console.log(` ā­ ${scaffold.continuity} (already exists)`);
521
+ } else {
522
+ writeFileSync(continuityPath, CONTINUITY_TEMPLATE, 'utf-8');
523
+ console.log(` āœ… ${scaffold.continuity}`);
524
+ agentFilesCreated++;
525
+ }
526
+
527
+ if (existsSync(memoryIndexPath)) {
528
+ console.log(` ā­ ${scaffold.memoryIndex} (already exists)`);
529
+ } else {
530
+ writeFileSync(memoryIndexPath, MEMORY_INDEX_TEMPLATE, 'utf-8');
531
+ console.log(` āœ… ${scaffold.memoryIndex}`);
532
+ agentFilesCreated++;
533
+ }
534
+
535
+ const entrypointPath = join(root, scaffold.entrypoint);
536
+ if (existsSync(entrypointPath)) {
537
+ console.log(` ā­ ${scaffold.entrypoint} (already exists)`);
538
+ } else {
539
+ writeFileSync(entrypointPath, agentEntrypointTemplate(scaffold), 'utf-8');
540
+ console.log(` āœ… ${scaffold.entrypoint}`);
541
+ agentFilesCreated++;
542
+ }
543
+ }
544
+
545
+ // Create markdown files (skip if they exist)
546
+ let created = 0;
547
+ for (const [filename, content] of Object.entries(TEMPLATES)) {
548
+ const filePath = join(root, filename);
549
+ if (existsSync(filePath)) {
550
+ console.log(` ā­ ${filename} (already exists)`);
551
+ } else {
552
+ writeFileSync(filePath, content, 'utf-8');
553
+ console.log(` āœ… ${filename}`);
554
+ created++;
555
+ }
556
+ }
557
+
558
+ // Append to .gitignore if needed
559
+ const gitignorePath = join(root, '.gitignore');
560
+ if (existsSync(gitignorePath)) {
561
+ const content = readFileSync(gitignorePath, 'utf-8');
562
+ if (!content.includes('.nexus/locks/')) {
563
+ writeFileSync(gitignorePath, content + GITIGNORE_ENTRY, 'utf-8');
564
+ console.log(' āœ… Updated .gitignore');
565
+ }
566
+ } else {
567
+ writeFileSync(gitignorePath, GITIGNORE_ENTRY.trim() + '\n', 'utf-8');
568
+ console.log(' āœ… Created .gitignore');
569
+ }
570
+
571
+ console.log(`\nšŸ Nexus initialized. ${created} Nexus files created, ${agentFilesCreated} agent session files created.`);
572
+ console.log(' Next steps:');
573
+ console.log(' 1. Copy _NEXUS_CONSTITUTION.md into your agent configs (CLAUDE.md, AGENTS.md, etc.)');
574
+ console.log(' 2. Add epics to _NEXUS_STANDUP.md');
575
+ console.log(' 3. Start claiming.\n');
576
+ }