@h-rig/harness-plugin 0.0.6-alpha.186

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 (82) hide show
  1. package/README.md +1 -0
  2. package/dist/bin/rig-agent-dispatch.d.ts +2 -0
  3. package/dist/bin/rig-agent-dispatch.js +826 -0
  4. package/dist/src/agent-command.d.ts +3 -0
  5. package/dist/src/agent-command.js +233 -0
  6. package/dist/src/agent-harness/agent-mode.d.ts +1 -0
  7. package/dist/src/agent-harness/agent-mode.js +48 -0
  8. package/dist/src/agent-harness/agent-wrapper.d.ts +60 -0
  9. package/dist/src/agent-harness/agent-wrapper.js +842 -0
  10. package/dist/src/agent-harness/controlled-bash.d.ts +3 -0
  11. package/dist/src/agent-harness/controlled-bash.js +45 -0
  12. package/dist/src/agent-harness/git-ops.d.ts +2 -0
  13. package/dist/src/agent-harness/git-ops.js +27 -0
  14. package/dist/src/agent-harness/repo-ops.d.ts +14 -0
  15. package/dist/src/agent-harness/repo-ops.js +37 -0
  16. package/dist/src/agent-harness/rig-agent-entrypoint.d.ts +1 -0
  17. package/dist/src/agent-harness/rig-agent-entrypoint.js +1362 -0
  18. package/dist/src/agent-harness/rig-agent.d.ts +2 -0
  19. package/dist/src/agent-harness/rig-agent.js +1324 -0
  20. package/dist/src/agent-harness/runtime-snapshot-config.d.ts +2 -0
  21. package/dist/src/agent-harness/runtime-snapshot-config.js +25 -0
  22. package/dist/src/agent-harness/task-data.d.ts +27 -0
  23. package/dist/src/agent-harness/task-data.js +286 -0
  24. package/dist/src/agent-harness/task-ops.d.ts +10 -0
  25. package/dist/src/agent-harness/task-ops.js +352 -0
  26. package/dist/src/index.d.ts +6 -0
  27. package/dist/src/index.js +4525 -0
  28. package/dist/src/model.d.ts +80 -0
  29. package/dist/src/model.js +64 -0
  30. package/dist/src/pi-command.d.ts +3 -0
  31. package/dist/src/pi-command.js +154 -0
  32. package/dist/src/pi-settings-materializer.d.ts +10 -0
  33. package/dist/src/pi-settings-materializer.js +52 -0
  34. package/dist/src/plugin.d.ts +24 -0
  35. package/dist/src/plugin.js +4486 -0
  36. package/dist/src/profile-command.d.ts +3 -0
  37. package/dist/src/profile-command.js +79 -0
  38. package/dist/src/profile-state.d.ts +7 -0
  39. package/dist/src/profile-state.js +39 -0
  40. package/dist/src/rig-task-run-skill.d.ts +8 -0
  41. package/dist/src/rig-task-run-skill.js +39 -0
  42. package/dist/src/runtime-instructions.d.ts +4 -0
  43. package/dist/src/runtime-instructions.js +26 -0
  44. package/dist/src/runtime-secrets.d.ts +6 -0
  45. package/dist/src/runtime-secrets.js +58 -0
  46. package/dist/src/service.d.ts +14 -0
  47. package/dist/src/service.js +33 -0
  48. package/dist/src/session-asset-materializer-service.d.ts +13 -0
  49. package/dist/src/session-asset-materializer-service.js +164 -0
  50. package/dist/src/session-hook-materializer-service.d.ts +34 -0
  51. package/dist/src/session-hook-materializer-service.js +142 -0
  52. package/dist/src/skill-materializer.d.ts +25 -0
  53. package/dist/src/skill-materializer.js +86 -0
  54. package/dist/src/tooling/browser-tool-entrypoint.d.ts +2 -0
  55. package/dist/src/tooling/browser-tool-entrypoint.js +125 -0
  56. package/dist/src/tooling/browser-tools.d.ts +3 -0
  57. package/dist/src/tooling/browser-tools.js +27 -0
  58. package/dist/src/tooling/claude-router-binary.d.ts +3 -0
  59. package/dist/src/tooling/claude-router-binary.js +62 -0
  60. package/dist/src/tooling/claude-router.d.ts +22 -0
  61. package/dist/src/tooling/claude-router.js +524 -0
  62. package/dist/src/tooling/embedded-native-assets.d.ts +7 -0
  63. package/dist/src/tooling/embedded-native-assets.js +6 -0
  64. package/dist/src/tooling/file-tools.d.ts +5 -0
  65. package/dist/src/tooling/file-tools.js +192 -0
  66. package/dist/src/tooling/gateway.d.ts +4 -0
  67. package/dist/src/tooling/gateway.js +400 -0
  68. package/dist/src/tooling/shell-tools.d.ts +5 -0
  69. package/dist/src/tooling/shell-tools.js +185 -0
  70. package/native/darwin-arm64/rig-shell +0 -0
  71. package/native/darwin-arm64/rig-shell.build-manifest.json +4 -0
  72. package/native/darwin-arm64/rig-tools +0 -0
  73. package/native/darwin-arm64/rig-tools.build-manifest.json +4 -0
  74. package/native/darwin-x64/rig-shell +0 -0
  75. package/native/darwin-x64/rig-tools +0 -0
  76. package/native/linux-arm64/rig-shell +0 -0
  77. package/native/linux-arm64/rig-tools +0 -0
  78. package/native/linux-x64/rig-shell +0 -0
  79. package/native/linux-x64/rig-tools +0 -0
  80. package/native/win32-x64/rig-shell.exe +0 -0
  81. package/native/win32-x64/rig-tools.exe +0 -0
  82. package/package.json +101 -0
