harnery 0.34.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/dist/commander.d.ts.map +1 -1
  2. package/dist/commander.js +2 -0
  3. package/dist/commands/agents.d.ts +15 -4
  4. package/dist/commands/agents.d.ts.map +1 -1
  5. package/dist/commands/agents.js +91 -162
  6. package/dist/commands/browse.d.ts.map +1 -1
  7. package/dist/commands/browse.js +26 -2
  8. package/dist/commands/decision.d.ts.map +1 -1
  9. package/dist/commands/decision.js +2 -2
  10. package/dist/commands/events.d.ts.map +1 -1
  11. package/dist/commands/events.js +18 -1
  12. package/dist/commands/presence.d.ts.map +1 -1
  13. package/dist/commands/presence.js +2 -2
  14. package/dist/commands/semantic.d.ts +4 -0
  15. package/dist/commands/semantic.d.ts.map +1 -0
  16. package/dist/commands/semantic.js +147 -0
  17. package/dist/commands/web.d.ts.map +1 -1
  18. package/dist/commands/web.js +17 -0
  19. package/dist/core/agents/canonical-emit.d.ts +3 -0
  20. package/dist/core/agents/canonical-emit.d.ts.map +1 -1
  21. package/dist/core/agents/canonical-emit.js +12 -0
  22. package/dist/core/agents/claim-path.d.ts +11 -0
  23. package/dist/core/agents/claim-path.d.ts.map +1 -0
  24. package/dist/core/agents/claim-path.js +22 -0
  25. package/dist/core/agents/coord-client.d.ts +29 -3
  26. package/dist/core/agents/coord-client.d.ts.map +1 -1
  27. package/dist/core/agents/coord-client.js +88 -9
  28. package/dist/core/agents/live-authority-v3.d.ts.map +1 -1
  29. package/dist/core/agents/live-authority-v3.js +1 -3
  30. package/dist/core/agents/live-lifecycle-v3.js +3 -3
  31. package/dist/core/agents/live-observation-v3.d.ts.map +1 -1
  32. package/dist/core/agents/live-observation-v3.js +2 -2
  33. package/dist/core/agents/render/prompt-context.js +12 -10
  34. package/dist/core/agents/rules/stop-hook.d.ts.map +1 -1
  35. package/dist/core/agents/rules/stop-hook.js +23 -11
  36. package/dist/core/agents/session-name-display.d.ts +2 -1
  37. package/dist/core/agents/session-name-display.d.ts.map +1 -1
  38. package/dist/core/agents/session-name-display.js +10 -3
  39. package/dist/core/agents/state/heartbeat-reader.d.ts +46 -0
  40. package/dist/core/agents/state/heartbeat-reader.d.ts.map +1 -0
  41. package/dist/core/agents/state/heartbeat-reader.js +25 -0
  42. package/dist/core/agents/state/heartbeat-writer.d.ts +3 -48
  43. package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
  44. package/dist/core/agents/state/heartbeat-writer.js +16 -34
  45. package/dist/core/agents/state/live-coordination-view.d.ts +1 -1
  46. package/dist/core/agents/state/live-coordination-view.d.ts.map +1 -1
  47. package/dist/core/agents/state/live-coordination-view.js +25 -1
  48. package/dist/core/agents/state/names.d.ts +9 -1
  49. package/dist/core/agents/state/names.d.ts.map +1 -1
  50. package/dist/core/agents/state/names.js +190 -182
  51. package/dist/core/agents/state/stale-sweep.d.ts.map +1 -1
  52. package/dist/core/agents/state/stale-sweep.js +23 -5
  53. package/dist/core/artifacts/constants.d.ts +5 -0
  54. package/dist/core/artifacts/constants.d.ts.map +1 -0
  55. package/dist/core/artifacts/constants.js +4 -0
  56. package/dist/core/artifacts/index.d.ts +3 -3
  57. package/dist/core/artifacts/index.d.ts.map +1 -1
  58. package/dist/core/artifacts/index.js +50 -7
  59. package/dist/core/events/v3/base-contract.d.ts +795 -0
  60. package/dist/core/events/v3/base-contract.d.ts.map +1 -1
  61. package/dist/core/events/v3/base-contract.js +33 -0
  62. package/dist/core/events/v3/capabilities.d.ts +11 -0
  63. package/dist/core/events/v3/capabilities.d.ts.map +1 -1
  64. package/dist/core/events/v3/capabilities.js +23 -0
  65. package/dist/core/events/v3/generated.d.ts +1 -1
  66. package/dist/core/events/v3/generated.js +1 -1
  67. package/dist/core/events/v3/index.d.ts +4 -3
  68. package/dist/core/events/v3/index.d.ts.map +1 -1
  69. package/dist/core/events/v3/index.js +4 -3
  70. package/dist/core/events/v3/latency.d.ts +31 -1
  71. package/dist/core/events/v3/latency.d.ts.map +1 -1
  72. package/dist/core/events/v3/latency.js +127 -3
  73. package/dist/core/events/v3/live-routing.d.ts +30 -0
  74. package/dist/core/events/v3/live-routing.d.ts.map +1 -1
  75. package/dist/core/events/v3/live-routing.js +109 -1
  76. package/dist/core/events/v3/producers/command-recorder.d.ts.map +1 -1
  77. package/dist/core/events/v3/producers/command-recorder.js +10 -1
  78. package/dist/core/events/v3/producers/coordination-recorder.d.ts.map +1 -1
  79. package/dist/core/events/v3/producers/coordination-recorder.js +14 -3
  80. package/dist/core/events/v3/producers/hook-base.d.ts +17 -1
  81. package/dist/core/events/v3/producers/hook-base.d.ts.map +1 -1
  82. package/dist/core/events/v3/producers/hook-base.js +82 -1
  83. package/dist/core/events/v3/producers/intake.d.ts +6 -0
  84. package/dist/core/events/v3/producers/intake.d.ts.map +1 -1
  85. package/dist/core/events/v3/producers/intake.js +11 -0
  86. package/dist/core/events/v3/producers/recorder.d.ts +62 -0
  87. package/dist/core/events/v3/producers/recorder.d.ts.map +1 -1
  88. package/dist/core/events/v3/producers/recorder.js +654 -18
  89. package/dist/core/events/v3/runtime-telemetry-capabilities.d.ts +51 -0
  90. package/dist/core/events/v3/runtime-telemetry-capabilities.d.ts.map +1 -0
  91. package/dist/core/events/v3/runtime-telemetry-capabilities.js +54 -0
  92. package/dist/core/events/v3/turn-telemetry.d.ts +9 -0
  93. package/dist/core/events/v3/turn-telemetry.d.ts.map +1 -1
  94. package/dist/core/hooks/adapter/parse.d.ts +3 -0
  95. package/dist/core/hooks/adapter/parse.d.ts.map +1 -1
  96. package/dist/core/hooks/adapter/parse.js +14 -0
  97. package/dist/core/hooks/adapter/runtime-telemetry.d.ts +119 -0
  98. package/dist/core/hooks/adapter/runtime-telemetry.d.ts.map +1 -0
  99. package/dist/core/hooks/adapter/runtime-telemetry.js +568 -0
  100. package/dist/core/hooks/cli.js +114 -38
  101. package/dist/core/hooks/remediation-cap.d.ts +34 -0
  102. package/dist/core/hooks/remediation-cap.d.ts.map +1 -0
  103. package/dist/core/hooks/remediation-cap.js +71 -0
  104. package/dist/core/hooks/resolve/transcript.d.ts +25 -9
  105. package/dist/core/hooks/resolve/transcript.d.ts.map +1 -1
  106. package/dist/core/hooks/resolve/transcript.js +35 -17
  107. package/dist/core/semantic/adapters.d.ts +34 -0
  108. package/dist/core/semantic/adapters.d.ts.map +1 -0
  109. package/dist/core/semantic/adapters.js +222 -0
  110. package/dist/core/semantic/contract.d.ts +588 -0
  111. package/dist/core/semantic/contract.d.ts.map +1 -0
  112. package/dist/core/semantic/contract.js +230 -0
  113. package/dist/core/semantic/evidence.d.ts +11 -0
  114. package/dist/core/semantic/evidence.d.ts.map +1 -0
  115. package/dist/core/semantic/evidence.js +262 -0
  116. package/dist/core/semantic/index.d.ts +10 -0
  117. package/dist/core/semantic/index.d.ts.map +1 -0
  118. package/dist/core/semantic/index.js +9 -0
  119. package/dist/core/semantic/once.d.ts +33 -0
  120. package/dist/core/semantic/once.d.ts.map +1 -0
  121. package/dist/core/semantic/once.js +293 -0
  122. package/dist/core/semantic/prompt.d.ts +12 -0
  123. package/dist/core/semantic/prompt.d.ts.map +1 -0
  124. package/dist/core/semantic/prompt.js +70 -0
  125. package/dist/core/semantic/scheduler.d.ts +16 -0
  126. package/dist/core/semantic/scheduler.d.ts.map +1 -0
  127. package/dist/core/semantic/scheduler.js +67 -0
  128. package/dist/core/semantic/service-status.d.ts +31 -0
  129. package/dist/core/semantic/service-status.d.ts.map +1 -0
  130. package/dist/core/semantic/service-status.js +84 -0
  131. package/dist/core/semantic/service.d.ts +51 -0
  132. package/dist/core/semantic/service.d.ts.map +1 -0
  133. package/dist/core/semantic/service.js +470 -0
  134. package/dist/core/semantic/storage.d.ts +71 -0
  135. package/dist/core/semantic/storage.d.ts.map +1 -0
  136. package/dist/core/semantic/storage.js +179 -0
  137. package/dist/core/semantic/validate.d.ts +16 -0
  138. package/dist/core/semantic/validate.d.ts.map +1 -0
  139. package/dist/core/semantic/validate.js +174 -0
  140. package/dist/lib/browser/client.d.ts +11 -0
  141. package/dist/lib/browser/client.d.ts.map +1 -1
  142. package/dist/lib/browser/client.js +13 -0
  143. package/dist/lib/browser/index.d.ts +1 -0
  144. package/dist/lib/browser/index.d.ts.map +1 -1
  145. package/dist/lib/browser/standalone-html.d.ts +25 -0
  146. package/dist/lib/browser/standalone-html.d.ts.map +1 -0
  147. package/dist/lib/browser/standalone-html.js +284 -0
  148. package/dist/lib/instructions/apply.d.ts.map +1 -1
  149. package/dist/lib/instructions/apply.js +1 -0
  150. package/dist/lib/instructions/templates.d.ts +2 -0
  151. package/dist/lib/instructions/templates.d.ts.map +1 -1
  152. package/dist/lib/instructions/templates.js +144 -4
  153. package/package.json +6 -1
  154. package/schemas/event-v3.schema.json +2758 -478
  155. package/src/commander.ts +2 -0
  156. package/src/commands/agents.ts +104 -152
  157. package/src/commands/browse.ts +25 -2
  158. package/src/commands/decision.ts +8 -2
  159. package/src/commands/events.ts +21 -1
  160. package/src/commands/presence.ts +7 -2
  161. package/src/commands/semantic.ts +179 -0
  162. package/src/commands/web.ts +15 -0
  163. package/src/core/agents/canonical-emit.ts +15 -0
  164. package/src/core/agents/claim-path.ts +23 -0
  165. package/src/core/agents/coord-client.ts +92 -8
  166. package/src/core/agents/live-authority-v3.ts +1 -4
  167. package/src/core/agents/live-lifecycle-v3.ts +8 -3
  168. package/src/core/agents/live-observation-v3.ts +7 -2
  169. package/src/core/agents/render/prompt-context.ts +13 -10
  170. package/src/core/agents/rules/stop-hook.ts +24 -11
  171. package/src/core/agents/session-name-display.ts +11 -3
  172. package/src/core/agents/state/heartbeat-reader.ts +69 -0
  173. package/src/core/agents/state/heartbeat-writer.ts +20 -84
  174. package/src/core/agents/state/live-coordination-view.ts +26 -1
  175. package/src/core/agents/state/names.ts +190 -182
  176. package/src/core/agents/state/stale-sweep.ts +25 -5
  177. package/src/core/artifacts/constants.ts +4 -0
  178. package/src/core/artifacts/index.ts +49 -7
  179. package/src/core/events/v3/base-contract.ts +39 -0
  180. package/src/core/events/v3/capabilities.ts +34 -0
  181. package/src/core/events/v3/generated.ts +1 -1
  182. package/src/core/events/v3/index.ts +21 -0
  183. package/src/core/events/v3/latency.ts +213 -2
  184. package/src/core/events/v3/live-routing.ts +120 -1
  185. package/src/core/events/v3/producers/command-recorder.ts +10 -1
  186. package/src/core/events/v3/producers/coordination-recorder.ts +17 -5
  187. package/src/core/events/v3/producers/hook-base.ts +115 -1
  188. package/src/core/events/v3/producers/intake.ts +18 -0
  189. package/src/core/events/v3/producers/recorder.ts +856 -21
  190. package/src/core/events/v3/runtime-telemetry-capabilities.ts +137 -0
  191. package/src/core/events/v3/turn-telemetry.ts +10 -0
  192. package/src/core/hooks/adapter/parse.ts +16 -0
  193. package/src/core/hooks/adapter/runtime-telemetry.ts +805 -0
  194. package/src/core/hooks/cli.ts +126 -41
  195. package/src/core/hooks/remediation-cap.ts +77 -0
  196. package/src/core/hooks/resolve/transcript.ts +49 -17
  197. package/src/core/semantic/adapters.ts +293 -0
  198. package/src/core/semantic/contract.ts +298 -0
  199. package/src/core/semantic/evidence.ts +336 -0
  200. package/src/core/semantic/index.ts +127 -0
  201. package/src/core/semantic/once.ts +410 -0
  202. package/src/core/semantic/prompt.ts +84 -0
  203. package/src/core/semantic/scheduler.ts +107 -0
  204. package/src/core/semantic/service-status.ts +118 -0
  205. package/src/core/semantic/service.ts +580 -0
  206. package/src/core/semantic/storage.ts +286 -0
  207. package/src/core/semantic/validate.ts +212 -0
  208. package/src/lib/browser/client.ts +21 -0
  209. package/src/lib/browser/index.ts +4 -0
  210. package/src/lib/browser/standalone-html.ts +312 -0
  211. package/src/lib/instructions/apply.ts +1 -0
  212. package/src/lib/instructions/templates.ts +149 -4
