@lamentis/naome 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/Cargo.lock +2 -2
  2. package/README.md +11 -2
  3. package/bin/naome.js +62 -24
  4. package/crates/naome-cli/Cargo.toml +1 -1
  5. package/crates/naome-cli/src/context_commands.rs +47 -0
  6. package/crates/naome-cli/src/dispatcher.rs +6 -0
  7. package/crates/naome-cli/src/main.rs +43 -6
  8. package/crates/naome-cli/src/quality_commands.rs +31 -46
  9. package/crates/naome-cli/src/quality_output.rs +34 -0
  10. package/crates/naome-cli/src/quality_reconcile_command.rs +45 -0
  11. package/crates/naome-cli/src/repository_model_commands.rs +84 -0
  12. package/crates/naome-cli/src/task_commands.rs +62 -0
  13. package/crates/naome-cli/src/workflow_commands.rs +100 -3
  14. package/crates/naome-core/Cargo.toml +1 -1
  15. package/crates/naome-core/src/context/helpers.rs +75 -0
  16. package/crates/naome-core/src/context/select.rs +134 -0
  17. package/crates/naome-core/src/context/types.rs +43 -0
  18. package/crates/naome-core/src/context.rs +6 -0
  19. package/crates/naome-core/src/decision/states.rs +1 -1
  20. package/crates/naome-core/src/decision.rs +4 -1
  21. package/crates/naome-core/src/install_plan.rs +18 -0
  22. package/crates/naome-core/src/journal.rs +2 -7
  23. package/crates/naome-core/src/lib.rs +33 -10
  24. package/crates/naome-core/src/quality/adapter_ios.rs +131 -0
  25. package/crates/naome-core/src/quality/adapter_support.rs +67 -0
  26. package/crates/naome-core/src/quality/adapters.rs +81 -18
  27. package/crates/naome-core/src/quality/cache.rs +7 -9
  28. package/crates/naome-core/src/quality/checks/duplicate_blocks.rs +4 -7
  29. package/crates/naome-core/src/quality/config.rs +21 -3
  30. package/crates/naome-core/src/quality/mod.rs +138 -7
  31. package/crates/naome-core/src/quality/reconcile.rs +138 -0
  32. package/crates/naome-core/src/quality/reconcile_anchors.rs +64 -0
  33. package/crates/naome-core/src/quality/scanner/analysis.rs +20 -5
  34. package/crates/naome-core/src/quality/scanner.rs +62 -17
  35. package/crates/naome-core/src/quality/semantic/checks.rs +17 -0
  36. package/crates/naome-core/src/quality/semantic/route.rs +1 -1
  37. package/crates/naome-core/src/quality/structure/adapter_ios.rs +149 -0
  38. package/crates/naome-core/src/quality/structure/adapters.rs +60 -42
  39. package/crates/naome-core/src/quality/structure/checks/directory.rs +6 -4
  40. package/crates/naome-core/src/quality/structure/classify/roles.rs +51 -5
  41. package/crates/naome-core/src/quality/structure/config.rs +24 -3
  42. package/crates/naome-core/src/quality/structure/mod.rs +3 -0
  43. package/crates/naome-core/src/quality/types.rs +20 -1
  44. package/crates/naome-core/src/repository_model/detect.rs +188 -0
  45. package/crates/naome-core/src/repository_model/explain.rs +121 -0
  46. package/crates/naome-core/src/repository_model/path_scan.rs +67 -0
  47. package/crates/naome-core/src/repository_model/path_support.rs +59 -0
  48. package/crates/naome-core/src/repository_model/types.rs +152 -0
  49. package/crates/naome-core/src/repository_model/world.rs +48 -0
  50. package/crates/naome-core/src/repository_model/world_adapters.rs +145 -0
  51. package/crates/naome-core/src/repository_model/world_path_facts.rs +55 -0
  52. package/crates/naome-core/src/repository_model/world_paths.rs +168 -0
  53. package/crates/naome-core/src/repository_model.rs +164 -0
  54. package/crates/naome-core/src/route/builtin_checks.rs +40 -1
  55. package/crates/naome-core/src/task_ledger/import.rs +142 -0
  56. package/crates/naome-core/src/task_ledger/model.rs +13 -0
  57. package/crates/naome-core/src/task_ledger/proof_record.rs +52 -0
  58. package/crates/naome-core/src/task_ledger/read.rs +118 -0
  59. package/crates/naome-core/src/task_ledger/render.rs +55 -0
  60. package/crates/naome-core/src/task_ledger/write.rs +38 -0
  61. package/crates/naome-core/src/task_ledger.rs +48 -0
  62. package/crates/naome-core/src/task_state/api.rs +4 -2
  63. package/crates/naome-core/src/task_state/completed_refresh.rs +5 -16
  64. package/crates/naome-core/src/task_state/diff.rs +2 -2
  65. package/crates/naome-core/src/task_state/evidence.rs +8 -3
  66. package/crates/naome-core/src/task_state/mod.rs +1 -1
  67. package/crates/naome-core/src/task_state/progress.rs +13 -0
  68. package/crates/naome-core/src/task_state/proof_model.rs +8 -8
  69. package/crates/naome-core/src/task_state/repair.rs +2 -2
  70. package/crates/naome-core/src/task_state/task_diff_api.rs +9 -18
  71. package/crates/naome-core/src/task_state/types.rs +24 -0
  72. package/crates/naome-core/src/verification.rs +29 -18
  73. package/crates/naome-core/src/workflow/agent/capability.rs +194 -0
  74. package/crates/naome-core/src/workflow/agent/context_delta.rs +42 -0
  75. package/crates/naome-core/src/workflow/agent/decision.rs +32 -0
  76. package/crates/naome-core/src/workflow/agent/execution.rs +80 -0
  77. package/crates/naome-core/src/workflow/agent/proof.rs +24 -0
  78. package/crates/naome-core/src/workflow/agent/support.rs +58 -0
  79. package/crates/naome-core/src/workflow/agent/watchdog.rs +47 -0
  80. package/crates/naome-core/src/workflow/agent.rs +34 -0
  81. package/crates/naome-core/src/workflow/agent_types.rs +105 -0
  82. package/crates/naome-core/src/workflow/doctor.rs +39 -0
  83. package/crates/naome-core/src/workflow/mod.rs +11 -0
  84. package/crates/naome-core/src/workflow/output.rs +8 -2
  85. package/crates/naome-core/src/workflow/phase_inference.rs +1 -1
  86. package/crates/naome-core/tests/context.rs +99 -0
  87. package/crates/naome-core/tests/harness_health.rs +4 -0
  88. package/crates/naome-core/tests/install_plan.rs +12 -0
  89. package/crates/naome-core/tests/quality.rs +178 -2
  90. package/crates/naome-core/tests/quality_performance.rs +39 -2
  91. package/crates/naome-core/tests/quality_structure_adapters.rs +39 -0
  92. package/crates/naome-core/tests/repo_support/mod.rs +5 -1
  93. package/crates/naome-core/tests/repo_support/verification_values.rs +55 -0
  94. package/crates/naome-core/tests/repository_model.rs +281 -0
  95. package/crates/naome-core/tests/route_user_diff.rs +49 -1
  96. package/crates/naome-core/tests/semantic_legacy.rs +72 -38
  97. package/crates/naome-core/tests/task_ledger.rs +328 -0
  98. package/crates/naome-core/tests/task_state.rs +28 -0
  99. package/crates/naome-core/tests/verification.rs +29 -36
  100. package/crates/naome-core/tests/workflow_agent.rs +233 -0
  101. package/crates/naome-core/tests/workflow_agent_support/mod.rs +159 -0
  102. package/crates/naome-core/tests/workflow_doctor.rs +21 -0
  103. package/installer/codex-hooks.js +121 -0
  104. package/installer/context.js +10 -0
  105. package/installer/filesystem.js +4 -0
  106. package/installer/flows.js +8 -4
  107. package/installer/harness-files.js +6 -0
  108. package/installer/install-plan.js +4 -0
  109. package/installer/main.js +1 -1
  110. package/installer/native.js +1 -1
  111. package/native/darwin-arm64/naome +0 -0
  112. package/native/linux-x64/naome +0 -0
  113. package/package.json +1 -1
  114. package/templates/naome-root/.codex/config.toml +2 -0
  115. package/templates/naome-root/.codex/hooks.json +70 -0
  116. package/templates/naome-root/.naome/bin/check-harness-health.js +8 -6
  117. package/templates/naome-root/.naome/bin/check-task-state.js +12 -7
  118. package/templates/naome-root/.naome/bin/codex-hook-io.js +122 -0
  119. package/templates/naome-root/.naome/bin/codex-hook-policy.js +180 -0
  120. package/templates/naome-root/.naome/bin/codex-hook-runtime.js +174 -0
  121. package/templates/naome-root/.naome/bin/codex-hook.js +6 -0
  122. package/templates/naome-root/.naome/bin/naome.js +35 -4
  123. package/templates/naome-root/.naome/manifest.json +12 -6
  124. package/templates/naome-root/.naome/repository-model.json +6 -0
  125. package/templates/naome-root/.naome/repository-quality.json +3 -1
  126. package/templates/naome-root/.naome/verification.json +15 -1
  127. package/templates/naome-root/AGENTS.md +38 -83
  128. package/templates/naome-root/docs/naome/agent-workflow.md +54 -18
  129. package/templates/naome-root/docs/naome/codex-hooks.md +82 -0
  130. package/templates/naome-root/docs/naome/context-economy.md +73 -0
  131. package/templates/naome-root/docs/naome/first-run.md +25 -14
  132. package/templates/naome-root/docs/naome/index.md +18 -10
  133. package/templates/naome-root/docs/naome/repository-model.md +92 -0
  134. package/templates/naome-root/docs/naome/repository-quality.md +47 -7
  135. package/templates/naome-root/docs/naome/repository-structure.md +10 -3
  136. package/templates/naome-root/docs/naome/task-ledger.md +71 -0
  137. package/templates/naome-root/docs/naome/testing.md +16 -3
