@haposoft/cafekit 0.16.0 → 0.16.2

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 (66) hide show
  1. package/README.md +5 -3
  2. package/bin/__tests__/codex-hooks.test.js +125 -0
  3. package/bin/__tests__/codex-native.test.js +95 -0
  4. package/bin/__tests__/develop-contract.test.js +43 -1
  5. package/bin/__tests__/grok-envelope.test.js +271 -0
  6. package/bin/__tests__/grok-platform.test.js +133 -0
  7. package/bin/__tests__/hook-payload.test.js +194 -0
  8. package/bin/__tests__/omp-bridge.test.js +168 -0
  9. package/bin/__tests__/omp-hooks.test.js +178 -0
  10. package/bin/__tests__/omp-runtime.test.js +150 -0
  11. package/bin/__tests__/orca-session.test.js +225 -0
  12. package/bin/__tests__/orca-skill.test.js +210 -0
  13. package/bin/__tests__/package-inventory.test.js +1 -0
  14. package/bin/__tests__/runtime-dir.test.js +158 -0
  15. package/bin/__tests__/runtime-schema.test.js +5 -3
  16. package/bin/__tests__/specs-v2-execution-closeout.test.js +28 -1
  17. package/bin/install.js +5 -5
  18. package/bin/lib/context.js +50 -3
  19. package/bin/lib/i18n.js +3 -30
  20. package/bin/phases/codex-hooks.js +90 -17
  21. package/bin/phases/copy-payload.js +7 -0
  22. package/bin/phases/omp-runtime.js +140 -0
  23. package/bin/phases/root-config.js +3 -0
  24. package/bin/phases/select-platform.js +22 -1
  25. package/bin/phases/summary.js +0 -4
  26. package/package.json +1 -1
  27. package/src/claude/hooks/__tests__/semantic-review-authority.test.js +2 -0
  28. package/src/claude/hooks/__tests__/spec-gate.test.js +338 -0
  29. package/src/claude/hooks/__tests__/state.test.js +2 -0
  30. package/src/claude/hooks/agent.cjs +12 -7
  31. package/src/claude/hooks/completion-authority.cjs +10 -4
  32. package/src/claude/hooks/docs-sync.cjs +2 -1
  33. package/src/claude/hooks/inspect-block.cjs +27 -7
  34. package/src/claude/hooks/lib/config.cjs +5 -2
  35. package/src/claude/hooks/lib/counter.cjs +7 -5
  36. package/src/claude/hooks/lib/hook-payload.cjs +160 -0
  37. package/src/claude/hooks/lib/hook-state-dir.cjs +2 -2
  38. package/src/claude/hooks/lib/runtime-dir.cjs +49 -0
  39. package/src/claude/hooks/precompact.cjs +2 -1
  40. package/src/claude/hooks/privacy-block.cjs +4 -2
  41. package/src/claude/hooks/rules.cjs +4 -2
  42. package/src/claude/hooks/secret-output-guardrail.cjs +2 -1
  43. package/src/claude/hooks/semantic-review-authority.cjs +6 -4
  44. package/src/claude/hooks/session.cjs +16 -8
  45. package/src/claude/hooks/spec-gate.cjs +18 -8
  46. package/src/claude/hooks/spec-state.cjs +9 -5
  47. package/src/claude/hooks/state.cjs +6 -4
  48. package/src/claude/hooks/task-scaffold-guard.cjs +29 -8
  49. package/src/claude/hooks/usage.cjs +5 -4
  50. package/src/claude/migration-manifest.json +3 -0
  51. package/src/claude/rules/skill-domain-routing.md +1 -0
  52. package/src/claude/rules/state-sync.md +7 -1
  53. package/src/claude/rules/workflow.md +2 -0
  54. package/src/claude/scripts/provenance.cjs +11 -4
  55. package/src/claude/scripts/spec-receipt.cjs +65 -4
  56. package/src/claude/skills/orca/SKILL.md +51 -0
  57. package/src/claude/skills/specs/SKILL.md +10 -11
  58. package/src/codex/hooks/session.cjs +6 -1
  59. package/src/codex/hooks/spec-state.cjs +1 -1
  60. package/src/codex/hooks.json +18 -18
  61. package/src/codex/rules/state-sync.md +7 -1
  62. package/src/omp/extensions/cafekit-bridge.mjs +233 -0
  63. package/src/omp/hooks/privacy-block.cjs +250 -0
  64. package/src/omp/runtime.json +33 -0
  65. package/bin/lib/rtk-run.js +0 -28
  66. package/bin/phases/setup-rtk.js +0 -159