@@ -0,0 +1,312 @@
1
+ // Self-contained HTML snapshots for `harn browse` trio mode.
2
+ //
3
+ // `page.content()` serializes the DOM but not the resources it points at, and
4
+ // framework pages reference those with root-absolute paths (`/_next/static/…`).
5
+ // Written to a file and reopened from anywhere else — the files origin, another
6
+ // host, `file://` — every one of those paths resolves against the wrong root and
7
+ // 404s, so the snapshot renders as unstyled black-on-white text with broken
8
+ // images. That is what an operator sees when they preview an artifact's `.html`.
9
+ //
10
+ // This rewrite makes the saved document stand on its own:
11
+ // - stylesheets are fetched and inlined as <style>
12
+ // - fonts, images, and icons are inlined as data: URIs under a byte budget
13
+ // - anything left over (too large, cross-origin, unreachable) is rewritten to
14
+ // an absolute URL on the captured origin rather than left root-relative
15
+ // - <script> and preload/prefetch hints are dropped: none of them can work in
16
+ // a snapshot, and a dead script tag only invites a hydration attempt
17
+ //
18
+ // The live page is untouched — everything happens on a clone of the document.
19
+
20
+ /** Byte budget for one inlined sub-resource. Larger ones stay as absolute URLs. */
21
+ export const DEFAULT_MAX_RESOURCE_BYTES = 512 * 1024;
22
+
23
+ /** Byte budget for all inlined sub-resources in one snapshot. */
24
+ export const DEFAULT_MAX_TOTAL_RESOURCE_BYTES = 8 * 1024 * 1024;
25
+
26
+ export interface StandaloneHtmlRequest {
27
+ maxResourceBytes: number;
28
+ maxTotalResourceBytes: number;
29
+ }
30
+
31
+ export interface StandaloneHtmlResult {
32
+ html: string;
33
+ /** Source URL the snapshot was taken from. */
34
+ source: string;
35
+ /** Stylesheets inlined as <style>. */
36
+ stylesheetsInlined: number;
37
+ /** Stylesheets left as absolute <link> (unreachable or cross-origin). */
38
+ stylesheetsLinked: number;
39
+ /** Sub-resources (fonts, images, icons) inlined as data: URIs. */
40
+ resourcesInlined: number;
41
+ /** Sub-resources left as absolute URLs (over budget or unreachable). */
42
+ resourcesLinked: number;
43
+ /** Bytes of sub-resource payload inlined. */
44
+ inlinedBytes: number;
45
+ }
46
+
47
+ export function buildStandaloneHtmlScript(): (
48
+ args: StandaloneHtmlRequest,
49
+ ) => Promise<StandaloneHtmlResult> {
50
+ return async ({ maxResourceBytes, maxTotalResourceBytes }) => {
51
+ const SKIP = /^(?:data:|blob:|javascript:|mailto:|tel:|sms:|about:|#)/i;
52
+ const base = document.baseURI;
53
+
54
+ let inlinedBytes = 0;
55
+ let resourcesInlined = 0;
56
+ let resourcesLinked = 0;
57
+ let stylesheetsInlined = 0;
58
+ let stylesheetsLinked = 0;
59
+
60
+ const absolute = (url: string, from: string): string | null => {
61
+ try {
62
+ return new URL(url, from).href;
63
+ } catch {
64
+ return null;
65
+ }
66
+ };
67
+
68
+ const dataUriCache = new Map<string, string | null>();
69
+
70
+ /** Fetch a resource as a data: URI, or null when it is unreachable or over budget. */
71
+ const toDataUri = async (url: string): Promise<string | null> => {
72
+ const cached = dataUriCache.get(url);
73
+ if (cached !== undefined) return cached;
74
+ let result: string | null = null;
75
+ try {
76
+ const res = await fetch(url, { credentials: "include" });
77
+ if (res.ok) {
78
+ const buf = await res.arrayBuffer();
79
+ const fits =
80
+ buf.byteLength <= maxResourceBytes &&
81
+ inlinedBytes + buf.byteLength <= maxTotalResourceBytes;
82
+ if (fits) {
83
+ const bytes = new Uint8Array(buf);
84
+ let binary = "";
85
+ const chunk = 0x8000;
86
+ for (let i = 0; i < bytes.length; i += chunk) {
87
+ binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
88
+ }
89
+ const type = (res.headers.get("content-type") ?? "").split(";")[0]?.trim();
90
+ result = `data:${type || "application/octet-stream"};base64,${btoa(binary)}`;
91
+ inlinedBytes += buf.byteLength;
92
+ }
93
+ }
94
+ } catch {
95
+ result = null;
96
+ }
97
+ dataUriCache.set(url, result);
98
+ return result;
99
+ };
100
+
101
+ /** Resolve one reference: data: URI when it fits, absolute URL otherwise. */
102
+ const resolveRef = async (
103
+ raw: string,
104
+ from: string,
105
+ inline: boolean,
106
+ ): Promise<string | null> => {
107
+ const trimmed = raw.trim();
108
+ if (!trimmed || SKIP.test(trimmed)) return null;
109
+ const url = absolute(trimmed, from);
110
+ if (!url) return null;
111
+ if (!inline) return url;
112
+ const dataUri = await toDataUri(url);
113
+ if (dataUri) {
114
+ resourcesInlined += 1;
115
+ return dataUri;
116
+ }
117
+ resourcesLinked += 1;
118
+ return url;
119
+ };
120
+
121
+ /** Rewrite url() and @import references inside a stylesheet against its own URL. */
122
+ const rewriteCss = async (css: string, from: string): Promise<string> => {
123
+ const urlRef = /url\(\s*(['"]?)([^'")]*)\1\s*\)/g;
124
+ const importRef = /@import\s+(['"])([^'"]+)\1/g;
125
+
126
+ const replacements = new Map<string, string>();
127
+ const collect = async (pattern: RegExp, inline: boolean) => {
128
+ pattern.lastIndex = 0;
129
+ const seen: string[] = [];
130
+ for (let m = pattern.exec(css); m; m = pattern.exec(css)) {
131
+ const raw = m[2];
132
+ if (raw !== undefined && !replacements.has(raw)) seen.push(raw);
133
+ }
134
+ for (const raw of seen) {
135
+ const resolved = await resolveRef(raw, from, inline);
136
+ if (resolved) replacements.set(raw, resolved);
137
+ }
138
+ };
139
+ await collect(urlRef, true);
140
+ await collect(importRef, false);
141
+
142
+ return css
143
+ .replace(urlRef, (full, _q, raw: string) => {
144
+ const next = replacements.get(raw);
145
+ return next ? `url("${next}")` : full;
146
+ })
147
+ .replace(importRef, (full, _q, raw: string) => {
148
+ const next = replacements.get(raw);
149
+ return next ? `@import "${next}"` : full;
150
+ });
151
+ };
152
+
153
+ const doc = document.cloneNode(true) as Document;
154
+
155
+ // Nothing executable survives a snapshot; leaving these in only produces
156
+ // console noise and a doomed hydration pass on reopen.
157
+ for (const node of Array.from(doc.querySelectorAll("script, base"))) node.remove();
158
+ const deadHints = 'link[rel~="preload"],link[rel~="modulepreload"],link[rel~="prefetch"]';
159
+ for (const node of Array.from(doc.querySelectorAll(deadHints))) node.remove();
160
+
161
+ // Stylesheets: fetch → inline. Falls back to the CSSOM (which covers rules a
162
+ // same-origin sheet already parsed) and finally to an absolute <link>.
163
+ for (const link of Array.from(doc.querySelectorAll('link[rel~="stylesheet"]'))) {
164
+ const href = link.getAttribute("href");
165
+ const url = href ? absolute(href, base) : null;
166
+ if (!url) {
167
+ link.remove();
168
+ continue;
169
+ }
170
+ let css: string | null = null;
171
+ try {
172
+ const res = await fetch(url, { credentials: "include" });
173
+ if (res.ok) css = await res.text();
174
+ } catch {
175
+ css = null;
176
+ }
177
+ if (css === null) {
178
+ for (const sheet of Array.from(document.styleSheets)) {
179
+ if (sheet.href !== url) continue;
180
+ try {
181
+ css = Array.from(sheet.cssRules)
182
+ .map((rule) => rule.cssText)
183
+ .join("\n");
184
+ } catch {
185
+ css = null;
186
+ }
187
+ break;
188
+ }
189
+ }
190
+ if (css === null) {
191
+ link.setAttribute("href", url);
192
+ stylesheetsLinked += 1;
193
+ continue;
194
+ }
195
+ const style = doc.createElement("style");
196
+ style.setAttribute("data-harnery-inlined-from", url);
197
+ const media = link.getAttribute("media");
198
+ if (media) style.setAttribute("media", media);
199
+ style.textContent = await rewriteCss(css, url);
200
+ link.replaceWith(style);
201
+ stylesheetsInlined += 1;
202
+ }
203
+
204
+ // Inline <style> blocks carry their own relative refs (framework @font-face
205
+ // rules in particular), so they need the same treatment.
206
+ for (const style of Array.from(doc.querySelectorAll("style"))) {
207
+ if (style.hasAttribute("data-harnery-inlined-from")) continue;
208
+ const css = style.textContent;
209
+ if (css) style.textContent = await rewriteCss(css, base);
210
+ }
211
+
212
+ // Stylesheets adopted via CSSOM never appear in the DOM and would be lost.
213
+ const adopted = (document as Document & { adoptedStyleSheets?: CSSStyleSheet[] })
214
+ .adoptedStyleSheets;
215
+ if (adopted?.length) {
216
+ const parts: string[] = [];
217
+ for (const sheet of adopted) {
218
+ try {
219
+ parts.push(
220
+ Array.from(sheet.cssRules)
221
+ .map((rule) => rule.cssText)
222
+ .join("\n"),
223
+ );
224
+ } catch {
225
+ // Constructed sheet with unreadable rules; nothing to recover.
226
+ }
227
+ }
228
+ if (parts.length) {
229
+ const style = doc.createElement("style");
230
+ style.setAttribute("data-harnery-adopted", "");
231
+ style.textContent = await rewriteCss(parts.join("\n"), base);
232
+ doc.head?.appendChild(style);
233
+ }
234
+ }
235
+
236
+ // Element references. Media and icons are worth inlining; navigation targets
237
+ // only need to stop pointing at the wrong root.
238
+ const inlineAttrs: Array<[string, string]> = [
239
+ ["img", "src"],
240
+ ["source", "src"],
241
+ ["video", "src"],
242
+ ["video", "poster"],
243
+ ["audio", "src"],
244
+ ["track", "src"],
245
+ ["input", "src"],
246
+ ["object", "data"],
247
+ ['link[rel~="icon"]', "href"],
248
+ ['link[rel~="apple-touch-icon"]', "href"],
249
+ ["image", "href"],
250
+ ["use", "href"],
251
+ ];
252
+ const absoluteAttrs: Array<[string, string]> = [
253
+ ["a", "href"],
254
+ ["area", "href"],
255
+ ["form", "action"],
256
+ ["iframe", "src"],
257
+ ["embed", "src"],
258
+ ["link", "href"],
259
+ ];
260
+
261
+ const applyAttrs = async (specs: Array<[string, string]>, inline: boolean) => {
262
+ for (const [selector, attr] of specs) {
263
+ for (const el of Array.from(doc.querySelectorAll(selector))) {
264
+ const raw = el.getAttribute(attr);
265
+ if (!raw) continue;
266
+ const next = await resolveRef(raw, base, inline);
267
+ if (next) el.setAttribute(attr, next);
268
+ }
269
+ }
270
+ };
271
+ await applyAttrs(inlineAttrs, true);
272
+ await applyAttrs(absoluteAttrs, false);
273
+
274
+ // srcset is a comma-separated list of `url descriptor` pairs.
275
+ for (const el of Array.from(doc.querySelectorAll("img[srcset], source[srcset]"))) {
276
+ const raw = el.getAttribute("srcset");
277
+ if (!raw) continue;
278
+ const rewritten: string[] = [];
279
+ for (const candidate of raw.split(",")) {
280
+ const parts = candidate.trim().split(/\s+/);
281
+ const url = parts.shift();
282
+ if (!url) continue;
283
+ const next = (await resolveRef(url, base, true)) ?? url;
284
+ rewritten.push([next, ...parts].join(" "));
285
+ }
286
+ if (rewritten.length) el.setAttribute("srcset", rewritten.join(", "));
287
+ }
288
+
289
+ // Inline style attributes can carry background-image url().
290
+ for (const el of Array.from(doc.querySelectorAll("[style]"))) {
291
+ const raw = el.getAttribute("style");
292
+ if (!raw?.includes("url(")) continue;
293
+ el.setAttribute("style", await rewriteCss(raw, base));
294
+ }
295
+
296
+ const provenance = doc.createElement("meta");
297
+ provenance.setAttribute("name", "harnery:snapshot-source");
298
+ provenance.setAttribute("content", location.href);
299
+ doc.head?.prepend(provenance);
300
+
301
+ const doctype = document.doctype ? `<!DOCTYPE ${document.doctype.name}>` : "<!DOCTYPE html>";
302
+ return {
303
+ html: `${doctype}\n${doc.documentElement.outerHTML}\n`,
304
+ source: location.href,
305
+ stylesheetsInlined,
306
+ stylesheetsLinked,
307
+ resourcesInlined,
308
+ resourcesLinked,
309
+ inlinedBytes,
310
+ };
311
+ };
312
+ }
@@ -99,6 +99,7 @@ function blockSkills(projectRoot: string, adapter: string): BlockSkills {
99
99
  decide: supported && !exclude.has("harn-decide"),
100
100
  council: supported && !exclude.has("harn-council"),
101
101
  end: supported && !exclude.has("harn-end"),
102
+ team: supported && !exclude.has("harn-team"),
102
103
  };
103
104
  }
104
105
 
@@ -34,6 +34,8 @@ export interface BlockSkills {
34
34
  council: boolean;
35
35
  /** the `harn-end` skill file is present */
36
36
  end: boolean;
37
+ /** the `harn-team` skill file is present */
38
+ team: boolean;
37
39
  }
38
40
 
39
41
  /**
@@ -50,7 +52,7 @@ export interface BlockSkills {
50
52
  */
51
53
  export function renderInstructionsBlock(
52
54
  binName: string,
53
- skills: BlockSkills = { decide: true, council: true, end: true },
55
+ skills: BlockSkills = { decide: true, council: true, end: true, team: true },
54
56
  ): string {
55
57
  const b = binName;
56
58
 
@@ -58,6 +60,7 @@ export function renderInstructionsBlock(
58
60
  skills.decide && "`harn-decide`",
59
61
  skills.council && "`harn-council`",
60
62
  skills.end && "`harn-end`",
63
+ skills.team && "`harn-team`",
61
64
  ].filter(Boolean) as string[];
62
65
  const deeper =
63
66
  named.length > 0
@@ -72,6 +75,9 @@ export function renderInstructionsBlock(
72
75
  const endPointer = skills.end
73
76
  ? "When the whole session is genuinely finished, use the `harn-end` skill as the final workflow."
74
77
  : `When the whole session is genuinely finished, run \`${b} agents status --end-turn --end-session\` as the final tool action.`;
78
+ const teamPointer = skills.team
79
+ ? "The `harn-team` skill owns the tier choice, the governor artifacts, and the drive loop."
80
+ : `See \`${b} governor --help\` for the tier choice and the drive loop.`;
75
81
  // Render the journal categories from the canonical enum so this prose can
76
82
  // never drift from what `journal add` actually accepts (the "note, plan…" list
77
83
  // silently lagged the tool by two categories before this).
@@ -115,6 +121,7 @@ first when one pass will do, the second when the objective must outlive the
115
121
  attempt, and the third when a human would otherwise have to babysit the loop. A
116
122
  run that needs authorization parks durably instead of failing, so check
117
123
  \`${b} approval list\` when one appears to be waiting rather than stuck.
124
+ ${teamPointer}
118
125
 
119
126
  **Durable role handoff.** When you are replacing a prior session in the same
120
127
  named role, run \`${b} agents identity assume <name>\` before declaring your task.
@@ -123,9 +130,10 @@ live process still holds the name; never hand-edit Harnery's history, heartbeat,
123
130
  or derived identity cache.
124
131
 
125
132
  **Declare intent on shell commands.** Every command you run is captured to the
126
- coordination ledger. Lead a shell command with a \`# intent: <why>\` comment (or set
127
- the tool's description) so the recorded event carries a reason instead of
128
- \`(no intent)\`.
133
+ coordination ledger (\`.harnery/ledgers/v3/\`). Lead a shell command with a
134
+ \`# intent: <why>\` comment (or set the tool's description) so the recorded event
135
+ carries a reason instead of \`(no intent)\`; the [tool-intent
136
+ guide](https://harnery.com/guides/tool-intent/) owns the details.
129
137
 
130
138
  **Journal.** \`${b} journal add <category> "<text>"\` (category = ${journalCats})
131
139
  leaves breadcrumbs that survive context compaction;
@@ -370,6 +378,131 @@ explicitly identifies it. Use the web control or \`${b} agents end --instance-id
370
378
  durably queues the end for its current turn.`;
371
379
  }
372
380
 
381
+ function teamBody(b: string): string {
382
+ return `Harnery gives you three ways to put more than one agent on a job. They differ
383
+ by how long the objective outlives a single execution, and picking the wrong one
384
+ is the usual reason a team spins. This skill owns that choice, the files a
385
+ governed team needs, and the drive loop.
386
+
387
+ ## Step 0: do not build a second team
388
+
389
+ Run this before anything else, every time:
390
+
391
+ \`\`\`bash
392
+ ${b} governor list
393
+ \`\`\`
394
+
395
+ If a goal already covers the objective, **you are done building** — drive the
396
+ existing one (Step 3). A second team pointed at the same tree fights the first:
397
+ both hold the same files and their frozen missions contradict each other. It is
398
+ the most expensive mistake available here, and it looks like progress while you
399
+ make it. Listings are tolerant: an unreadable record prints a warning row with
400
+ its id, which is evidence the goal *exists* — inspect it before creating a
401
+ replacement. Treat stale or suffixed experiment goals as shared runtime state;
402
+ archiving them is an operator call, not yours.
403
+
404
+ ## Step 1: pick the tier
405
+
406
+ Match the tier to how long the objective must survive, not to how big it feels.
407
+
408
+ | Surface | Use when | Dies when |
409
+ |---|---|---|
410
+ | \`${b} run <script>\` | One bounded pass: deterministic JS stages fan out to headless subagents. | The pass ends. Nothing remembers it. |
411
+ | \`${b} work create <title> <workflow>\` | The objective must outlive the attempt: retries, failures, review rounds. | You accept or cancel it. |
412
+ | \`${b} governor create\` | A graph of interdependent work with distinct roles, where a human would otherwise babysit the loop. | You accept the root or it exhausts its bounds. |
413
+
414
+ When unsure, start with \`${b} run\`: it is the only tier you can throw away for
415
+ free, and iterating a script there before freezing it is how you avoid
416
+ invalidating a durable work item later. And check the sizing first: a single
417
+ agent often matches a team on a task that does not truly decompose — reliability
418
+ is multiplicative across steps, and the metric that decides is cost per
419
+ completed task, not agent count.
420
+
421
+ ## Step 2: build the governor team
422
+
423
+ Four artifacts, kept in a managed workspace
424
+ (\`${b} artifacts create <slug> --purpose "<why>"\`), then frozen:
425
+
426
+ **team.json** maps specialist id to profile: \`instructions\` (the role's whole
427
+ charter) plus optional \`adapter\`, \`effort\`, \`maxAttempts\`. Two role rules
428
+ carry most of the value: **split producing evidence from judging it** (a
429
+ verifier that runs gates, a separate reviewer that accepts or refuses — no agent
430
+ grades its own homework), and **add a standing scope-auditor** that reports at
431
+ each milestone whether the finish line moved, since no one else is positioned to
432
+ notice a rising bar. Write each role's hard boundaries explicitly, in the
433
+ negative: name every act that is somebody else's. Write every brief as a
434
+ four-part contract — objective, output (the named artifact that proves it),
435
+ tools, boundaries — and pass references, not pasted content. \`timeoutMs\` and
436
+ \`maxTurns\` are workflow-script options, never specialist-profile keys; the
437
+ create command rejects unsupported keys with the offending key and the allowed
438
+ set.
439
+
440
+ **mission.json** carries \`objective\`, \`acceptance\` (criteria), and
441
+ \`max_milestones\`. Write acceptance so **refusing is a representable outcome**
442
+ ("X exists, or the blocker is stated with its citation") — a criterion an agent
443
+ cannot satisfy by correctly refusing gets reissued forever. Every criterion
444
+ names the artifact that satisfies it (a path, a passing command, a review
445
+ record); a criterion satisfiable by prose will eventually be satisfied exactly
446
+ that way.
447
+
448
+ **replanning.json** freezes the planner policy: \`planner_specialist\`,
449
+ \`auto_apply\`, \`max_replans\`, \`max_work_items_per_plan\`,
450
+ \`max_total_work_items\`, a \`templates\` catalog, and \`review\` with
451
+ \`reviewer_specialists\` and \`max_revision_rounds\`. Keep \`auto_apply: false\`
452
+ and proof auto-acceptance off for anything that can touch public state.
453
+
454
+ **Workflow templates** are the plain-JS scripts the planner may choose from;
455
+ route product decisions to a decision-brief template, never an implement one.
456
+ Authoring traps (frozen script hashes, the five-minute \`timeoutMs\` default,
457
+ schema caps, child sandboxes) live in the
458
+ [workflow-authoring guide](https://harnery.com/guides/workflow-authoring/).
459
+
460
+ \`\`\`bash
461
+ ${b} governor create --id <goal-id> --title "<title>" \\
462
+ --team <ws>/team.json --mission <ws>/mission.json \\
463
+ --replanning <ws>/replanning.json --max-parallel-work 2 --json
464
+ \`\`\`
465
+
466
+ ## Step 3: drive it
467
+
468
+ \`${b} governor show <goal-id> --json\` — the \`projection\` object is the whole
469
+ dashboard: read \`state\`, \`reason\`, and \`next_action\`, then do exactly that
470
+ action. Useful fields: \`ready_work\` / \`retryable_work\` / \`attention_work\`,
471
+ \`decision_blocked_work\` (parked on a docket entry, not broken),
472
+ \`replans_used\` / \`replans_remaining\`, and the milestone counters.
473
+
474
+ \`\`\`bash
475
+ ${b} governor tick <goal-id> # at most one scheduling cycle
476
+ ${b} governor run <goal-id> # cycles until success, attention, or budget
477
+ ${b} approval list # a run needing authorization parks, not fails
478
+ \`\`\`
479
+
480
+ Rules that prevent stranded work:
481
+
482
+ - **Never drive a governed item with \`${b} work retry\` or \`${b} work run\`.**
483
+ Only the governor supplies the frozen specialist map; a bare retry starts a
484
+ run with no team, dies at the first specialist stage, and still burns the
485
+ attempt. \`${b} work retry\` is for standalone work only.
486
+ - **A blocked item cannot be accepted.** When its objective was met out of band,
487
+ the door back is \`${b} work reopen\` plus a fresh governor cycle, not accept.
488
+ - **Read the spin signals before retrying.** Zero milestones with climbing
489
+ \`replans_used\` and repeated reviewer rejections means the mission prose or
490
+ acceptance criteria are wrong, not the agents. Replans are capped; diagnose
491
+ first.
492
+ - **A frozen mission cannot be edited** — deliberately. Pass corrections as
493
+ retry context on individual items, or create a new goal and cancel the old
494
+ one. Do not keep re-planning against prose you know is stale.
495
+ - **"ended without terminal evidence"** means the child died before writing its
496
+ proof, not that the work failed. Check whether the outcome landed before
497
+ redoing it.
498
+
499
+ ## Reporting back
500
+
501
+ Tell the operator which tier you chose and why, the goal id, the roles, and the
502
+ single next action. If you declined to build a team because one already existed,
503
+ say that first; it is the most useful sentence in the reply.`;
504
+ }
505
+
373
506
  export const SKILLS: SkillTemplate[] = [
374
507
  {
375
508
  id: "harn-decide",
@@ -407,4 +540,16 @@ export const SKILLS: SkillTemplate[] = [
407
540
  body: endBody(binName),
408
541
  }),
409
542
  },
543
+ {
544
+ id: "harn-team",
545
+ relPath: "harn-team/SKILL.md",
546
+ render: (binName) =>
547
+ buildOwnedSkill({
548
+ name: "harn-team",
549
+ description:
550
+ "Stand up and drive a multi-agent team on an objective: pick between a bounded run, durable work, and a governed role team; build the governor artifacts; drive off projection.next_action. Use when asked to put a team of agents on a job, orchestrate agents, or check on a goal already running. Refuses to build a second team when one already covers the objective.",
551
+ binName,
552
+ body: teamBody(binName),
553
+ }),
554
+ },
410
555
  ];