@tech-leads-club/harness-toolkit 0.2.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 (300) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/LICENSE +84 -0
  3. package/NOTICE +9 -0
  4. package/README.md +480 -0
  5. package/bin/tlc +10 -0
  6. package/bin/tlc-build +80 -0
  7. package/bin/tlc-cli.ts +1509 -0
  8. package/bin/tlc-exec +10 -0
  9. package/bin/tlc-exec.cmd +4 -0
  10. package/bin/tlc-exec.d.mts +60 -0
  11. package/bin/tlc-exec.mjs +248 -0
  12. package/bin/tlc.cmd +4 -0
  13. package/bin/tlc.mjs +7 -0
  14. package/bin/write-user-hooks.d.mts +40 -0
  15. package/bin/write-user-hooks.mjs +123 -0
  16. package/capabilities/catalog.json +418 -0
  17. package/config.example.json +51 -0
  18. package/dist/compact-before.mjs +7839 -0
  19. package/dist/doctor.mjs +8263 -0
  20. package/dist/help-topic.mjs +82 -0
  21. package/dist/init-project.mjs +993 -0
  22. package/dist/install-runtime.mjs +969 -0
  23. package/dist/lessons-cli.mjs +7258 -0
  24. package/dist/obs-cli.mjs +7025 -0
  25. package/dist/price-lookup.mjs +221 -0
  26. package/dist/prompt-submit.mjs +7860 -0
  27. package/dist/refresh-model-prices.mjs +158 -0
  28. package/dist/response-after.mjs +7879 -0
  29. package/dist/run.mjs +7830 -0
  30. package/dist/session-end.mjs +7937 -0
  31. package/dist/session-start.mjs +8056 -0
  32. package/dist/shim.mjs +52 -0
  33. package/dist/stop.mjs +8494 -0
  34. package/dist/subagent-start.mjs +7861 -0
  35. package/dist/subagent-stop.mjs +7851 -0
  36. package/dist/support.mjs +7045 -0
  37. package/dist/tlc-cli.mjs +8063 -0
  38. package/dist/tool-after.mjs +8113 -0
  39. package/dist/tool-before.mjs +7985 -0
  40. package/dist/tool-failure.mjs +7850 -0
  41. package/dist/uninstall-runtime.mjs +1307 -0
  42. package/docs/architecture.md +270 -0
  43. package/docs/concepts.md +562 -0
  44. package/docs/coverage.md +55 -0
  45. package/docs/decisions/ad-001.md +32 -0
  46. package/docs/decisions/ad-002.md +51 -0
  47. package/docs/decisions/ad-003.md +30 -0
  48. package/docs/decisions/ad-004.md +37 -0
  49. package/docs/decisions/ad-005.md +36 -0
  50. package/docs/decisions/ad-006.md +49 -0
  51. package/docs/decisions/ad-007.md +36 -0
  52. package/docs/decisions/ad-008.md +54 -0
  53. package/docs/decisions/ad-009.md +61 -0
  54. package/docs/decisions/ad-010.md +45 -0
  55. package/docs/decisions/ad-011.md +59 -0
  56. package/docs/decisions/ad-012.md +71 -0
  57. package/docs/decisions/ad-013.md +87 -0
  58. package/docs/decisions/ad-014.md +56 -0
  59. package/docs/decisions/ad-015.md +33 -0
  60. package/docs/decisions/ad-016.md +98 -0
  61. package/docs/decisions/ad-017.md +65 -0
  62. package/docs/decisions/ad-018.md +77 -0
  63. package/docs/decisions/ad-019.md +75 -0
  64. package/docs/decisions/ad-020.md +88 -0
  65. package/docs/decisions/ad-021.md +57 -0
  66. package/docs/decisions/ad-022.md +120 -0
  67. package/docs/decisions/ad-023.md +87 -0
  68. package/docs/decisions/ad-024.md +85 -0
  69. package/docs/decisions/ad-025.md +92 -0
  70. package/docs/decisions/ad-026.md +131 -0
  71. package/docs/decisions/ad-027.md +90 -0
  72. package/docs/decisions/ad-028.md +90 -0
  73. package/docs/decisions/ad-029.md +73 -0
  74. package/docs/decisions/ad-030.md +97 -0
  75. package/docs/decisions/ad-031.md +94 -0
  76. package/docs/decisions/ad-032.md +83 -0
  77. package/docs/decisions/ad-033.md +89 -0
  78. package/docs/decisions/ad-034.md +86 -0
  79. package/docs/decisions/ad-035.md +86 -0
  80. package/docs/decisions/ad-036.md +68 -0
  81. package/docs/decisions/ad-037.md +47 -0
  82. package/docs/decisions/ad-038.md +52 -0
  83. package/docs/decisions/ad-039.md +69 -0
  84. package/docs/decisions/ad-040.md +89 -0
  85. package/docs/decisions/ad-041.md +98 -0
  86. package/docs/decisions/ad-042.md +82 -0
  87. package/docs/decisions/ad-043.md +79 -0
  88. package/docs/decisions/ad-044.md +61 -0
  89. package/docs/decisions/ad-045.md +94 -0
  90. package/docs/decisions/ad-046.md +111 -0
  91. package/docs/decisions/ad-047.md +96 -0
  92. package/docs/decisions/ad-048.md +85 -0
  93. package/docs/decisions/ad-049.md +66 -0
  94. package/docs/decisions/ad-050.md +94 -0
  95. package/docs/decisions/ad-051.md +69 -0
  96. package/docs/decisions/ad-052.md +69 -0
  97. package/docs/decisions/ad-053.md +78 -0
  98. package/docs/decisions/ad-054.md +98 -0
  99. package/docs/decisions/ad-055.md +74 -0
  100. package/docs/decisions/ad-056.md +85 -0
  101. package/docs/decisions/ad-057.md +68 -0
  102. package/docs/decisions/ad-058.md +97 -0
  103. package/docs/decisions/ad-059.md +82 -0
  104. package/docs/decisions/ad-060.md +75 -0
  105. package/docs/decisions/ad-061.md +68 -0
  106. package/docs/decisions/ad-062.md +72 -0
  107. package/docs/decisions/ad-063.md +84 -0
  108. package/docs/decisions/ad-064.md +79 -0
  109. package/docs/decisions/ad-065.md +81 -0
  110. package/docs/decisions/ad-066.md +111 -0
  111. package/docs/decisions/ad-067.md +64 -0
  112. package/docs/decisions/ad-068.md +79 -0
  113. package/docs/decisions/ad-069.md +74 -0
  114. package/docs/decisions/ad-070.md +86 -0
  115. package/docs/decisions/ad-071.md +93 -0
  116. package/docs/decisions/ad-072.md +82 -0
  117. package/docs/decisions/ad-073.md +102 -0
  118. package/docs/decisions/ad-074.md +91 -0
  119. package/docs/decisions/ad-075.md +79 -0
  120. package/docs/decisions/ad-076.md +102 -0
  121. package/docs/decisions/ad-077.md +94 -0
  122. package/docs/decisions/ad-078.md +84 -0
  123. package/docs/decisions/ad-079.md +73 -0
  124. package/docs/decisions/ad-080.md +86 -0
  125. package/docs/decisions/ad-081.md +70 -0
  126. package/docs/decisions/ad-082.md +79 -0
  127. package/docs/decisions/ad-083.md +88 -0
  128. package/docs/decisions/index.md +111 -0
  129. package/docs/diagnose.md +248 -0
  130. package/docs/index.md +52 -0
  131. package/docs/init.md +101 -0
  132. package/docs/lessons.md +294 -0
  133. package/docs/log.md +139 -0
  134. package/docs/measure.md +178 -0
  135. package/docs/providers/claude-code.md +118 -0
  136. package/docs/providers/cursor.md +110 -0
  137. package/docs/providers/index.md +71 -0
  138. package/docs/troubleshooting.md +138 -0
  139. package/model-aliases.json +12 -0
  140. package/model-prices.cursor.json +410 -0
  141. package/model-prices.json +1 -0
  142. package/package.json +57 -0
  143. package/skills/harness-init/SKILL.md +241 -0
  144. package/skills/harness-init/evals/trigger_evals.json +86 -0
  145. package/skills/harness-init/references/capabilities.md +113 -0
  146. package/src/contracts/capabilities.ts +30 -0
  147. package/src/contracts/decision.ts +21 -0
  148. package/src/contracts/effort.ts +15 -0
  149. package/src/contracts/harness-event.ts +87 -0
  150. package/src/contracts/index.ts +6 -0
  151. package/src/contracts/policy-defaults.ts +14 -0
  152. package/src/contracts/wiring.ts +20 -0
  153. package/src/core/attest/attest.service.ts +0 -0
  154. package/src/core/capability/capability.service.ts +62 -0
  155. package/src/core/capability/capability.store.ts +51 -0
  156. package/src/core/capability/capability.types.ts +56 -0
  157. package/src/core/comment-policy/comment-policy.service.ts +307 -0
  158. package/src/core/comment-policy/comment-policy.types.ts +6 -0
  159. package/src/core/comment-policy/comment-resolvability.ts +134 -0
  160. package/src/core/comment-policy/comment-syntax.catalog.ts +310 -0
  161. package/src/core/comment-policy/comment-syntax.store.ts +65 -0
  162. package/src/core/comment-policy/comment-syntax.types.ts +24 -0
  163. package/src/core/core.facade.ts +461 -0
  164. package/src/core/duplication/duplication.service.ts +219 -0
  165. package/src/core/floor/floor.catalog.ts +54 -0
  166. package/src/core/floor/floor.paths.ts +90 -0
  167. package/src/core/floor/floor.policy-surface.ts +311 -0
  168. package/src/core/floor/floor.service.ts +306 -0
  169. package/src/core/floor/floor.tokenize.ts +179 -0
  170. package/src/core/floor/floor.verb.ts +28 -0
  171. package/src/core/floor/index.ts +1 -0
  172. package/src/core/gate/gate.artifact.ts +157 -0
  173. package/src/core/gate/gate.command.ts +130 -0
  174. package/src/core/gate/gate.findings.ts +201 -0
  175. package/src/core/gate/gate.inputs.ts +0 -0
  176. package/src/core/gate/gate.lock.ts +283 -0
  177. package/src/core/gate/gate.service.ts +28 -0
  178. package/src/core/gate/gate.types.ts +67 -0
  179. package/src/core/handoff/handoff.service.ts +43 -0
  180. package/src/core/handoff/handoff.store.ts +59 -0
  181. package/src/core/handoff/handoff.types.ts +89 -0
  182. package/src/core/index.ts +52 -0
  183. package/src/core/integrity/state-seal.ts +81 -0
  184. package/src/core/lesson/lesson.authored.ts +96 -0
  185. package/src/core/lesson/lesson.credit.ts +51 -0
  186. package/src/core/lesson/lesson.garden.ts +283 -0
  187. package/src/core/lesson/lesson.link.ts +93 -0
  188. package/src/core/lesson/lesson.score.ts +61 -0
  189. package/src/core/lesson/lesson.select.ts +209 -0
  190. package/src/core/lesson/lesson.service.ts +110 -0
  191. package/src/core/lesson/lesson.store.ts +317 -0
  192. package/src/core/lesson/lesson.sync.ts +70 -0
  193. package/src/core/lesson/lesson.types.ts +92 -0
  194. package/src/core/lesson/lesson.validity.ts +44 -0
  195. package/src/core/observability/observability.report.ts +326 -0
  196. package/src/core/observability/observability.service.ts +328 -0
  197. package/src/core/observability/observability.store.ts +269 -0
  198. package/src/core/observability/observability.types.ts +193 -0
  199. package/src/core/observability/observability.why.ts +206 -0
  200. package/src/core/observe/observe.service.ts +76 -0
  201. package/src/core/plan/plan.detect.ts +47 -0
  202. package/src/core/plan/plan.service.ts +81 -0
  203. package/src/core/plan/plan.types.ts +25 -0
  204. package/src/core/policy/policy.defaults.ts +103 -0
  205. package/src/core/policy/policy.guard.ts +34 -0
  206. package/src/core/policy/policy.integrity.ts +238 -0
  207. package/src/core/policy/policy.loader.ts +118 -0
  208. package/src/core/policy/policy.operator.ts +82 -0
  209. package/src/core/policy/policy.posture.ts +79 -0
  210. package/src/core/policy/policy.rails.ts +45 -0
  211. package/src/core/policy/policy.types.ts +157 -0
  212. package/src/core/presence/presence.service.ts +111 -0
  213. package/src/core/presence/presence.store.ts +59 -0
  214. package/src/core/presence/presence.types.ts +9 -0
  215. package/src/core/release/release.decisions.ts +147 -0
  216. package/src/core/release/release.seen.ts +38 -0
  217. package/src/core/shell-policy/shell-policy.service.ts +215 -0
  218. package/src/core/shell-policy/shell-policy.stall.ts +57 -0
  219. package/src/core/shell-policy/shell-policy.types.ts +26 -0
  220. package/src/core/ship/ship.ledger.ts +76 -0
  221. package/src/core/ship/ship.service.ts +137 -0
  222. package/src/core/ship/ship.types.ts +19 -0
  223. package/src/core/stagnation/stagnation.resolution.ts +87 -0
  224. package/src/core/stagnation/stagnation.service.ts +20 -0
  225. package/src/core/stagnation/stagnation.store.ts +49 -0
  226. package/src/core/stagnation/stagnation.types.ts +12 -0
  227. package/src/core/subagent-policy/subagent-policy.parent-model.ts +202 -0
  228. package/src/core/subagent-policy/subagent-policy.service.ts +139 -0
  229. package/src/core/subagent-policy/subagent-policy.types.ts +22 -0
  230. package/src/core/supply-chain/supply-chain.catalog.ts +51 -0
  231. package/src/core/supply-chain/supply-chain.service.ts +217 -0
  232. package/src/core/turn/turn.activity.ts +94 -0
  233. package/src/core/turn/turn.autopilot.ts +131 -0
  234. package/src/core/turn/turn.failure-signals.ts +193 -0
  235. package/src/core/turn/turn.loop-counter.ts +71 -0
  236. package/src/core/turn/turn.types.ts +14 -0
  237. package/src/core/untrusted/untrusted.detect.ts +53 -0
  238. package/src/core/untrusted/untrusted.recall.ts +87 -0
  239. package/src/core/untrusted/untrusted.service.ts +129 -0
  240. package/src/core/untrusted/untrusted.store.ts +75 -0
  241. package/src/core/untrusted/untrusted.types.ts +42 -0
  242. package/src/entrypoints/compact-before.ts +14 -0
  243. package/src/entrypoints/prompt-submit.ts +25 -0
  244. package/src/entrypoints/response-after.ts +60 -0
  245. package/src/entrypoints/run.ts +179 -0
  246. package/src/entrypoints/session-end.ts +58 -0
  247. package/src/entrypoints/session-start.ts +172 -0
  248. package/src/entrypoints/shim.ts +46 -0
  249. package/src/entrypoints/stop.ts +876 -0
  250. package/src/entrypoints/subagent-start.ts +16 -0
  251. package/src/entrypoints/subagent-stop.ts +32 -0
  252. package/src/entrypoints/support.ts +182 -0
  253. package/src/entrypoints/tool-after.ts +111 -0
  254. package/src/entrypoints/tool-before.ts +186 -0
  255. package/src/entrypoints/tool-failure.ts +26 -0
  256. package/src/platform/backoff.ts +49 -0
  257. package/src/platform/cli-output.ts +30 -0
  258. package/src/platform/env-scope.ts +22 -0
  259. package/src/platform/fs-atomic.ts +142 -0
  260. package/src/platform/fs-jsonl.ts +24 -0
  261. package/src/platform/git.ts +187 -0
  262. package/src/platform/paths.ts +80 -0
  263. package/src/platform/pricing.ts +229 -0
  264. package/src/platform/process.ts +64 -0
  265. package/src/platform/sanitize.ts +23 -0
  266. package/src/platform/screen.ts +46 -0
  267. package/src/platform/style.ts +103 -0
  268. package/src/providers/claude/claude.capabilities.ts +25 -0
  269. package/src/providers/claude/claude.detect.ts +14 -0
  270. package/src/providers/claude/claude.inbound.ts +252 -0
  271. package/src/providers/claude/claude.lessons-view.ts +33 -0
  272. package/src/providers/claude/claude.outbound.ts +65 -0
  273. package/src/providers/claude/claude.policy-defaults.ts +9 -0
  274. package/src/providers/claude/claude.transcript.ts +62 -0
  275. package/src/providers/claude/claude.wiring.ts +245 -0
  276. package/src/providers/claude/index.ts +17 -0
  277. package/src/providers/cursor/cursor.capabilities.ts +28 -0
  278. package/src/providers/cursor/cursor.detect.ts +14 -0
  279. package/src/providers/cursor/cursor.inbound.ts +203 -0
  280. package/src/providers/cursor/cursor.lessons-view.ts +30 -0
  281. package/src/providers/cursor/cursor.outbound.ts +43 -0
  282. package/src/providers/cursor/cursor.policy-defaults.ts +9 -0
  283. package/src/providers/cursor/cursor.wiring.ts +214 -0
  284. package/src/providers/cursor/index.ts +17 -0
  285. package/src/providers/index.ts +9 -0
  286. package/src/providers/provider.degrade.ts +152 -0
  287. package/src/providers/provider.port.ts +20 -0
  288. package/src/providers/provider.registry.ts +28 -0
  289. package/tools/doctor.ts +631 -0
  290. package/tools/help-topic.ts +74 -0
  291. package/tools/init-project.ts +277 -0
  292. package/tools/install-runtime.ts +164 -0
  293. package/tools/lessons-cli.ts +474 -0
  294. package/tools/obs-cli.ts +175 -0
  295. package/tools/price-lookup.ts +57 -0
  296. package/tools/refresh-model-prices.ts +210 -0
  297. package/tools/test-env.mjs +28 -0
  298. package/tools/test-env.names.d.mts +1 -0
  299. package/tools/test-env.names.mjs +14 -0
  300. package/tools/uninstall-runtime.ts +463 -0
