@ngockhoale/ukit 2.6.6 → 2.6.8

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 (59) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +40 -177
  3. package/manifests/documentation.yaml +143 -15
  4. package/manifests/hostCapabilities.yaml +49 -0
  5. package/manifests/instructionRules.yaml +383 -0
  6. package/manifests/platform.full.yaml +15 -0
  7. package/package.json +3 -1
  8. package/scripts/bench/goldTasks.json +38 -0
  9. package/scripts/bench/runGold.mjs +220 -0
  10. package/scripts/docs/render-instructions.mjs +42 -0
  11. package/scripts/release/verify-release.mjs +6 -0
  12. package/src/cli/commands/code.js +182 -0
  13. package/src/cli/commands/doctor.js +35 -3
  14. package/src/cli/commands/indexTools.js +102 -1
  15. package/src/cli/commands/memory.js +137 -0
  16. package/src/cli/index.js +7 -0
  17. package/src/core/codeintel/compiler.js +316 -0
  18. package/src/core/codeintel/diagnostics.js +114 -0
  19. package/src/core/codeintel/freshness.js +295 -0
  20. package/src/core/codeintel/impact.js +251 -0
  21. package/src/core/codeintel/invalidation.js +150 -0
  22. package/src/core/codeintel/manifest.js +176 -0
  23. package/src/core/codeintel/packet.js +146 -0
  24. package/src/core/codeintel/providers.js +201 -0
  25. package/src/core/codeintel/retriever.js +372 -0
  26. package/src/core/codeintel/router.js +149 -0
  27. package/src/core/codeintel/semanticProvider.js +235 -0
  28. package/src/core/docContracts.js +723 -0
  29. package/src/core/memory/migrate.js +324 -0
  30. package/src/core/memory/records.js +172 -0
  31. package/src/core/memory/retrieval.js +161 -11
  32. package/src/core/memory/store.js +398 -0
  33. package/src/core/memory/storeV2.js +171 -0
  34. package/src/core/memory/storeV2Loader.js +22 -0
  35. package/src/core/projectImportant.js +1 -1
  36. package/src/core/runtimeConfig.js +125 -0
  37. package/src/core/runtimePaths.js +3 -0
  38. package/src/core/uninstall.js +1 -1
  39. package/src/index/taskRouting.js +39 -0
  40. package/src/render/instructionRenderer.js +226 -0
  41. package/templates/.claude/ukit/index/route-task.mjs +40 -0
  42. package/templates/.gitignore +2 -2
  43. package/templates/.omp/RULES.md +1 -0
  44. package/templates/AGENTS.md +89 -218
  45. package/templates/CLAUDE.md +85 -212
  46. package/templates/docs/AI_HANDOFF/tasks/_TEMPLATE.md +5 -0
  47. package/templates/docs/BUGFIX.md +2 -19
  48. package/templates/docs/BUG_INDEX.md +43 -0
  49. package/templates/docs/BUG_METRICS.md +1 -5
  50. package/templates/docs/BUG_TEMPLATE.md +1 -11
  51. package/templates/docs/UKIT_INTERNALS.md +223 -0
  52. package/templates/instructions/core.md +157 -0
  53. package/templates/instructions/layout.yaml +149 -0
  54. package/templates/instructions/overlays/agents.md +15 -0
  55. package/templates/instructions/overlays/claude.md +3 -0
  56. package/templates/instructions/overlays/omp-rules.md +74 -0
  57. package/templates/instructions/overlays/repo.md +9 -0
  58. package/templates/instructions/repo-vars.yaml +23 -0
  59. package/templates/ukit/storage/config.json +30 -0
