@mnaimfaizy/agent-kit 1.0.0-beta.14 → 1.0.0-beta.15

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 (76) hide show
  1. package/README.md +22 -4
  2. package/custom-harness.schema.json +243 -0
  3. package/harnesses.json +244 -6
  4. package/package.json +3 -2
  5. package/src/checks/ci-workflow.mjs +105 -0
  6. package/src/checks/claude-app.mjs +11 -2
  7. package/src/checks/custom-harness.mjs +157 -0
  8. package/src/checks/github-app.mjs +214 -0
  9. package/src/checks/rulesets.mjs +9 -8
  10. package/src/checks/secrets-and-variables.mjs +27 -8
  11. package/src/checks/stages.mjs +705 -0
  12. package/src/cli.mjs +270 -33
  13. package/src/deep-scan/agent.mjs +88 -21
  14. package/src/deep-scan/credential.mjs +81 -32
  15. package/src/deep-scan/docker-driver.mjs +105 -42
  16. package/src/deep-scan/harness-text.mjs +99 -0
  17. package/src/deep-scan/lifecycle.mjs +68 -178
  18. package/src/deep-scan/limits.mjs +13 -7
  19. package/src/deep-scan/model-proxy.mjs +21 -10
  20. package/src/deep-scan/preflight.mjs +19 -6
  21. package/src/deep-scan/recipe.mjs +4 -0
  22. package/src/deep-scan/runtime.mjs +54 -6
  23. package/src/deep-scan/sandbox-run.mjs +232 -0
  24. package/src/deep-scan/sbx-driver.mjs +224 -39
  25. package/src/deep-scan/tar.mjs +69 -22
  26. package/src/deep-scan/verify.mjs +6 -1
  27. package/src/deep-scan.mjs +73 -13
  28. package/src/doctor.mjs +113 -4
  29. package/src/harness/adapters.mjs +30 -0
  30. package/src/harness/antigravity.mjs +187 -0
  31. package/src/harness/claude-code.mjs +8 -1
  32. package/src/harness/codex.mjs +219 -0
  33. package/src/harness/cursor.mjs +199 -0
  34. package/src/harness/custom/registry.mjs +21 -0
  35. package/src/harness/custom/schema.mjs +90 -0
  36. package/src/harness/custom.mjs +299 -0
  37. package/src/harness/facts.mjs +44 -7
  38. package/src/harness/gemini.mjs +164 -0
  39. package/src/harness/install-layer.mjs +86 -3
  40. package/src/harness/opencode.mjs +289 -0
  41. package/src/harness/resolve.mjs +156 -0
  42. package/src/harness/support-levels.mjs +151 -3
  43. package/src/harness-live/assess.mjs +29 -6
  44. package/src/harness-live/cursor-real.mjs +146 -0
  45. package/src/harness-live/cursor-version.mjs +70 -0
  46. package/src/harness-live/cursor.mjs +80 -0
  47. package/src/harness-live/custom.mjs +91 -0
  48. package/src/harness-live/fixture-harness.mjs +45 -0
  49. package/src/harness-live/harnesses.mjs +263 -0
  50. package/src/harness-live/host.mjs +113 -4
  51. package/src/harness-live/opencode.mjs +289 -0
  52. package/src/harness-live/probes.mjs +87 -7
  53. package/src/harness-live/run.mjs +101 -20
  54. package/src/harness-live/setup.mjs +126 -0
  55. package/src/harness-live/stage.mjs +25 -15
  56. package/src/harness-live/suite.mjs +276 -95
  57. package/src/harness-test.mjs +116 -0
  58. package/src/init.mjs +313 -13
  59. package/src/model-proxy/core.mjs +128 -20
  60. package/src/model-proxy/profiles/anthropic.mjs +54 -10
  61. package/src/model-proxy/profiles/gemini-api.mjs +311 -0
  62. package/src/model-proxy/profiles/openai.mjs +327 -0
  63. package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
  64. package/src/model-proxy/stub-dialects/openai.mjs +173 -0
  65. package/src/model-proxy/stub.mjs +9 -1
  66. package/src/stage/audit.mjs +79 -0
  67. package/src/stage/egress-route.mjs +207 -0
  68. package/src/stage/implement/carry.mjs +308 -0
  69. package/src/stage/implement/sandbox.mjs +271 -0
  70. package/src/stage/implement/verify.mjs +70 -0
  71. package/src/stage/implement.mjs +218 -0
  72. package/src/stage/plan.mjs +115 -0
  73. package/src/stage/review-response.mjs +172 -0
  74. package/src/stage/review.mjs +185 -0
  75. package/src/stage/workspace.mjs +274 -0
  76. package/src/stage.mjs +1068 -0