@@ -0,0 +1,993 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
4
+ // tools/init-project.ts
5
+ import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "node:fs";
6
+ import { dirname as dirname3, join as join4 } from "node:path";
7
+
8
+ // bin/write-user-hooks.mjs
9
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
10
+ import { dirname as dirname2, join as join3 } from "node:path";
11
+
12
+ // src/providers/claude/claude.wiring.ts
13
+ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
14
+ import { dirname, join as join2 } from "node:path";
15
+
16
+ // src/platform/paths.ts
17
+ import { homedir } from "node:os";
18
+ import { join } from "node:path";
19
+ function harnessDir(root) {
20
+ return join(root, ".tlc", "harness");
21
+ }
22
+ function conventionalRuntimeHome() {
23
+ return join(homedir(), ".tlc", "harness");
24
+ }
25
+ function runtimeHome(env = process.env) {
26
+ return env.TLC_HOME ?? conventionalRuntimeHome();
27
+ }
28
+ function projectConfigPath(root) {
29
+ return join(harnessDir(root), "config.json");
30
+ }
31
+ function claudeConfigDir() {
32
+ const custom = process.env.CLAUDE_CONFIG_DIR?.trim();
33
+ return custom && custom.length > 0 ? custom : join(homedir(), ".claude");
34
+ }
35
+ function cursorConfigDir() {
36
+ const custom = process.env.CURSOR_CONFIG_DIR?.trim();
37
+ return custom && custom.length > 0 ? custom : join(homedir(), ".cursor");
38
+ }
39
+
40
+ // src/providers/claude/claude.wiring.ts
41
+ function isPlainRecord(value) {
42
+ return value !== null && typeof value === "object" && !Array.isArray(value);
43
+ }
44
+ function isHooksRecord(value) {
45
+ return isPlainRecord(value);
46
+ }
47
+ function deepEqual(a, b) {
48
+ if (a === b) {
49
+ return true;
50
+ }
51
+ if (Array.isArray(a) || Array.isArray(b)) {
52
+ if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
53
+ return false;
54
+ }
55
+ return a.every((item, index) => deepEqual(item, b[index]));
56
+ }
57
+ if (isPlainRecord(a) && isPlainRecord(b)) {
58
+ const aKeys = Object.keys(a);
59
+ const bKeys = Object.keys(b);
60
+ if (aKeys.length !== bKeys.length) {
61
+ return false;
62
+ }
63
+ return aKeys.every((key) => bKeys.includes(key) && deepEqual(a[key], b[key]));
64
+ }
65
+ return false;
66
+ }
67
+ function desiredHooksFor(entries) {
68
+ const hooks = {};
69
+ for (const entry of entries) {
70
+ const group = {
71
+ hooks: [{ type: "command", command: entry.command, args: entry.args }]
72
+ };
73
+ hooks[entry.hookEvent] = [...hooks[entry.hookEvent] ?? [], group];
74
+ }
75
+ return hooks;
76
+ }
77
+ var LAUNCHER_MARKER = "tlc-exec.mjs";
78
+ function isHarnessGroup(group) {
79
+ return JSON.stringify(group ?? null).includes(LAUNCHER_MARKER);
80
+ }
81
+ function canonicalLauncherPath(path, resolve = realpathSync) {
82
+ try {
83
+ return resolve(path);
84
+ } catch {
85
+ return path;
86
+ }
87
+ }
88
+ function canonicalizeGroups(groups, resolve) {
89
+ return JSON.parse(JSON.stringify(groups ?? null, (_key, value) => typeof value === "string" && value.includes(LAUNCHER_MARKER) ? canonicalLauncherPath(value, resolve) : value));
90
+ }
91
+ function mergeClaudeSettings(existingText, entries) {
92
+ const desired = desiredHooksFor(entries);
93
+ let settings = {};
94
+ if (existingText !== null && existingText.trim() !== "") {
95
+ let parsed;
96
+ try {
97
+ parsed = JSON.parse(existingText);
98
+ } catch (error) {
99
+ const message = error instanceof Error ? error.message : String(error);
100
+ return { ok: false, error: message, block: JSON.stringify({ hooks: desired }, null, 2) };
101
+ }
102
+ if (!isPlainRecord(parsed)) {
103
+ return {
104
+ ok: false,
105
+ error: "settings.json root is not a JSON object",
106
+ block: JSON.stringify({ hooks: desired }, null, 2)
107
+ };
108
+ }
109
+ settings = parsed;
110
+ }
111
+ const currentHooks = isHooksRecord(settings.hooks) ? settings.hooks : {};
112
+ const mergedHooks = { ...currentHooks };
113
+ let changed = false;
114
+ for (const [hookEvent, groups] of Object.entries(desired)) {
115
+ const existingGroups = mergedHooks[hookEvent] ?? [];
116
+ const foreign = existingGroups.filter((group) => !isHarnessGroup(group));
117
+ const nextGroups = [...foreign, ...groups];
118
+ if (!deepEqual(canonicalizeGroups(existingGroups), canonicalizeGroups(nextGroups))) {
119
+ changed = true;
120
+ }
121
+ mergedHooks[hookEvent] = nextGroups;
122
+ }
123
+ const mergedSettings = { ...settings, hooks: mergedHooks };
124
+ return { ok: true, settingsText: JSON.stringify(mergedSettings, null, 2), changed };
125
+ }
126
+ function applyClaudeWiring(settingsPath, entries) {
127
+ const existingText = existsSync(settingsPath) ? readFileSync(settingsPath, "utf8") : null;
128
+ const result = mergeClaudeSettings(existingText, entries);
129
+ if (result.ok && result.changed) {
130
+ mkdirSync(dirname(settingsPath), { recursive: true });
131
+ writeFileSync(settingsPath, result.settingsText, "utf8");
132
+ }
133
+ return result;
134
+ }
135
+ // src/providers/provider.degrade.ts
136
+ var NO_HUMAN_MODES = new Set(["bypassPermissions", "dontAsk"]);
137
+ // bin/write-user-hooks.mjs
138
+ var CURSOR_MARKER = "tlc-exec.mjs";
139
+ function quoteIfNeeded(token) {
140
+ return token.includes(" ") ? `"${token}"` : token;
141
+ }
142
+ function commandStringFor(entry) {
143
+ return [entry.command, ...entry.args].map(quoteIfNeeded).join(" ");
144
+ }
145
+ function renderCursorHooksDocument(entries) {
146
+ const hooks = {};
147
+ for (const entry of entries) {
148
+ const rendered = { command: commandStringFor(entry), timeout: entry.timeoutSeconds };
149
+ if (entry.failClosed) {
150
+ rendered.failClosed = true;
151
+ }
152
+ if (entry.matcher !== undefined) {
153
+ rendered.matcher = entry.matcher;
154
+ }
155
+ if (entry.loopLimit !== undefined) {
156
+ rendered.loop_limit = entry.loopLimit;
157
+ }
158
+ hooks[entry.hookEvent] = [...hooks[entry.hookEvent] ?? [], rendered];
159
+ }
160
+ return { version: 1, hooks };
161
+ }
162
+ function isCursorWired(targetPath) {
163
+ return existsSync2(targetPath) && readFileSync2(targetPath, "utf8").includes(CURSOR_MARKER);
164
+ }
165
+ function applyCursorWiring(wiring, { force = false } = {}) {
166
+ const targetPath = wiring.target;
167
+ const document = renderCursorHooksDocument(wiring.entries);
168
+ const rendered = `${JSON.stringify(document, null, 2)}
169
+ `;
170
+ if (existsSync2(targetPath) && !force) {
171
+ if (isCursorWired(targetPath)) {
172
+ return { status: "unchanged", target: targetPath };
173
+ }
174
+ return {
175
+ status: "refused",
176
+ target: targetPath,
177
+ reason: `${targetPath} exists without harness entries — rerun with --force to overwrite, or merge manually.`
178
+ };
179
+ }
180
+ mkdirSync2(dirname2(targetPath), { recursive: true });
181
+ writeFileSync2(targetPath, rendered);
182
+ return { status: "written", target: targetPath };
183
+ }
184
+ if (false) {}
185
+
186
+ // src/core/comment-policy/comment-syntax.catalog.ts
187
+ var COMMENT_SYNTAX = [
188
+ {
189
+ id: "typescript",
190
+ extensions: [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"],
191
+ line: ["//"],
192
+ block: [["/*", "*/"]],
193
+ middle: ["*"]
194
+ },
195
+ {
196
+ id: "python",
197
+ extensions: [".py", ".pyi", ".pyw"],
198
+ line: ["#"],
199
+ block: [
200
+ ['"""', '"""'],
201
+ ["'''", "'''"]
202
+ ],
203
+ middle: []
204
+ },
205
+ {
206
+ id: "ruby",
207
+ extensions: [".rb", ".rake", ".gemspec"],
208
+ line: ["#"],
209
+ block: [["=begin", "=end"]],
210
+ middle: []
211
+ },
212
+ {
213
+ id: "shell",
214
+ extensions: [".sh", ".bash", ".zsh", ".ksh", ".fish"],
215
+ line: ["#"],
216
+ block: [],
217
+ middle: []
218
+ },
219
+ {
220
+ id: "go",
221
+ extensions: [".go"],
222
+ line: ["//"],
223
+ block: [["/*", "*/"]],
224
+ middle: ["*"]
225
+ },
226
+ {
227
+ id: "rust",
228
+ extensions: [".rs"],
229
+ line: ["//"],
230
+ block: [["/*", "*/"]],
231
+ middle: ["*"]
232
+ },
233
+ {
234
+ id: "java",
235
+ extensions: [".java"],
236
+ line: ["//"],
237
+ block: [["/*", "*/"]],
238
+ middle: ["*"]
239
+ },
240
+ {
241
+ id: "kotlin",
242
+ extensions: [".kt", ".kts"],
243
+ line: ["//"],
244
+ block: [["/*", "*/"]],
245
+ middle: ["*"]
246
+ },
247
+ {
248
+ id: "swift",
249
+ extensions: [".swift"],
250
+ line: ["//"],
251
+ block: [["/*", "*/"]],
252
+ middle: ["*"]
253
+ },
254
+ {
255
+ id: "c",
256
+ extensions: [".c", ".h"],
257
+ line: ["//"],
258
+ block: [["/*", "*/"]],
259
+ middle: ["*"]
260
+ },
261
+ {
262
+ id: "cpp",
263
+ extensions: [".cc", ".cpp", ".cxx", ".hpp", ".hh", ".hxx"],
264
+ line: ["//"],
265
+ block: [["/*", "*/"]],
266
+ middle: ["*"]
267
+ },
268
+ {
269
+ id: "csharp",
270
+ extensions: [".cs"],
271
+ line: ["//"],
272
+ block: [["/*", "*/"]],
273
+ middle: ["*"]
274
+ },
275
+ {
276
+ id: "php",
277
+ extensions: [".php"],
278
+ line: ["//", "#"],
279
+ block: [["/*", "*/"]],
280
+ middle: ["*"]
281
+ },
282
+ {
283
+ id: "scala",
284
+ extensions: [".scala", ".sc"],
285
+ line: ["//"],
286
+ block: [["/*", "*/"]],
287
+ middle: ["*"]
288
+ },
289
+ {
290
+ id: "dart",
291
+ extensions: [".dart"],
292
+ line: ["//"],
293
+ block: [["/*", "*/"]],
294
+ middle: ["*"]
295
+ },
296
+ {
297
+ id: "elixir",
298
+ extensions: [".ex", ".exs"],
299
+ line: ["#"],
300
+ block: [],
301
+ middle: []
302
+ },
303
+ {
304
+ id: "erlang",
305
+ extensions: [".erl", ".hrl"],
306
+ line: ["%"],
307
+ block: [],
308
+ middle: []
309
+ },
310
+ {
311
+ id: "haskell",
312
+ extensions: [".hs"],
313
+ line: ["--"],
314
+ block: [["{-", "-}"]],
315
+ middle: []
316
+ },
317
+ {
318
+ id: "lua",
319
+ extensions: [".lua"],
320
+ line: ["--"],
321
+ block: [["--[[", "]]"]],
322
+ middle: []
323
+ },
324
+ {
325
+ id: "sql",
326
+ extensions: [".sql"],
327
+ line: ["--"],
328
+ block: [["/*", "*/"]],
329
+ middle: ["*"]
330
+ },
331
+ {
332
+ id: "css",
333
+ extensions: [".css", ".scss", ".sass", ".less"],
334
+ line: ["//"],
335
+ block: [["/*", "*/"]],
336
+ middle: ["*"]
337
+ },
338
+ {
339
+ id: "yaml",
340
+ extensions: [".yaml", ".yml"],
341
+ line: ["#"],
342
+ block: [],
343
+ middle: []
344
+ },
345
+ {
346
+ id: "toml",
347
+ extensions: [".toml"],
348
+ line: ["#"],
349
+ block: [],
350
+ middle: []
351
+ },
352
+ {
353
+ id: "ini",
354
+ extensions: [".ini", ".cfg", ".conf", ".properties"],
355
+ line: [";", "#"],
356
+ block: [],
357
+ middle: []
358
+ },
359
+ {
360
+ id: "dockerfile",
361
+ extensions: [".dockerfile", "dockerfile"],
362
+ line: ["#"],
363
+ block: [],
364
+ middle: []
365
+ },
366
+ {
367
+ id: "makefile",
368
+ extensions: [".mk", "makefile"],
369
+ line: ["#"],
370
+ block: [],
371
+ middle: []
372
+ },
373
+ {
374
+ id: "terraform",
375
+ extensions: [".tf", ".tfvars"],
376
+ line: ["#", "//"],
377
+ block: [["/*", "*/"]],
378
+ middle: ["*"]
379
+ },
380
+ {
381
+ id: "powershell",
382
+ extensions: [".ps1", ".psm1", ".psd1"],
383
+ line: ["#"],
384
+ block: [["<#", "#>"]],
385
+ middle: []
386
+ },
387
+ {
388
+ id: "perl",
389
+ extensions: [".pl", ".pm"],
390
+ line: ["#"],
391
+ block: [],
392
+ middle: []
393
+ },
394
+ {
395
+ id: "r",
396
+ extensions: [".r"],
397
+ line: ["#"],
398
+ block: [],
399
+ middle: []
400
+ },
401
+ {
402
+ id: "julia",
403
+ extensions: [".jl"],
404
+ line: ["#"],
405
+ block: [["#=", "=#"]],
406
+ middle: []
407
+ },
408
+ {
409
+ id: "vue",
410
+ extensions: [".vue", ".svelte"],
411
+ line: ["//"],
412
+ block: [
413
+ ["/*", "*/"],
414
+ ["<!--", "-->"]
415
+ ],
416
+ middle: ["*"]
417
+ },
418
+ {
419
+ id: "html",
420
+ extensions: [".html", ".htm", ".xml", ".xhtml"],
421
+ line: [],
422
+ block: [["<!--", "-->"]],
423
+ middle: []
424
+ },
425
+ {
426
+ id: "graphql",
427
+ extensions: [".graphql", ".gql"],
428
+ line: ["#"],
429
+ block: [],
430
+ middle: []
431
+ },
432
+ {
433
+ id: "protobuf",
434
+ extensions: [".proto"],
435
+ line: ["//"],
436
+ block: [["/*", "*/"]],
437
+ middle: ["*"]
438
+ },
439
+ {
440
+ id: "zig",
441
+ extensions: [".zig"],
442
+ line: ["//"],
443
+ block: [],
444
+ middle: []
445
+ },
446
+ {
447
+ id: "clojure",
448
+ extensions: [".clj", ".cljs", ".cljc", ".edn"],
449
+ line: [";"],
450
+ block: [],
451
+ middle: []
452
+ },
453
+ {
454
+ id: "ocaml",
455
+ extensions: [".ml", ".mli"],
456
+ line: [],
457
+ block: [["(*", "*)"]],
458
+ middle: ["*"]
459
+ },
460
+ {
461
+ id: "fsharp",
462
+ extensions: [".fs", ".fsi", ".fsx"],
463
+ line: ["//"],
464
+ block: [["(*", "*)"]],
465
+ middle: ["*"]
466
+ },
467
+ {
468
+ id: "vim",
469
+ extensions: [".vim"],
470
+ line: ['"'],
471
+ block: [],
472
+ middle: []
473
+ },
474
+ {
475
+ id: "tex",
476
+ extensions: [".tex", ".sty", ".cls"],
477
+ line: ["%"],
478
+ block: [],
479
+ middle: []
480
+ }
481
+ ];
482
+
483
+ // src/core/comment-policy/comment-syntax.store.ts
484
+ function buildIndex(entries) {
485
+ const byKey = new Map;
486
+ for (const entry of entries) {
487
+ const syntax = { line: entry.line, block: entry.block, middle: entry.middle };
488
+ for (const extension of entry.extensions) {
489
+ byKey.set(extension.toLowerCase(), syntax);
490
+ }
491
+ }
492
+ return byKey;
493
+ }
494
+ var INDEX = buildIndex(COMMENT_SYNTAX);
495
+ var KNOWN_EXTENSION_COUNT = INDEX.size;
496
+
497
+ // src/core/comment-policy/comment-policy.service.ts
498
+ var STOPWORDS = new Set([
499
+ "a",
500
+ "an",
501
+ "and",
502
+ "are",
503
+ "as",
504
+ "at",
505
+ "be",
506
+ "by",
507
+ "for",
508
+ "from",
509
+ "get",
510
+ "gets",
511
+ "has",
512
+ "in",
513
+ "into",
514
+ "is",
515
+ "it",
516
+ "its",
517
+ "of",
518
+ "on",
519
+ "or",
520
+ "return",
521
+ "returns",
522
+ "set",
523
+ "sets",
524
+ "that",
525
+ "the",
526
+ "then",
527
+ "this",
528
+ "to",
529
+ "true",
530
+ "when",
531
+ "which",
532
+ "with"
533
+ ]);
534
+
535
+ // src/core/duplication/duplication.service.ts
536
+ var MIN_RUN = 6;
537
+
538
+ // src/core/observability/observability.types.ts
539
+ var DEFAULT_OBS = {
540
+ enabled: true,
541
+ signalPath: "obs.jsonl",
542
+ debugPath: "debug.jsonl",
543
+ debugEnabled: false,
544
+ includePayloads: false,
545
+ maxAttrChars: 500,
546
+ sessionCostAlertUsd: 5,
547
+ retentionDays: 14,
548
+ maxSignalEvents: 50000,
549
+ globalSpool: false
550
+ };
551
+ var SIGNAL_KINDS = new Set([
552
+ "session.start",
553
+ "session.end",
554
+ "generation.end",
555
+ "tool.fail",
556
+ "subagent.start",
557
+ "subagent.end",
558
+ "prompt.submit",
559
+ "compact",
560
+ "gate.outcome",
561
+ "cost.turn",
562
+ "cost.session_alert",
563
+ "ship.claim",
564
+ "policy.deny",
565
+ "policy.observe"
566
+ ]);
567
+ var LIVE_ALLOWLIST = new Set([
568
+ "session.start",
569
+ "session.end",
570
+ "generation.end",
571
+ "tool.fail",
572
+ "shell.end",
573
+ "subagent.start",
574
+ "subagent.end",
575
+ "gate.outcome",
576
+ "cost.turn",
577
+ "cost.session_alert",
578
+ "ship.claim",
579
+ "policy.deny",
580
+ "compact",
581
+ "prompt.submit"
582
+ ]);
583
+
584
+ // src/core/policy/policy.defaults.ts
585
+ var DEFAULT_LESSONS_POLICY = {
586
+ enabled: false,
587
+ maxInjectSession: 5,
588
+ maxInjectRetry: 8,
589
+ maxCharsSession: 900,
590
+ maxCharsRetry: 1400,
591
+ promoteHitCount: 2,
592
+ decayLambda: 0.02,
593
+ projectBoost: 1.5,
594
+ syncRulesFile: "auto",
595
+ gardenOnSessionEnd: true
596
+ };
597
+ var DEFAULTS = {
598
+ version: 1,
599
+ mode: "solo",
600
+ codePaths: ["src", "apps", "libs", "packages"],
601
+ grind: {
602
+ enabled: false,
603
+ maxLoops: 5,
604
+ lintCommand: null,
605
+ testCommand: null,
606
+ appendFiles: "auto"
607
+ },
608
+ shipGate: {
609
+ enabled: false,
610
+ runtimePathPrefixes: ["src", "apps", "libs", "packages", "deploy", "scripts"],
611
+ runtimePathExcludes: [".tlc/", "**/node_modules/", "**/.git/"],
612
+ evidenceDir: null,
613
+ evidenceMaxAgeHours: 48,
614
+ emptyDiffAntiShip: false,
615
+ claimWindowMinutes: 10
616
+ },
617
+ subagents: {
618
+ enforceAllowlist: false,
619
+ requireModel: false,
620
+ allowedModels: [],
621
+ blockedPatterns: ["-fast(?:$|[^a-z0-9])", "/fast(?:$|[^a-z0-9])"],
622
+ minEffort: null,
623
+ blockParentFast: false,
624
+ blockMode: "deny",
625
+ readOnlyTypes: ["explore"]
626
+ },
627
+ docs: {
628
+ command: null,
629
+ severity: "warn"
630
+ },
631
+ observe: {
632
+ enabled: false,
633
+ rails: []
634
+ },
635
+ comments: {
636
+ enabled: false,
637
+ onViolation: "followup",
638
+ mode: "declared"
639
+ },
640
+ supplyChain: {
641
+ enabled: false
642
+ },
643
+ duplication: {
644
+ enabled: false,
645
+ minRun: MIN_RUN
646
+ },
647
+ obs: {
648
+ globalSpool: false,
649
+ includePayloads: DEFAULT_OBS.includePayloads,
650
+ maxAttrChars: DEFAULT_OBS.maxAttrChars,
651
+ sessionCostAlertUsd: DEFAULT_OBS.sessionCostAlertUsd,
652
+ retentionDays: DEFAULT_OBS.retentionDays
653
+ },
654
+ untrustedContent: {
655
+ mode: "frame",
656
+ enabled: false,
657
+ extraTools: [],
658
+ extraCommandPatterns: []
659
+ },
660
+ planGate: {
661
+ enabled: false,
662
+ windowMinutes: 120
663
+ },
664
+ shell: {
665
+ catastrophicAsk: true,
666
+ stallDetection: false,
667
+ stallRepeatThreshold: 3
668
+ },
669
+ intelligence: {
670
+ gapFeedback: true,
671
+ failureClassification: true,
672
+ progressiveHandoff: true,
673
+ progressiveContext: true,
674
+ autopilot: true,
675
+ idleTurnGate: false,
676
+ budgetContinue: false,
677
+ budgetContinueAfterLoops: 3,
678
+ lessons: { ...DEFAULT_LESSONS_POLICY }
679
+ },
680
+ mcpPrime: [],
681
+ bootstrapExtra: []
682
+ };
683
+
684
+ // src/platform/style.ts
685
+ var COLORS = {
686
+ structure: "#3d3a4a",
687
+ accent: "#a78bfa",
688
+ success: "#6ee7b7",
689
+ warning: "#d4a574",
690
+ error: "#f87171",
691
+ info: "#93c5fd",
692
+ textMain: "#f5f5f7",
693
+ textMuted: "#9ca3af",
694
+ textDim: "#6b7280"
695
+ };
696
+ var SYMBOLS = {
697
+ check: "✔",
698
+ cross: "✖",
699
+ warning: "⚠",
700
+ arrow: "→",
701
+ arrowRight: "▸",
702
+ dot: "•",
703
+ bar: "│",
704
+ rule: "══",
705
+ dash: "──"
706
+ };
707
+ function rgb(hex) {
708
+ const match = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex.trim());
709
+ if (!match) {
710
+ return "255;255;255";
711
+ }
712
+ return [match[1], match[2], match[3]].map((part) => Number.parseInt(part, 16)).join(";");
713
+ }
714
+ var ESC = String.fromCharCode(27);
715
+ var RESET = `${ESC}[0m`;
716
+ function colorEnabled(env = process.env, argv = process.argv, isTty = process.stdout.isTTY === true) {
717
+ if ("NO_COLOR" in env) {
718
+ return false;
719
+ }
720
+ if (argv.includes("--no-color")) {
721
+ return false;
722
+ }
723
+ return isTty;
724
+ }
725
+ var STATUS_COLOR = {
726
+ ok: "success",
727
+ warn: "warning",
728
+ fail: "error",
729
+ info: "info"
730
+ };
731
+ var STATUS_MARK = {
732
+ ok: SYMBOLS.check,
733
+ warn: SYMBOLS.warning,
734
+ fail: SYMBOLS.cross,
735
+ info: SYMBOLS.arrowRight
736
+ };
737
+ var KV_WIDTH = 16;
738
+ function createStyle(enabled = colorEnabled()) {
739
+ const wrap = (code, text) => enabled ? `${ESC}[${code}m${text}${RESET}` : text;
740
+ const paint = (name, text) => wrap(`38;2;${rgb(COLORS[name])}`, text);
741
+ return {
742
+ enabled,
743
+ paint,
744
+ bold: (text) => wrap("1", text),
745
+ dim: (text) => paint("textDim", text),
746
+ heading: (text) => paint("accent", `${SYMBOLS.rule} ${text} ${SYMBOLS.rule}`),
747
+ footer: (text) => paint("textDim", `${SYMBOLS.dash} ${text} ${SYMBOLS.dash}`),
748
+ kv: (label, value, width = KV_WIDTH) => ` ${paint("textMuted", `${label}:`.padEnd(width))} ${value}`,
749
+ status: (level, text) => `${paint(STATUS_COLOR[level], STATUS_MARK[level])} ${text}`
750
+ };
751
+ }
752
+ var PLAIN = createStyle(false);
753
+
754
+ // src/platform/screen.ts
755
+ function render(screen, style) {
756
+ const out = [style.heading(screen.title.toUpperCase())];
757
+ if (screen.summary && screen.summary.length > 0) {
758
+ out.push(` ${screen.summary.join(style.dim(` ${SYMBOLS.bar} `))}`);
759
+ }
760
+ const width = Math.max(KV_WIDTH, ...screen.sections.flatMap((section) => (section.rows ?? []).map((row) => row.label.length + 1)));
761
+ for (const section of screen.sections) {
762
+ out.push("");
763
+ if (section.title) {
764
+ out.push(style.paint("accent", section.title));
765
+ }
766
+ for (const row of section.rows ?? []) {
767
+ const value = row.level ? style.status(row.level, row.value) : row.value;
768
+ out.push(style.kv(row.label, value, width));
769
+ }
770
+ for (const line of section.lines ?? []) {
771
+ out.push(line === "" ? "" : ` ${line}`);
772
+ }
773
+ }
774
+ if (screen.footer) {
775
+ out.push("", style.footer(screen.footer));
776
+ }
777
+ return out.join(`
778
+ `);
779
+ }
780
+
781
+ // tools/init-project.ts
782
+ class UsageError extends Error {
783
+ }
784
+ function parseFlags(args) {
785
+ return {
786
+ dryRun: args.includes("--dry-run"),
787
+ write: args.includes("--write") || args.includes("--minimal"),
788
+ minimal: args.includes("--minimal"),
789
+ stdinJson: args.includes("--stdin-json"),
790
+ force: args.includes("--force")
791
+ };
792
+ }
793
+ function usageScreen() {
794
+ return {
795
+ title: "harness init",
796
+ sections: [
797
+ {
798
+ lines: ` tlc harness init --dry-run
799
+ tlc harness init --write [--stdin-json] [--force]
800
+ tlc harness init --minimal
801
+
802
+ --minimal writes a safe agnostic stub (grind/ship off). Prefer the harness-init skill for full discovery.`.split(`
803
+ `)
804
+ }
805
+ ]
806
+ };
807
+ }
808
+ function usageText(style = PLAIN) {
809
+ return render(usageScreen(), style);
810
+ }
811
+ function launcherPath(home = runtimeHome()) {
812
+ return join4(home, "bin", "tlc-exec.mjs");
813
+ }
814
+ function shimCommand(platform = process.platform) {
815
+ if (platform === "win32") {
816
+ return { command: "cmd", argsPrefix: ["/c", "node"] };
817
+ }
818
+ return { command: "node", argsPrefix: [] };
819
+ }
820
+ var CURSOR_SHIM_SPECS = [
821
+ { hookEvent: "sessionStart", handler: "session-start", timeoutSeconds: 10 },
822
+ { hookEvent: "sessionEnd", handler: "session-end", timeoutSeconds: 10 },
823
+ { hookEvent: "preToolUse", handler: "tool-before", timeoutSeconds: 10 },
824
+ { hookEvent: "beforeShellExecution", handler: "tool-before", timeoutSeconds: 10 },
825
+ { hookEvent: "beforeMCPExecution", handler: "tool-before", timeoutSeconds: 10 },
826
+ { hookEvent: "beforeReadFile", handler: "tool-before", timeoutSeconds: 5 },
827
+ { hookEvent: "subagentStart", handler: "subagent-start", timeoutSeconds: 5 },
828
+ { hookEvent: "stop", handler: "stop", timeoutSeconds: 120, loopLimit: 5 },
829
+ { hookEvent: "afterAgentResponse", handler: "response-after", timeoutSeconds: 5, matcher: "AgentResponse" }
830
+ ];
831
+ var CLAUDE_SHIM_SPECS = [
832
+ { hookEvent: "SessionStart", handler: "session-start", timeoutSeconds: 10 },
833
+ { hookEvent: "SessionEnd", handler: "session-end", timeoutSeconds: 10 },
834
+ { hookEvent: "PreToolUse", handler: "tool-before", timeoutSeconds: 10 },
835
+ { hookEvent: "SubagentStart", handler: "subagent-start", timeoutSeconds: 5 },
836
+ { hookEvent: "Stop", handler: "stop", timeoutSeconds: 120, loopLimit: 5 },
837
+ { hookEvent: "MessageDisplay", handler: "response-after", timeoutSeconds: 5 }
838
+ ];
839
+ function cursorShimEntries(launcher) {
840
+ const { command, argsPrefix } = shimCommand();
841
+ return CURSOR_SHIM_SPECS.map((spec) => ({
842
+ hookEvent: spec.hookEvent,
843
+ handler: spec.handler,
844
+ command,
845
+ args: [...argsPrefix, launcher, "shim", spec.handler],
846
+ timeoutSeconds: spec.timeoutSeconds,
847
+ ...spec.loopLimit !== undefined ? { loopLimit: spec.loopLimit } : {},
848
+ ...spec.matcher !== undefined ? { matcher: spec.matcher } : {}
849
+ }));
850
+ }
851
+ function claudeShimEntries(launcher) {
852
+ return CLAUDE_SHIM_SPECS.map((spec) => ({
853
+ hookEvent: spec.hookEvent,
854
+ handler: spec.handler,
855
+ command: "node",
856
+ args: [launcher, "shim", spec.handler],
857
+ timeoutSeconds: spec.timeoutSeconds,
858
+ ...spec.loopLimit !== undefined ? { loopLimit: spec.loopLimit } : {}
859
+ }));
860
+ }
861
+ var GITIGNORE_LINE = ".tlc/harness/state/";
862
+ function mergeGitignore(root) {
863
+ const path = join4(root, ".gitignore");
864
+ const existing = existsSync3(path) ? readFileSync3(path, "utf8") : "";
865
+ const lines = existing.split(`
866
+ `);
867
+ const alreadyPresent = lines.includes(GITIGNORE_LINE);
868
+ if (alreadyPresent) {
869
+ return { text: existing.endsWith(`
870
+ `) || existing === "" ? existing : `${existing}
871
+ `, changed: false };
872
+ }
873
+ lines.push(GITIGNORE_LINE);
874
+ const withoutTrailingBlank = lines.filter((line, index, all) => line.length > 0 || index < all.length - 1);
875
+ return { text: `${withoutTrailingBlank.join(`
876
+ `).replace(/\n+$/, "")}
877
+ `, changed: true };
878
+ }
879
+ function resolvePolicy(root, flags, stdinText) {
880
+ if (flags.stdinJson && !flags.minimal) {
881
+ if (!stdinText || stdinText.trim() === "") {
882
+ throw new Error("stdin-json: empty stdin");
883
+ }
884
+ return JSON.parse(stdinText);
885
+ }
886
+ if (!flags.minimal && !flags.stdinJson && existsSync3(projectConfigPath(root))) {
887
+ return JSON.parse(readFileSync3(projectConfigPath(root), "utf8"));
888
+ }
889
+ return DEFAULTS;
890
+ }
891
+ function detectProviders(dirs = {}) {
892
+ return {
893
+ cursor: existsSync3(dirs.cursor ?? cursorConfigDir()),
894
+ claude: existsSync3(dirs.claude ?? claudeConfigDir())
895
+ };
896
+ }
897
+ function buildPlan(root, flags, stdinText, presence) {
898
+ const policy = resolvePolicy(root, flags, stdinText);
899
+ const launcher = launcherPath();
900
+ return {
901
+ policy,
902
+ cursorHooksDocument: presence.cursor ? renderCursorHooksDocument(cursorShimEntries(launcher)) : null,
903
+ claudeHooksPreview: presence.claude ? claudeShimEntries(launcher) : null,
904
+ gitignoreLine: GITIGNORE_LINE
905
+ };
906
+ }
907
+ function applyPlan(root, flags, presence, stdinText) {
908
+ const policy = resolvePolicy(root, flags, stdinText);
909
+ const configPath = projectConfigPath(root);
910
+ mkdirSync3(dirname3(configPath), { recursive: true });
911
+ writeFileSync3(configPath, `${JSON.stringify(policy, null, 2)}
912
+ `);
913
+ const launcher = launcherPath();
914
+ const cursor = presence.cursor ? (() => {
915
+ const result = applyCursorWiring({
916
+ target: join4(root, ".cursor", "hooks.json"),
917
+ strategy: "replace",
918
+ entries: cursorShimEntries(launcher)
919
+ }, { force: flags.force });
920
+ return { skipped: false, status: result.status, target: result.target };
921
+ })() : { skipped: true };
922
+ const claude = presence.claude ? (() => {
923
+ const result = applyClaudeWiring(join4(root, ".claude", "settings.json"), claudeShimEntries(launcher));
924
+ return {
925
+ skipped: false,
926
+ status: result.ok ? result.changed ? "written" : "unchanged" : "failed",
927
+ target: join4(root, ".claude", "settings.json")
928
+ };
929
+ })() : { skipped: true };
930
+ const gitignore = mergeGitignore(root);
931
+ writeFileSync3(join4(root, ".gitignore"), gitignore.text);
932
+ return { configPath, cursor, claude };
933
+ }
934
+ async function readStdin() {
935
+ const chunks = [];
936
+ for await (const chunk of process.stdin) {
937
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
938
+ }
939
+ return Buffer.concat(chunks).toString("utf8").trim();
940
+ }
941
+ async function main(argv) {
942
+ const root = process.env.TLC_PROJECT_DIR ?? process.cwd();
943
+ const flags = parseFlags(argv);
944
+ if (!flags.dryRun && !flags.write) {
945
+ throw new UsageError(usageText());
946
+ }
947
+ const stdinText = flags.stdinJson ? await readStdin() : null;
948
+ const presence = detectProviders();
949
+ if (flags.dryRun) {
950
+ console.log(JSON.stringify(buildPlan(root, flags, stdinText, presence), null, 2));
951
+ return;
952
+ }
953
+ const outcome = applyPlan(root, flags, presence, stdinText);
954
+ console.log(`wrote ${outcome.configPath}`);
955
+ if (outcome.cursor.skipped) {
956
+ console.log("init: cursor not installed — skipped project hooks.json");
957
+ } else {
958
+ console.log(`hooks: ${outcome.cursor.status} ${outcome.cursor.target}`);
959
+ }
960
+ if (outcome.claude.skipped) {
961
+ console.log("init: claude not installed — skipped project settings.json");
962
+ } else {
963
+ console.log(`hooks: ${outcome.claude.status} ${outcome.claude.target}`);
964
+ }
965
+ console.log("updated .gitignore harness entries");
966
+ }
967
+ if (__require.main == __require.module) {
968
+ try {
969
+ await main(process.argv.slice(2));
970
+ } catch (error) {
971
+ if (error instanceof UsageError) {
972
+ console.error(error.message);
973
+ process.exit(1);
974
+ }
975
+ throw error;
976
+ }
977
+ }
978
+ export {
979
+ usageText,
980
+ usageScreen,
981
+ resolvePolicy,
982
+ parseFlags,
983
+ mergeGitignore,
984
+ main,
985
+ launcherPath,
986
+ detectProviders,
987
+ cursorShimEntries,
988
+ claudeShimEntries,
989
+ buildPlan,
990
+ applyPlan,
991
+ UsageError,
992
+ GITIGNORE_LINE
993
+ };