@@ -0,0 +1,223 @@
1
+ # UKIT Internal Orchestration
2
+
3
+ Loaded on demand — root contracts carry the compact contract; this file carries the detail.
4
+
5
+ Everything below is internal orchestration: end users only ever need `ukit install` plus
6
+ natural language. None of it adds commands or user-facing surface.
7
+
8
+ ## Long-Run Continuity — detail
9
+
10
+ The root contract carries the LAND/DEFER/DELEGATE summary. This section mirrors what UKit
11
+ hooks inject at runtime on Claude Code and omp; on harnesses without hooks (Codex, OpenCode)
12
+ the root contract is the only carrier — keep both in sync with
13
+ `.claude/hooks/context-window-guard.sh`.
14
+
15
+ - Near token-cap: **LAND one thing** — finish the smallest in-flight item end-to-end
16
+ (edit + verify, ≤3 tool calls) and report it done. **DEFER the rest** — one line per
17
+ remaining step into `docs/STATUS.md`, or split into bounded `docs/AI_HANDOFF/` tasks.
18
+ **DELEGATE** broad work (searches, big reads, multi-file edits) to subagents whose tool
19
+ output lives in their own windows. Only then compact.
20
+ - After any compact or handoff: do not reread pre-compact context — continue from the
21
+ persisted disk state, delegate broad work, keep replies short. If the first turn after a
22
+ compact still sits at ≥60% of the cap, stop rereading immediately and recover by
23
+ delegating or starting a fresh session from the disk state; do not burn the window again.
24
+ - A run ends only on completion evidence, a genuine blocker, or a user-only action — and
25
+ every such stop names its reason in the final reply.
26
+
27
+ ## Index-First Loop — helper commands
28
+
29
+ - `node .claude/ukit/index/refresh-index.mjs` — refresh when `.cache/index/` is stale or
30
+ missing; fallback: `node .claude/ukit/index/build-index.mjs`.
31
+ - `node .claude/ukit/index/query-index.mjs "<error|symbol|path>"` — likely files.
32
+ - `node .claude/ukit/index/triage.mjs "<error signature>"` — bug signatures.
33
+ - `query-index` and `resolve-context` print an `outline:` block (`line: signature`) for the
34
+ top suspects — jump straight to the relevant region with `Read(file, offset=<line>)`
35
+ instead of reading the whole file.
36
+
37
+ ## Automatic Skill Activation — route memory
38
+
39
+ - If docs work is detected, read `.claude/skills/docs-quality/SKILL.md` when present.
40
+ - Reuse `.claude/ukit/skill-router-state.json` when it already carries compact route memory.
41
+ - If shared route state already includes `previous-context` or `recent-output`, reuse those
42
+ first.
43
+ - Prefer routed context and routed verification over ad-hoc broad reading.
44
+
45
+ ## Internal Helper Policy — detail
46
+
47
+ - Prefer `node .claude/ukit/index/route-task.mjs "<prompt>" [--tool-command <cmd>]
48
+ [--target <file>]` when routing is complex or ambiguous.
49
+ - Prefer `node .claude/ukit/index/resolve-context.mjs ...` for indexed related-file context.
50
+ - Prefer `node .claude/ukit/index/verify-context.mjs ...` for concrete verification lanes.
51
+ - Context-layer docs are declared in `manifests/documentation.yaml` (`context_layers`) and
52
+ surfaced in the route summary line via the `docs=[...]` basename segment
53
+ (`routeSummary.contextDocs`; DOC-201). The routing-side copy is `CONTEXT_LAYER_DOCS` in
54
+ `src/index/taskRouting.js` / `route-task.mjs` — keep it in sync with the manifest.
55
+ - Do not ask normal contributors to memorize `ukit doctor`, `ukit diff`, `ukit uninstall`,
56
+ or `ukit index ...` unless they explicitly need maintainer/debug help.
57
+ - If the workspace needs a refresh, prefer telling them to rerun `ukit install`.
58
+
59
+ ## Skill Quality (maintainer-only)
60
+
61
+ - When editing a template skill/agent under `templates/.claude/`, read
62
+ `.claude/skills/skill-quality/SKILL.md` before shipping the change.
63
+
64
+ ## Shared Runtime — detail
65
+
66
+ - Shared runtime state lives in `.ukit/storage/`.
67
+ - Treat `.ukit/storage/config.json` as the source of runtime toggles for compact, token
68
+ pipeline, router, memory, validation, and Safe Patch behavior.
69
+ - Reusable cache/compact/output state lives in
70
+ `.ukit/storage/cache/prompt-cache.json`,
71
+ `.ukit/storage/cache/compact-history.json`,
72
+ `.ukit/storage/cache/compact-pressure.json`,
73
+ `.ukit/storage/cache/output-history.json`, and preserved raw tool outputs under
74
+ `.ukit/storage/cache/tee/`.
75
+ - If an older repo still has a visible `ukit/` runtime root, rerun `ukit install`; UKit
76
+ should migrate the shared runtime into hidden `.ukit/` when safe.
77
+ - Maintainers can inspect runtime state with `ukit status` and `ukit memory export`, but
78
+ normal teammates should still only need `ukit install`.
79
+ - Threshold-based compact pressure is internal orchestration; do not expose it to users.
80
+ - For Codex Desktop long sessions, UKit can use soft auto-compact handoffs. Default
81
+ `compact.codexContext.compactTarget=150` means about 150 compact handoff lines
82
+ (120-150 preferred, hard max 170), not 150 tokens.
83
+
84
+ ## Safe Patch — internal helper
85
+
86
+ - Use `node .claude/ukit/index/safe-patch.mjs` internally when normal Edit/Write may
87
+ normalize bytes or when anchor-based matching is needed.
88
+ - Safe Patch is internal orchestration: normal users still only need `ukit install` and
89
+ natural language.
90
+
91
+ ## Context + Verification Budget — detail
92
+
93
+ - `docs/STATUS.md`: stale status is orientation only.
94
+ - `docs/TASKS.md`: safely clean exact duplicates/completed overflow by default without
95
+ deleting unfinished human-authored tasks.
96
+ - `docs/WORKLOG.md`: follow the Budget Rules at the top of the file; archive oldest entries
97
+ to `docs/WORKLOG_ARCHIVE.md` when over limits.
98
+ - Follow routed verification policy: targeted first, widen only when risk/shared scope
99
+ justifies it, ask before blanket broad runs.
100
+
101
+ ## Living Status Workflow — detail
102
+
103
+ - `docs/STATUS.md` captures compact current state, active work, debug threads, blockers,
104
+ verification, and next candidates.
105
+ - For "what next?" / "continue" prompts without a concrete target, use `next-step` and show
106
+ a freshness cue before relying on the status file.
107
+ - For concrete debug/implementation/review prompts, keep the concrete workflow primary even
108
+ if the user asks for an approach or next step.
109
+ - After meaningful work, use `update-status`; skip trivial/no-state-change tasks and avoid
110
+ transcript-style noise.
111
+ - `docs/TASKS.md` is a local AI task queue: prefer `Ready for AI` when asked to pick queued
112
+ work, and clean duplicates/prune `Done Recently` safely when reading/updating it.
113
+
114
+ ## Small-Task Maintainer — detail
115
+
116
+ - UKit may route low-risk internal decisions to the `ukit-small-task-maintainer` subagent
117
+ using `subagents.smallTaskModel` (default `unic-lite`).
118
+ - Use it for safe/reversible UKit chores: cleaning `docs/TASKS.md`, queued-task
119
+ classification, fast-vs-slow/safe-vs-risky lane decisions, skill-routing/step-budget
120
+ hints, agent context-budget decisions, compact/summary decisions, docs/status
121
+ summarization, auto-triage, queue maintenance, and small workspace cleanup.
122
+ - Run it as a sidecar/parallel lane only; do not block, replace, or slow the user task.
123
+ - If the small-task lane sees security, risky/shared code, release/publish, data-loss,
124
+ architecture, deep-reasoning risk, weak context, or quality risk, it hands back to the
125
+ main model.
126
+ - This is optional internal orchestration config from `.ukit/storage/config.json`; never
127
+ turn it into an end-user workflow.
128
+ - Always preserve the CoDev priority: quality > safety > speed > token discipline.
129
+
130
+ ## Post-Edit Sidecar Review — detail
131
+
132
+ - If routed state's `routeSummary.line` includes a `review=code-reviewer(diff)` segment, a
133
+ `local-build` or `shared-edit` task qualifies for a non-blocking second opinion — this
134
+ exists because the daily-flow executor model can miss edge cases.
135
+ - Only launch it once write evidence AND verification evidence already exist for the task
136
+ (never before; never as a substitute for either).
137
+ - Launch the `code-reviewer` agent (see the harness table under 3-Tier Model Routing) with
138
+ `REVIEW_TARGET_TYPE=diff`, in the background, on the `smart` tier per
139
+ `subagents.diffReviewModel`. Do not wait for it — continue and report the task as done
140
+ using the normal completion rules.
141
+ - Its findings are advisory only: never re-open, block, or delay the already-reported
142
+ completion on their account. Surface them to the user as a follow-up note if/when they
143
+ arrive.
144
+ - This is internal orchestration — end users never invoke it directly; `ukit install` plus
145
+ natural language remains the whole surface. No new commands.
146
+
147
+ ## Selective Subagent Policy — detail
148
+
149
+ - Good delegation triggers:
150
+ - noisy side lanes (broad logs/search/test output)
151
+ - 3+ independent failures/files/checks
152
+ - explicit batch/plan execution
153
+ - broad implementation/debug lanes that can return a concise summary
154
+ - If route memory includes `delegate=<lane>`, treat it as an internal hint after any
155
+ required indexed-context step.
156
+
157
+ ## 3-Tier Model Routing — full detail
158
+
159
+ UKit routes tasks to one of three model tiers based on task complexity. The main session
160
+ model never changes mid-turn: a tier only takes effect when work is handed to an agent
161
+ whose own definition binds that model.
162
+
163
+ | Tier | Generic alias | Claude model | Typical tasks |
164
+ |------|--------------|--------------|---------------|
165
+ | lite | `unic-lite` | claude-haiku | Reads, git queries, bash summaries, small doc edits |
166
+ | code | `unic-code` | claude-sonnet | Normal coding, local fixes, shared edits, builds, debugging, impact mapping |
167
+ | smart | `unic-smart` | claude-opus | Release review/audit, and escalated deep reasoning after repeated failure |
168
+
169
+ ### Contract-to-tier mapping
170
+
171
+ | Contract | Tier |
172
+ |----------|------|
173
+ | `tiny-fix` | lite |
174
+ | `local-fix`, `local-build`, `shared-edit`, `find-cause`, `map-impact` | code |
175
+ | `review-release` | smart |
176
+
177
+ ### How a tier is actually bound
178
+
179
+ | Harness | Agent definitions | How to launch one |
180
+ |---------|-------------------|-------------------|
181
+ | Claude Code | `.claude/agents/*.md` (`model:` frontmatter) | Agent tool, `subagent_type: "<name>"` |
182
+ | omp | `.omp/agents/*.md` (`model: "@lite"` / `"@code"` / `"@smart"` / `"@vision"`, resolved through `modelRoles` in `.omp/config.yml`) | task-agent `<name>` |
183
+
184
+ When a task's contract maps to a tier other than the current session model, hand it to the
185
+ matching agent instead of doing it inline. Doing everything inline is exactly what makes
186
+ UKIT behave as if it only had one model — the tier table above has no effect on its own.
187
+
188
+ ### Escalation rule
189
+
190
+ When the same file or symbol fails `debugLoopThreshold` (default: 2) times in one session,
191
+ UKit routes the next attempt one tier higher (capped at `smart`). Config:
192
+ `orchestration.escalation` in `.ukit/storage/config.json`.
193
+
194
+ ### Vision lane (capability, not a cost tier)
195
+
196
+ `unic-vision` is a **capability lane**, not a fourth cost tier — it is orthogonal to
197
+ lite/code/smart above and never appears as a row in the tier table. Whether a mapping can
198
+ read images is a capability fact, not a provider fact: a mapping that has not **verified**
199
+ native vision must never guess at image contents — choose native-first when verified,
200
+ otherwise route to the specialist.
201
+
202
+ - **Gateway detection**: UNIC routing for a Claude Code session is decided ONLY by what
203
+ changes Claude Code's own outbound endpoint — `ANTHROPIC_BASE_URL` (env var, or the
204
+ `env.ANTHROPIC_BASE_URL` key in project/home `.claude/settings.json`) containing
205
+ `unicjsc.com`. Other tools' configs — Codex `config.toml`, Kilo `secrets.json`, or an
206
+ `OPENAI_BASE_URL` env var — describe a different tool's endpoint entirely and never
207
+ decide this session's routing.
208
+ - **Advisory routing (no hard block)**: when an image reaches the prompt, the vision router
209
+ reminds the session to have `ukit-vision-analyst` analyse it before relying on its
210
+ contents. Edits are **never blocked** — correctness relies on the model routing images
211
+ to the analyst instead of guessing.
212
+ - This is internal orchestration — end users never invoke a vision command directly;
213
+ `ukit install` plus natural language remains the whole surface. No new commands.
214
+
215
+ ## DuraOne — detail
216
+
217
+ - Khi active: luôn đọc `.claude/skills/duraone/SKILL.md` trước khi code.
218
+ - References:
219
+ - `.claude/skills/duraone/references/frontend.md`
220
+ - `.claude/skills/duraone/references/backend.md`
221
+ - `.claude/skills/duraone/references/sql.md`
222
+ - `.claude/skills/duraone/references/workflow.md`
223
+ - Khi không active: dùng generic coding standards + project-specific patterns từ index.
@@ -0,0 +1,157 @@
1
+ ## Core Rule
2
+ <!-- RULES: CORE-01 CORE-02 -->
3
+ - Human-facing UKit workflow collapses to one remembered command: `ukit install`.
4
+ - After install, default to natural-language work inside **Claude Code / Codex / OpenCode / omp**.
5
+ - **Quality first, then speed, then token discipline.**
6
+ - **Never stop after read-only steps** — implement/apply/fix requests continue to Edit/Write + verification in the same turn.
7
+
8
+ ## Fast Classification
9
+ <!-- RULE: CLS-01 -->
10
+ - **Trivial** — typo, label, small rename, spacing, toggle flag, obvious config change. Act directly. No doc reads, planning, index, or agents.
11
+ <!-- RULE: CLS-02 -->
12
+ - **Simple** — 1-2 files, clear scope, existing pattern. Handle directly; pull only the smallest useful context via resolver or targeted read.
13
+ <!-- RULE: CLS-03 -->
14
+ - **Non-trivial / Risky** — auth, security, migration, uninstall, shared runtime, race/flaky, data-loss. Read deeper, verify harder; index-first loop → skill activation → targeted verification.
15
+
16
+ ## Execution Contract (mandatory)
17
+ <!-- RULE: EXEC-01 -->
18
+ - For explicit implement/apply/fix requests, **continue until the actual edit is made** or a real blocker is found — never stop after a read-only inspection step.
19
+ <!-- RULE: EXEC-03 -->
20
+ - Routed states like `pull-indexed-context` or `continuation required` — treat it as an internal continuation step, not a stopping point; finish the named milestone before widening reads.
21
+ <!-- RULE: EXEC-02 -->
22
+ - **Do NOT say "done"/"applied"/"fixed" after Read/Grep/analysis alone** — completion wording requires concrete Edit/Write evidence this turn, plus verification when scope is risky.
23
+ <!-- RULE: EXEC-04 -->
24
+ - **Every stop says why — no silent idle.** Turns ending on a user-only action open with `WAITING ON YOU: <command/action>` plus a one-shot wakeup (~20-30 min) when available — an ended turn cannot observe external changes, so without it idle looks identical to a stall. Report any error verbatim the same turn.
25
+
26
+ ## Long-Run Continuity
27
+ <!-- RULES: LONG-01 LONG-02 -->
28
+ - Near token-cap: **LAND one thing** end-to-end (edit + verify, ≤3 tool calls), **DEFER** the rest into `docs/STATUS.md` or bounded `docs/AI_HANDOFF/` tasks, **DELEGATE** broad work to subagents. Only then compact.
29
+ - After any compact or handoff: continue from persisted disk state — never reread pre-compact context; delegate broad work, keep replies short.
30
+ - A run ends only on completion evidence, a genuine blocker, or a user-only action — every stop names its reason. Detail: `docs/UKIT_INTERNALS.md`.
31
+
32
+ ## Index-First Loop
33
+ For any task needing code context:
34
+
35
+ <!-- RULE: IDX-01 -->
36
+ 1. Check the index is fresh (`.cache/index/`); if stale/missing, refresh via `node .claude/ukit/index/refresh-index.mjs`.
37
+ 2. Query files: `node .claude/ukit/index/query-index.mjs "<error|symbol|path>"`; bug signatures: `triage.mjs "<error signature>"`.
38
+ <!-- RULE: IDX-02 -->
39
+ 3. Open only the **top 1-3 suspect files first**, then widen if needed — the `outline:` block lets you jump straight to `Read(file, offset=<line>)`.
40
+ <!-- RULE: IDX-03 -->
41
+ The outline locates code; it does not describe behaviour — **any code you are about to change must still be read**.
42
+ 4. For analog/reuse patterns, check `resolve-context`. Non-code lanes (docs-only, status, task queue) skip the source-code index.
43
+
44
+ ## Automatic Skill Activation (mandatory)
45
+ <!-- RULE: SKILL-01 -->
46
+ - On every non-trivial task — and again after the first relevant tool calls — inspect installed project-local skills and **auto-activate the matching skill immediately**; end users should not need skill names. Match from prompt wording and tool/file evidence.
47
+ <!-- RULES: SKILL-02 SKILL-03 -->
48
+ - Use the smallest effective set (usually 1-2 skills); if evidence sharpens, upgrade the active skill choice immediately.
49
+ - Prefer routed context/verification over ad-hoc broad reading; reuse `.claude/ukit/skill-router-state.json` compact route memory.
50
+
51
+ ### Common skill triggers
52
+
53
+ - review / audit / diff / PR feedback → `code-review` · bug / error / crash / triage → `debugging-toolkit` · test / spec / coverage / fixture → `testing-quality`
54
+ - docs / README / changelog / handoff / `docs/` edits → `docs-quality` (`.claude/skills/docs-quality/SKILL.md`) · open-ended / status / continue / queued task → `next-step` · wrap up / `docs/STATUS.md` update → `update-status`
55
+ - auth / security / token / permission / risky work → `discover-security` · stale workspace / reinstall / cleanup → `repo-maintenance` (all under `.claude/skills/<name>/SKILL.md`)
56
+
57
+ ## Internal Helper Policy
58
+ <!-- RULES: HELP-01 HELP-02 -->
59
+ - Prefer the internal index helpers (`node .claude/ukit/index/route-task.mjs`, `resolve-context.mjs`, `verify-context.mjs`) for routing, related-file context, and verification.
60
+ - **Do not ask normal contributors to run internal helper commands** or memorize maintainer commands (`ukit doctor`, `ukit diff`, `ukit uninstall`) — run them yourself.
61
+ <!-- RULE: FALLBACK-01 -->
62
+ - Missing/corrupt runtime files or stale workspace → tell maintainers to rerun `ukit install`. Detail: `docs/UKIT_INTERNALS.md`.
63
+
64
+ ## Skill Quality (maintainer-only)
65
+ - When editing a template skill/agent under `templates/.claude/`, read `.claude/skills/skill-quality/SKILL.md` before shipping.
66
+
67
+ ## UKit v{{ukit.version}} Shared Runtime
68
+ - Runtime state lives in `.ukit/storage/`; `.ukit/storage/config.json` holds runtime toggles (compact, token pipeline, router, memory, validation, Safe Patch).
69
+ - Reuse `.ukit/storage/memory/` + `ukit memory recall "<current task>"` before asking users to restate decisions; inspect via `ukit status` / `ukit memory export`.
70
+ - Route memory: `.claude/ukit/skill-router-state.json` — reuse compact `previous-context`/`recent-output` first. Cache state: `.ukit/storage/cache/output-history.json`, tee/. Missing/corrupt runtime or old `ukit/` root → rerun `ukit install`. Detail: `docs/UKIT_INTERNALS.md`.
71
+
72
+ ## Prompt Caching
73
+ <!-- RULES: CTX-01 CTX-02 CTX-03 CTX-04 CTX-05 CTX-06 CTX-07 CTX-08 CTX-09 CTX-10 -->
74
+ - Full ruleset: `docs/PROMPT_CACHING.md` (read on demand; not loaded every session).
75
+ - CTX-01 deterministic segment bytes · CTX-02 keep roles and order · CTX-03 keep tool IDs and continuation state · CTX-04 no clock/random IDs in static blocks · CTX-05 compaction starts a new epoch · CTX-06 never change data to match a cache · CTX-07 no unconfirmed cache fields · CTX-08 tool-result reuse needs valid freshness · CTX-09 missing usage is unknown, not zero · CTX-10 never cut a required check to reduce calls.
76
+
77
+ ## Safe Patch Protocol
78
+ <!-- RULES: SAFE-02 SAFE-03 SAFE-01 -->
79
+ - Risky/shared/large edits: prefer unique current-file anchors over line numbers or stale pasted blocks; if `old_string` is missing/ambiguous, re-read current source and ask whether to apply as-is, adapt, or skip.
80
+ - Preserve UTF-8 BOM/no-BOM and LF/CRLF for existing multilingual/user-authored files. Helper: `node .claude/ukit/index/safe-patch.mjs`; detail: `docs/UKIT_INTERNALS.md`.
81
+
82
+ ## Handoff Quality Gate — OPT-IN
83
+ <!-- RULE: HAND-01 -->
84
+ CHỈ kích hoạt khi task đi qua `docs/AI_HANDOFF/` (user nói "execute task TASK-xxx" hoặc target là `docs/AI_HANDOFF/tasks/*.md`). Daily prompt → KHÔNG đụng, flow cũ giữ nguyên.
85
+
86
+ Khi Handoff mode: đọc `docs/AI_HANDOFF/RULES.md` để biết 4 phase (Idea+Plan → Create Tasks → Implement+Test → Review+Test) + state machine + self-report model. Config: `.ukit/storage/config.json` → `handoff.*`.
87
+
88
+ ## Context + Verification Budget
89
+ <!-- RULE: BUDGET-01 -->
90
+ - **Trivial**: no docs, no index query unless the file target is unclear. **Simple**: `docs/MEMORY.md` only + resolver-selected files/tests. **Non-trivial**: `docs/MEMORY.md` + `docs/PROJECT.md` + `docs/CODE_MAP.md`.
91
+ <!-- RULES: BUDGET-02 BUDGET-03 -->
92
+ - `docs/STATUS.md` for open-ended/continue prompts; `docs/TASKS.md` only for queued-task prompts; `docs/WORKLOG.md` recent entries only (archive overflow). Verification: targeted first, widen only on risk/shared scope, ask before blanket broad runs.
93
+
94
+ ## Living Status Workflow
95
+ <!-- RULE: STATUS-01 -->
96
+ - `docs/STATUS.md` captures compact current state — not source truth, never replaces source/index-first investigation.
97
+ - "What next?"/"continue" → `next-step` with a freshness cue; after meaningful work → `update-status`. `docs/TASKS.md` is the local AI task queue — prefer `Ready for AI`. Detail: `docs/UKIT_INTERNALS.md`.
98
+
99
+ ## Small-Task Maintainer (internal)
100
+ <!-- RULE: SUBAG-02 -->
101
+ - The `ukit-small-task-maintainer` subagent (`subagents.smallTaskModel`, default `unic-lite`) handles safe/reversible UKit chores as a sidecar lane — never block or slow the user task; risky work hands back to the main model. Detail: `docs/UKIT_INTERNALS.md`.
102
+
103
+ ## Post-Edit Sidecar Review (internal)
104
+ - When routed state's `routeSummary.line` carries `review=code-reviewer(diff)`, launch `code-reviewer` in background (`smart` tier) **only after** write + verification evidence; findings advisory — never block the reported completion. Detail: `docs/UKIT_INTERNALS.md`.
105
+
106
+ ## Selective Subagent Policy (internal only)
107
+ <!-- RULE: SUBAG-01 -->
108
+ - Direct execution is default for trivial/simple work; delegate only on meaningful context shrink or parallel gains (noisy side lanes, 3+ independent failures, batch plans). Never ask end users to name agents or remember agent commands.
109
+
110
+ ## Adaptive Autonomy
111
+ <!-- RULE: AUTO-01 -->
112
+ - `autonomy.level` in `.ukit/storage/config.json` controls how much UKit acts without asking: `conservative` (ask more), `balanced` (default), `free-run` (auto-run more), `vibecode` (one prompt to a finished result; the gate stops only on completion evidence, a genuine blocker, or a dangerous-command decision). End users should not need to change it.
113
+
114
+ ## 3-Tier Model Routing
115
+ <!-- RULES: TIER-01 TIER-02 -->
116
+ **Internal orchestration only — end users still just use natural language. No new commands.**
117
+
118
+ | Tier | Generic alias | Claude model | Typical tasks |
119
+ |------|--------------|--------------|---------------|
120
+ | lite | `unic-lite` | claude-haiku | Reads, git queries, bash summaries, small doc edits |
121
+ | code | `unic-code` | claude-sonnet | Normal coding, local fixes, shared edits, builds, debugging, impact mapping |
122
+ | smart | `unic-smart` | claude-opus | Release review/audit, escalated deep reasoning after repeated failure |
123
+
124
+ - A tier takes effect only when work is handed to an agent whose definition binds that model (`model:` frontmatter in `.claude/agents/*.md`; `model:` `@lite`/`@code`/`@smart`/`@vision` in `.omp/agents/*.md` via `modelRoles`) — the main session model never changes mid-turn.
125
+ - Contract map: `tiny-fix` → lite · `local-fix`, `local-build`, `shared-edit`, `find-cause`, `map-impact` → code · `review-release` → smart. Escalation: same file/symbol failing `debugLoopThreshold` (default 2) times routes the next attempt one tier higher, capped at `smart`.
126
+ - `unic-vision` is a capability lane, not a cost tier — unverified vision must never guess image contents; route images to `ukit-vision-analyst`. Harness table: `docs/UKIT_INTERNALS.md`.
127
+
128
+ ## Skills
129
+ - Canonical skills live in `.claude/skills/`; adapter mirrors may exist (`.codex/skills/` → symlink). **omp** reads `.claude/skills/` via its `claude` discovery provider.
130
+ - **OpenCode**: reads `AGENTS.md` at session start only — it does NOT auto-load skills; the model must explicitly read the triggered SKILL.md.
131
+ - `ukit-*` commands in `opencode.json` are internal helper entrypoints — never ask end users to run them.
132
+
133
+ ## Project Snapshot
134
+ - Project: {{project.name}} | Root: {{project.root}}
135
+ - Packs: {{project.stack}} | Frontend: {{stack.frontend}} | Backend API: {{stack.backendApi}} | PostgreSQL: {{stack.postgres}}
136
+ - Package manager: {{runtime.packageManager}} | OS: {{runtime.os}} | Node: {{runtime.nodeVersion}} | Provider: {{providers.unic}}
137
+
138
+ ## Working Rules
139
+ - Keep scope tight, prefer the smallest correct change set, and reuse existing code.
140
+ - Update `docs/WORKLOG.md` after significant work; if source contradicts docs, update docs immediately.
141
+ - Use `{{runtime.packageManager}}`.
142
+
143
+ ## DuraOne Skill — Conditional Activation
144
+ <!-- RULE: DURA-01 -->
145
+ DuraOne skill chỉ active khi pack `duraone` được cài hoặc `.claude/skills/duraone/SKILL.md` tồn tại — khi active, luôn đọc SKILL.md + references trước khi code; khi không, dùng generic standards + index patterns. Chi tiết: `docs/UKIT_INTERNALS.md`.
146
+
147
+ ## Completion Checklist
148
+ - Requirements implemented · No unrelated changes · Verification executed and reported · Docs updated when source truth changed.
149
+
150
+ ## Handoff Fullstack Rules
151
+ <!-- RULE: HAND-02 -->
152
+ - `docs/AI_HANDOFF/RUN.md` là run cursor có thẩm quyền; `Phase:` ≠ `done`/`blocked` nghĩa là run còn sống — Stop gate từ chối stop và trả về `Next:` step.
153
+ - Recap/checkpoint không bao giờ là completion — chỉ `HANDOFF FULLSTACK COMPLETE` (sau `Phase: done`) hoặc `HANDOFF FULLSTACK BLOCKED` (sau `Phase: blocked`) mới kết thúc run. Resume tự động mọi task chưa xong (current, legacy, pending, interrupted, recovery `-R<n>`).
154
+ - Kết thúc cycle: docs sync → archive `docs/AI_HANDOFF/archive/cycle-NN/` → `Phase: done`. `handoff-clear` bắt buộc đóng RUN.md. Full rules: `docs/AI_HANDOFF/RULES.md`.
155
+
156
+ ## Compact Instructions
157
+ Khi compact giữa một handoff run: giữ lại goal, RUN.md path + phase hiện tại, task inventory, task đang làm, `Next:` step, blockers, verification evidence, commits, worktree/copy-back state, và quy tắc "compact không phải completion". Sau compact: đọc lại RUN.md + INDEX.md rồi chạy tiếp `Next:` ngay.
@@ -0,0 +1,149 @@
1
+ version: 1
2
+ description: >-
3
+ Deterministic layout for the five rendered instruction-contract outputs.
4
+ `sections` enumerates every ## block of the named source in output order;
5
+ reserved specifiers: `__preamble__` (source's leading non-## block, emitted
6
+ verbatim with no ## prefix) and `*` (all ## sections of the source in file
7
+ order). Every source ## section must be referenced by ≥1 output (FR-006).
8
+ outputs:
9
+ - target: templates/CLAUDE.md
10
+ h1: '# CLAUDE.md — {{project.name}}'
11
+ banner: '<!-- generated: templates/instructions/ — edit sources, then yarn docs:render -->'
12
+ resolve_vars: false
13
+ sections:
14
+ - { from: core, heading: Core Rule }
15
+ - { from: core, heading: Fast Classification }
16
+ - { from: core, heading: Execution Contract (mandatory) }
17
+ - { from: core, heading: Long-Run Continuity }
18
+ - { from: core, heading: Index-First Loop }
19
+ - { from: core, heading: Automatic Skill Activation (mandatory) }
20
+ - { from: core, heading: Internal Helper Policy }
21
+ - { from: core, heading: Skill Quality (maintainer-only) }
22
+ - { from: core, heading: 'UKit v{{ukit.version}} Shared Runtime' }
23
+ - { from: core, heading: Prompt Caching }
24
+ - { from: core, heading: Safe Patch Protocol }
25
+ - { from: core, heading: Handoff Quality Gate — OPT-IN }
26
+ - { from: core, heading: Context + Verification Budget }
27
+ - { from: core, heading: Living Status Workflow }
28
+ - { from: core, heading: Small-Task Maintainer (internal) }
29
+ - { from: core, heading: Post-Edit Sidecar Review (internal) }
30
+ - { from: core, heading: Selective Subagent Policy (internal only) }
31
+ - { from: core, heading: Adaptive Autonomy }
32
+ - { from: core, heading: 3-Tier Model Routing }
33
+ - { from: core, heading: Skills }
34
+ - { from: core, heading: Project Snapshot }
35
+ - { from: core, heading: Working Rules }
36
+ - { from: core, heading: DuraOne Skill — Conditional Activation }
37
+ - { from: core, heading: Completion Checklist }
38
+ - { from: core, heading: Handoff Fullstack Rules }
39
+ - { from: core, heading: Compact Instructions }
40
+ trailer: '{{codegraphSection}}'
41
+ - target: templates/AGENTS.md
42
+ h1: '# AGENTS.md — {{project.name}}'
43
+ banner: '<!-- generated: templates/instructions/ — edit sources, then yarn docs:render -->'
44
+ resolve_vars: false
45
+ sections:
46
+ - { from: core, heading: Core Rule }
47
+ - { from: core, heading: Fast Classification }
48
+ - { from: core, heading: Execution Contract (mandatory) }
49
+ - { from: core, heading: Long-Run Continuity }
50
+ - { from: core, heading: Index-First Loop }
51
+ - { from: core, heading: Automatic Skill Activation (mandatory) }
52
+ - { from: core, heading: Internal Helper Policy }
53
+ - { from: core, heading: Skill Quality (maintainer-only) }
54
+ - { from: core, heading: 'UKit v{{ukit.version}} Shared Runtime' }
55
+ - { from: core, heading: Prompt Caching }
56
+ - { from: core, heading: Safe Patch Protocol }
57
+ - { from: core, heading: Handoff Quality Gate — OPT-IN }
58
+ - { from: core, heading: Context + Verification Budget }
59
+ - { from: core, heading: Living Status Workflow }
60
+ - { from: core, heading: Small-Task Maintainer (internal) }
61
+ - { from: core, heading: Post-Edit Sidecar Review (internal) }
62
+ - { from: core, heading: Selective Subagent Policy (internal only) }
63
+ - { from: core, heading: Adaptive Autonomy }
64
+ - { from: core, heading: 3-Tier Model Routing }
65
+ - { from: 'overlay:agents', heading: Session Start — OpenCode }
66
+ - { from: 'overlay:agents', heading: Project Owner Instructions — Codex and OpenCode }
67
+ - { from: core, heading: Skills }
68
+ - { from: core, heading: Project Snapshot }
69
+ - { from: core, heading: Working Rules }
70
+ - { from: core, heading: DuraOne Skill — Conditional Activation }
71
+ - { from: core, heading: Completion Checklist }
72
+ - { from: core, heading: Handoff Fullstack Rules }
73
+ - { from: core, heading: Compact Instructions }
74
+ trailer: '{{codegraphSection}}'
75
+ - target: templates/.omp/RULES.md
76
+ h1: '# .omp/RULES.md — sticky always-apply rules'
77
+ banner: '<!-- generated: templates/instructions/ — edit sources, then yarn docs:render -->'
78
+ resolve_vars: false
79
+ sections:
80
+ - { from: 'overlay:omp-rules', heading: __preamble__ }
81
+ - { from: 'overlay:omp-rules', heading: '*' }
82
+ - target: CLAUDE.md
83
+ h1: '# CLAUDE.md — @ngockhoale/ukit'
84
+ banner: '<!-- generated: templates/instructions/ + repo overlay — edit sources, then yarn docs:render -->'
85
+ resolve_vars: true
86
+ sections:
87
+ - { from: 'overlay:repo', heading: Release Policy (mandatory — never replace) }
88
+ - { from: core, heading: Core Rule }
89
+ - { from: core, heading: Fast Classification }
90
+ - { from: core, heading: Execution Contract (mandatory) }
91
+ - { from: core, heading: Long-Run Continuity }
92
+ - { from: core, heading: Index-First Loop }
93
+ - { from: core, heading: Automatic Skill Activation (mandatory) }
94
+ - { from: core, heading: Internal Helper Policy }
95
+ - { from: core, heading: Skill Quality (maintainer-only) }
96
+ - { from: core, heading: 'UKit v{{ukit.version}} Shared Runtime' }
97
+ - { from: core, heading: Prompt Caching }
98
+ - { from: core, heading: Safe Patch Protocol }
99
+ - { from: core, heading: Handoff Quality Gate — OPT-IN }
100
+ - { from: core, heading: Context + Verification Budget }
101
+ - { from: core, heading: Living Status Workflow }
102
+ - { from: core, heading: Small-Task Maintainer (internal) }
103
+ - { from: core, heading: Post-Edit Sidecar Review (internal) }
104
+ - { from: core, heading: Selective Subagent Policy (internal only) }
105
+ - { from: core, heading: Adaptive Autonomy }
106
+ - { from: core, heading: 3-Tier Model Routing }
107
+ - { from: core, heading: Skills }
108
+ - { from: core, heading: Project Snapshot }
109
+ - { from: core, heading: Working Rules }
110
+ - { from: core, heading: DuraOne Skill — Conditional Activation }
111
+ - { from: core, heading: Completion Checklist }
112
+ - { from: core, heading: Handoff Fullstack Rules }
113
+ - { from: core, heading: Compact Instructions }
114
+ trailer: '{{codegraphSection}}'
115
+ - target: AGENTS.md
116
+ h1: '# AGENTS.md — @ngockhoale/ukit'
117
+ banner: '<!-- generated: templates/instructions/ + repo overlay — edit sources, then yarn docs:render -->'
118
+ resolve_vars: true
119
+ sections:
120
+ - { from: 'overlay:repo', heading: Release Policy (mandatory — never replace) }
121
+ - { from: core, heading: Core Rule }
122
+ - { from: core, heading: Fast Classification }
123
+ - { from: core, heading: Execution Contract (mandatory) }
124
+ - { from: core, heading: Long-Run Continuity }
125
+ - { from: core, heading: Index-First Loop }
126
+ - { from: core, heading: Automatic Skill Activation (mandatory) }
127
+ - { from: core, heading: Internal Helper Policy }
128
+ - { from: core, heading: Skill Quality (maintainer-only) }
129
+ - { from: core, heading: 'UKit v{{ukit.version}} Shared Runtime' }
130
+ - { from: core, heading: Prompt Caching }
131
+ - { from: core, heading: Safe Patch Protocol }
132
+ - { from: core, heading: Handoff Quality Gate — OPT-IN }
133
+ - { from: core, heading: Context + Verification Budget }
134
+ - { from: core, heading: Living Status Workflow }
135
+ - { from: core, heading: Small-Task Maintainer (internal) }
136
+ - { from: core, heading: Post-Edit Sidecar Review (internal) }
137
+ - { from: core, heading: Selective Subagent Policy (internal only) }
138
+ - { from: core, heading: Adaptive Autonomy }
139
+ - { from: core, heading: 3-Tier Model Routing }
140
+ - { from: 'overlay:agents', heading: Session Start — OpenCode }
141
+ - { from: 'overlay:agents', heading: Project Owner Instructions — Codex and OpenCode }
142
+ - { from: core, heading: Skills }
143
+ - { from: core, heading: Project Snapshot }
144
+ - { from: core, heading: Working Rules }
145
+ - { from: core, heading: DuraOne Skill — Conditional Activation }
146
+ - { from: core, heading: Completion Checklist }
147
+ - { from: core, heading: Handoff Fullstack Rules }
148
+ - { from: core, heading: Compact Instructions }
149
+ trailer: '{{codegraphSection}}'
@@ -0,0 +1,15 @@
1
+ ## Session Start — OpenCode
2
+
3
+ <!-- RULE: HOST-OC-01 -->
4
+ At the start of every OpenCode session, before working on the first task:
5
+ 1. Reuse matching route hints from `.claude/ukit/skill-router-state.json`; scan `.claude/skills/` (listing only) and read a SKILL.md only when a task triggers it.
6
+ 2. For every non-trivial task, run `/ukit-route <task summary>` for skill + context hints **before** writing code; if it names a skill, read that SKILL.md — do not skip. When `router.enabled: true` in `.ukit/storage/config.json`, prefer router output over guessing; treat it as internal continuation — continue to edit/verify, don't stop.
7
+
8
+ ## Project Owner Instructions — Codex and OpenCode
9
+
10
+ When running in Codex or OpenCode, read and follow the root
11
+ `PROJECT_IMPORTANT.md` before doing project work. It is the canonical
12
+ project-owner instruction source. Do not copy its contents into this file.
13
+ If it is missing or unreadable, state that limitation and continue with the
14
+ remaining project instructions.
15
+ <!-- RULES: OWN-01 HOST-OWN-01 -->
@@ -0,0 +1,3 @@
1
+ <!-- Claude-only overlay. Intentionally carries no ## sections today: every
2
+ section of templates/CLAUDE.md is shared core. Kept as a comment-only
3
+ source so the overlay allowlist mechanism is exercised (SPEC §7.5). -->
@@ -0,0 +1,74 @@
1
+ omp re-attaches this file near every turn from its native location (`.omp/RULES.md` only, never a
2
+ copy elsewhere). It carries the always-apply subset of root `AGENTS.md` that must survive even when
3
+ nothing else is loaded. Keep this short: every line here is a per-turn tax.
4
+
5
+ ## 1. Classify first, then act
6
+
7
+ - **Trivial** (typo, rename, flag, obvious config) — act directly. No doc reads, no index, no agents.
8
+ - **Simple** (1-2 files, existing pattern) — act directly, pull the smallest useful context.
9
+ - **Non-trivial / risky** (auth, migration, shared runtime, data-loss, flaky) — index-first, then
10
+ activate the matching skill, then verify.
11
+
12
+ Pick the lane before the first tool call. Skipping this is what turns a direct chat into a
13
+ scattershot one.
14
+
15
+ ## 2. Execution Contract
16
+
17
+ For implement/apply/fix requests, continue until the actual edit is made or a real blocker is found.
18
+ Do not stop after a read-only inspection step (read/grep/glob/search).
19
+
20
+ ## 3. No "done" after read-only
21
+
22
+ Never say "done", "applied", or "fixed" after a read-only step. Completion wording requires concrete
23
+ edit/write evidence in the current turn, plus verification when the change is risky.
24
+
25
+ ## 4. Index-first loop
26
+
27
+ Check `.cache/index/` freshness first. Then run
28
+ `node .claude/ukit/index/query-index.mjs "<error|symbol|path>"` and open only the top 1-3 suspect
29
+ files before widening further. These node scripts work unchanged under omp.
30
+
31
+ ## 5. Auto-activate skills
32
+
33
+ Skills live in `.claude/skills/` and omp reads them through its `claude` discovery provider — no
34
+ mirror under `.omp/`. On any non-trivial task, and again after the first tool calls reveal what the
35
+ work really is, read the matching `SKILL.md` without being asked. Users never name skills.
36
+
37
+ ## 6. Delegate to bind a model tier
38
+
39
+ Your own model does not change mid-turn. A tier only applies when work is handed to a task-agent in
40
+ `.omp/agents/`, whose `model:` field (`@lite` / `@code` / `@smart` / `@vision`) resolves through
41
+ `modelRoles` in `.omp/config.yml`.
42
+
43
+ - `tiny-fix` → `@lite` · `local-fix`, `local-build`, `shared-edit`, `find-cause`, `map-impact` →
44
+ `@code` · `review-release` → `@smart`
45
+ - Images: `@vision` only. `@code`/`@smart` cannot see images on the UNIC gateway and must never
46
+ guess at their contents — hand every image to `ukit-vision-analyst` first.
47
+
48
+ Doing everything inline is exactly what makes UKit look like it only has one model. Keep direct
49
+ execution for trivial/simple work; delegate when the tier differs or when a noisy lane would other-
50
+ wise flood this context.
51
+
52
+ ## 7. Safe Patch
53
+
54
+ Prefer unique current-file anchors over line numbers or stale pasted blocks. Never silently merge a
55
+ stale spec — re-read current source and confirm before applying. Preserve existing BOM and line
56
+ endings.
57
+
58
+ ## 8. Handoff runs never park mid-cycle
59
+
60
+ While `docs/AI_HANDOFF/RUN.md` `Phase:` is not `done`/`blocked`, a handoff-fullstack run is
61
+ still in flight: a recap or checkpoint is progress output, never a stopping point. Continue
62
+ the cursor's `Next:` step; only `HANDOFF FULLSTACK COMPLETE` or `HANDOFF FULLSTACK BLOCKED`
63
+ ends the run. `handoff-clear` must close the cursor (`Phase: done` or delete) or the gate
64
+ keeps the next session running too.
65
+
66
+ ## 9. Never end a turn silently
67
+
68
+ Ending a turn with no output is a defect, not a pause. If you stop before the work is finished, the
69
+ last thing you emit is one short line naming what is unfinished and what you need. Silence is never
70
+ a status — the user cannot distinguish it from a crash.
71
+
72
+ > Maintainer note, not a per-turn rule: `modelRoles` in `.omp/config.yml` ships UNIC gateway names.
73
+ > On a non-UNIC provider, edit only the three cost tiers — `lite`, `code`, `smart` — never `vision`,
74
+ > which stays `unic-vision` because it is a capability lane, not a cost tier.
@@ -0,0 +1,9 @@
1
+ ## Release Policy (mandatory — never replace)
2
+
3
+ > User-mandated 2026-09-13. This file uses `mergeStrategy: skip` — ukit install/update never overwrite it. This section is permanent.
4
+
5
+ - **Latest code must always be on npm.** Every version bump ships with `npm publish` in the same cycle, before the work counts as done. A release that only commits to git is not a release (this gap left 2.3.18–2.3.19 unpublished).
6
+ - **npm and git always hold the same latest version.** After publish, `npm view @ngockhoale/ukit version` must equal the `package.json` version; if they ever diverge, publishing wins and happens first.
7
+ - **Never ask the user for npm publish permission** — approval is permanently granted for this package. Use `npm publish --dry-run` for pre-verification, then run the real publish in the same cycle.
8
+ - Users update with `ukit update`, which pulls from npm — an unpublished fix reaches no one. Git is code history/tracking only; npm is the distribution channel.
9
+ - **Repo-only rule:** this policy applies to the UKit development repo itself and must NEVER be added to `templates/CLAUDE.md` / `templates/AGENTS.md` (it must not ship to installed projects). Mirrored at the top of root CLAUDE.md + AGENTS.md; those copies can be wiped by a `ukit update` run inside this repo — if missing, restore them from this section.