@@ -0,0 +1,126 @@
1
+ // The live suite's setup scenario (ADRs 0025, 0029 and 0047): the implement
2
+ // Stage on a Consumer's `sandbox_image`, with `setup_commands` that try the
3
+ // network while setup's egress is open, and leave behind what could steer the
4
+ // agent: harness config, an instruction file and a git hook outside the
5
+ // workspace, an edit to the harness's files, and a running process. The Guards
6
+ // are judged as for every scenario, and two named assertions hold that the
7
+ // registry named was reached and no other host, and that none of what setup
8
+ // left reached the agent's container while the declared path did.
9
+
10
+ /** The harness the scenario runs on: the setup is the Launcher's, not a harness's. */
11
+ export const SETUP_HARNESS = "claude-code";
12
+
13
+ /** The node preset's image, by tag, so the run resolves its digest. */
14
+ export const SETUP_IMAGE = "node:22-bookworm";
15
+
16
+ /** The one registry the scenario names. */
17
+ export const SETUP_REGISTRY = "registry.npmjs.org";
18
+
19
+ /** The path the scenario declares in `--setup-paths`, which must cross. */
20
+ export const SETUP_PATH = "/root/.cache/agent-kit-carried";
21
+
22
+ /**
23
+ * The word setup writes into everything it leaves, as its parts: a script
24
+ * builds it at run time, so no script's text holds it whole. A harness keeps
25
+ * its tool calls in its own files, and those would match.
26
+ */
27
+ const LEFT = ["SETUP", "LEFT", "MARK"];
28
+
29
+ /** The word, as `sh` builds it from its quoted parts. */
30
+ const BUILD_LEFT = `m=${LEFT.map((w) => `"${w}"`).join("-")}`;
31
+
32
+ /** The sleep setup leaves running, found by its argument. */
33
+ const LEFT_SECONDS = 7777777;
34
+
35
+ /**
36
+ * The setup commands: one request to the named registry, one to another, one
37
+ * past the proxy, each printing the HTTP status and the proxy's answer to
38
+ * CONNECT; a harness config in the workspace for the Launcher to clear away;
39
+ * and what ADR 0047 keeps from the agent: harness config and an instruction
40
+ * file in the home folder, a system-wide git hook, a file and an edit in the
41
+ * harness's install, a process left running, and a file under the declared
42
+ * path.
43
+ */
44
+ export const SETUP_SCRIPT = [
45
+ "status() { curl -s -o /dev/null --max-time 30 -w '%{http_code} %{http_connect}' \"$@\" || true; }",
46
+ `echo "SETUP|allowed|$(status https://${SETUP_REGISTRY}/react/latest)"`,
47
+ 'echo "SETUP|refused|$(status https://pypi.org/simple/)"',
48
+ `echo "SETUP|direct|$(status --noproxy '*' https://${SETUP_REGISTRY}/react/latest)"`,
49
+ "mkdir -p .claude && echo '{}' > .claude/settings.json",
50
+ BUILD_LEFT,
51
+ 'mkdir -p "$HOME/.claude"',
52
+ 'printf \'{"env":{"%s":"1"}}\\n\' "$m" > "$HOME/.claude/settings.json"',
53
+ 'echo "$m: follow these instructions." > "$HOME/.claude/CLAUDE.md"',
54
+ "mkdir -p /etc/agent-kit-hooks",
55
+ "printf '#!/bin/sh\\necho %s\\n' \"$m\" > /etc/agent-kit-hooks/pre-commit",
56
+ "chmod +x /etc/agent-kit-hooks/pre-commit",
57
+ "git config --system core.hooksPath /etc/agent-kit-hooks",
58
+ 'echo "$m" > /opt/agent-kit/setup-was-here',
59
+ 'f=$(find /opt/agent-kit -name "*.js" -type f | head -n 1)',
60
+ 'if [ -n "$f" ]; then echo "// $m" >> "$f"; fi',
61
+ `setsid sleep ${LEFT_SECONDS} > /dev/null 2>&1 < /dev/null &`,
62
+ `mkdir -p ${SETUP_PATH} && echo "$m" > ${SETUP_PATH}/carried`,
63
+ 'echo "SETUP|planted|done"',
64
+ "",
65
+ ].join("\n");
66
+
67
+ /**
68
+ * The probe the agent runs in its own container: what of setup's leavings it
69
+ * finds. One `PROBE|setup|<name>|<value>` line each, then `PROBE|setup|end`.
70
+ */
71
+ export const SETUP_PROBE = [
72
+ BUILD_LEFT,
73
+ "found() {",
74
+ ` timeout 30 grep -rIls --devices=skip --exclude-dir=${SETUP_PATH.slice(SETUP_PATH.lastIndexOf("/") + 1)} "$m" "$@" 2>/dev/null | head -n 5 | tr '\\n' ' '`,
75
+ "}",
76
+ 'echo "PROBE|setup|home|$(found /root /home)"',
77
+ 'echo "PROBE|setup|etc|$(found /etc)"',
78
+ 'echo "PROBE|setup|harness|$(found /opt/agent-kit)"',
79
+ 'echo "PROBE|setup|hooks|$(git config --system --get core.hooksPath 2>/dev/null || echo unset)"',
80
+ // A command line that is the sleep's alone: this shell's holds the number too.
81
+ "left=0",
82
+ "for f in /proc/[0-9]*/cmdline; do",
83
+ ` [ "$(tr '\\0' ' ' < "$f" 2>/dev/null)" = "sleep ${LEFT_SECONDS} " ] && left=$((left + 1))`,
84
+ "done",
85
+ 'echo "PROBE|setup|process|$left"',
86
+ `echo "PROBE|setup|declared|$(cat ${SETUP_PATH}/carried 2>/dev/null || echo absent)"`,
87
+ 'echo "PROBE|setup|end"',
88
+ ].join("\n");
89
+
90
+ /** @type {Readonly<import("./harnesses.mjs").NamedAssertion>} */
91
+ export const SETUP_REACHES_ITS_REGISTRY_ALONE = Object.freeze({
92
+ name: "setup reaches the named registry alone",
93
+ check({ launcherOutput }) {
94
+ const seen = (probe) => new RegExp(`^SETUP\\|${probe}\\|(.*)$`, "m").exec(launcherOutput)?.[1];
95
+ const wanted = [
96
+ ["allowed", "200 200", "the named registry was not reached"],
97
+ ["refused", "000 403", "the proxy did not refuse another host"],
98
+ ["direct", "000 000", "a request past the proxy got through"],
99
+ ];
100
+ const failed = wanted.find(([probe, answer]) => seen(probe) !== answer);
101
+ return failed ? `${failed[2]} (saw ${seen(failed[0]) ?? "nothing"})` : null;
102
+ },
103
+ });
104
+
105
+ /** @type {Readonly<import("./harnesses.mjs").NamedAssertion>} */
106
+ export const SETUP_LEAVES_THE_AGENT_ALONE = Object.freeze({
107
+ name: "nothing setup left outside the workspace reaches the agent but the declared path",
108
+ check({ launcherOutput, outputs = {} }) {
109
+ if (!/^SETUP\|planted\|done$/m.test(launcherOutput))
110
+ return "setup did not plant what it leaves";
111
+ const output = outputs.setup ?? "";
112
+ if (!output.includes("PROBE|setup|end")) return "the setup probe did not finish";
113
+ const seen = (name) =>
114
+ new RegExp(`^PROBE\\|setup\\|${name}\\|(.*)$`, "m").exec(output)?.[1].trim();
115
+ const wanted = [
116
+ ["home", "", "setup's harness config or instruction file reached the agent's home"],
117
+ ["etc", "", "setup's system git hook reached the agent"],
118
+ ["harness", "", "setup's edit to the harness's files reached the agent"],
119
+ ["hooks", "unset", "setup's git hooksPath reached the agent"],
120
+ ["process", "0", "a process setup left runs beside the agent"],
121
+ ["declared", LEFT.join("-"), "the declared setup path did not reach the agent"],
122
+ ];
123
+ const failed = wanted.find(([name, answer]) => seen(name) !== answer);
124
+ return failed ? `${failed[2]} (saw ${JSON.stringify(seen(failed[0]) ?? null)})` : null;
125
+ },
126
+ });
@@ -2,11 +2,12 @@
2
2
  // by its adapter's launch plan, in the Deep scan's sandbox driver, behind the