@@ -1,159 +0,0 @@
1
- /**
2
- * setup-rtk — opt-in install of the rtk token-saver and its Claude Code hook.
3
- *
4
- * Phase order (per specs/rtk-installer-integration/design.md):
5
- * shouldRunRtk → ensureRtkBinary → `rtk init -g` → jq precheck → manifest
6
- *
7
- * R1-01 wired the consent gate (`shouldRunRtk`) and a thin `setupRtk` wrapper.
8
- * R2-01 adds the orchestrator: `ensureRtkBinary` (detect/install), the
9
- * `rtk init -g` hook registration, the `jq` precheck, and the manifest write.
10
- *
11
- * Non-fatal invariant (R2.7, R4.1): the entire `setupRtk` body is wrapped in
12
- * try/catch. Any throw / non-zero exit / timeout is logged as a warning via
13
- * `ctx.t('rtkFailed')` (with `{reason}` interpolation) and the cafekit
14
- * install continues with its existing exit code. Mirrors the non-fatal
15
- * contract of `phases/skills-setup.js`.
16
- *
17
- * Idempotency (R2.1, R2.6): re-runs see `hasCmd('rtk')` short-circuit the
18
- * binary install path and re-invoke `rtk init -g` (rtk's own command handles
19
- * its hook idempotency). The in-memory `ctx.rtkSetupRan` flag records that
20
- * setup executed, so downstream consumers (R3-01 summary line) can read it.
21
- *
22
- * Cross-OS install (validated 2026-06-15): best-effort order
23
- * (1) official prebuilt install script (pinned source)
24
- * (2) `cargo install rtk` when `hasCmd('cargo')`
25
- * (3) skip + warn
26
- * covers macOS/Linux dev machines (cargo fall-through) and CI (skip+warn).
27
- *
28
- * No timeout for `cargo install rtk` (validated 2026-06-15): user accepted
29
- * default `spawnSync` timeout; non-fatal guarantee holds via try/catch.
30
- */
31
-
32
- const dep = require('../lib/skill-deps');
33
- const rtkRun = require('../lib/rtk-run');
34
- const { hasCmd } = dep;
35
- const { run } = rtkRun;
36
-
37
- const RTK_INIT_TIMEOUT_MS = 30_000; // `rtk init -g` is a fast global-hook write
38
- const RTK_PREBUILT_TIMEOUT_MS = 120_000; // prebuilt install: curl download + sh pipe; slow networks need headroom
39
- const RTK_PREBUILT_INSTALL_URL =
40
- 'https://raw.githubusercontent.com/rtk-ai/rtk/main/install.sh';
41
-
42
- /**
43
- * Detect rtk binary, installing it if absent. Pure function over `ctx`.
44
- *
45
- * @param {object} ctx
46
- * @returns {'present'|'installed'|'absent'}
47
- */
48
- function ensureRtkBinary(ctx) {
49
- if (hasCmd('rtk')) return 'present';
50
- return installRtkBinary(ctx) ? 'installed' : 'absent';
51
- }
52
-
53
- /**
54
- * Best-effort rtk install. Tries the official prebuilt install script first
55
- * (R5.2: surface source), then falls back to `cargo install rtk` if cargo is
56
- * available, otherwise returns false (R2.3 non-fatal skip).
57
- *
58
- * @param {object} ctx
59
- * @returns {boolean} true on success, false on failure or no method available
60
- */
61
- function installRtkBinary(ctx) {
62
- // Method 1: official prebuilt install script (pinned URL).
63
- ctx.ui.info(ctx.t('rtkInstalling', { method: `prebuilt script (${RTK_PREBUILT_INSTALL_URL})` }));
64
- const prebuilt = run('sh', ['-c', `curl -fsSL ${RTK_PREBUILT_INSTALL_URL} | sh`], {
65
- timeout: RTK_PREBUILT_TIMEOUT_MS
66
- });
67
- if (prebuilt.ok) return true;
68
-
69
- // Method 2: `cargo install rtk` if cargo is on PATH.
70
- if (hasCmd('cargo')) {
71
- ctx.ui.info(ctx.t('rtkInstalling', { method: 'cargo install rtk' }));
72
- const cargo = run('cargo', ['install', 'rtk']);
73
- if (cargo.ok) return true;
74
- }
75
-
76
- // No method succeeded.
77
- return false;
78
- }
79
-
80
- /**
81
- * Phase entrypoint. R2-01 wires the full install + hook + manifest pipeline.
82
- * The consent gate is delegated to `shouldRunRtk(ctx)` (R1-01).
83
- *
84
- * @param {object} ctx
85
- * @returns {Promise<object>} the same ctx
86
- */
87
- async function setupRtk(ctx) {
88
- if (!(await shouldRunRtk(ctx))) {
89
- // Dry-run: enumerate the action set that would have run (validated 2026-06-15).
90
- if (ctx.dryRun) {
91
- ctx.ui.info(
92
- '[dry-run] rtk setup skipped (would: detect rtk binary, install if missing via prebuilt/cargo, run rtk init -g, check jq)'
93
- );
94
- } else {
95
- ctx.ui.info(ctx.t('rtkSkipped'));
96
- }
97
- return ctx;
98
- }
99
-
100
- try {
101
- // Step 1: ensure the binary is on PATH (R2.1, R2.2, R2.3).
102
- const state = ensureRtkBinary(ctx);
103
- if (state === 'absent') {
104
- ctx.ui.warn(ctx.t('rtkInstallFailed'));
105
- return ctx;
106
- }
107
- if (state === 'installed') {
108
- ctx.ui.info(ctx.t('rtkInstalled'));
109
- }
110
-
111
- // Step 2: register rtk's official Claude Code hook via `rtk init -g` (R2.4).
112
- const init = run('rtk', ['init', '-g'], { timeout: RTK_INIT_TIMEOUT_MS });
113
- if (!init.ok) {
114
- ctx.ui.warn(ctx.t('rtkInitFailed', { reason: init.stderr || `exit ${init.status}` }));
115
- return ctx;
116
- }
117
-
118
- // Step 3: `jq` precheck (R2.5). Warn if missing; do not fail.
119
- if (!hasCmd('jq')) {
120
- ctx.ui.warn(ctx.t('rtkNeedsJq'));
121
- }
122
-
123
- // Step 4: record the action (R2.6, idempotency). In-memory flag — re-runs
124
- // observe `hasCmd('rtk')` short-circuit and re-invoke `rtk init -g`,
125
- // which is itself idempotent. R3-01 reads this flag for the summary line.
126
- ctx.rtkSetupRan = true;
127
- return ctx;
128
- } catch (err) {
129
- // Non-fatal boundary: any unexpected throw becomes a warning, the
130
- // installer continues (R2.7, R4.1).
131
- ctx.ui.warn(ctx.t('rtkFailed', { reason: (err && err.message) || String(err) }));
132
- return ctx;
133
- }
134
- }
135
-
136
- /**
137
- * Decision matrix for whether the rtk setup phase should run. R1-01.
138
- *
139
- * 1. --dry-run → false (R1.4)
140
- * 2. ctx.options.withRtk === true → true (R1.1)
141
- * 3. !ctx.interactive → false (R1.3)
142
- * 4. interactive confirm resolves true → true (R1.2)
143
- * 5. interactive confirm resolves false → false (R1.2)
144
- *
145
- * @param {object} ctx
146
- * @returns {Promise<boolean>}
147
- */
148
- async function shouldRunRtk(ctx) {
149
- if (ctx.dryRun) return false;
150
- if (ctx.options.withRtk) return true;
151
- if (!ctx.interactive) return false;
152
- const yes = await ctx.ui.confirm(
153
- { message: ctx.t('rtkConfirm'), initialValue: false },
154
- false
155
- );
156
- return yes === true;
157
- }
158
-
159
- module.exports = { shouldRunRtk, setupRtk, ensureRtkBinary, installRtkBinary };