@@ -0,0 +1,352 @@
1
+ // @bun
2
+ // packages/harness-plugin/src/agent-harness/task-ops.ts
3
+ import { LIFECYCLE_VERIFICATION_SERVICE } from "@rig/contracts";
4
+ import { defineServiceCapability } from "@rig/core/capability";
5
+ import { buildPluginHostContext } from "@rig/core/plugin-host-context";
6
+
7
+ // packages/harness-plugin/src/agent-harness/task-data.ts
8
+ import { basename } from "path";
9
+ import {
10
+ REPO_CHANGE_SET,
11
+ TASK_ARTIFACTS,
12
+ TASK_STATE_STORE,
13
+ TASK_SOURCE_CONFIG_PROJECTION
14
+ } from "@rig/contracts";
15
+ import { defineCapability } from "@rig/core/capability";
16
+ import { requireInstalledCapability } from "@rig/core/capability-loaders";
17
+ var RepoChangeSetCap = defineCapability(REPO_CHANGE_SET);
18
+ var TaskArtifactsCap = defineCapability(TASK_ARTIFACTS);
19
+ var TaskStateStoreCap = defineCapability(TASK_STATE_STORE);
20
+ var TaskSourceConfigProjectionCap = defineCapability(TASK_SOURCE_CONFIG_PROJECTION);
21
+ function stateStore() {
22
+ return requireInstalledCapability(TaskStateStoreCap, "task state store capability unavailable: load @rig/tasks-plugin (default bundle) before running the provider agent harness.");
23
+ }
24
+ function artifacts() {
25
+ return requireInstalledCapability(TaskArtifactsCap, "task artifacts capability unavailable: load @rig/tasks-plugin (default bundle) before running the provider agent harness.");
26
+ }
27
+ function taskSourceConfigProjection() {
28
+ return requireInstalledCapability(TaskSourceConfigProjectionCap, "task source config projection capability unavailable: load @rig/tasks-plugin (default bundle) before reading validation descriptions.");
29
+ }
30
+ function repoChangeSet() {
31
+ return requireInstalledCapability(RepoChangeSetCap, "repo change-set capability unavailable: load @rig/repos-plugin (default bundle) before reading task file changes.");
32
+ }
33
+ function currentTaskId(projectRoot) {
34
+ return stateStore().readCurrentTaskId(projectRoot) ?? "";
35
+ }
36
+ function readTaskConfig(projectRoot) {
37
+ return stateStore().readTaskConfig(projectRoot);
38
+ }
39
+ function readSourceTaskConfig(projectRoot) {
40
+ return stateStore().readSourceTaskConfig(projectRoot);
41
+ }
42
+ function readValidationDescriptions(projectRoot) {
43
+ return taskSourceConfigProjection().readSourceValidationDescriptions(projectRoot);
44
+ }
45
+ function lookupTask(_projectRoot, input) {
46
+ return input;
47
+ }
48
+ function artifactDirForId(projectRoot, id) {
49
+ return artifacts().artifactDir({ projectRoot, taskId: id });
50
+ }
51
+ function readStringList(candidate) {
52
+ return Array.isArray(candidate) ? candidate.filter((entry) => typeof entry === "string") : [];
53
+ }
54
+ function firstStringList(...candidates) {
55
+ for (const candidate of candidates) {
56
+ const values = readStringList(candidate);
57
+ if (values.length > 0)
58
+ return values;
59
+ }
60
+ return [];
61
+ }
62
+ function unique(values) {
63
+ return Array.from(new Set(values));
64
+ }
65
+ function readTaskEntry(projectRoot, taskId) {
66
+ try {
67
+ return readTaskConfig(projectRoot)[taskId] ?? readSourceTaskConfig(projectRoot)[taskId] ?? null;
68
+ } catch {
69
+ return null;
70
+ }
71
+ }
72
+ function taskDependencyIds(projectRoot, taskId) {
73
+ const entry = readTaskEntry(projectRoot, taskId);
74
+ if (!entry)
75
+ return [];
76
+ const record = entry;
77
+ return unique(firstStringList(record.deps, record.dependencies, record.validation_deps, record.validationDeps)).filter((id) => id !== taskId);
78
+ }
79
+ function taskScopePatterns(projectRoot, taskId) {
80
+ const entry = readTaskEntry(projectRoot, taskId);
81
+ return entry ? readStringList(entry.scope) : [];
82
+ }
83
+ function syncRepoChangeSetPaths(result, operation) {
84
+ if (result && typeof result.then === "function") {
85
+ throw new Error(`repo change-set ${operation} returned a Promise; lifecycle task adapter requires a synchronous provider.`);
86
+ }
87
+ return unique(result.map((entry) => entry.path).filter(Boolean));
88
+ }
89
+ function changedFilesForTask(projectRoot, taskId, scoped) {
90
+ return syncRepoChangeSetPaths(repoChangeSet().changedFiles({ projectRoot, selector: { kind: "task", taskId, scoped } }), "changedFiles");
91
+ }
92
+ function pendingFilesForTask(projectRoot, taskId, scoped) {
93
+ return syncRepoChangeSetPaths(repoChangeSet().pendingFiles({ projectRoot, selector: { kind: "task", taskId, scoped } }), "pendingFiles");
94
+ }
95
+ function taskLookup(projectRoot, id) {
96
+ const result = lookupTask(projectRoot, id);
97
+ if (!result)
98
+ throw new Error(`Not found: ${id}`);
99
+ return result;
100
+ }
101
+ function taskConfigEntryToRecord(id, entry, source) {
102
+ const record = entry;
103
+ const deps = firstStringList(record.deps, record.dependencies, record.validation_deps, record.validationDeps);
104
+ return {
105
+ id,
106
+ deps,
107
+ status: typeof entry.status === "string" ? entry.status : "open",
108
+ source,
109
+ ...typeof entry.title === "string" ? { title: entry.title } : {},
110
+ ...typeof entry.description === "string" ? { description: entry.description } : {},
111
+ ...typeof entry.acceptance_criteria === "string" ? { acceptanceCriteria: entry.acceptance_criteria } : {},
112
+ ...Array.isArray(entry.scope) ? { scope: entry.scope } : {},
113
+ ...Array.isArray(entry.validation) ? { validation: entry.validation } : {},
114
+ ...typeof entry.role === "string" ? { role: entry.role } : {},
115
+ ...entry.browser ? { browser: entry.browser } : {},
116
+ ...entry.repo_pins ? { repo_pins: entry.repo_pins } : {},
117
+ ...entry.criticality ? { criticality: entry.criticality } : {},
118
+ ...typeof entry.queue_weight === "number" ? { queue_weight: entry.queue_weight } : {},
119
+ ...entry.creates_repo !== undefined ? { creates_repo: entry.creates_repo } : {},
120
+ ...entry.auto_synced !== undefined ? { auto_synced: entry.auto_synced } : {}
121
+ };
122
+ }
123
+ async function taskInfo(projectRoot, taskId, deprecatedRuntimeProviderOverride) {
124
+ const activeTask = taskId || currentTaskId(projectRoot);
125
+ if (!activeTask)
126
+ throw new Error("No active task.");
127
+ const entry = readTaskEntry(projectRoot, activeTask);
128
+ if (!entry)
129
+ throw new Error(`Not found: ${activeTask}`);
130
+ process.stdout.write(`${JSON.stringify(taskConfigEntryToRecord(activeTask, entry, "task-config"), null, 2)}
131
+ `);
132
+ }
133
+ async function taskDeps(projectRoot, taskId) {
134
+ const activeTask = taskId || currentTaskId(projectRoot);
135
+ if (!activeTask)
136
+ throw new Error("No active task.");
137
+ const deps = taskDependencyIds(projectRoot, activeTask);
138
+ if (deps.length > 0)
139
+ process.stdout.write(`${deps.join(`
140
+ `)}
141
+ `);
142
+ }
143
+ function taskStatus(projectRoot) {
144
+ let tasks = [];
145
+ try {
146
+ tasks = Object.entries(readSourceTaskConfig(projectRoot)).map(([id, entry]) => taskConfigEntryToRecord(id, entry, "source-task-config"));
147
+ } catch {
148
+ tasks = Object.entries(readTaskConfig(projectRoot)).map(([id, entry]) => taskConfigEntryToRecord(id, entry, "legacy-task-config"));
149
+ }
150
+ const counts = tasks.reduce((acc, task) => {
151
+ const key = typeof task.status === "string" && task.status.length > 0 ? task.status : "open";
152
+ acc[key] = (acc[key] ?? 0) + 1;
153
+ return acc;
154
+ }, {});
155
+ console.log(`=== Project Rig Progress ===
156
+ `);
157
+ console.log(`Total tasks: ${tasks.length}`);
158
+ for (const status of Object.keys(counts).sort())
159
+ console.log(` ${status}: ${counts[status]}`);
160
+ }
161
+ async function taskScope(projectRoot, expandFiles, taskId) {
162
+ const activeTask = taskId || currentTaskId(projectRoot);
163
+ if (!activeTask)
164
+ throw new Error("No active task.");
165
+ const scopes = taskScopePatterns(projectRoot, activeTask);
166
+ if (scopes.length > 0)
167
+ process.stdout.write(`${scopes.join(`
168
+ `)}
169
+ `);
170
+ }
171
+ async function taskRecord(projectRoot, type, text, taskId) {
172
+ const activeTask = taskId || currentTaskId(projectRoot);
173
+ if (!activeTask)
174
+ throw new Error("No active task.");
175
+ const timestamp = new Date().toISOString();
176
+ if (type === "decision") {
177
+ const artifactService = artifacts();
178
+ const filename = "decision-log.md";
179
+ const existingNames = await artifactNames(artifactService, { projectRoot, taskId: activeTask });
180
+ const existing = existingNames.has(filename) ? (await artifactService.readArtifact({
181
+ projectRoot,
182
+ taskId: activeTask,
183
+ filename,
184
+ maxBytes: Number.MAX_SAFE_INTEGER
185
+ })).contents : "";
186
+ const result2 = await artifactService.writeArtifact({
187
+ projectRoot,
188
+ taskId: activeTask,
189
+ filename,
190
+ content: `${existing}
191
+ ### ${timestamp}
192
+
193
+ ${text}
194
+
195
+ `
196
+ });
197
+ console.log(`Decision recorded for ${activeTask}.`);
198
+ return;
199
+ }
200
+ const result = stateStore().recordFailedApproach({ projectRoot, taskId: activeTask, text, timestamp });
201
+ console.log(result.message);
202
+ }
203
+ function taskArtifactDir(projectRoot, taskId) {
204
+ return artifacts().artifactDir({ projectRoot, ...taskId !== undefined ? { taskId } : {} });
205
+ }
206
+ async function taskArtifactWrite(projectRoot, filename, content, taskId) {
207
+ const result = await artifacts().writeArtifact({
208
+ projectRoot,
209
+ filename,
210
+ content,
211
+ ...taskId !== undefined ? { taskId } : {}
212
+ });
213
+ console.log(`Wrote: ${result.path}`);
214
+ }
215
+ async function taskArtifactRead(projectRoot, filename, options = {}) {
216
+ return artifacts().readArtifact({
217
+ projectRoot,
218
+ filename,
219
+ ...options.taskId !== undefined ? { taskId: options.taskId } : {},
220
+ ...options.maxBytes !== undefined ? { maxBytes: options.maxBytes } : {}
221
+ });
222
+ }
223
+ async function taskArtifacts(projectRoot, taskId) {
224
+ const activeTask = taskId || currentTaskId(projectRoot);
225
+ if (!activeTask)
226
+ throw new Error("No active task.");
227
+ const artifactService = artifacts();
228
+ const ref = { projectRoot, taskId: activeTask };
229
+ const artifactDir = artifactService.artifactDir(ref);
230
+ await artifactService.writeArtifact({
231
+ ...ref,
232
+ filename: "changed-files.txt",
233
+ content: `${changedFilesForTask(projectRoot, activeTask, true).join(`
234
+ `)}
235
+ `
236
+ });
237
+ const existingNames = await artifactNames(artifactService, ref);
238
+ if (!existingNames.has("task-result.json")) {
239
+ await artifactService.writeArtifact({
240
+ ...ref,
241
+ filename: "task-result.json",
242
+ content: `${JSON.stringify({ task_id: activeTask, status: "completed", summary: "TODO: Write a one-line summary of what you did", completed_at: new Date().toISOString() }, null, 2)}
243
+ `
244
+ });
245
+ }
246
+ for (const [filename, content] of [
247
+ ["decision-log.md", `# Decision Log: ${activeTask}
248
+
249
+ Record key decisions here using: rig-agent record decision "..."
250
+ `],
251
+ ["next-actions.md", `# Next Actions: ${activeTask}
252
+
253
+ - TODO: Replace this scaffold with real content before completion
254
+ `]
255
+ ]) {
256
+ if (!existingNames.has(filename)) {
257
+ await artifactService.writeArtifact({ ...ref, filename, content });
258
+ }
259
+ }
260
+ console.log(`Artifacts at: ${artifactDir}/`);
261
+ }
262
+ async function artifactNames(artifactService, ref) {
263
+ const entries = await artifactService.listArtifacts(ref);
264
+ return new Set(entries.filter((entry) => entry.kind === "file").map((entry) => basename(entry.path)));
265
+ }
266
+ function taskData() {
267
+ return {
268
+ currentTaskId,
269
+ readTaskConfig,
270
+ readSourceTaskConfig,
271
+ readValidationDescriptions,
272
+ lookupTask,
273
+ taskLookup,
274
+ artifactDirForId,
275
+ taskInfo,
276
+ taskDeps,
277
+ taskStatus,
278
+ taskScope,
279
+ taskRecord,
280
+ taskArtifacts,
281
+ taskArtifactDir,
282
+ taskArtifactWrite,
283
+ taskArtifactRead,
284
+ taskDependencyIds,
285
+ changedFilesForTask,
286
+ pendingFilesForTask
287
+ };
288
+ }
289
+
290
+ // packages/harness-plugin/src/agent-harness/task-ops.ts
291
+ var LifecycleVerificationServiceCap = defineServiceCapability(LIFECYCLE_VERIFICATION_SERVICE);
292
+ var hostContextByRoot = new Map;
293
+ async function ensureHostContext(projectRoot) {
294
+ let cached = hostContextByRoot.get(projectRoot);
295
+ if (!cached) {
296
+ cached = buildPluginHostContext(projectRoot);
297
+ hostContextByRoot.set(projectRoot, cached);
298
+ }
299
+ return cached;
300
+ }
301
+ function taskArtifactDir2(projectRoot, taskId) {
302
+ return taskData().taskArtifactDir(projectRoot, taskId);
303
+ }
304
+ function taskArtifacts2(projectRoot, taskId) {
305
+ return taskData().taskArtifacts(projectRoot, taskId);
306
+ }
307
+ function taskArtifactWrite2(projectRoot, filename, content, taskId) {
308
+ return taskData().taskArtifactWrite(projectRoot, filename, content, taskId);
309
+ }
310
+ function taskDeps2(projectRoot, taskId) {
311
+ return taskData().taskDeps(projectRoot, taskId);
312
+ }
313
+ function taskInfo2(projectRoot, taskId) {
314
+ return taskData().taskInfo(projectRoot, taskId);
315
+ }
316
+ function taskLookup2(projectRoot, id) {
317
+ return taskData().taskLookup(projectRoot, id);
318
+ }
319
+ function taskRecord2(projectRoot, type, text, taskId) {
320
+ return taskData().taskRecord(projectRoot, type, text, taskId);
321
+ }
322
+ function taskScope2(projectRoot, expandFiles, taskId) {
323
+ return taskData().taskScope(projectRoot, expandFiles, taskId);
324
+ }
325
+ function taskStatus2(projectRoot) {
326
+ taskData().taskStatus(projectRoot);
327
+ }
328
+ async function taskValidate(projectRoot, taskId, validatorRegistry) {
329
+ const hostCtx = await ensureHostContext(projectRoot);
330
+ const verification = hostCtx ? await LifecycleVerificationServiceCap.resolveService(hostCtx.pluginHost) : null;
331
+ const validate = verification ? verification.validate : null;
332
+ if (!validate) {
333
+ throw new Error("task validation capability unavailable: load @rig/lifecycle-plugin (default bundle) before running rig-agent validate.");
334
+ }
335
+ return validate({
336
+ projectRoot,
337
+ ...taskId !== undefined ? { taskId } : {},
338
+ ...validatorRegistry !== undefined ? { validatorRegistry } : hostCtx?.validatorRegistry !== undefined ? { validatorRegistry: hostCtx.validatorRegistry } : {}
339
+ });
340
+ }
341
+ export {
342
+ taskValidate,
343
+ taskStatus2 as taskStatus,
344
+ taskScope2 as taskScope,
345
+ taskRecord2 as taskRecord,
346
+ taskLookup2 as taskLookup,
347
+ taskInfo2 as taskInfo,
348
+ taskDeps2 as taskDeps,
349
+ taskArtifacts2 as taskArtifacts,
350
+ taskArtifactWrite2 as taskArtifactWrite,
351
+ taskArtifactDir2 as taskArtifactDir
352
+ };
@@ -0,0 +1,6 @@
1
+ export { providerPlugin, createProviderPlugin, PROVIDER_PLUGIN_NAME, } from "./plugin";
2
+ export { runtimeInstructionService, svc } from "./service";
3
+ export { normalizeRuntimeInstructionProvider, buildProviderTaskRunInstructionLines, buildProviderRuntimeContextLines, } from "./runtime-instructions";
4
+ export { loadRigTaskRunSkillBody } from "./rig-task-run-skill";
5
+ export * from "./model";
6
+ export { default } from "./plugin";