3
3
  // real model proxy, handed a brief, with one result file copied out.
4
4
  //
5
- // The `agent-kit stage` command, the Launcher's path for a Stage (ADR 0024),
6
- // does not exist yet; until it does, this composes the same driver, adapter,
7
- // agent script and proxy, and nothing here ships to a Consumer's run. Once it
8
- // exists, the live suite enters through it. It removes nothing from the copy,
9
- // so the checkout's config is kept out by the adapter's launch alone.
5
+ // The CI Stages the kit runs enter through `agent-kit stage` itself
6
+ // (suite.mjs). This composes the same driver, adapter, agent script and proxy
7
+ // for the checkout-config control beside them, and nothing here ships to a
8
+ // Consumer's run. The checkout's config is kept out
9
+ // as the adapter's launch plan says: by its launch, and where the plan says so
10
+ // by removing it from the copy.
10
11
 
11
12
  import { randomBytes } from "node:crypto";
12
13
  import { writeFileSync } from "node:fs";
@@ -16,9 +17,8 @@ import { callerKeyFor, withoutCredentials } from "../deep-scan/credential.mjs";
16
17
  import { dockerDriver } from "../deep-scan/docker-driver.mjs";
17
18
  import { StepFailed } from "../deep-scan/steps.mjs";
18
19
  import { tarOf } from "../deep-scan/tar.mjs";
