diff --git a/.github/docs-sync/agent-permissions.json b/.github/docs-sync/agent-permissions.json new file mode 100644 index 00000000000..3bd0a3f1a04 --- /dev/null +++ b/.github/docs-sync/agent-permissions.json @@ -0,0 +1,74 @@ +{ + "//": "Tool and path scope for the headless Kilo CLI passes of the docs-sync bot. agent-policy.mjs turns one mode into KILO_CONFIG_CONTENT, which the CLI enforces. Rule order matters: permission evaluation takes the LAST matching rule, so every map starts with the catch-all deny and lists exceptions after it. `bash` patterns are matched against the tree-sitter text of each parsed sub-command, with operators masked only where the parser proves them inert.", + "modes": { + "tools-denied": { + "//": "Batch classification and learnings extraction answer from the attached files. The CLI's read of a -f attachment is a read-tool call, so read is the only tool this mode permits.", + "permission": { + "*": "deny", + "read": "allow" + } + }, + "docs-write": { + "//": "Docs editing and the verify-repair pass read the tree, write inside the docs pages and navigation, and run the docs build and tests.", + "permission": { + "*": "deny", + "read": "allow", + "grep": "allow", + "glob": "allow", + "doom_loop": "deny", + "external_directory": "deny", + "edit": { + "*": "deny", + "packages/kilo-docs/pages/*.md": "allow", + "packages/kilo-docs/lib/nav/*": "allow", + "docs-sync-out/edit-summary-*.json": "allow", + "edit-summary-*.json": "allow" + }, + "bash": { + "*": "deny", + "ls *": "allow", + "cat *": "allow", + "head *": "allow", + "tail *": "allow", + "wc *": "allow", + "grep *": "allow", + "rg *": "allow", + "find *": "allow", + "echo *": "allow", + "printf *": "allow", + "cut *": "allow", + "tr *": "allow", + "jq *": "allow", + "nl *": "allow", + "stat *": "allow", + "file *": "allow", + "pwd *": "allow", + "basename *": "allow", + "dirname *": "allow", + "realpath *": "allow", + "bun run --filter @kilocode/kilo-docs build": "allow", + "bun run --filter @kilocode/kilo-docs test": "allow", + "bun run --filter @kilocode/kilo-docs typecheck": "allow", + "git *": "deny", + "find *-delete*": "deny", + "find *-exec*": "deny", + "find *-execdir*": "deny", + "find *-fprint*": "deny", + "find *-fprintf*": "deny", + "find *-fls*": "deny", + "find *-ok*": "deny", + "rg *--pre *": "deny", + "rg *--pre=*": "deny", + "rg *--hostname-bin*": "deny", + "tail *--pid*": "deny", + "wc *--files0-from*": "deny", + "*\n*": "deny", + "*<(*": "deny", + "*$(*": "deny", + "*`*": "deny", + "*>*": "deny" + } + } + } + } +} diff --git a/.github/docs-sync/agent-policy.mjs b/.github/docs-sync/agent-policy.mjs new file mode 100644 index 00000000000..07cab4310b2 --- /dev/null +++ b/.github/docs-sync/agent-policy.mjs @@ -0,0 +1,147 @@ +// kilocode_change - new file + +/** + * Tool and path scope for the headless Kilo CLI passes. + * + * Every pass that runs a model declares its scope here rather than relying on + * the prompt: each mode in `agent-permissions.json` is one `KILO_CONFIG_CONTENT` + * value, `lib.mjs` spawns `kilo run` with it, and the workflow's repair step + * prints it from this module. The CLI enforces the map, so the permitted tools, + * commands and write paths are the same for a scheduled run and a manual one. + * + * Usage: `node .github/docs-sync/agent-policy.mjs ` + */ + +import fs from "node:fs" +import path from "node:path" +import { fileURLToPath } from "node:url" + +const HERE = path.dirname(fileURLToPath(import.meta.url)) +export const POLICY_FILE = path.join(HERE, "agent-permissions.json") + +/** Modes the scripts pass to `runKilo`. */ +export const MODE = { + /** Classification and extraction: the answer comes from the attached files. */ + toolsDenied: "tools-denied", + /** Docs editing and the verify-failure repair pass. */ + docsWrite: "docs-write", +} + +export function policy() { + return JSON.parse(fs.readFileSync(POLICY_FILE, "utf8")) +} + +/** + * The action literals a permission rule may take; `null` clears a rule. + * + * `ask` is not one of them. No client is attached to these runs, so an ask + * would be auto-rejected mid-pass and end the run; a mode has to state its + * decision up front instead of leaving one to a prompt that nobody answers. + */ +const ACTIONS = new Set(["allow", "deny"]) + +/** One accepted rule value: an action literal, or `null`. */ +const isAction = (value) => value === null || ACTIONS.has(value) + +/** + * Require every mode to state a usable rule map before it becomes + * `KILO_CONFIG_CONTENT`: the leading catch-all deny, and an allow or deny for + * each rule and pattern. `ask` is refused here rather than at the first tool + * call, because a headless run cannot answer one. A malformed mode stops the + * run here, so a run always carries the scope its mode declares. + */ +export function validateMode(mode, entry) { + const fail = (message) => { + throw new Error(`agent policy mode ${mode}: ${message}`) + } + if (!entry || typeof entry !== "object" || Array.isArray(entry)) fail("no mode entry") + const permission = entry.permission + if (!permission || typeof permission !== "object" || Array.isArray(permission)) { + fail("permission must be an object of tool rules") + } + const keys = Object.keys(permission) + if (keys.length === 0) fail("permission is empty") + if (keys[0] !== "*" || permission["*"] !== "deny") { + fail('the first rule must be "*": "deny", because permission evaluation takes the last matching rule') + } + for (const key of keys) { + const rule = permission[key] + if (isAction(rule)) continue + if (!rule || typeof rule !== "object" || Array.isArray(rule)) { + fail(`rule ${JSON.stringify(key)} must be allow, deny, null or a map of patterns to one of them`) + } + for (const pattern of Object.keys(rule)) { + if (!isAction(rule[pattern])) { + fail(`rule ${JSON.stringify(key)} pattern ${JSON.stringify(pattern)} must be allow, deny or null`) + } + } + } +} + +/** + * `KILO_CONFIG_CONTENT` for one mode, merged over the value already in the + * environment so a caller's own provider or model settings survive. The mode + * owns `permission` outright: a rule from the base would otherwise land before + * the catch-all, and evaluation takes the last matching rule. + */ +export function configContent(mode, base = process.env.KILO_CONFIG_CONTENT) { + const modes = policy().modes + const entry = modes[mode] + if (!entry) throw new Error(`unknown agent policy mode: ${mode} (expected one of ${Object.keys(modes).join(", ")})`) + validateMode(mode, entry) + const merged = base ? JSON.parse(base) : {} + merged.permission = { ...entry.permission } + return JSON.stringify(merged) +} + +/** + * The git credential-helper definition a step sets for its own git calls. The + * model never needs it, so `env` withholds it instead of handing a repository + * token to the CLI. + */ +const STEP_ONLY = /^GIT_CONFIG_(?:COUNT|KEY_[0-9]+|VALUE_[0-9]+)$/ + +/** + * Credential-shaped names, matched on the name ending: `KEY`, `TOKEN`, + * `SECRET`, `CREDENTIAL`, `PASSWORD`, `ORG_ID` and `_PAT`. The environment is + * filtered rather than rebuilt from a keep-list, so a pass keeps the caller's + * provider and model settings while a step's credential stays with the step. + * The match is on the ending alone: a name that ends differently is outside + * this rule and needs its own entry when a step starts setting it. + */ +const SECRET_NAME = /(?:KEY|TOKEN|SECRET|CREDENTIAL|PASSWORD|ORG_ID|_PAT)$/i + +/** + * The credentials the CLI authenticates with, and the only names the shape + * rule must not remove. + */ +const GATEWAY = new Set(["KILO_API_KEY", "KILO_ORG_ID"]) + +/** + * Child environment for a `kilo run` under `mode`. + * + * The child receives the caller's environment without the names the two rules + * above match, so a step's credential and credential-helper definition stay + * with the step. The gateway credentials stay, because the CLI authenticates + * with them. + */ +export function env(mode, base = process.env) { + const child = { ...base } + for (const name of Object.keys(child)) { + if (GATEWAY.has(name)) continue + if (STEP_ONLY.test(name) || SECRET_NAME.test(name)) delete child[name] + } + // `?? ""` keeps an explicit base authoritative: a base without the key means + // "no caller config", never a re-read of the ambient value. + child.KILO_CONFIG_CONTENT = configContent(mode, child.KILO_CONFIG_CONTENT ?? "") + return child +} + +if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { + const mode = process.argv[2] + if (!mode) { + console.error(`usage: node ${path.relative(process.cwd(), fileURLToPath(import.meta.url))} <${Object.values(MODE).join("|")}>`) + process.exit(2) + } + process.stdout.write(configContent(mode) + "\n") +} diff --git a/.github/docs-sync/agent-policy.test.mjs b/.github/docs-sync/agent-policy.test.mjs new file mode 100644 index 00000000000..525d7aad2b6 --- /dev/null +++ b/.github/docs-sync/agent-policy.test.mjs @@ -0,0 +1,416 @@ +// kilocode_change - new file + +/** + * Guards the declared scope of the headless Kilo CLI passes: the committed + * policy exists and is what the scripts and the workflow pass, the gateway + * credentials sit on the steps that call the CLI, and the checkout keeps no + * credential on disk. + * + * Run: node .github/docs-sync/agent-policy.test.mjs + */ + +import assert from "node:assert/strict" +import fs from "node:fs" +import path from "node:path" +import { fileURLToPath } from "node:url" + +const HERE = path.dirname(fileURLToPath(import.meta.url)) +const ROOT = path.resolve(HERE, "..", "..") +const read = (p) => fs.readFileSync(path.join(ROOT, p), "utf8") + +const { MODE, configContent, env, policy, validateMode } = await import("./agent-policy.mjs") + +const workflow = read(".github/workflows/docs-sync.yml") + +const failures = [] +function check(label, fn) { + try { + fn() + console.log(`ok - ${label}`) + } catch (err) { + failures.push(`${label}: ${err.message}`) + console.error(`not ok - ${label}: ${err.message}`) + } +} + +/** The `sync` job block only: the selftest job must stay out of these checks. */ +function syncJob() { + const start = workflow.indexOf("\n sync:\n") + assert.ok(start >= 0, "sync job not found") + return workflow.slice(start) +} + +/** One step block, from its `- name:` line to the next step. */ +function step(name) { + const blocks = syncJob().split("\n - name: ") + const block = blocks.find((b) => b.startsWith(name)) + assert.ok(block, `step "${name}" not found`) + return block.split("\n - name: ")[0] +} + +// 1. The policy is data a reviewer can read, with one mode per call site. +check("agent-permissions.json declares both modes", () => { + const modes = policy().modes + assert.deepEqual(Object.keys(modes).sort(), ["docs-write", "tools-denied"]) +}) + +check("tools-denied denies every tool except the attachment read", () => { + assert.deepEqual(policy().modes["tools-denied"].permission, { "*": "deny", read: "allow" }) +}) + +check("docs-write confines edits to markdown docs, nav files and the agent summary file", () => { + const edit = policy().modes["docs-write"].permission.edit + const keys = Object.keys(edit) + assert.equal(keys[0], "*", "the catch-all must come first: permission evaluation takes the last matching rule") + assert.equal(edit["*"], "deny") + const allowed = keys.filter((k) => edit[k] === "allow") + // The exact list, so a new allow fails here. The page entry names `.md` + // because pages/ also holds the Next.js app modules and API routes. + assert.deepEqual( + allowed, + ["packages/kilo-docs/pages/*.md", "packages/kilo-docs/lib/nav/*", "docs-sync-out/edit-summary-*.json", "edit-summary-*.json"], + "only markdown docs, navigation files and the agent's own summary file may be written", + ) +}) + +check("docs-write denies every tool it does not name", () => { + const permission = policy().modes["docs-write"].permission + assert.equal(Object.keys(permission)[0], "*", "the catch-all must come first") + assert.equal(permission["*"], "deny") +}) + +check("both modes allow read, which the CLI uses for a -f attachment", () => { + for (const mode of ["tools-denied", "docs-write"]) { + assert.equal(policy().modes[mode].permission.read, "allow", `${mode} must allow read`) + } +}) + +check("docs-write denies bash by default and allows no interpreter", () => { + const bash = policy().modes["docs-write"].permission.bash + assert.equal(Object.keys(bash)[0], "*", "the catch-all must come first") + assert.equal(bash["*"], "deny") + for (const cmd of ["python3", "python", "node", "bun", "sh", "bash", "env", "docker"]) { + const rule = Object.entries(bash).find(([pattern]) => pattern === `${cmd} *` || pattern === cmd) + assert.ok(!rule || rule[1] !== "allow", `${cmd} must not be allowed`) + } +}) + +check("docs-write denies git", () => { + const bash = policy().modes["docs-write"].permission.bash + assert.equal(bash["git *"], "deny", "git must be denied for the agent") +}) + +check("docs-write allows no command with a file-writing form it cannot bound", () => { + const bash = policy().modes["docs-write"].permission.bash + for (const cmd of ["sed", "uniq", "diff", "sort"]) { + assert.ok(!(`${cmd} *` in bash), `${cmd} must not be allowed: it can write a file or run a command`) + } +}) + +check("docs-write denies the operator blocklist after the allows", () => { + const bash = policy().modes["docs-write"].permission.bash + const keys = Object.keys(bash) + for (const operator of ["*>*", "*$(*", "*`*", "*<(*"]) { + assert.ok(keys.includes(operator), `operator rule ${operator} missing`) + assert.equal(bash[operator], "deny") + const firstAllow = keys.findIndex((k) => bash[k] === "allow") + assert.ok(keys.indexOf(operator) > firstAllow, `${operator} must come after the allows (last match wins)`) + } +}) + +check("docs-write denies every find form that runs a command", () => { + const bash = policy().modes["docs-write"].permission.bash + const keys = Object.keys(bash) + const allow = keys.indexOf("find *") + assert.ok(allow > -1, "the find * allow rule missing") + for (const rule of ["find *-delete*", "find *-exec*", "find *-execdir*", "find *-fprint*", "find *-fprintf*", "find *-fls*", "find *-ok*"]) { + assert.ok(keys.includes(rule), `${rule} missing`) + assert.equal(bash[rule], "deny", `${rule} must be deny`) + assert.ok(keys.indexOf(rule) > allow, `${rule} must come after the find * allow, because the last match wins`) + } +}) + +check("docs-write keeps the docs build and test commands", () => { + const bash = policy().modes["docs-write"].permission.bash + for (const cmd of [ + "bun run --filter @kilocode/kilo-docs build", + "bun run --filter @kilocode/kilo-docs test", + "bun run --filter @kilocode/kilo-docs typecheck", + ]) { + assert.equal(bash[cmd], "allow", `${cmd} must be allowed`) + } +}) + +// 2. The exported config is what the CLI reads, and it preserves a caller's +// provider settings instead of replacing them. +// The second argument must be an explicit empty string: the default parameter +// would read the ambient KILO_CONFIG_CONTENT, and this check must not depend on +// the environment it runs in. +check("configContent returns the mode's permission map as JSON", () => { + const cfg = JSON.parse(configContent(MODE.docsWrite, "")) + assert.deepEqual(cfg.permission, policy().modes["docs-write"].permission) +}) + +check("env withholds credentials and the git credential helper", () => { + // The filter is by name shape, so this pins both the fixed key of a step's own + // git call and a credential-shaped key from a step that does not exist yet. + const base = { + GH_TOKEN: "gh-token-value", + GITHUB_TOKEN: "github-token-value", + CROSS_REPO_ACCESS_TOKEN: "cross-value", + CLOUD_REPO_TOKEN: "cloud-value", + SOME_BUILD_TOKEN: "build-token-value", + AWS_SECRET_ACCESS_KEY: "aws-value", + NPM_TOKEN: "npm-value", + DEPLOY_PASSWORD: "deploy-value", + GIT_CONFIG_COUNT: "1", + GIT_CONFIG_KEY_0: "credential.helper", + GIT_CONFIG_VALUE_0: "/tmp/helper.sh", + KILO_API_KEY: "kilo-key-value", + KILO_ORG_ID: "org-value", + PATH: "/usr/bin:/bin", + UNRELATED: "keep-me", + } + const child = env(MODE.toolsDenied, base) + const withheld = [ + "GH_TOKEN", + "GITHUB_TOKEN", + "CROSS_REPO_ACCESS_TOKEN", + "CLOUD_REPO_TOKEN", + "SOME_BUILD_TOKEN", + "AWS_SECRET_ACCESS_KEY", + "NPM_TOKEN", + "DEPLOY_PASSWORD", + "GIT_CONFIG_COUNT", + "GIT_CONFIG_KEY_0", + "GIT_CONFIG_VALUE_0", + ] + for (const name of withheld) assert.equal(child[name], undefined, `${name} must not reach the child`) + assert.equal(child.KILO_API_KEY, "kilo-key-value", "the CLI authenticates with the gateway key") + assert.equal(child.KILO_ORG_ID, "org-value") + assert.equal(child.PATH, "/usr/bin:/bin", "a non-credential name must survive the filter") + assert.equal(child.UNRELATED, "keep-me") + assert.ok(child.KILO_CONFIG_CONTENT, "the child needs the mode's config") + assert.deepEqual(JSON.parse(child.KILO_CONFIG_CONTENT).permission, policy().modes["tools-denied"].permission) +}) + +check("configContent merges over an existing KILO_CONFIG_CONTENT", () => { + const base = JSON.stringify({ provider: { test: { npm: "@ai-sdk/openai-compatible" } } }) + const cfg = JSON.parse(configContent(MODE.toolsDenied, base)) + assert.ok(cfg.provider.test, "existing provider config must survive") + assert.deepEqual(cfg.permission, { "*": "deny", read: "allow" }) +}) + +// A base may carry provider settings, and the mode still owns every rule: a +// base rule would land before the catch-all, where evaluation never reaches it, +// and a base value the CLI rejects would drop the whole config. +check("the emitted permission map is the mode's, whatever the base holds", () => { + const base = JSON.stringify({ + provider: { test: { npm: "@ai-sdk/openai-compatible" } }, + permission: { read: "deny", webfetch: 5, bash: { "*": "allow" } }, + }) + for (const mode of [MODE.docsWrite, MODE.toolsDenied]) { + const cfg = JSON.parse(configContent(mode, base)) + assert.deepEqual(cfg.permission, policy().modes[mode].permission, `${mode} must own its permission map`) + assert.equal(Object.keys(cfg.permission)[0], "*", `${mode} must keep the catch-all first`) + assert.ok(cfg.provider.test, `${mode} must keep the caller's provider settings`) + validateMode(mode, { permission: cfg.permission }) + } +}) + +check("configContent rejects an unknown mode", () => { + assert.throws(() => configContent("nope"), /unknown agent policy mode/) +}) + +// 2b. Each mode must state a usable rule map, so a run always carries the +// scope its mode declares. +check("validateMode accepts both committed modes", () => { + for (const mode of [MODE.toolsDenied, MODE.docsWrite]) { + validateMode(mode, policy().modes[mode]) + } +}) + +check("validateMode rejects a mode without the leading catch-all deny", () => { + assert.throws(() => validateMode("x", { permission: { read: "allow" } }), /first rule must be "\*": "deny"/) + assert.throws( + () => validateMode("x", { permission: { "*": "allow", read: "allow" } }), + /first rule must be "\*": "deny"/, + ) +}) + +check("validateMode rejects an invalid action value", () => { + assert.throws(() => validateMode("x", { permission: { "*": "deny", edit: "permit" } }), /rule "edit" must be/) + assert.throws( + () => validateMode("x", { permission: { "*": "deny", edit: { "*": "deny", "docs/*.md": "write" } } }), + /rule "edit" pattern "docs\/\*\.md" must be/, + ) + assert.throws(() => validateMode("x", { permission: { "*": "deny", read: 5 } }), /rule "read" must be/) +}) + +// A headless run has no one to answer an ask, so a mode that leaves one would +// fail at that tool call instead of before the model starts. The validator is +// where that guarantee is kept, for a whole rule and for one pattern. +check("validateMode rejects an ask, at a rule and at a pattern", () => { + assert.throws( + () => validateMode("x", { permission: { "*": "deny", bash: "ask" } }), + /rule "bash" must be allow, deny, null/, + ) + assert.throws( + () => validateMode("x", { permission: { "*": "deny", bash: { "*": "deny", "ls *": "ask" } } }), + /rule "bash" pattern "ls \*" must be allow, deny or null/, + ) +}) + +check("validateMode rejects a non-object permission map", () => { + assert.throws(() => validateMode("x", {}), /permission must be an object/) + assert.throws(() => validateMode("x", { permission: "deny" }), /permission must be an object/) + assert.throws(() => validateMode("x", { permission: [] }), /permission must be an object/) + assert.throws(() => validateMode("x", undefined), /no mode entry/) +}) + +check("configContent validates the mode before it merges", () => { + const src = read(".github/docs-sync/agent-policy.mjs") + const call = src.lastIndexOf("validateMode(mode, entry)") + assert.ok(call >= 0, "configContent must call validateMode, so env and the CLI entry point fail too") + assert.ok(call > src.indexOf("unknown agent policy mode"), "the unknown-mode error must stay the first rejection") + assert.ok(call < src.indexOf("merged.permission"), "validation must run before the merge") +}) + +// 3. Every kilo call site names a mode, and none passes --auto. +check("runKilo requires a mode", () => { + assert.match(read(".github/docs-sync/lib.mjs"), /if \(!mode\) throw new Error\(`runKilo: mode is required/) +}) + +for (const file of ["triage.mjs", "edit.mjs", "learn.mjs"]) { + check(`${file} names its policy mode`, () => { + assert.match(read(`.github/docs-sync/${file}`), /mode: MODE\.(docsWrite|toolsDenied)/) + }) + check(`${file} never passes --auto`, () => { + const src = read(`.github/docs-sync/${file}`) + assert.ok(!/"--auto"/.test(src), `${file} must not pass --auto`) + }) +} + +check("the fix step runs kilo without --auto and with the policy", () => { + const block = step("Fix verify failures") + assert.ok(block.includes("agent-policy.mjs docs-write"), "fix step must export the docs-write policy") + assert.ok(!/\s--auto\b/.test(block), "fix step must not pass --auto") +}) + +check("the fix step requires a built policy before it runs", () => { + const block = step("Fix verify failures") + // Build the policy into a variable of its own, so its result is visible + // before `kilo run` starts. + assert.match( + block, + /if ! \w+="\$\(node \.github\/docs-sync\/agent-policy\.mjs docs-write\)" \|\| \[ -z "\$\w+" \]; then/, + "the fix step must assign the policy to a variable and check the assignment", + ) + assert.match(block, /^\s+exit 1$/m, "the check must stop the step") + const guard = block.search(/if ! \w+="\$\(node \.github\/docs-sync\/agent-policy\.mjs docs-write\)"/) + const kilo = block.indexOf("kilo run") + assert.ok( + guard >= 0 && kilo > guard, + "`kilo run` must come after the check, so the pass always carries its policy", + ) + // The policy variable, not a second inline substitution, is what the CLI gets. + assert.match( + block, + /KILO_CONFIG_CONTENT="\$\w+" \\\n\s+kilo run/, + "kilo run must read KILO_CONFIG_CONTENT from the guarded variable", + ) + assert.ok( + block.includes('--variant "$DOCS_SYNC_VARIANT"') && block.includes("-f docs-sync-out/verify.log"), + "the step keeps --variant and the verify.log attachment", + ) + assert.match(block, /\| node \.github\/docs-sync\/redact-stream\.mjs/, "the step keeps the redaction filter") + assert.match( + block, + /tee -a docs-sync-out\/edit-log\.txt[\s\S]*\|\| echo "::warning::/, + "the redaction + tee pipeline keeps its || echo warning guard", + ) +}) + +check("the re-verify step is bounded", () => { + assert.match( + step("Re-verify docs after the fix pass"), + /^ timeout-minutes: 10$/m, + "the rebuild must not run to the job timeout", + ) +}) + +check("the edit pass pipes the CLI stream through the redaction filter", () => { + assert.match( + step("Update docs"), + /node \.github\/docs-sync\/edit\.mjs \| node \.github\/docs-sync\/redact-stream\.mjs/, + "the streamed CLI output must pass the same filter the fix step uses", + ) +}) + +// 4. Gateway credentials live on the steps that call the CLI, nowhere else. +const agentSteps = ["Learn from maintainer corrections", "Triage merged PRs", "Update docs", "Fix verify failures"] +const agentKeys = ["KILO_API_KEY", "KILO_ORG_ID"] + +check("no gateway secret sits at job level", () => { + const job = syncJob() + const header = job.slice(0, job.indexOf("\n steps:")) + for (const key of agentKeys) assert.ok(!new RegExp(`^\\s+${key}:`, "m").test(header), `${key} must not be job-level`) +}) + +for (const name of agentSteps) { + check(`step "${name}" carries the gateway credentials it calls with`, () => { + const block = step(name) + for (const key of agentKeys) assert.ok(block.includes(key + ": ${{ secrets." + key + " }}"), `${name} must set ${key}`) + }) +} + +check("no non-agent step carries a gateway credential", () => { + const blocks = syncJob().split("\n - name: ") + for (const block of blocks) { + const name = block.split("\n")[0] + if (!name || agentSteps.some((n) => name.startsWith(n))) continue + for (const key of agentKeys) assert.ok(!block.includes(key), `step "${name}" must not carry ${key}`) + } +}) + +check("the docs build secret stays out of the agent step", () => { + const block = step("Fix verify failures") + assert.ok(!block.includes("POSTHOG_API_KEY"), "the agent step must not hold the docs build secret") + assert.ok(step("Re-verify docs after the fix pass").includes("POSTHOG_API_KEY"), "the rebuild step keeps it") +}) + +// 5. No git credential is left in the worktree, and the steps that push carry +// the token only in their own environment. +check("the checkout does not persist credentials", () => { + const block = step("Checkout repository") + assert.match(block, /persist-credentials: false/, "checkout must not persist the token") +}) + +for (const name of ["Learn from maintainer corrections", "Prepare rolling branch", "Upsert rolling PR"]) { + check(`step "${name}" authenticates git from its own environment`, () => { + const block = step(name) + assert.ok(block.includes("GH_TOKEN: ${{ github.token }}"), `${name} needs the token for its git calls`) + assert.ok( + block.includes("GIT_CONFIG_VALUE_0: ${{ runner.temp }}/docs-sync-credential.sh"), + `${name} must use the env credential helper`, + ) + }) +} + +check("the helper step writes the credential helper outside the worktree", () => { + const block = step("Install git credential helper") + assert.ok(block.includes('"$RUNNER_TEMP/docs-sync-credential.sh"'), "helper must live in RUNNER_TEMP") + assert.ok(!/git config/.test(block), "helper install must not touch git config") +}) + +check("the helper reads the token from the calling step's environment", () => { + const block = step("Install git credential helper") + assert.match(block, /test -n "\$GH_TOKEN" \|\| exit 0/, "the helper must fail closed without a token") + assert.match(block, /printf 'username=x-access-token\\npassword=%s\\n' "\$GH_TOKEN"/, "the helper must supply the token") +}) + +if (failures.length > 0) { + console.error(`\n${failures.length} check(s) failed`) + process.exit(1) +} +console.log("\nagent-policy: all checks passed") diff --git a/.github/docs-sync/edit.mjs b/.github/docs-sync/edit.mjs index 48a19a0c372..e37387e0343 100644 --- a/.github/docs-sync/edit.mjs +++ b/.github/docs-sync/edit.mjs @@ -19,6 +19,7 @@ import fs from "node:fs" import path from "node:path" import { fileURLToPath } from "node:url" +import { MODE } from "./agent-policy.mjs" import { backoffMsForAttempt, deadline, remainingMs, REASONING_VARIANT, runKilo, sleepSync } from "./lib.mjs" import { readLearningsBlock } from "./learn.mjs" @@ -77,15 +78,13 @@ Batch specifics for this run: the PRs to handle are in the attached ${batchFile} break } - // Headless `kilo run` auto-rejects every permission ask; without --auto the - // agent cannot run shell commands. SECURITY: --auto grants unrestricted bash - // to an agent steered by external PR content. Hardening deferred: a scoped - // permission.bash map via KILO_CONFIG_CONTENT should replace --auto once the - // required shell patterns are stable (see PR #12605 review thread). + // The run's tool and path scope comes from agent-permissions.json (mode + // docs-write), passed as KILO_CONFIG_CONTENT: writes under packages/kilo-docs, + // read-only inspection and the docs build and tests, everything else denied. const result = runKilo({ + mode: MODE.docsWrite, args: [ "run", - "--auto", prompt, "-m", model, diff --git a/.github/docs-sync/learn.mjs b/.github/docs-sync/learn.mjs index 99eb0aca205..cb16352ac49 100644 --- a/.github/docs-sync/learn.mjs +++ b/.github/docs-sync/learn.mjs @@ -434,6 +434,7 @@ async function extract() { runKilo, sleepSync, } = await import("./lib.mjs") + const { MODE } = await import("./agent-policy.mjs") // Step 1: resolve every open auto-docs surface PR. With one PR per surface, // maintainer corrections live on any of them, so learn from all of them @@ -783,10 +784,9 @@ async function extract() { log(`wrote ${inputFile} with ${candidates.length} candidates`) // Step 10: call the model. - // Deliberately no --auto. Every input is in the attached file and the output goes to - // stdout, so the agent needs no tool. Omitting --auto makes "the extraction step never - // writes outside LEARNINGS.md" structurally true instead of prompt-deep. triage.mjs:76 - // and edit.mjs:86 carry the opposite comment; do not copy them without updating the reason. + // Every input is in the attached file and the output goes to stdout, so the + // extraction needs no tool. The tools-denied mode (agent-permissions.json) + // makes that a CLI-enforced property of the run. const prompt = fs.readFileSync(path.join(HERE, "learnings-prompt.md"), "utf8") const model = process.env.TRIAGE_MODEL if (!model) throw new Error("TRIAGE_MODEL is required") @@ -804,6 +804,7 @@ async function extract() { } const result = runKilo({ + mode: MODE.toolsDenied, args: ["run", prompt, "-m", model, "--variant", REASONING_VARIANT, "--dir", process.cwd(), "-f", inputFile], timeoutMs: Math.min(EXTRACTION_TIMEOUT_MS, left), streamStdout: false, diff --git a/.github/docs-sync/lib.mjs b/.github/docs-sync/lib.mjs index e10f4564c06..d5835b240a5 100644 --- a/.github/docs-sync/lib.mjs +++ b/.github/docs-sync/lib.mjs @@ -8,6 +8,7 @@ import { spawnSync } from "node:child_process" import fs from "node:fs" +import { env as policyEnv } from "./agent-policy.mjs" // Test hook: DOCS_SYNC_API_BASE points the API at a local stub server. The workflow // never sets it — only selftests do. @@ -234,12 +235,19 @@ const STDERR_LOG_MAX_CHARS = 8 * 1024 * 1024 * Always writes the full captured stderr to * docs-sync-out/kilo-stderr-.log (unconditional — success and * failure). The console return value still uses the short tailText. + * + * `mode` is the policy from agent-permissions.json, exported as + * KILO_CONFIG_CONTENT so the CLI enforces the tool and path scope of the run. + * A permission left as an ask would end a headless run, so every mode either + * allows or denies each one. */ -export function runKilo({ args, timeoutMs, streamStdout = false, label = "kilo" }) { +export function runKilo({ args, timeoutMs, streamStdout = false, label = "kilo", mode }) { + if (!mode) throw new Error(`runKilo: mode is required (agent-policy MODE) for ${label}`) const result = spawnSync("kilo", args, { encoding: "utf8", maxBuffer: 32 * 1024 * 1024, timeout: timeoutMs, + env: policyEnv(mode), stdio: ["ignore", streamStdout ? "inherit" : "pipe", "pipe"], }) diff --git a/.github/docs-sync/model-config.test.mjs b/.github/docs-sync/model-config.test.mjs index a4543c4caa0..c6c827d5f7e 100644 --- a/.github/docs-sync/model-config.test.mjs +++ b/.github/docs-sync/model-config.test.mjs @@ -128,17 +128,31 @@ for (const file of ["triage.mjs", "edit.mjs", "learn.mjs"]) { }) } -// 5. The deliberate --auto difference is preserved: triage/edit grant bash to the -// agent; the learnings extraction stays tool-free (learn.mjs:694-697). -for (const file of ["triage.mjs", "edit.mjs"]) { - check(`${file} keeps --auto`, () => { +// 5. The agent scope is enforced by config, not by --auto. Every runKilo call +// names a policy mode, and no docs-sync kilo invocation passes --auto. +for (const file of ["triage.mjs", "edit.mjs", "learn.mjs"]) { + check(`${file} passes a policy mode to runKilo`, () => { + const src = read(`.github/docs-sync/${file}`) + assert.match(src, /runKilo\(\{\s*\n\s*mode: MODE\.(docsWrite|toolsDenied),/, `${file} must pass mode: MODE.* to runKilo`) + }) + check(`${file} does not pass --auto`, () => { const arrays = runKiloArgArrays(read(`.github/docs-sync/${file}`)) - for (const args of arrays) assert.ok(args.includes('"--auto"'), `argv is missing --auto: ${args}`) + for (const args of arrays) assert.ok(!args.includes('"--auto"'), `${file} must not pass --auto: ${args}`) }) } -check("learn.mjs stays without --auto", () => { - const arrays = runKiloArgArrays(read(".github/docs-sync/learn.mjs")) - for (const args of arrays) assert.ok(!args.includes('"--auto"'), `learn.mjs must not pass --auto: ${args}`) +check("agent-policy.mjs exports both modes", () => { + const src = read(".github/docs-sync/agent-policy.mjs") + assert.match(src, /toolsDenied: "tools-denied"/) + assert.match(src, /docsWrite: "docs-write"/) +}) + +// 5b. The workflow's repair pass uses the same policy and no --auto. +check("workflow fix step runs kilo under the committed policy without --auto", () => { + const block = stepBlock("Fix verify failures") + assert.ok(block, "Fix verify failures step not found") + assert.ok(block.includes("node .github/docs-sync/agent-policy.mjs docs-write"), "fix step must export the docs-write policy") + assert.ok(block.includes("KILO_CONFIG_CONTENT="), "fix step must pass KILO_CONFIG_CONTENT to kilo run") + assert.ok(!/\s--auto\b/.test(block), "fix step must not pass --auto") }) // 6. The workflow's fix step passes the same effort as the scripts. diff --git a/.github/docs-sync/selftest.mjs b/.github/docs-sync/selftest.mjs index c2193aac1d5..4823473033e 100644 --- a/.github/docs-sync/selftest.mjs +++ b/.github/docs-sync/selftest.mjs @@ -91,7 +91,7 @@ const mode = ${JSON.stringify(mode)}; const callLog = ${JSON.stringify(callLog ?? "")}; const stderrText = ${JSON.stringify(stderrText)}; if (callLog) { - fs.appendFileSync(callLog, JSON.stringify({ argv: process.argv.slice(2), cwd: process.cwd() }) + "\\n"); + fs.appendFileSync(callLog, JSON.stringify({ argv: process.argv.slice(2), cwd: process.cwd(), policy: process.env.KILO_CONFIG_CONTENT ?? null }) + "\\n"); } if (mode === "stderr-exit0") { process.stderr.write(stderrText + "\\n"); @@ -475,16 +475,19 @@ function kiloStderrLogName(label) { } function case2b_autoFlag() { - console.log("case 2b: AC4a (--auto on every docs-sync kilo run)") + console.log("case 2b: AC4a (agent scope from the committed policy, never --auto)") // (i) region-scoped static check on triage.mjs / edit.mjs argv arrays for (const name of ["triage.mjs", "edit.mjs"]) { const src = fs.readFileSync(path.join(HERE, name), "utf8") const slice = extractArgsArraySlice(src) - assert.ok(slice.includes('"--auto"'), `${name} args array must contain "--auto"; got:\n${slice}`) + assert.ok(!slice.includes('"--auto"'), `${name} args array must not contain "--auto"; got:\n${slice}`) + assert.match(src, /mode: MODE\.(docsWrite|toolsDenied)/, `${name} must pass a policy mode to runKilo`) } - // (ii) Fix verify failures step: join the run: | block and require --auto on kilo run + // (ii) Fix verify failures step: no --auto, and the policy comes from the + // committed file. The rebuild lives in its own step now, so the guard check + // covers only the agent's pipeline. { const yml = fs.readFileSync(path.join(HERE, "..", "workflows", "docs-sync.yml"), "utf8") const stepIdx = yml.indexOf("Fix verify failures") @@ -513,29 +516,24 @@ function case2b_autoFlag() { .replace(/\s+/g, " ") assert.match(joined, /kilo run\b/, `expected kilo run in Fix verify block:\n${joined}`) const kiloCmd = joined.match(/kilo run\b[^|]*/)?.[0] ?? "" - assert.ok( - /\s--auto\b/.test(kiloCmd) || /kilo run\s+--auto\b/.test(kiloCmd), - `Fix verify kilo run must contain --auto; got: ${kiloCmd}`, - ) + assert.ok(!/\s--auto\b/.test(kiloCmd), `Fix verify kilo run must not contain --auto; got: ${kiloCmd}`) + assert.match(joined, /agent-policy\.mjs docs-write/, "Fix verify must export the docs-write policy") // The step runs under `set -o pipefail` + the default `bash -e`, so an - // unguarded kilo pipeline aborts the block before verify2.log is written - // once the CLI exits nonzero on a mid-stream error. The rebuild must decide - // this step's outcome, not the agent's exit code. - // Window is the end of the kilo pipeline → the rebuild, so a comment - // elsewhere in the block cannot satisfy the guard assertion. + // unguarded kilo pipeline aborts the block once the CLI exits nonzero on a + // mid-stream error. The agent's exit code must not decide the job. const teeIdx = joined.indexOf("tee -a docs-sync-out/edit-log.txt") assert.ok(teeIdx >= 0, `expected the kilo pipeline to tee edit-log.txt:\n${joined}`) - const kiloPipeline = joined.slice(teeIdx, joined.indexOf("bun run", teeIdx)) + const kiloPipeline = joined.slice(teeIdx) assert.match( kiloPipeline, /\|\|\s*(echo|true)\b/, - `Fix verify kilo pipeline must be guarded (|| echo/true) so bash -e cannot skip the rebuild; got: ${kiloPipeline}`, + `Fix verify kilo pipeline must be guarded (|| echo/true) so bash -e cannot abort; got: ${kiloPipeline}`, ) - assert.match(joined, /verify2\.log/, "Fix verify block must still write verify2.log") } - // (iii) authoritative: real stub invocations with callLog — every argv has --auto + // (iii) authoritative: real stub invocations with callLog — every argv is + // --auto-free and carries the docs-write policy the CLI enforces. { const prs = [1, 2, 3, 4, 5].map((n) => samplePr(n)) const worthy = prs @@ -568,11 +566,18 @@ function case2b_autoFlag() { const lines = fs.readFileSync(callLog, "utf8").trim().split("\n").filter(Boolean) assert.ok(lines.length > 0, "callCount > 0 required (vacuous empty log forbidden)") for (const line of lines) { - const { argv } = JSON.parse(line) + const { argv, policy } = JSON.parse(line) assert.ok( - Array.isArray(argv) && argv.includes("--auto"), - `every kilo argv must include --auto; got ${JSON.stringify(argv)}`, + Array.isArray(argv) && !argv.includes("--auto"), + `every kilo argv must omit --auto; got ${JSON.stringify(argv)}`, ) + assert.ok(typeof policy === "string" && policy.length > 0, "every kilo invocation must carry KILO_CONFIG_CONTENT") + const permission = JSON.parse(policy).permission + assert.equal(permission.edit["*"], "deny", "the edit policy must deny writes by default") + assert.equal(permission.edit["packages/kilo-docs/pages/*.md"], "allow", "the edit policy must allow the docs pages") + assert.equal(permission.edit["packages/kilo-docs/lib/nav/*"], "allow", "the edit policy must allow the docs navigation") + assert.equal(permission.read, "allow", "the edit policy must allow read, which the CLI uses for a -f attachment") + assert.equal(permission.bash["git *"], "deny", "the edit policy must deny git") } } } diff --git a/.github/docs-sync/triage.mjs b/.github/docs-sync/triage.mjs index 87b2fde8e3a..72a262f2df7 100644 --- a/.github/docs-sync/triage.mjs +++ b/.github/docs-sync/triage.mjs @@ -21,6 +21,7 @@ import fs from "node:fs" import path from "node:path" import { fileURLToPath } from "node:url" import { parseTriageEntries } from "./extract-json.mjs" +import { MODE } from "./agent-policy.mjs" import { appendSummary, backoffMsForAttempt, @@ -81,15 +82,12 @@ function triageChunk(chunk, index, budgetDeadline) { break } - // Headless `kilo run` auto-rejects every permission ask; without --auto the - // agent cannot run shell commands. SECURITY: --auto grants unrestricted bash - // to an agent steered by external PR content. Hardening deferred: a scoped - // permission.bash map via KILO_CONFIG_CONTENT should replace --auto once the - // required shell patterns are stable (see PR #12605 review thread). + // Classification reads the attached digest only. The mode permits nothing + // but the attachment read, which the CLI itself issues for a -f file. const result = runKilo({ + mode: MODE.toolsDenied, args: [ "run", - "--auto", prompt, "-m", model, diff --git a/.github/workflows/docs-sync.yml b/.github/workflows/docs-sync.yml index 6fe23bc00d0..666d7cdc8a0 100644 --- a/.github/workflows/docs-sync.yml +++ b/.github/workflows/docs-sync.yml @@ -10,6 +10,14 @@ name: docs-sync # this workflow and .github/docs-sync/**) execute branch code only in a # read-only, secretless `selftest` job that never pushes, comments, or calls an # LLM. `pull_request` (not `pull_request_target`) keeps fork tokens read-only. +# +# Every headless Kilo CLI pass runs under the committed policy in +# .github/docs-sync/agent-permissions.json (exported as KILO_CONFIG_CONTENT), so +# the CLI itself bounds the agent's tools and write paths. Each pass carries only +# the gateway credentials it calls, the checkout persists no git credential, and +# the steps that need git authentication get the token from their own +# environment through the credential helper installed below. +# # State is derived from the bot's own PRs (watermark marker in the PR body), so # missed or failed runs self-heal on the next run. @@ -76,23 +84,31 @@ jobs: sync: if: github.repository == 'Kilo-Org/kilocode' && github.event_name != 'pull_request' runs-on: blacksmith-4vcpu-ubuntu-2404 - # Budget: 4 setup/collect + 10 learn + 90 triage + 120 edit + 2 verify + 10 fix + 2 upsert = 238 min, 12-minute reserve. + # Budget: 4 setup/collect + 10 learn + 90 triage + 120 edit + 2 verify + 10 fix + 10 re-verify + 2 upsert = 248 min, 2-minute reserve. # These are ceilings, not costs: a caught-up run triages ~2 chunks and edits # ~1 batch and finishes in ~25 min. The old 35/50 pair was the binding # constraint on backlog drain — run 30306629290 deferred 54 PRs untriaged and # 31 unedited purely on budget, with no attempt made. See the throughput note # in the PR description for the arithmetic. timeout-minutes: 250 - env: - # Both are required: without KILO_ORG_ID the gateway bills the key - # owner's personal balance (402 "Add credits") instead of the org. - KILO_API_KEY: ${{ secrets.KILO_API_KEY }} - KILO_ORG_ID: ${{ secrets.KILO_ORG_ID }} steps: - name: Checkout repository uses: actions/checkout@v6 with: fetch-depth: 0 # prepare-branch merges main into the rolling branch + persist-credentials: false # git steps authenticate per step, see Install git credential helper + + - name: Install git credential helper + # Written outside the worktree, so prepare-branch's branch switches cannot + # replace it mid-step. The helper reads the token from the calling step's + # own environment, so no credential is written to .git/config. + run: | + cat > "$RUNNER_TEMP/docs-sync-credential.sh" <<'HELPER' + test "$1" = get || exit 0 + test -n "$GH_TOKEN" || exit 0 + printf 'username=x-access-token\npassword=%s\n' "$GH_TOKEN" + HELPER + chmod +x "$RUNNER_TEMP/docs-sync-credential.sh" - name: Configure git identity run: | @@ -125,6 +141,12 @@ jobs: continue-on-error: true env: GH_TOKEN: ${{ github.token }} + # The CLI reads these natively; only the steps that call it carry them. + KILO_API_KEY: ${{ secrets.KILO_API_KEY }} + KILO_ORG_ID: ${{ secrets.KILO_ORG_ID }} + GIT_CONFIG_COUNT: "1" + GIT_CONFIG_KEY_0: credential.helper + GIT_CONFIG_VALUE_0: ${{ runner.temp }}/docs-sync-credential.sh LEARNINGS_BUDGET_MINUTES: "10" DRY_RUN: ${{ inputs.dry_run }} run: node .github/docs-sync/learn.mjs @@ -139,9 +161,11 @@ jobs: id: triage if: steps.collect.outputs.count != '0' env: + KILO_API_KEY: ${{ secrets.KILO_API_KEY }} + KILO_ORG_ID: ${{ secrets.KILO_ORG_ID }} SINCE_OVERRIDE: ${{ steps.wm.outputs.since_override }} # Default 35 fit only 8 of 11 chunks on a 254-PR window. Headroom for - # --auto making chunks slower now that the agent really runs commands. + # a chunk that has to re-read a large digest. TRIAGE_BUDGET_MINUTES: "90" run: node .github/docs-sync/triage.mjs @@ -166,6 +190,9 @@ jobs: if: (steps.worthy.outputs.count || '0') != '0' && inputs.dry_run != true env: GH_TOKEN: ${{ github.token }} + GIT_CONFIG_COUNT: "1" + GIT_CONFIG_KEY_0: credential.helper + GIT_CONFIG_VALUE_0: ${{ runner.temp }}/docs-sync-credential.sh run: node .github/docs-sync/prepare-branch.mjs # After prepare-branch checks out the rolling branch and merges main, the @@ -181,11 +208,17 @@ jobs: if: (steps.worthy.outputs.count || '0') != '0' && inputs.dry_run != true continue-on-error: true env: - # Default 50 fit only 4 of 11 batches. A healthy --auto batch is ~8 min, + KILO_API_KEY: ${{ secrets.KILO_API_KEY }} + KILO_ORG_ID: ${{ secrets.KILO_ORG_ID }} + # Default 50 fit only 4 of 11 batches. A healthy batch is ~8 min, # and edit.mjs will not start a batch without EDIT_BATCH_TIMEOUT_MINUTES # (15) left, so 120 covers 14 batches = 70 PRs against ~5 worthy/day. EDIT_BUDGET_MINUTES: "120" - run: node .github/docs-sync/edit.mjs + # This pass streams the CLI's own output, so the same line filter that + # guards the fix step must guard this stream before it reaches the job log. + run: | + set -o pipefail + node .github/docs-sync/edit.mjs | node .github/docs-sync/redact-stream.mjs - name: Verify docs build and tests id: verify @@ -203,22 +236,38 @@ jobs: continue-on-error: true timeout-minutes: 10 env: - NEXT_PUBLIC_POSTHOG_KEY: ${{ secrets.POSTHOG_API_KEY }} + KILO_API_KEY: ${{ secrets.KILO_API_KEY }} + KILO_ORG_ID: ${{ secrets.KILO_ORG_ID }} run: | set -o pipefail - # Headless kilo run auto-rejects every permission ask; the runner has no - # user config granting bash, so without --auto the agent cannot run ordinary - # shell commands against the repository. - kilo run --auto "The docs build or tests failed. Read the attached docs-sync-out/verify.log and fix the packages/kilo-docs changes so they pass. Do not revert doc edits; fix them. Do not modify anything outside packages/kilo-docs." \ + # The run's tool and path scope comes from agent-permissions.json + # (mode docs-write), passed as KILO_CONFIG_CONTENT: markdown docs and + # navigation files, read-only inspection, and the docs build and tests. + # Build the policy into a variable first and require a non-empty + # value: this step runs only when the policy is in place, and + # agent-policy.mjs validates the mode as it builds it. + if ! KILO_POLICY="$(node .github/docs-sync/agent-policy.mjs docs-write)" || [ -z "$KILO_POLICY" ]; then + echo "::error::the docs-write agent policy is required for this pass and could not be built" + exit 1 + fi + KILO_CONFIG_CONTENT="$KILO_POLICY" \ + kilo run "The docs build or tests failed. Read the attached docs-sync-out/verify.log and fix the packages/kilo-docs changes so they pass. Do not revert doc edits; fix them. Do not modify anything outside packages/kilo-docs." \ -m "$EDIT_MODEL" --variant "$DOCS_SYNC_VARIANT" --dir "$GITHUB_WORKSPACE" -f docs-sync-out/verify.log \ | node .github/docs-sync/redact-stream.mjs \ | tee -a docs-sync-out/edit-log.txt \ || echo "::warning::kilo fix pass exited nonzero; re-verifying anyway" - # The rebuild below decides this step's outcome, not the agent's exit code. - # Without the guard above, `set -o pipefail` + the default `bash -e` would - # abort here once the CLI half of this PR ships: a mid-stream session error - # (or an auto-rejected ask) exits 1, verify2.log is never written, and - # `Re-verify status` reports VERIFIED=false even when the docs build fine. + + - name: Re-verify docs after the fix pass + id: verify2 + if: steps.verify.outcome == 'failure' + continue-on-error: true + timeout-minutes: 10 + env: + NEXT_PUBLIC_POSTHOG_KEY: ${{ secrets.POSTHOG_API_KEY }} + run: | + set -o pipefail + # This step decides the outcome: a failed build or test fails it, and + # `set -o pipefail` is what carries that through the tee. { bun run --filter @kilocode/kilo-docs build && bun run --filter @kilocode/kilo-docs test; } 2>&1 | tee docs-sync-out/verify2.log - name: Re-verify status @@ -226,9 +275,9 @@ jobs: if: (steps.worthy.outputs.count || '0') != '0' && inputs.dry_run != true env: VERIFY_OUTCOME: ${{ steps.verify.outcome }} - FIX_OUTCOME: ${{ steps.fix.outcome }} + VERIFY2_OUTCOME: ${{ steps.verify2.outcome }} run: | - if [ "$VERIFY_OUTCOME" = "success" ] || [ "$FIX_OUTCOME" = "success" ]; then + if [ "$VERIFY_OUTCOME" = "success" ] || [ "$VERIFY2_OUTCOME" = "success" ]; then echo "ok=true" >> "$GITHUB_OUTPUT" else echo "ok=false" >> "$GITHUB_OUTPUT" @@ -242,6 +291,9 @@ jobs: if: (steps.worthy.outputs.count || '0') != '0' && inputs.dry_run != true env: GH_TOKEN: ${{ github.token }} + GIT_CONFIG_COUNT: "1" + GIT_CONFIG_KEY_0: credential.helper + GIT_CONFIG_VALUE_0: ${{ runner.temp }}/docs-sync-credential.sh # Read-only token for the Kilo-Org/cloud history; a cloud surface # falls back to the fixed `other` reviewers when it is unset. CLOUD_REPO_TOKEN: ${{ secrets.CROSS_REPO_ACCESS_TOKEN }}