@@ -52,6 +52,19 @@
52
52
  ".naome/repository-quality-baseline.json"
53
53
  ],
54
54
  "lastVerified": null
55
+ },
56
+ {
57
+ "id": "repository-semantic-check",
58
+ "command": "node .naome/bin/naome.js semantic check --changed",
59
+ "cwd": ".",
60
+ "purpose": "Validate changed files against deterministic NAOME semantic cleanup rules.",
61
+ "cost": "fast",
62
+ "source": "NAOME built-in",
63
+ "evidence": [
64
+ ".naome/repository-quality.json",
65
+ ".naome/repository-quality-baseline.json"
66
+ ],
67
+ "lastVerified": null
55
68
  }
56
69
  ],
57
70
  "phases": [
@@ -67,7 +80,8 @@
67
80
  "id": "quality",
68
81
  "order": 20,
69
82
  "checkIds": [
70
- "repository-quality-check"
83
+ "repository-quality-check",
84
+ "repository-semantic-check"
71
85
  ]
72
86
  },
73
87
  {
@@ -4,101 +4,56 @@ This repository uses NAOME as its coding-agent harness.
4
4
 
5
5
  ## Start Here
6
6
 
7
- 1. Read `.naomeignore`.
8
- 2. Do not read any file or directory matched by `.naomeignore`.
9
- 3. If `docs/naome/index.md` or `.naome/bin/check-harness-health.js` is missing,
10
- do not begin feature work. Install the NAOME CLI with
11
- `npm install -g @lamentis/naome`, then run `naome sync --check-update`
12
- from the repository root. Then restart this list.
13
- 4. Read `docs/naome/index.md`.
14
- 5. Read `.naome/init-state.json`.
15
- 6. Read `.naome/task-state.json`.
16
- 7. Read `.naome/upgrade-state.json`.
17
- 8. Run `node .naome/bin/check-harness-health.js`.
18
- 9. If harness health fails, do not begin feature work. Repair the machine-owned
19
- harness files with `naome update` followed by `naome sync`, or ask the user
20
- for one of the listed repair decisions.
21
- 10. If upgrade status is `needs_agent_upgrade`, do not begin feature work. Run
22
- or continue `docs/naome/upgrade.md`.
23
- 11. If `initialized` is `false`, do not begin feature work. Run or continue the
24
- NAOME first-run protocol in `docs/naome/first-run.md`.
25
- 12. Before accepting feature work, run
26
- `node .naome/bin/check-task-state.js --admission`.
27
- 13. If task admission fails, follow `docs/naome/execution.md`.
28
- 14. If `initialized` is `true`, follow `docs/naome/agent-workflow.md`.
7
+ 1. Read `.naomeignore`; it is a hard read boundary.
8
+ 2. Do not read paths matched by `.naomeignore`.
9
+ 3. If `.naome/bin/check-harness-health.js` is missing, run
10
+ `naome sync --check-update` from the repository root, then restart.
11
+ 4. Read `.naome/task-state.json`.
12
+ 5. Run `node .naome/bin/check-harness-health.js`.
13
+ 6. If harness health fails, stop normal feature work and repair with
14
+ `naome update` followed by `naome sync`, or ask for the listed decision.
15
+ 7. Run `node .naome/bin/check-task-state.js --admission` before accepting new
16
+ feature work.
17
+ 8. For natural-language work, write the request to a prompt file and run
18
+ `node .naome/bin/naome.js route --prompt-file <path> --execute --json`.
19
+ 9. Run `node .naome/bin/naome.js context select --prompt-file <path> --json`
20
+ after route, or `node .naome/bin/naome.js context select --changed --json`
21
+ when continuing an existing diff.
22
+ 10. Read only `requiredContext` from context selection. Read `optionalContext`
23
+ only when blocked.
24
+ 11. If first-run or upgrade state blocks work, read only the document named by
25
+ the blocker, such as `docs/naome/first-run.md` or `docs/naome/upgrade.md`.
29
26
 
30
27
  ## Core Rules
31
28
 
32
- - Prefer discovered repository facts over assumptions.
33
- - Do not look for generic root steering files such as `ARCHITECTURE.md` or
34
- `docs/index.md` unless this repository's NAOME docs explicitly name them.
35
- NAOME's default architecture and index files are
36
- `docs/naome/architecture.md` and `docs/naome/index.md`.
37
- - Record only facts from this target repository or from the user. Do not import
38
- parent-workspace, outer-agent, chat, or unrelated repository instructions into
39
- this repository's NAOME docs.
29
+ - Prefer deterministic NAOME JSON commands over broad Markdown reading.
40
30
  - Keep changes small and task-focused.
41
- - Read only the NAOME docs relevant to the current task.
42
- - Run Harness Health before Task Admission.
43
- - For natural-language work requests, prefer
44
- `naome route --prompt-file <path> --execute --json` and follow its
45
- `userMessage`, `humanOptions`, `requiredContext`, `taskRoot`, `worktree`, and
46
- `canCreateTask` fields. If `taskRoot` differs from the current directory,
47
- continue the task in `taskRoot`; the original worktree contains unrelated user
48
- edits that must remain untouched. Pure deterministic harness refresh diffs
49
- are baselined in the current worktree before task creation; they must not
50
- create repair-loop task worktrees. Use `naome explain --prompt-file <path>
51
- --json` only for debugging policy.
52
- - If route blocks or performs no mutation, do not fall back to raw `git commit`,
53
- IDE commit, `git add`, or hook bypass commands. Only execute a commit when
54
- NAOME route/commit performs it successfully or the user takes manual Git
55
- ownership outside the agent task.
56
- - If the user explicitly asks to commit their own unowned changes, use NAOME
57
- route so the configured quality gate runs first. NAOME commits only the exact
58
- paths it evaluated, requires committed verification coverage for every path,
59
- and rechecks the final stabilized diff before creating the commit.
60
- - Repair requests may baseline deterministic harness refresh files, but they
61
- must leave unrelated user edits untouched unless the user explicitly takes
62
- manual Git ownership.
63
- - Machine-owned NAOME command shims, schemas, workflow docs, archives, and
64
- native binaries may be local-only ignored files. Missing local-only files are
65
- repaired with `naome update` followed by `naome sync`; they are not project
66
- context.
67
- - Enforce Task Admission before accepting new feature work.
68
31
  - Do not start feature work while the git diff contains setup, upgrade,
69
32
  previous-task, or other unowned changes.
70
- - Treat `.naomeignore` as a hard read boundary. Do not inspect ignored paths
71
- unless the user first removes the path from `.naomeignore`.
72
- - Use `naome workflow search-profile` or equivalent excludes for broad searches;
73
- hidden searches must exclude `.git`, `.naome/archive`, dependencies, build
33
+ - If route blocks or performs no mutation, do not fall back to raw `git commit`,
34
+ IDE commit, `git add`, or hook bypass commands.
35
+ - Use `node .naome/bin/naome.js repo explain --path <path> --json`,
36
+ `structure explain --path <path> --json`, and
37
+ `quality check --path <path>` for path-specific facts and early feedback.
38
+ - For broad searches, use `node .naome/bin/naome.js workflow search-profile`
39
+ or equivalent excludes for `.git`, `.naome/archive`, dependencies, build
74
40
  outputs, caches, and `.naomeignore` paths.
75
- - Use `docs/naome/testing.md` and `.naome/verification.json` before claiming
76
- completion.
77
- - Before claiming completion, run the narrowest meaningful verification that can
78
- falsify the change.
41
+ - Before claiming completion, use `docs/naome/testing.md` and
42
+ `.naome/verification.json`, run the narrowest meaningful proof, then run the
43
+ final changed-file gates.
79
44
  - Report what changed, what was verified, and what remains uncertain.
80
45
 
81
46
  ## Local Authority Boundary
82
47
 
83
48
  The root `AGENTS.md` and NAOME files are the repository harness authority.
84
-
85
- Global skills, editor rules, or agent defaults may be used only as generic
86
- execution technique. They must not add repository policy, required files,
87
- architecture layers, plan formats, verification rules, or product assumptions
88
- unless those rules exist in this repository or the user explicitly confirms them
89
- for this repository.
90
-
91
- If global instructions conflict with NAOME, follow NAOME for repository-local
92
- workflow. Record a conflict in `docs/naome/decisions.md` only when the user makes
93
- a durable local decision.
94
-
95
- ## Nested Agent Instructions
96
-
97
- Nested `AGENTS.md` files may provide task-local evidence for the directory they
98
- govern. They must not override `.naomeignore`, NAOME workflow, security rules,
99
- or the root harness authority.
100
-
101
- ## Archived Instructions
49
+ Global skills or editor defaults may be used only as generic technique. They
50
+ must not add repository policy, required files, architecture layers,
51
+ verification rules, or product assumptions unless this repository or the user
52
+ explicitly confirms them.
53
+
54
+ Nested `AGENTS.md` files may provide task-local evidence for their directory.
55
+ They must not override `.naomeignore`, NAOME workflow, security rules, or the
56
+ root harness authority.
102
57
 
103
58
  Files matched by `.naomeignore` are not active instructions. Historical
104
59
  snapshots in `.naome/archive/` must not be read or used as context unless the
@@ -48,11 +48,30 @@ Use this workflow after first-run intake is complete.
48
48
  15. For broad searches, use `node .naome/bin/naome.js workflow search-profile`
49
49
  or equivalent excludes for `.git`, `.naome/archive`, dependencies, build
50
50
  outputs, caches, and `.naomeignore` paths.
51
- 16. Read only the `requiredContext` returned by route/status plus the smallest
52
- task-relevant NAOME docs.
53
- 17. Inspect the existing code or docs before proposing changes.
54
- 18. Read `testing.md` and `.naome/verification.json`.
55
- 19. Identify the required proof before claiming success.
51
+ 16. Run `node .naome/bin/naome.js context select --prompt-file <path> --json`
52
+ for the routed request, or `node .naome/bin/naome.js context select
53
+ --changed --json` when continuing an existing diff.
54
+ 17. Read only `requiredContext` from context selection. Read `optionalContext`
55
+ only when blocked.
56
+ 18. Run `node .naome/bin/naome.js workflow agent-plan --json` to get the
57
+ execution plan ledger, context delta, proof plan, capability graph,
58
+ edit-session watchdog, and decision gate before broad exploration.
59
+ 19. Inspect the existing code or docs before proposing changes.
60
+ 20. When stack, build, source-root, test-root, or generated-path facts matter,
61
+ run `naome repo check --json`. If it reports stale facts, run
62
+ `naome repo model --write --json`; use
63
+ `naome repo explain --path <path> --json` for path-specific facts instead
64
+ of reading broad Markdown summaries. Normal gates also report stale
65
+ repository facts through `naome doctor`, progress checks, and
66
+ `quality check --changed`.
67
+ 21. When adding or encountering a new language, framework, package manager,
68
+ build system, or generated-file convention, run
69
+ `naome quality reconcile --json`. If it reports missing adapters, run
70
+ `naome quality reconcile --write` instead of hand-editing
71
+ `enabledAdapters`. Quality gates also report `adapter-policy-stale` when
72
+ repository signals and committed policy drift.
73
+ 22. Read `testing.md` and `.naome/verification.json`.
74
+ 23. Identify the required proof before claiming success.
56
75
 
57
76
  ## Instruction Boundaries
58
77
 
@@ -74,6 +93,14 @@ Use this workflow after first-run intake is complete.
74
93
  - Do not read or use files matched by `.naomeignore`.
75
94
  - Do not overwrite user work or existing project policy.
76
95
  - Update NAOME docs only when the change reveals durable project knowledge.
96
+ - Prefer deterministic NAOME JSON commands for repository facts; Markdown should
97
+ explain workflow or contain human-readable views, not become hidden policy.
98
+ - After writing or heavily editing a file, run
99
+ `node .naome/bin/naome.js quality check --path <path>` for early feedback.
100
+ - For a small touched set, run
101
+ `node .naome/bin/naome.js workflow edit-watchdog --path <path> --json` to
102
+ get path-scoped quality commands and scope-drift findings before the final
103
+ changed gate.
77
104
  - Use `node .naome/bin/check-task-state.js --progress` for in-flight task
78
105
  validation. Use the normal task-state check only after setting `complete`.
79
106
  Scope changes outside `allowedPaths` require human review before continuing.
@@ -83,24 +110,33 @@ Use this workflow after first-run intake is complete.
83
110
  1. Identify changed files.
84
111
  2. Match them against `.naome/verification.json`.
85
112
  3. Run the required checks when available.
86
- 4. Record proof in `.naome/task-state.json`, using compact `proofPathSets` and
87
- `proofBatches` when several checks share the same evidence or timestamp.
88
- Include every changed in-scope path reported by git in expanded proof
89
- evidence.
90
- 5. Do not list `.naome/task-state.json` as task scope or proof evidence.
91
- 6. Stop tracked long-running processes or mark them explicitly allowed in
113
+ 4. Prefer ledger-backed task updates. `naome sync` migrates active legacy
114
+ task-state automatically; if a legacy-only active task is still present, run
115
+ `node .naome/bin/naome.js task migrate-ledger --write --json` before adding
116
+ completion proof.
117
+ 5. Record proof in `.naome/tasks/<task-id>/proofs/`. If legacy compatibility
118
+ work is unavoidable, use compact `proofPathSets` and `proofBatches` in
119
+ `.naome/task-state.json` and include every changed in-scope path reported by
120
+ git in expanded proof evidence.
121
+ 6. Run `node .naome/bin/naome.js task render-state --write --json` before
122
+ external compatibility checks. Do not hand-edit the rendered projection when
123
+ `.naome/tasks/active.json` exists.
124
+ 7. Do not list `.naome/task-state.json` or `.naome/tasks/` as task scope or
125
+ proof evidence.
126
+ 8. Stop tracked long-running processes or mark them explicitly allowed in
92
127
  `.naome/processes.json`.
93
- 7. Set task state to `complete`.
94
- 8. Run `node .naome/bin/check-task-state.js`.
95
- 9. If the task-state check prints a next-task admission notice, do not repeat
128
+ 9. Set task status to `complete` in the ledger event stream or legacy task
129
+ state, then render the projection.
130
+ 10. Run `node .naome/bin/check-task-state.js`.
131
+ 11. If the task-state check prints a next-task admission notice, do not repeat
96
132
  internal baseline options in the final response. Use the machine-generated
97
133
  `userMessage` from route/status and mention `humanOptions` only when that
98
134
  array is non-empty.
99
- 10. If no rule matches or the task check fails, report the gap and ask for human
135
+ 12. If no rule matches or the task check fails, report the gap and ask for human
100
136
  review before claiming completion.
101
- 11. Report changed files, exact commands, results, and remaining risk.
102
- 12. Only ask the user for options when intent blocks, the user explicitly asks
103
- to review/revise/cancel, or automatic baselining fails.
137
+ 13. Report changed files, exact commands, results, and remaining risk.
138
+ 14. Only ask the user for options when intent blocks, the user explicitly asks
139
+ to review/revise/cancel, or automatic baselining fails.
104
140
 
105
141
  ## Commit And Push
106
142
 
@@ -0,0 +1,82 @@
1
+ # Optional Codex Hooks
2
+
3
+ NAOME can install repo-local Codex hooks as an optional acceleration layer for coding agents.
4
+
5
+ Hooks are not the source of truth. They provide earlier feedback before an agent spends tokens on work that normal NAOME gates would reject later.
6
+
7
+ Authoritative enforcement remains in:
8
+
9
+ - `.naome/task-state.json` validation
10
+ - `naome route`
11
+ - `naome quality` and `naome semantic` gates
12
+ - `naome commit`
13
+ - repository Git hooks
14
+ - verification proof checks
15
+
16
+ ## Install Or Skip
17
+
18
+ `naome install` and `naome sync` may ask whether to install optional Codex hooks.
19
+
20
+ Answering no is valid. The repository remains fully usable for humans, CI, and agents without Codex hook support.
21
+
22
+ For non-interactive environments, NAOME skips optional hooks unless explicitly requested:
23
+
24
+ ```sh
25
+ NAOME_CODEX_HOOKS=1 naome sync
26
+ NAOME_CODEX_HOOKS=0 naome sync
27
+ ```
28
+
29
+ ## Events
30
+
31
+ The installed dispatcher listens to these Codex events:
32
+
33
+ - `UserPromptSubmit`: performs read-only prompt classification and repo/task inspection. Codex Desktop currently accepts no non-blocking warning decision here, so advisory output is intentionally silent.
34
+ - `PreToolUse`: blocks clear unsafe commands before execution, including destructive Git operations, hook bypasses, force pushes, `.naome/archive` reads, `.naomeignore` reads, and broad searches that do not honor NAOME search boundaries. It also runs commit/push preflight checks.
35
+ - `PostToolUse`: after edits, records changed-file state, narrows checks to files touched by the current tool call when Codex provides a path, compares those files with active task ownership, checks repository-model freshness, and runs cheap path-scoped gates. Non-blocking edit guidance is cached for later Stop/preflight decisions rather than emitted as an unsupported warning.
36
+ - `PermissionRequest`: performs read-only escalation risk classification. Codex Desktop currently accepts no non-blocking warning decision here, so advisory output is intentionally silent.
37
+ - `Stop`: prevents misleading completion claims when scope drift, stale repository-model data, missing proof, an unpushed requested branch, or unresolved requested review comments are still visible.
38
+
39
+ ## Blocking And Advisory Checks
40
+
41
+ Hard blocks are reserved for clear safety violations:
42
+
43
+ - destructive commands such as hard resets, forced cleans, and deleting `.git`
44
+ - hook bypasses such as `--no-verify`
45
+ - force pushes, including `--force`, `--force-with-lease`, and `-f`
46
+ - reads or searches inside `.naome/archive` or paths matched by `.naomeignore`
47
+ - broad search commands that fail NAOME search-profile validation
48
+ - commit/push attempts that would skip required ownership, scope, proof, or repository-model checks
49
+ - final responses that would claim completion while required proof or scope checks are still failing
50
+
51
+ Hook output is conservative for Codex Desktop compatibility: hooks emit `{}` for allowed/advisory outcomes and emit only `{"decision":"block","reason":"..."}` for true blocks. Stable reason codes are embedded in the block reason text.
52
+
53
+ ## Edit-Time Gates
54
+
55
+ After file edits, hooks run only fast deterministic gates. When the tool input identifies touched files, PostToolUse scopes these checks to those files instead of the whole diff:
56
+
57
+ - `git diff --check -- <touched-paths>`
58
+ - `node .naome/bin/naome.js quality check --path <touched-path>`
59
+ - `node .naome/bin/naome.js semantic check --path <touched-path>`
60
+ - active-task scope checking for the touched paths
61
+
62
+ If the touched paths cannot be inferred, PostToolUse falls back to the current changed-file set. These checks are debounced by the current diff signature plus the checked path set. Repeated hook calls over the same content reuse the previous result so normal editing stays responsive.
63
+
64
+ Stop, commit, and push preflight stay full-diff checks. They verify the complete changed-file set so earlier unrelated drift or proof failures cannot be hidden by a later narrow edit.
65
+
66
+ Full suites such as installer tests, Rust builds, package dry-runs, and CI-like workflows are treated as owed proof based on changed paths. They are not run automatically after every edit because they are too slow and noisy for real-time feedback.
67
+
68
+ Every hook advisory calculation maps to a normal NAOME command or gate. If hooks are unavailable, disabled, or not installed, humans can keep working by following the normal route, context-selection, task-state, quality, semantic, verification, and commit gates directly.
69
+
70
+ ## Local Files
71
+
72
+ Opting in installs:
73
+
74
+ - `.codex/config.toml`
75
+ - `.codex/hooks.json`
76
+ - `.naome/bin/codex-hook.js`
77
+ - `.naome/bin/codex-hook-io.js`
78
+ - `.naome/bin/codex-hook-policy.js`
79
+ - `.naome/bin/codex-hook-runtime.js`
80
+ - `docs/naome/codex-hooks.md`
81
+
82
+ These files are repo-local. They are managed only after opt-in and are not required by repositories that decline hooks.
@@ -0,0 +1,73 @@
1
+ # Context Economy
2
+
3
+ NAOME reduces agent token use by selecting task context before broad reading.
4
+
5
+ ## Commands
6
+
7
+ - `node .naome/bin/naome.js workflow agent-plan --json` returns the full
8
+ deterministic run-control bundle for the current task: execution plan,
9
+ context delta, proof plan, capability graph, edit watchdog, and decision
10
+ gate.
11
+ - `node .naome/bin/naome.js context select --prompt-file <path> --json`
12
+ selects context from explicit file/path mentions in a user request.
13
+ - `node .naome/bin/naome.js context select --changed --json` selects context
14
+ from the current diff.
15
+ - `node .naome/bin/naome.js context select --prompt <text> --json` is useful
16
+ for diagnostics and small local prompts.
17
+
18
+ ## Output
19
+
20
+ The selector returns:
21
+
22
+ - `requiredContext`: read these files first.
23
+ - `optionalContext`: read only when required context is insufficient.
24
+ - `forbiddenContext`: paths that must not be used as agent context.
25
+ - `capsule`: compact task type, such as `quality-work` or `source-work`.
26
+ - `commands`: early path-scoped checks plus final changed gates.
27
+ - `budgetLedger`: selected file count, avoided file count, estimated lines, and
28
+ estimated tokens.
29
+
30
+ ## Agent Rule
31
+
32
+ After routing a task, run context selection and read only `requiredContext`.
33
+ Do not read broad NAOME docs just because they exist. Use `optionalContext`
34
+ only when blocked, and prefer path-specific commands such as
35
+ `repo explain --path`, `structure explain --path`, and
36
+ `quality check --path`.
37
+
38
+ ## Run-Control Models
39
+
40
+ The agent-run plan combines seven token-saving models:
41
+
42
+ - Execution plan ledger: ordered read, edit, quality, progress, and proof
43
+ steps for the active task.
44
+ - Context delta: which already-read files are reusable, stale, or still
45
+ required.
46
+ - Proof planner: the next minimal checks in verification phase order, with
47
+ broad checks withheld until earlier gates pass.
48
+ - Output digest: stable command summaries that keep exit code, command, cwd,
49
+ relevant lines, affected paths, and artifacts without expanding full logs.
50
+ - Capability graph: machine-readable languages, build systems, adapters, roots,
51
+ and verification edges.
52
+ - Edit-session watchdog: path-scoped quality commands and scope-drift findings
53
+ for touched files.
54
+ - Decision gate: `continue`, `create_task`, `ask_human`, or `stop` with reason
55
+ codes.
56
+
57
+ Use the focused subcommands when only one model is needed:
58
+
59
+ ```text
60
+ node .naome/bin/naome.js workflow context-delta --read-path <path> --json
61
+ node .naome/bin/naome.js workflow proof-plan --json
62
+ node .naome/bin/naome.js workflow capabilities --json
63
+ node .naome/bin/naome.js workflow edit-watchdog --path <path> --json
64
+ node .naome/bin/naome.js workflow decision-gate --json
65
+ node .naome/bin/naome.js workflow digest --command <cmd> --exit-code <code> --output-file <path> --json
66
+ ```
67
+
68
+ ## Why Runs Get Faster
69
+
70
+ Agent runs become faster because fewer files are loaded, fewer long outputs are
71
+ expanded, and quality or structure issues are caught while the touched file is
72
+ still small. The final changed-file gates remain required; context selection is
73
+ an early feedback and read-boundary tool, not a replacement for verification.
@@ -30,21 +30,32 @@ context.
30
30
 
31
31
  1. Read `.naomeignore` and exclude every matched path from intake.
32
32
  2. Inspect existing repository instructions and docs, including README,
33
- contributing docs, architecture docs, agent instruction files, and CI config.
34
- 3. Detect stack, frameworks, package managers, project layout, entrypoints,
35
- test tools, lint/typecheck/build commands, and deployment hints.
36
- 4. Identify risky areas such as auth, billing, secrets, migrations, production
33
+ contributing docs, agent instruction files, and CI config.
34
+ 3. Refresh deterministic repository facts with
35
+ `naome repo model --write --json`. This records stack, package managers,
36
+ source roots, test roots, generated roots, and verification ids in
37
+ `.naome/repository-model.json`.
38
+ 4. Detect entrypoints, test tools, lint/typecheck/build commands, deployment
39
+ hints, and sensitive areas that are not yet derivable from deterministic
40
+ files.
41
+ Run `naome quality reconcile --json` after policy files exist; if detected
42
+ repository signals require missing adapters, use
43
+ `naome quality reconcile --write` so quality and structure policy match the
44
+ observed stack.
45
+ 5. Identify risky areas such as auth, billing, secrets, migrations, production
37
46
  config, customer data, generated files, or fragile inherited code.
38
- 5. Build the Proof Harness:
47
+ 6. Build the Proof Harness:
39
48
  - inspect package files, build files, Makefiles, and CI workflows
40
49
  - record real checks in `.naome/verification.json`
41
- - mirror the human-readable map in `testing.md`
50
+ - keep `testing.md` as a human-readable view, not the source of truth
42
51
  - run the fastest safe check when possible and record the result
43
52
  - preserve the JSON keys and allowed values documented below
44
- 6. Fill `repo-profile.md`, `testing.md`, `architecture.md`, and `security.md`.
45
- 7. Ask the user for critical missing product intent, forbidden zones, or
53
+ 7. Fill only the minimal human-readable notes still needed in `repo-profile.md`,
54
+ `testing.md`, `architecture.md`, and `security.md`. Do not duplicate facts
55
+ that already live in deterministic JSON.
56
+ 8. Ask the user for critical missing product intent, forbidden zones, or
46
57
  verification commands only if repository evidence is insufficient.
47
- 8. Update `.naome/init-state.json`:
58
+ 9. Update `.naome/init-state.json`:
48
59
  - use `intakeStatus: "complete"` and `initialized: true` only when the
49
60
  completion gate is satisfied
50
61
  - use `intakeStatus: "needs_user_context"` and keep `initialized: false`
@@ -57,11 +68,11 @@ context.
57
68
  Initialization is complete only when:
58
69
 
59
70
  - `repo-profile.md` describes this specific repository.
60
- - `testing.md` records at least one real verification path.
61
- - `.naome/verification.json` contains the same durable checks and change-type
62
- rules recorded in `testing.md`.
63
- - `architecture.md` describes observed structure and known or assumed
64
- boundaries.
71
+ - `.naome/repository-model.json` is current.
72
+ - `.naome/verification.json` contains durable checks and change-type rules.
73
+ - `testing.md` records a readable summary of the real verification paths.
74
+ - `architecture.md` records only structure or boundaries that are not already
75
+ represented in deterministic model or structure policy.
65
76
  - `security.md` records sensitive areas or states that none are known yet.
66
77
  - remaining unknowns are explicit.
67
78
 
@@ -13,18 +13,23 @@ for the current step.
13
13
  6. `execution.md`, before accepting or completing feature work
14
14
  7. `first-run.md`, only when `initialized` is `false`
15
15
  8. `upgrade.md`, only when upgrade `status` is `needs_agent_upgrade`
16
- 9. `repo-profile.md`
17
- 10. `architecture.md`
18
- 11. `testing.md`
16
+ 9. `.naome/repository-model.json`
17
+ 10. `context-economy.md`, when selecting task context
18
+ 11. `repository-model.md`, when stack, build, or path facts matter
19
19
  12. `.naome/verification.json`
20
- 13. `repository-quality.md`, when repository-quality checks or cleanup are relevant
21
- 14. `repository-structure.md`, when path roles or structure cleanup are relevant
22
- 15. `security.md`
23
- 16. `agent-workflow.md`
24
- 17. `decisions.md`, when changing durable project policy
20
+ 13. `repo-profile.md`, only for legacy human-readable project notes
21
+ 14. `architecture.md`, only for legacy human-readable project notes
22
+ 15. `testing.md`
23
+ 16. `repository-quality.md`, when repository-quality checks or cleanup are relevant
24
+ 17. `repository-structure.md`, when path roles or structure cleanup are relevant
25
+ 18. `security.md`
26
+ 19. `agent-workflow.md`
27
+ 20. `decisions.md`, when changing durable project policy
25
28
 
26
29
  ## Source Types
27
30
 
31
+ - Deterministic repository facts live in `.naome/repository-model.json` and are
32
+ refreshed with `naome repo model --write`.
28
33
  - Discovered facts come from repository files and commands.
29
34
  - Confirmed facts were explicitly confirmed by a human or existing
30
35
  authoritative documentation.
@@ -33,8 +38,11 @@ for the current step.
33
38
 
34
39
  ## Context Rule
35
40
 
36
- Do not load every NAOME document by default. Start from this index, then open the
37
- smallest set of files needed for the task.
41
+ Do not load every NAOME document by default. Run
42
+ `node .naome/bin/naome.js context select --prompt-file <path> --json` after
43
+ routing natural-language work, or `node .naome/bin/naome.js context select
44
+ --changed --json` for an existing diff. Read `requiredContext` first and
45
+ `optionalContext` only when blocked.
38
46
  Do not search for generic root `ARCHITECTURE.md` or `docs/index.md` files unless
39
47
  this repository's NAOME docs explicitly reference them.
40
48
 
@@ -0,0 +1,92 @@
1
+ # Repository World Model
2
+
3
+ The repository model is the deterministic source for machine-readable facts
4
+ about this repository. It keeps stack and layout facts out of free-form
5
+ Markdown so agents can make repeatable decisions.
6
+
7
+ ## Files
8
+
9
+ - `.naome/repository-model.json` stores canonical facts.
10
+ - `.naome/verification.json` stores runnable checks and change-type proof
11
+ policy.
12
+ - Repository-quality and repository-structure policy store quality adapters and
13
+ layout rules.
14
+ - Markdown documents explain workflow and summarize human context; they are not
15
+ the primary store for build, stack, or path-role facts.
16
+
17
+ ## Commands
18
+
19
+ - `naome repo model --write --json` refreshes the model from repository files.
20
+ - `naome repo check --json` verifies the committed model is current.
21
+ - `naome repo explain --path <path> --json` explains the role and language for a
22
+ path using the canonical model.
23
+
24
+ ## Facts
25
+
26
+ `naome.repository-model.v2` keeps the backward-compatible flat `facts[]` list
27
+ and adds typed world-model sections. `naome.repository-model.v1` remains
28
+ readable; new writes prefer v2.
29
+
30
+ Flat facts are deterministic records with stable ids:
31
+
32
+ - `language:<value>`
33
+ - `packageManager:<value>`
34
+ - `buildSystem:<value>`
35
+ - `sourceRoot:<path>`
36
+ - `testRoot:<path>`
37
+ - `docsRoot:<path>`
38
+ - `generatedRoot:<path>`
39
+ - `artifactRoot:<path>`
40
+ - `verificationCheck:<id>`
41
+
42
+ Each fact includes evidence paths and a source. Do not hand-edit generated facts
43
+ as normal workflow. Refresh them with the command above.
44
+
45
+ ## World Sections
46
+
47
+ The v2 model stores typed sections so agents do not need to infer repository
48
+ shape from prose:
49
+
50
+ - `languages`, `packageManagers`, and `buildSystems`
51
+ - `adapters` detected from deterministic stack signals
52
+ - `roots` for source, test, docs, generated, and artifact paths
53
+ - `entities` for packages, apps, and modules
54
+ - `pathFacts` for significant paths with role, module, entity, language, and
55
+ generated/artifact flags
56
+ - `verificationChecks` copied from `.naome/verification.json`
57
+
58
+ These sections are generic and adapter-extensible. Product defaults must not
59
+ contain repository-specific exceptions.
60
+
61
+ ## Agent Rule
62
+
63
+ When a task depends on the stack, package manager, build system, source roots,
64
+ test roots, generated roots, or verification ids, read or refresh the repository
65
+ model instead of searching broad Markdown files. If the model is stale, update it
66
+ first, then continue with the task.
67
+
68
+ For a specific path, use:
69
+
70
+ ```text
71
+ naome repo explain --path <path> --json
72
+ ```
73
+
74
+ The explanation returns the canonical role, language, module, entity, matching
75
+ facts, and evidence for that path.
76
+
77
+ ## Drift Gates
78
+
79
+ NAOME does not silently rewrite `.naome/repository-model.json` during normal
80
+ gates. Instead, stale facts are reported deterministically:
81
+
82
+ - `naome doctor --json` reports a stale repository model section.
83
+ - `node .naome/bin/check-task-state.js --progress` blocks active work until the
84
+ model is refreshed.
85
+ - `naome quality check --changed --json` emits `repository-model-stale` as a
86
+ changed-code finding.
87
+
88
+ The fix is explicit and idempotent:
89
+
90
+ ```text
91
+ naome repo model --write --json
92
+ ```