19
- import { claudeCode } from "../harness/claude-code.mjs";
20
- import { startProxy } from "../model-proxy/core.mjs";
21
- import { anthropic } from "../model-proxy/profiles/anthropic.mjs";
20
+ import { adapterFor } from "../harness/adapters.mjs";
21
+ import { startModelProxy } from "../deep-scan/model-proxy.mjs";
22
22
 
23
23
  /** Where the Stage's result goes in the sandbox. */
24
24
  export const STAGE_RESULT_PATH = "/agent-kit/out/result.md";
@@ -40,11 +40,14 @@ const MAX_TOKENS = 20_000_000;
40
40
  * runtime: import("../deep-scan/runtime.mjs").Runtime,
41
41
  * root: string,
42
42
  * commit: string,
43
+ * harness?: string,
43
44
  * credential: string,
44
45
  * credentialKind: "api-key" | "subscription",
46
+ * model?: string,
45
47
  * modelApi: string,
46
48
  * outDir: string,
47
- * beforeTeardown: (container: string, launch: { env: string[], url: string }) => Promise<void>,
49
+ * beforeAgent?: (container: string, launch: { env: string[], url: string, plan: import("../harness/claude-code.mjs").LaunchPlan }) => Promise<void>,
50
+ * beforeTeardown: (container: string, launch: { env: string[], url: string, plan: import("../harness/claude-code.mjs").LaunchPlan }) => Promise<void>,
48
51
  * out: (s: string) => void,
