@h-rig/runtime 0.0.6-alpha.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.
- package/README.md +27 -0
- package/dist/bin/rig-agent-dispatch.js +9615 -0
- package/dist/bin/rig-agent.js +9512 -0
- package/dist/bin/rig-browser-tool.js +269 -0
- package/dist/src/agent-mode.js +48 -0
- package/dist/src/baked-secrets.js +121 -0
- package/dist/src/binary-build-worker.js +312 -0
- package/dist/src/binary-run.js +540 -0
- package/dist/src/boundaries.js +1 -0
- package/dist/src/build-time-config.js +25 -0
- package/dist/src/control-plane/agent-roles.js +27 -0
- package/dist/src/control-plane/agent-wrapper.js +9621 -0
- package/dist/src/control-plane/authority-files.js +582 -0
- package/dist/src/control-plane/browser-contract.js +135 -0
- package/dist/src/control-plane/controlled-bash.js +1111 -0
- package/dist/src/control-plane/errors.js +13 -0
- package/dist/src/control-plane/harness-main.js +10828 -0
- package/dist/src/control-plane/hook-materializer.js +75 -0
- package/dist/src/control-plane/hooks/audit-trail.js +353 -0
- package/dist/src/control-plane/hooks/completion-verification.js +7552 -0
- package/dist/src/control-plane/hooks/import-guard.js +890 -0
- package/dist/src/control-plane/hooks/inject-context.js +4189 -0
- package/dist/src/control-plane/hooks/post-edit-lint.js +43 -0
- package/dist/src/control-plane/hooks/safety-guard.js +910 -0
- package/dist/src/control-plane/hooks/scope-guard.js +907 -0
- package/dist/src/control-plane/hooks/shared.js +44 -0
- package/dist/src/control-plane/hooks/submodule-branch.js +7797 -0
- package/dist/src/control-plane/hooks/task-runtime-start.js +7799 -0
- package/dist/src/control-plane/hooks/test-integrity-guard.js +891 -0
- package/dist/src/control-plane/materialize-task-config.js +453 -0
- package/dist/src/control-plane/memory-sync/cli.js +2019 -0
- package/dist/src/control-plane/memory-sync/db.js +753 -0
- package/dist/src/control-plane/memory-sync/embed.js +281 -0
- package/dist/src/control-plane/memory-sync/index.js +2049 -0
- package/dist/src/control-plane/memory-sync/query.js +294 -0
- package/dist/src/control-plane/memory-sync/read.js +784 -0
- package/dist/src/control-plane/memory-sync/types.js +6 -0
- package/dist/src/control-plane/memory-sync/write.js +1547 -0
- package/dist/src/control-plane/native/git-native.js +490 -0
- package/dist/src/control-plane/native/git-ops.js +2860 -0
- package/dist/src/control-plane/native/harness-cli.js +9721 -0
- package/dist/src/control-plane/native/pr-automation.js +373 -0
- package/dist/src/control-plane/native/profile-ops.js +481 -0
- package/dist/src/control-plane/native/repo-ops.js +2342 -0
- package/dist/src/control-plane/native/root-resolver.js +66 -0
- package/dist/src/control-plane/native/run-ops.js +3281 -0
- package/dist/src/control-plane/native/runtime-native-sidecar.js +299 -0
- package/dist/src/control-plane/native/runtime-native.js +392 -0
- package/dist/src/control-plane/native/scope-rules.js +17 -0
- package/dist/src/control-plane/native/task-ops.js +6320 -0
- package/dist/src/control-plane/native/task-state.js +1512 -0
- package/dist/src/control-plane/native/utils.js +535 -0
- package/dist/src/control-plane/native/validator-binaries.js +889 -0
- package/dist/src/control-plane/native/validator.js +2197 -0
- package/dist/src/control-plane/native/verifier.js +3249 -0
- package/dist/src/control-plane/native/workspace-ops.js +1635 -0
- package/dist/src/control-plane/plugin-host-context.js +334 -0
- package/dist/src/control-plane/project-main-pre-run-sync.js +630 -0
- package/dist/src/control-plane/provider/claude-stream-records.js +158 -0
- package/dist/src/control-plane/provider/codex-app-server.js +885 -0
- package/dist/src/control-plane/provider/codex-exec-records.js +203 -0
- package/dist/src/control-plane/provider/rig-task-run-skill.js +39 -0
- package/dist/src/control-plane/provider/runtime-instructions.js +96 -0
- package/dist/src/control-plane/remote.js +854 -0
- package/dist/src/control-plane/repos/index.js +473 -0
- package/dist/src/control-plane/repos/layout.js +124 -0
- package/dist/src/control-plane/repos/mirror/bootstrap.js +268 -0
- package/dist/src/control-plane/repos/mirror/refresh.js +398 -0
- package/dist/src/control-plane/repos/mirror/state.js +167 -0
- package/dist/src/control-plane/repos/registry.js +77 -0
- package/dist/src/control-plane/repos/types.js +1 -0
- package/dist/src/control-plane/runtime/agent-mode.js +48 -0
- package/dist/src/control-plane/runtime/baked-secrets.js +120 -0
- package/dist/src/control-plane/runtime/claude-tool-router-binary.js +343 -0
- package/dist/src/control-plane/runtime/claude-tool-router.js +520 -0
- package/dist/src/control-plane/runtime/context.js +216 -0
- package/dist/src/control-plane/runtime/events.js +218 -0
- package/dist/src/control-plane/runtime/guard-types.js +6 -0
- package/dist/src/control-plane/runtime/guard.js +880 -0
- package/dist/src/control-plane/runtime/image/fingerprint-sidecar.js +1194 -0
- package/dist/src/control-plane/runtime/image/index.js +2255 -0
- package/dist/src/control-plane/runtime/image-fingerprint-sidecar.js +1191 -0
- package/dist/src/control-plane/runtime/image.js +2255 -0
- package/dist/src/control-plane/runtime/index.js +8511 -0
- package/dist/src/control-plane/runtime/isolation/discovery.js +599 -0
- package/dist/src/control-plane/runtime/isolation/home.js +1217 -0
- package/dist/src/control-plane/runtime/isolation/index.js +8193 -0
- package/dist/src/control-plane/runtime/isolation/runner.js +2651 -0
- package/dist/src/control-plane/runtime/isolation/shared.js +501 -0
- package/dist/src/control-plane/runtime/isolation/toolchain.js +1892 -0
- package/dist/src/control-plane/runtime/isolation/types.js +1 -0
- package/dist/src/control-plane/runtime/isolation/worktree.js +509 -0
- package/dist/src/control-plane/runtime/isolation.js +8193 -0
- package/dist/src/control-plane/runtime/overlay.js +67 -0
- package/dist/src/control-plane/runtime/plugin-mode.js +41 -0
- package/dist/src/control-plane/runtime/plugins.js +1131 -0
- package/dist/src/control-plane/runtime/provisioning-env.js +220 -0
- package/dist/src/control-plane/runtime/queue.js +8358 -0
- package/dist/src/control-plane/runtime/rig-shell.js +205 -0
- package/dist/src/control-plane/runtime/rig-tools.js +182 -0
- package/dist/src/control-plane/runtime/runner-context.js +1 -0
- package/dist/src/control-plane/runtime/runtime-paths.js +184 -0
- package/dist/src/control-plane/runtime/sandbox/backend-bwrap.js +311 -0
- package/dist/src/control-plane/runtime/sandbox/backend-none.js +21 -0
- package/dist/src/control-plane/runtime/sandbox/backend-seatbelt.js +268 -0
- package/dist/src/control-plane/runtime/sandbox/backend.js +1718 -0
- package/dist/src/control-plane/runtime/sandbox/orchestrator.js +1745 -0
- package/dist/src/control-plane/runtime/sandbox/utils.js +137 -0
- package/dist/src/control-plane/runtime/sandbox-backend-bwrap.js +311 -0
- package/dist/src/control-plane/runtime/sandbox-backend-none.js +21 -0
- package/dist/src/control-plane/runtime/sandbox-backend-seatbelt.js +268 -0
- package/dist/src/control-plane/runtime/sandbox-backend.js +1718 -0
- package/dist/src/control-plane/runtime/sandbox-orchestrator.js +1745 -0
- package/dist/src/control-plane/runtime/sandbox-utils.js +137 -0
- package/dist/src/control-plane/runtime/snapshot/index.js +454 -0
- package/dist/src/control-plane/runtime/snapshot/sidecar.js +502 -0
- package/dist/src/control-plane/runtime/snapshot/task-run.js +1578 -0
- package/dist/src/control-plane/runtime/snapshot-sidecar.js +498 -0
- package/dist/src/control-plane/runtime/snapshot.js +454 -0
- package/dist/src/control-plane/runtime/task-run-snapshot.js +1578 -0
- package/dist/src/control-plane/runtime/tool-gateway.js +422 -0
- package/dist/src/control-plane/runtime/tooling/browser-tools.js +32 -0
- package/dist/src/control-plane/runtime/tooling/claude-router-binary.js +343 -0
- package/dist/src/control-plane/runtime/tooling/claude-router.js +524 -0
- package/dist/src/control-plane/runtime/tooling/file-tools.js +182 -0
- package/dist/src/control-plane/runtime/tooling/gateway.js +422 -0
- package/dist/src/control-plane/runtime/tooling/index.js +1290 -0
- package/dist/src/control-plane/runtime/tooling/shell.js +205 -0
- package/dist/src/control-plane/runtime/types.js +1 -0
- package/dist/src/control-plane/setup-version.js +14 -0
- package/dist/src/control-plane/state-sync/index.js +1509 -0
- package/dist/src/control-plane/state-sync/read.js +856 -0
- package/dist/src/control-plane/state-sync/reconcile.js +260 -0
- package/dist/src/control-plane/state-sync/repo.js +302 -0
- package/dist/src/control-plane/state-sync/types.js +111 -0
- package/dist/src/control-plane/state-sync/write.js +1469 -0
- package/dist/src/control-plane/task-fields.js +38 -0
- package/dist/src/control-plane/task-source-bootstrap.js +46 -0
- package/dist/src/control-plane/task-source.js +30 -0
- package/dist/src/control-plane/tasks/legacy-task-config-source.js +130 -0
- package/dist/src/control-plane/tasks/plugin-task-source.js +103 -0
- package/dist/src/control-plane/tasks/source-aware-task-config-source.js +611 -0
- package/dist/src/control-plane/tasks/source-lifecycle.js +1093 -0
- package/dist/src/control-plane/tasks/task-record-reader.js +9 -0
- package/dist/src/control-plane/validators/boundary/public-apis.js +107 -0
- package/dist/src/control-plane/validators/integration/_shared.js +51 -0
- package/dist/src/control-plane/validators/integration/adm-audit-http.js +85 -0
- package/dist/src/control-plane/validators/integration/adm-auth-http.js +78 -0
- package/dist/src/control-plane/validators/integration/adm-issuer-http.js +80 -0
- package/dist/src/control-plane/validators/integration/adm-migration.js +78 -0
- package/dist/src/control-plane/validators/integration/adm-scaffold.js +78 -0
- package/dist/src/control-plane/validators/runtime-registration.js +64 -0
- package/dist/src/control-plane/validators/shared.js +683 -0
- package/dist/src/events.js +218 -0
- package/dist/src/execution.js +35 -0
- package/dist/src/index.js +1633 -0
- package/dist/src/layout.js +145 -0
- package/dist/src/local-server.js +202 -0
- package/dist/src/plugins.js +329 -0
- package/dist/src/remote-http.js +83 -0
- package/dist/src/runtime-context.js +216 -0
- package/dist/src/types.js +1 -0
- package/native/darwin-arm64/bin/rig-git +0 -0
- package/native/darwin-arm64/bin/rig-shell +0 -0
- package/native/darwin-arm64/bin/rig-tools +0 -0
- package/native/darwin-arm64/lib/runtime-native-darwin-arm64.dylib +0 -0
- package/native/darwin-arm64/lib/runtime-native.dylib +0 -0
- package/native/darwin-arm64/manifest.json +1 -0
- package/native/linux-x64/bin/rig-git +0 -0
- package/native/linux-x64/bin/rig-shell +0 -0
- package/native/linux-x64/bin/rig-tools +0 -0
- package/native/linux-x64/lib/runtime-native-linux-x64.so +0 -0
- package/native/linux-x64/lib/runtime-native.so +0 -0
- package/native/linux-x64/manifest.json +1 -0
- package/package.json +74 -0
- package/skills/rig-task-run.md +71 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/runtime/src/remote-http.ts
|
|
3
|
+
function trimTrailingSlash(value) {
|
|
4
|
+
return value.endsWith("/") ? value.slice(0, -1) : value;
|
|
5
|
+
}
|
|
6
|
+
function normalizeAuthToken(value) {
|
|
7
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
8
|
+
}
|
|
9
|
+
function authHeaders(authToken) {
|
|
10
|
+
return authToken ? { authorization: `Bearer ${authToken}` } : {};
|
|
11
|
+
}
|
|
12
|
+
async function readJsonResponse(response, endpoint) {
|
|
13
|
+
if (!response.ok) {
|
|
14
|
+
const text = await response.text();
|
|
15
|
+
throw new Error(`Rig runtime request failed for ${endpoint}: ${response.status} ${text}`.trim());
|
|
16
|
+
}
|
|
17
|
+
return await response.json();
|
|
18
|
+
}
|
|
19
|
+
async function postJson(fetchImpl, baseUrl, path, body, authToken) {
|
|
20
|
+
const endpoint = `${trimTrailingSlash(baseUrl)}${path}`;
|
|
21
|
+
const response = await fetchImpl(endpoint, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: { "content-type": "application/json", ...authHeaders(authToken) },
|
|
24
|
+
body: JSON.stringify(body)
|
|
25
|
+
});
|
|
26
|
+
return readJsonResponse(response, endpoint);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class HttpRuntimeHostSession {
|
|
30
|
+
baseUrl;
|
|
31
|
+
fetchImpl;
|
|
32
|
+
authToken;
|
|
33
|
+
constructor(baseUrl, fetchImpl = fetch, options = {}) {
|
|
34
|
+
this.baseUrl = baseUrl;
|
|
35
|
+
this.fetchImpl = fetchImpl;
|
|
36
|
+
this.authToken = normalizeAuthToken(options.authToken ?? process.env.RIG_SERVER_AUTH_TOKEN ?? process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
37
|
+
}
|
|
38
|
+
register(input) {
|
|
39
|
+
return postJson(this.fetchImpl, this.baseUrl, "/api/remote/hosts/register", input, this.authToken);
|
|
40
|
+
}
|
|
41
|
+
heartbeat(input) {
|
|
42
|
+
return postJson(this.fetchImpl, this.baseUrl, "/api/remote/hosts/heartbeat", input, this.authToken);
|
|
43
|
+
}
|
|
44
|
+
claimLease(input) {
|
|
45
|
+
return postJson(this.fetchImpl, this.baseUrl, "/api/remote/runs/claim", input, this.authToken);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class HttpRuntimeRunReporter {
|
|
50
|
+
baseUrl;
|
|
51
|
+
fetchImpl;
|
|
52
|
+
authToken;
|
|
53
|
+
constructor(baseUrl, fetchImpl = fetch, options = {}) {
|
|
54
|
+
this.baseUrl = baseUrl;
|
|
55
|
+
this.fetchImpl = fetchImpl;
|
|
56
|
+
this.authToken = normalizeAuthToken(options.authToken ?? process.env.RIG_SERVER_AUTH_TOKEN ?? process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
57
|
+
}
|
|
58
|
+
reportStarted(input) {
|
|
59
|
+
return postJson(this.fetchImpl, this.baseUrl, "/api/remote/runs/start", input, this.authToken);
|
|
60
|
+
}
|
|
61
|
+
reportLog(input) {
|
|
62
|
+
return postJson(this.fetchImpl, this.baseUrl, "/api/remote/runs/log", input, this.authToken);
|
|
63
|
+
}
|
|
64
|
+
reportMessage(input) {
|
|
65
|
+
return postJson(this.fetchImpl, this.baseUrl, "/api/remote/runs/message", input, this.authToken);
|
|
66
|
+
}
|
|
67
|
+
reportCompleted(input) {
|
|
68
|
+
return postJson(this.fetchImpl, this.baseUrl, "/api/remote/runs/complete", input, this.authToken);
|
|
69
|
+
}
|
|
70
|
+
reportFailed(input) {
|
|
71
|
+
return postJson(this.fetchImpl, this.baseUrl, "/api/remote/runs/fail", input, this.authToken);
|
|
72
|
+
}
|
|
73
|
+
reportReleased(input) {
|
|
74
|
+
return postJson(this.fetchImpl, this.baseUrl, "/api/remote/runs/release", input, this.authToken);
|
|
75
|
+
}
|
|
76
|
+
reportArtifact(input) {
|
|
77
|
+
return postJson(this.fetchImpl, this.baseUrl, "/api/remote/runs/artifact", input, this.authToken);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
HttpRuntimeRunReporter,
|
|
82
|
+
HttpRuntimeHostSession
|
|
83
|
+
};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/runtime/src/control-plane/runtime/context.ts
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
4
|
+
import { dirname, resolve } from "path";
|
|
5
|
+
var RUNTIME_CONTEXT_ENV = "RIG_RUNTIME_CONTEXT_FILE";
|
|
6
|
+
var DEFAULT_RUNTIME_MEMORY_RETRIEVAL = {
|
|
7
|
+
topK: 5,
|
|
8
|
+
lexicalWeight: 0.35,
|
|
9
|
+
vectorWeight: 0.45,
|
|
10
|
+
recencyWeight: 0.1,
|
|
11
|
+
confidenceWeight: 0.1
|
|
12
|
+
};
|
|
13
|
+
var runtimeContextStringFields = [
|
|
14
|
+
"runtimeId",
|
|
15
|
+
"taskId",
|
|
16
|
+
"role",
|
|
17
|
+
"workspaceDir",
|
|
18
|
+
"stateDir",
|
|
19
|
+
"logsDir",
|
|
20
|
+
"sessionDir",
|
|
21
|
+
"sessionFile",
|
|
22
|
+
"policyFile",
|
|
23
|
+
"binDir",
|
|
24
|
+
"createdAt"
|
|
25
|
+
];
|
|
26
|
+
var runtimeContextArrayFields = ["scopes", "validation"];
|
|
27
|
+
var runtimeContextOptionalStringFields = [
|
|
28
|
+
"artifactRoot",
|
|
29
|
+
"hostProjectRoot",
|
|
30
|
+
"monorepoMainRoot",
|
|
31
|
+
"monorepoBaseRef",
|
|
32
|
+
"monorepoBaseCommit"
|
|
33
|
+
];
|
|
34
|
+
function writeRuntimeContext(path, ctx) {
|
|
35
|
+
const absPath = resolve(path);
|
|
36
|
+
const dir = dirname(absPath);
|
|
37
|
+
if (!existsSync(dir)) {
|
|
38
|
+
mkdirSync(dir, { recursive: true });
|
|
39
|
+
}
|
|
40
|
+
writeFileSync(absPath, JSON.stringify(ctx, null, 2), "utf8");
|
|
41
|
+
}
|
|
42
|
+
function loadRuntimeContext(path) {
|
|
43
|
+
const absPath = resolve(path);
|
|
44
|
+
if (!existsSync(absPath)) {
|
|
45
|
+
throw new Error(`RuntimeTaskContext file not found: ${absPath}`);
|
|
46
|
+
}
|
|
47
|
+
let raw;
|
|
48
|
+
try {
|
|
49
|
+
raw = JSON.parse(readFileSync(absPath, "utf8"));
|
|
50
|
+
} catch (err) {
|
|
51
|
+
throw new Error(`Failed to parse RuntimeTaskContext at ${absPath}: ${String(err)}`);
|
|
52
|
+
}
|
|
53
|
+
if (typeof raw !== "object" || raw === null) {
|
|
54
|
+
throw new Error(`RuntimeTaskContext at ${absPath} is not an object`);
|
|
55
|
+
}
|
|
56
|
+
const obj = raw;
|
|
57
|
+
for (const field of runtimeContextStringFields) {
|
|
58
|
+
if (typeof obj[field] !== "string" || obj[field].length === 0) {
|
|
59
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be a non-empty string (at ${absPath})`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const field of runtimeContextArrayFields) {
|
|
63
|
+
if (!Array.isArray(obj[field])) {
|
|
64
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be an array (at ${absPath})`);
|
|
65
|
+
}
|
|
66
|
+
if (!obj[field].every((entry) => typeof entry === "string")) {
|
|
67
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be a string[] (at ${absPath})`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (const field of runtimeContextOptionalStringFields) {
|
|
71
|
+
if (field in obj && obj[field] !== undefined && typeof obj[field] !== "string") {
|
|
72
|
+
throw new Error(`RuntimeTaskContext field "${field}" must be a string when present (at ${absPath})`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (obj.browser !== undefined) {
|
|
76
|
+
if (typeof obj.browser !== "object" || obj.browser === null || Array.isArray(obj.browser)) {
|
|
77
|
+
throw new Error(`RuntimeTaskContext field "browser" must be an object when present (at ${absPath})`);
|
|
78
|
+
}
|
|
79
|
+
const browser = obj.browser;
|
|
80
|
+
for (const field of [
|
|
81
|
+
"preset",
|
|
82
|
+
"mode",
|
|
83
|
+
"stateDir",
|
|
84
|
+
"defaultProfile",
|
|
85
|
+
"effectiveProfile",
|
|
86
|
+
"defaultAttachUrl",
|
|
87
|
+
"effectiveAttachUrl",
|
|
88
|
+
"launchHelper",
|
|
89
|
+
"checkHelper",
|
|
90
|
+
"attachInfoHelper",
|
|
91
|
+
"e2eHelper",
|
|
92
|
+
"resetProfileHelper"
|
|
93
|
+
]) {
|
|
94
|
+
if (typeof browser[field] !== "string" || browser[field].length === 0) {
|
|
95
|
+
throw new Error(`RuntimeTaskContext field "browser.${field}" must be a non-empty string (at ${absPath})`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for (const field of ["devCommand", "launchCommand", "checkCommand", "e2eCommand"]) {
|
|
99
|
+
if (browser[field] !== undefined && typeof browser[field] !== "string") {
|
|
100
|
+
throw new Error(`RuntimeTaskContext field "browser.${field}" must be a string when present (at ${absPath})`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (typeof browser.required !== "boolean") {
|
|
104
|
+
throw new Error(`RuntimeTaskContext field "browser.required" must be a boolean (at ${absPath})`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (obj.memory !== undefined) {
|
|
108
|
+
if (typeof obj.memory !== "object" || obj.memory === null || Array.isArray(obj.memory)) {
|
|
109
|
+
throw new Error(`RuntimeTaskContext field "memory" must be an object when present (at ${absPath})`);
|
|
110
|
+
}
|
|
111
|
+
const memory = obj.memory;
|
|
112
|
+
for (const field of ["canonicalPath", "canonicalRef", "canonicalBaseOid", "hydratedPath"]) {
|
|
113
|
+
if (typeof memory[field] !== "string" || memory[field].length === 0) {
|
|
114
|
+
throw new Error(`RuntimeTaskContext field "memory.${field}" must be a non-empty string (at ${absPath})`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (typeof memory.createdFresh !== "boolean") {
|
|
118
|
+
throw new Error(`RuntimeTaskContext field "memory.createdFresh" must be a boolean (at ${absPath})`);
|
|
119
|
+
}
|
|
120
|
+
if (typeof memory.retrieval !== "object" || memory.retrieval === null || Array.isArray(memory.retrieval)) {
|
|
121
|
+
throw new Error(`RuntimeTaskContext field "memory.retrieval" must be an object (at ${absPath})`);
|
|
122
|
+
}
|
|
123
|
+
const retrieval = memory.retrieval;
|
|
124
|
+
for (const field of ["topK", "lexicalWeight", "vectorWeight", "recencyWeight", "confidenceWeight"]) {
|
|
125
|
+
if (typeof retrieval[field] !== "number" || Number.isNaN(retrieval[field])) {
|
|
126
|
+
throw new Error(`RuntimeTaskContext field "memory.retrieval.${field}" must be a number (at ${absPath})`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (obj.initialDirtyFiles !== undefined) {
|
|
131
|
+
if (typeof obj.initialDirtyFiles !== "object" || obj.initialDirtyFiles === null || Array.isArray(obj.initialDirtyFiles)) {
|
|
132
|
+
throw new Error(`RuntimeTaskContext field "initialDirtyFiles" must be an object when present (at ${absPath})`);
|
|
133
|
+
}
|
|
134
|
+
const dirtyFiles = obj.initialDirtyFiles;
|
|
135
|
+
for (const key of ["project", "monorepo"]) {
|
|
136
|
+
if (dirtyFiles[key] === undefined) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (!Array.isArray(dirtyFiles[key]) || !dirtyFiles[key].every((entry) => typeof entry === "string")) {
|
|
140
|
+
throw new Error(`RuntimeTaskContext field "initialDirtyFiles.${key}" must be a string[] when present (at ${absPath})`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (obj.initialHeadCommits !== undefined) {
|
|
145
|
+
if (typeof obj.initialHeadCommits !== "object" || obj.initialHeadCommits === null || Array.isArray(obj.initialHeadCommits)) {
|
|
146
|
+
throw new Error(`RuntimeTaskContext field "initialHeadCommits" must be an object when present (at ${absPath})`);
|
|
147
|
+
}
|
|
148
|
+
const headCommits = obj.initialHeadCommits;
|
|
149
|
+
for (const key of ["project", "monorepo"]) {
|
|
150
|
+
if (headCommits[key] === undefined) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (typeof headCommits[key] !== "string") {
|
|
154
|
+
throw new Error(`RuntimeTaskContext field "initialHeadCommits.${key}" must be a string when present (at ${absPath})`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return obj;
|
|
159
|
+
}
|
|
160
|
+
function runtimeMemoryEnvFromContext(ctx) {
|
|
161
|
+
if (!ctx?.memory) {
|
|
162
|
+
return {};
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
RIG_MEMORY_DB_PATH: ctx.memory.hydratedPath,
|
|
166
|
+
RIG_MEMORY_CANONICAL_PATH: ctx.memory.canonicalPath,
|
|
167
|
+
RIG_MEMORY_CANONICAL_REF: ctx.memory.canonicalRef,
|
|
168
|
+
RIG_MEMORY_CANONICAL_BASE_OID: ctx.memory.canonicalBaseOid,
|
|
169
|
+
RIG_MEMORY_CREATED_FRESH: ctx.memory.createdFresh ? "1" : "0",
|
|
170
|
+
RIG_MEMORY_RETRIEVAL_TOP_K: String(ctx.memory.retrieval.topK),
|
|
171
|
+
RIG_MEMORY_RETRIEVAL_LEXICAL_WEIGHT: String(ctx.memory.retrieval.lexicalWeight),
|
|
172
|
+
RIG_MEMORY_RETRIEVAL_VECTOR_WEIGHT: String(ctx.memory.retrieval.vectorWeight),
|
|
173
|
+
RIG_MEMORY_RETRIEVAL_RECENCY_WEIGHT: String(ctx.memory.retrieval.recencyWeight),
|
|
174
|
+
RIG_MEMORY_RETRIEVAL_CONFIDENCE_WEIGHT: String(ctx.memory.retrieval.confidenceWeight)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function loadRuntimeContextFromEnv(env = process.env) {
|
|
178
|
+
const contextFile = env[RUNTIME_CONTEXT_ENV];
|
|
179
|
+
if (contextFile) {
|
|
180
|
+
return loadRuntimeContext(contextFile);
|
|
181
|
+
}
|
|
182
|
+
const inferred = findRuntimeContextFile(process.cwd());
|
|
183
|
+
if (!inferred) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return loadRuntimeContext(inferred);
|
|
187
|
+
}
|
|
188
|
+
function findRuntimeContextFile(startPath) {
|
|
189
|
+
let current = resolve(startPath);
|
|
190
|
+
while (true) {
|
|
191
|
+
const candidate = resolve(current, "runtime-context.json");
|
|
192
|
+
if (existsSync(candidate) && isAgentRuntimeContextPath(candidate)) {
|
|
193
|
+
return candidate;
|
|
194
|
+
}
|
|
195
|
+
const parent = dirname(current);
|
|
196
|
+
if (parent === current) {
|
|
197
|
+
return "";
|
|
198
|
+
}
|
|
199
|
+
current = parent;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function isAgentRuntimeContextPath(path) {
|
|
203
|
+
const normalized = path.replace(/\\/g, "/");
|
|
204
|
+
return /\/\.rig\/runtime-context\.json$/.test(normalized);
|
|
205
|
+
}
|
|
206
|
+
export {
|
|
207
|
+
writeRuntimeContext,
|
|
208
|
+
runtimeMemoryEnvFromContext,
|
|
209
|
+
runtimeContextStringFields,
|
|
210
|
+
runtimeContextOptionalStringFields,
|
|
211
|
+
runtimeContextArrayFields,
|
|
212
|
+
loadRuntimeContextFromEnv,
|
|
213
|
+
loadRuntimeContext,
|
|
214
|
+
RUNTIME_CONTEXT_ENV,
|
|
215
|
+
DEFAULT_RUNTIME_MEMORY_RETRIEVAL
|
|
216
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @bun
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"platform":"darwin-arm64","suffix":"dylib","builtAt":"2026-06-07T22:55:24Z"}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"platform":"linux-x64","suffix":"so","builtAt":"2026-06-07T22:56:41Z"}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@h-rig/runtime",
|
|
3
|
+
"version": "0.0.6-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Rig package",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md",
|
|
10
|
+
"native",
|
|
11
|
+
"skills"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./dist/src/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./layout": {
|
|
18
|
+
"import": "./dist/src/layout.js"
|
|
19
|
+
},
|
|
20
|
+
"./local-server": {
|
|
21
|
+
"import": "./dist/src/local-server.js"
|
|
22
|
+
},
|
|
23
|
+
"./baked-secrets": {
|
|
24
|
+
"import": "./dist/src/baked-secrets.js"
|
|
25
|
+
},
|
|
26
|
+
"./binary-run": {
|
|
27
|
+
"import": "./dist/src/binary-run.js"
|
|
28
|
+
},
|
|
29
|
+
"./build-time-config": {
|
|
30
|
+
"import": "./dist/src/build-time-config.js"
|
|
31
|
+
},
|
|
32
|
+
"./control-plane/memory-sync": {
|
|
33
|
+
"import": "./dist/src/control-plane/memory-sync/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./control-plane/repos": {
|
|
36
|
+
"import": "./dist/src/control-plane/repos/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./control-plane/runtime": {
|
|
39
|
+
"import": "./dist/src/control-plane/runtime/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./control-plane/runtime/image": {
|
|
42
|
+
"import": "./dist/src/control-plane/runtime/image/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./control-plane/runtime/isolation": {
|
|
45
|
+
"import": "./dist/src/control-plane/runtime/isolation/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./control-plane/runtime/snapshot": {
|
|
48
|
+
"import": "./dist/src/control-plane/runtime/snapshot/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./control-plane/runtime/tooling": {
|
|
51
|
+
"import": "./dist/src/control-plane/runtime/tooling/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./control-plane/state-sync": {
|
|
54
|
+
"import": "./dist/src/control-plane/state-sync/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./control-plane/*": {
|
|
57
|
+
"import": "./dist/src/control-plane/*.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"bun": ">=1.3.11"
|
|
62
|
+
},
|
|
63
|
+
"main": "./dist/src/index.js",
|
|
64
|
+
"module": "./dist/src/index.js",
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"@libsql/client": "^0.17.2",
|
|
67
|
+
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.0",
|
|
68
|
+
"@rig/core": "npm:@h-rig/core@0.0.6-alpha.0",
|
|
69
|
+
"@rig/hook-kit": "npm:@h-rig/hook-kit@0.0.6-alpha.0",
|
|
70
|
+
"@rig/shared": "npm:@h-rig/shared@0.0.6-alpha.0",
|
|
71
|
+
"@rig/validator-kit": "npm:@h-rig/validator-kit@0.0.6-alpha.0",
|
|
72
|
+
"effect": "4.0.0-beta.78"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rig-task-run
|
|
3
|
+
description: Rig task-run workflow contract — how an agent should execute a Rig-dispatched task end-to-end. Used by the server to brief the agent at run start.
|
|
4
|
+
audience: agent
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Rig Task-Run Workflow
|
|
8
|
+
|
|
9
|
+
Use the baked Rig runtime workflow only. Start by running `rig-agent info` and `rig-agent deps`. Use the baked agent binary via `$RIG_AGENT_BIN` for all Rig actions. Do not rely on bare `rig-agent` being on PATH.
|
|
10
|
+
|
|
11
|
+
## Environment
|
|
12
|
+
|
|
13
|
+
- `$RIG_TASK_WORKSPACE` and `$MONOREPO_ROOT` — absolute task worktree root.
|
|
14
|
+
- `$PROJECT_RIG_ROOT` — outer control-plane repo root.
|
|
15
|
+
- `$MONOREPO_MAIN_ROOT` — host monorepo checkout root (use only when you explicitly need the non-worktree path).
|
|
16
|
+
- `$RIG_LOGS_DIR` / `$RIG_TASK_ID` — task validation logs land under `$RIG_LOGS_DIR/$RIG_TASK_ID/`.
|
|
17
|
+
|
|
18
|
+
## Required first calls
|
|
19
|
+
|
|
20
|
+
1. `"$RIG_AGENT_BIN" info` — confirm your assigned task, scope, validators.
|
|
21
|
+
2. `"$RIG_AGENT_BIN" deps` — read decisions and next-actions from prior tasks.
|
|
22
|
+
|
|
23
|
+
## Validation and completion
|
|
24
|
+
|
|
25
|
+
- `"$RIG_AGENT_BIN" validate` — run validators for the task.
|
|
26
|
+
- `"$RIG_AGENT_BIN" completion-verification` — final gate before finish.
|
|
27
|
+
|
|
28
|
+
Before completion verification, scaffold and fill the required completion artifacts so the verifier has real inputs:
|
|
29
|
+
|
|
30
|
+
1. `"$RIG_AGENT_BIN" artifacts` — write template files.
|
|
31
|
+
2. Update `task-result.json`, `decision-log.md`, `next-actions.md`.
|
|
32
|
+
3. Re-run `"$RIG_AGENT_BIN" artifacts` after real file edits to refresh `changed-files.txt`. Do not hand-edit runtime/control-plane paths into it.
|
|
33
|
+
|
|
34
|
+
Make `decision-log.md` substantive: at least 3 distinct concrete lines covering what changed, why, and any downstream follow-up or risk. If you touch proto/OpenAPI/contract files, add `contract-changes.md` describing the contract impact before finishing.
|
|
35
|
+
|
|
36
|
+
## Git flow
|
|
37
|
+
|
|
38
|
+
After validation passes, use `"$RIG_AGENT_BIN" git status` or `"$RIG_AGENT_BIN" git preflight` to confirm branch state.
|
|
39
|
+
|
|
40
|
+
To inspect or customize the PR before finish:
|
|
41
|
+
|
|
42
|
+
- `"$RIG_AGENT_BIN" git commit --target monorepo`
|
|
43
|
+
- `"$RIG_AGENT_BIN" git open-pr --target monorepo`
|
|
44
|
+
|
|
45
|
+
Otherwise completion verification will auto-commit, open/refresh the PR, run Greptile review, and enable auto-merge when policy requires it.
|
|
46
|
+
|
|
47
|
+
## AI review loop
|
|
48
|
+
|
|
49
|
+
When AI review is required, **PR creation is not completion**. Treat `artifacts/<taskId>/review-status.txt`, `review-state.json`, and `review-feedback.md` as the source of truth.
|
|
50
|
+
|
|
51
|
+
If Greptile returns `SKIP`, `REJECTED`, a timeout, unresolved comments, or any verdict other than `APPROVE`:
|
|
52
|
+
|
|
53
|
+
1. Stay in the same runtime workspace.
|
|
54
|
+
2. Resolve the concrete review feedback.
|
|
55
|
+
3. Push the follow-up changes.
|
|
56
|
+
4. Rerun `"$RIG_AGENT_BIN" completion-verification`.
|
|
57
|
+
5. Repeat until `review-status.txt` is `APPROVED` and the review verdict is `APPROVE`.
|
|
58
|
+
|
|
59
|
+
Do not commit or push artifact-only refreshes on review-loop retries. Only create a new commit when scoped task code, tests, configs, or generated contract outputs actually changed.
|
|
60
|
+
|
|
61
|
+
Do not stop after opening the PR, after the first completion-verification run, or after an implementation-only success if review is still pending.
|
|
62
|
+
|
|
63
|
+
## Validation failures
|
|
64
|
+
|
|
65
|
+
If validation fails, inspect the generated task validation logs under `$RIG_LOGS_DIR/$RIG_TASK_ID/` and retry validation after fixing the concrete issue. Do not start searching unrelated workspace files for clues — the logs name the problem.
|
|
66
|
+
|
|
67
|
+
## Conventions
|
|
68
|
+
|
|
69
|
+
- Use `"$RIG_AGENT_BIN" git ...` commands for git status/commit/PR flow instead of raw git whenever possible.
|
|
70
|
+
- Do not inspect or guess hidden control-plane script paths; use the baked Rig commands and files available in the runtime worktree.
|
|
71
|
+
- Implement the task in the dedicated Rig runtime worktree, leave artifacts as needed, and finish through Rig's completion verification flow.
|