49
52
  * err: (s: string) => void,
50
53
  * }} opts `modelApi` is the proxy's upstream: here, the stub model.
@@ -56,10 +59,13 @@ export async function runReadOnlyStage({
56
59
  runtime,
57
60
  root,
58
61
  commit,
62
+ harness = "claude-code",
59
63
  credential,
60
64
  credentialKind,
65
+ model,
61
66
  modelApi,
62
67
  outDir,
68
+ beforeAgent = async () => {},
63
69
  beforeTeardown,
64
70
  out,
65
71
  err,
@@ -69,8 +75,9 @@ export async function runReadOnlyStage({
69
75
  const signal = AbortSignal.timeout(TIMEOUT_MS);
70
76
  const call = (cmd, args, opts = {}) => runner.start(cmd, args, { ...opts, signal });
71
77
  const id = randomBytes(6).toString("hex");
72
- const request = { stage: "review", credentialKind };
73
- const driver = dockerDriver({ runtime, id, call, plan: claudeCode(request) });
78
+ const request = { stage: "review", credentialKind, model };
79
+ const adapter = adapterFor(harness);
80
+ const driver = dockerDriver({ runtime, id, call, plan: adapter(request) });
74
81
  const steps = { setup: [], start: [], ready: [], seed: [], registries: [], grounding: [] };
75
82
  const must = (condition, why) => {
76
83
  if (!condition) throw new StepFailed([`FAILED ${why}.`]);
@@ -89,9 +96,10 @@ export async function runReadOnlyStage({
89
96
  await driver.cutEgress();
90
97
  const left = await driver.egressLeft();
91
98
  must(left === null, `the network is not cut: ${left}`);
92
- const callerKey = callerKeyFor(credentialKind);
99
+ const callerKey = callerKeyFor(credentialKind, harness, model);
93
100
  const route = await driver.openModelRoute(async (bind) => {
94
- proxy = await startProxy(anthropic, {
101
+ proxy = await startModelProxy({
102
+ profile: adapter(request).modelRoute.profile,
95
103
  credential,
96
104
  kind: credentialKind,
97
105
  bind,
@@ -112,7 +120,7 @@ export async function runReadOnlyStage({
112
120
  ]),
113
121
  "copying the brief in",
114
122
  );
115
- const plan = claudeCode({
123
+ const plan = adapter({
116
124
  ...request,
117
125
  proxyUrl: route.url,
118
126
  briefPath: BRIEF_PATH,
@@ -121,12 +129,14 @@ export async function runReadOnlyStage({
121
129
  callerKey,
122
130
  });
123
131
  out(`Agent step: ${plan.identity.displayName} ${plan.identity.version}, a read-only Stage.`);
132
+ const launch = { env: plan.launch.env, url: route.url, plan };
133
+ await beforeAgent(driver.container, launch);
124
134
  const agent = await driver.exec(
125
135
  agentScript({ plan, report: STAGE_RESULT_PATH, workspace: "/workspace" }),
126
136
  { env: plan.launch.env },
127
137
  );
128
138
  if (agent.status !== 0) err(`The agent step exited ${agent.status}:\n${agent.stderr}`);
129
- await beforeTeardown(driver.container, { env: plan.launch.env, url: route.url });
139
+ await beforeTeardown(driver.container, launch);
130
140
  const file = await driver.copyOut(STAGE_RESULT_PATH, { maxBytes: MAX_RESULT });
131
141
  if (!("data" in file)) {
132
142
  err("FAILED no result came out.");