@kody-ade/kody-engine 0.2.8 → 0.2.9

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/dist/bin/kody2.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // package.json
4
4
  var package_default = {
5
5
  name: "@kody-ade/kody-engine",
6
- version: "0.2.8",
6
+ version: "0.2.9",
7
7
  description: "kody2 \u2014 autonomous development engine. Single-session Claude Code agent behind a generic executor + declarative executable profiles.",
8
8
  license: "MIT",
9
9
  type: "module",
@@ -108,6 +108,7 @@ function loadConfig(projectDir = process.cwd()) {
108
108
  },
109
109
  issueContext: parseIssueContext(raw.issueContext),
110
110
  testRequirements: parseTestRequirements(raw.testRequirements),
111
+ defaultExecutable: typeof raw.defaultExecutable === "string" && raw.defaultExecutable.length > 0 ? raw.defaultExecutable : void 0,
111
112
  release: parseReleaseConfig(raw.release)
112
113
  };
113
114
  }
@@ -3223,11 +3224,13 @@ import * as path12 from "path";
3223
3224
 
3224
3225
  // src/dispatch.ts
3225
3226
  import * as fs14 from "fs";
3226
- function autoDispatch(explicit) {
3227
- if (explicit?.mode && explicit.target) {
3227
+ function autoDispatch(opts) {
3228
+ const explicit = opts?.explicit;
3229
+ if (explicit?.issueNumber && explicit.issueNumber > 0) {
3228
3230
  return {
3229
- mode: explicit.mode,
3230
- target: explicit.target
3231
+ executable: "build",
3232
+ cliArgs: { mode: "run", issue: explicit.issueNumber },
3233
+ target: explicit.issueNumber
3231
3234
  };
3232
3235
  }
3233
3236
  const eventName = process.env.GITHUB_EVENT_NAME;
@@ -3241,30 +3244,60 @@ function autoDispatch(explicit) {
3241
3244
  }
3242
3245
  if (eventName === "workflow_dispatch") {
3243
3246
  const n = parseInt(String(event.inputs?.issue_number ?? ""), 10);
3244
- if (!Number.isNaN(n) && n > 0) return { mode: "run", target: n };
3247
+ if (!Number.isNaN(n) && n > 0) {
3248
+ return { executable: "build", cliArgs: { mode: "run", issue: n }, target: n };
3249
+ }
3245
3250
  return null;
3246
3251
  }
3247
- if (eventName === "issue_comment") {
3248
- const body = String(event.comment?.body ?? "").toLowerCase();
3249
- const issueNum = Number(event.issue?.number ?? 0);
3250
- const isPr = !!event.issue?.pull_request;
3251
- if (!issueNum) return null;
3252
- const afterTag = extractAfterTag(body);
3253
- if (isPr) {
3254
- if (/\bfix-ci\b/.test(afterTag)) return { mode: "fix-ci", target: issueNum };
3255
- if (/\bresolve\b/.test(afterTag)) return { mode: "resolve", target: issueNum };
3256
- const feedbackText = extractFeedback(afterTag);
3257
- return { mode: "fix", target: issueNum, feedback: feedbackText };
3252
+ if (eventName !== "issue_comment") return null;
3253
+ const body = String(event.comment?.body ?? "").toLowerCase();
3254
+ const targetNum = Number(event.issue?.number ?? 0);
3255
+ const isPr = !!event.issue?.pull_request;
3256
+ if (!targetNum) return null;
3257
+ const afterTag = extractAfterTag(body);
3258
+ if (isPr) {
3259
+ if (/\bfix-ci\b/.test(afterTag)) {
3260
+ return { executable: "build", cliArgs: { mode: "fix-ci", pr: targetNum }, target: targetNum };
3261
+ }
3262
+ if (/\bresolve\b/.test(afterTag)) {
3263
+ return { executable: "build", cliArgs: { mode: "resolve", pr: targetNum }, target: targetNum };
3258
3264
  }
3259
- return { mode: "run", target: issueNum };
3265
+ const feedback = extractFeedback(afterTag);
3266
+ return {
3267
+ executable: "build",
3268
+ cliArgs: { mode: "fix", pr: targetNum, ...feedback ? { feedback } : {} },
3269
+ target: targetNum
3270
+ };
3260
3271
  }
3261
- return null;
3272
+ const sub = extractSubcommand(afterTag);
3273
+ const defaultExec = opts?.config?.defaultExecutable ?? "build";
3274
+ if (!sub) {
3275
+ return asDispatch(defaultExec, targetNum);
3276
+ }
3277
+ if (sub === "build") {
3278
+ return { executable: "build", cliArgs: { mode: "run", issue: targetNum }, target: targetNum };
3279
+ }
3280
+ if (sub === "orchestrate" || sub === "orchestrator") {
3281
+ return { executable: "orchestrator", cliArgs: { issue: targetNum }, target: targetNum };
3282
+ }
3283
+ return asDispatch(sub, targetNum);
3284
+ }
3285
+ function asDispatch(executable, target) {
3286
+ if (executable === "build") {
3287
+ return { executable, cliArgs: { mode: "run", issue: target }, target };
3288
+ }
3289
+ return { executable, cliArgs: { issue: target }, target };
3262
3290
  }
3263
3291
  function extractAfterTag(body) {
3264
3292
  const idx = body.indexOf("@kody2");
3265
3293
  if (idx === -1) return body;
3266
3294
  return body.slice(idx + "@kody2".length).trim();
3267
3295
  }
3296
+ function extractSubcommand(afterTag) {
3297
+ const match = afterTag.match(/^([a-z][a-z0-9-]{1,40})\b/);
3298
+ if (!match) return null;
3299
+ return match[1];
3300
+ }
3268
3301
  function extractFeedback(afterTag) {
3269
3302
  const cleaned = afterTag.replace(/^(fix|please|kindly)[\s:,.-]+/i, "").trim();
3270
3303
  return cleaned.length > 0 ? cleaned : void 0;
@@ -3463,7 +3496,13 @@ async function runCi(argv) {
3463
3496
  return 0;
3464
3497
  }
3465
3498
  const args = parseCiArgs(argv);
3466
- const autoFallback = !args.issueNumber ? autoDispatch() : null;
3499
+ const cwd = args.cwd ? path12.resolve(args.cwd) : process.cwd();
3500
+ let earlyConfig;
3501
+ try {
3502
+ earlyConfig = loadConfig(cwd);
3503
+ } catch {
3504
+ }
3505
+ const autoFallback = !args.issueNumber ? autoDispatch({ config: earlyConfig }) : null;
3467
3506
  if (!args.issueNumber && !autoFallback) {
3468
3507
  } else {
3469
3508
  args.errors = args.errors.filter((e) => !e.includes("--issue"));
@@ -3475,14 +3514,13 @@ async function runCi(argv) {
3475
3514
  ${CI_HELP}`);
3476
3515
  return 64;
3477
3516
  }
3478
- const cwd = args.cwd ? path12.resolve(args.cwd) : process.cwd();
3479
3517
  const dispatch = autoFallback ?? {
3480
- mode: "run",
3481
- target: args.issueNumber,
3482
- feedback: void 0
3518
+ executable: "build",
3519
+ cliArgs: { mode: "run", issue: args.issueNumber },
3520
+ target: args.issueNumber
3483
3521
  };
3484
3522
  const issueNumber = dispatch.target;
3485
- process.stdout.write(`\u2192 kody2 preflight (cwd=${cwd}, mode=${dispatch.mode}, target=${issueNumber})
3523
+ process.stdout.write(`\u2192 kody2 preflight (cwd=${cwd}, executable=${dispatch.executable}, target=${issueNumber})
3486
3524
  `);
3487
3525
  try {
3488
3526
  const n = unpackAllSecrets();
@@ -3519,17 +3557,13 @@ ${CI_HELP}`);
3519
3557
  postFailureTail(issueNumber, cwd, `preflight crashed: ${msg}`);
3520
3558
  return 99;
3521
3559
  }
3522
- process.stdout.write(`\u2192 kody2: preflight done, handing off to kody2 ${dispatch.mode}
3560
+ process.stdout.write(`\u2192 kody2: preflight done, handing off to kody2 ${dispatch.executable}
3523
3561
 
3524
3562
  `);
3525
3563
  try {
3526
- const config = loadConfig(cwd);
3527
- const cliArgs = { mode: dispatch.mode };
3528
- if (dispatch.mode === "run") cliArgs.issue = issueNumber;
3529
- else cliArgs.pr = issueNumber;
3530
- if (dispatch.feedback) cliArgs.feedback = dispatch.feedback;
3531
- const result = await runExecutable("build", {
3532
- cliArgs,
3564
+ const config = earlyConfig ?? loadConfig(cwd);
3565
+ const result = await runExecutable(dispatch.executable, {
3566
+ cliArgs: dispatch.cliArgs,
3533
3567
  cwd,
3534
3568
  config,
3535
3569
  verbose: args.verbose,
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "orchestrator",
3
+ "describe": "Drive a chain of kody2 executables by posting @kody2 subcommand comments and polling the task-state comment. Atomic — one orchestrator run fires one flow.",
4
+
5
+ "inputs": [
6
+ {
7
+ "name": "issue",
8
+ "flag": "--issue",
9
+ "type": "int",
10
+ "required": true,
11
+ "describe": "GitHub issue number to drive."
12
+ },
13
+ {
14
+ "name": "flow",
15
+ "flag": "--flow",
16
+ "type": "string",
17
+ "required": false,
18
+ "describe": "Named flow to run (e.g. 'plan-then-build'). Defaults to plan-then-build."
19
+ }
20
+ ],
21
+
22
+ "claudeCode": {
23
+ "model": "inherit",
24
+ "permissionMode": "default",
25
+ "maxTurns": null,
26
+ "systemPromptAppend": null,
27
+ "tools": ["Bash", "Read"],
28
+ "hooks": { "PreToolUse": [], "PostToolUse": [], "Stop": [] },
29
+ "skills": [],
30
+ "commands": [],
31
+ "subagents": [],
32
+ "plugins": [],
33
+ "mcpServers": []
34
+ },
35
+
36
+ "cliTools": [],
37
+
38
+ "scripts": {
39
+ "preflight": [
40
+ { "script": "runFlow" },
41
+ { "script": "loadTaskState" },
42
+ { "script": "composePrompt" }
43
+ ],
44
+ "postflight": [
45
+ { "script": "parseAgentResult" },
46
+ { "script": "postIssueComment" },
47
+ { "script": "writeRunSummary" },
48
+ { "script": "saveTaskState" }
49
+ ]
50
+ },
51
+
52
+ "output": {
53
+ "actionTypes": ["ORCHESTRATION_COMPLETED", "ORCHESTRATION_FAILED"]
54
+ }
55
+ }
@@ -0,0 +1,56 @@
1
+ You are the **kody2 orchestrator** for issue #{{issue.number}} on {{repoOwner}}/{{repoName}}.
2
+
3
+ Your job: drive a 2-step flow **plan → build** by posting `@kody2 <subcommand>` comments on the issue and watching the state-comment for completion signals. You do NOT edit files. You do NOT run git. You use `gh` (via Bash) only to post comments and read the state-comment.
4
+
5
+ ---
6
+
7
+ # Issue #{{issue.number}}: {{issue.title}}
8
+
9
+ {{issue.body}}
10
+
11
+ # Required flow (plan-then-build)
12
+
13
+ 1. **Kick off plan.** Post an issue comment with EXACTLY this body:
14
+ ```
15
+ @kody2 plan
16
+ ```
17
+ Use: `gh issue comment {{issue.number}} --body "@kody2 plan"` (in the cwd).
18
+ 2. **Wait for plan to complete.** Poll the issue's state-comment every ~30s. The state-comment is the one whose body starts with `<!-- kody2:state:v1:begin -->`. Fetch it with:
19
+ ```
20
+ gh api repos/{{repoOwner}}/{{repoName}}/issues/{{issue.number}}/comments --paginate --jq '.[] | select(.body | contains("kody2:state:v1:begin")) | .body'
21
+ ```
22
+ Parse the JSON block inside the sentinels. Look for `core.lastOutcome.type == "PLAN_COMPLETED"`.
23
+ If `core.lastOutcome.type == "PLAN_FAILED"` OR if 10 minutes pass without completion → abort with:
24
+ ```
25
+ FAILED: plan did not complete (<reason from state or "timeout">)
26
+ ```
27
+ 3. **Kick off build.** Post:
28
+ ```
29
+ @kody2 build
30
+ ```
31
+ Same `gh issue comment` command.
32
+ 4. **Wait for build to complete.** Same poll technique. Look for `core.lastOutcome.type == "RUN_COMPLETED"` (build's success marker) or `RUN_FAILED`. If `RUN_FAILED` or 30 minutes pass → abort with `FAILED: build did not complete (...)`.
33
+ 5. **Emit final summary.**
34
+
35
+ # Required final output
36
+
37
+ On success:
38
+
39
+ ```
40
+ DONE
41
+ COMMIT_MSG: chore(orchestrator): plan-then-build for #{{issue.number}}
42
+ PR_SUMMARY:
43
+ - Posted `@kody2 plan` and observed PLAN_COMPLETED.
44
+ - Posted `@kody2 build` and observed RUN_COMPLETED.
45
+ - Final PR: <prUrl from state>
46
+ ```
47
+
48
+ On failure, a single line: `FAILED: <concrete reason>`.
49
+
50
+ # Rules
51
+
52
+ - NEVER edit files. Read-only flow.
53
+ - NEVER run git. Only `gh` via Bash for comment posting and state polling.
54
+ - Between polls, sleep ~30 seconds. Do NOT poll faster than once every 30 seconds.
55
+ - Hard cap: 40 turns total across the whole flow. If you're approaching the cap, fail early with `FAILED: turn budget exhausted`.
56
+ - If you post an `@kody2` comment and the state-comment does NOT update within the poll window, the child executable likely didn't run — check the GitHub Actions runs tab URL via `gh run list --limit 5 --json conclusion,status,url` to diagnose, then fail with a concrete reason.
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "plan",
3
+ "describe": "Research an issue and produce a concrete implementation plan as a comment. Read-only — no branches, no commits.",
4
+
5
+ "inputs": [
6
+ {
7
+ "name": "issue",
8
+ "flag": "--issue",
9
+ "type": "int",
10
+ "required": true,
11
+ "describe": "GitHub issue number to plan."
12
+ }
13
+ ],
14
+
15
+ "claudeCode": {
16
+ "model": "inherit",
17
+ "permissionMode": "default",
18
+ "maxTurns": null,
19
+ "systemPromptAppend": null,
20
+ "tools": ["Read", "Grep", "Glob", "Bash"],
21
+ "hooks": { "PreToolUse": [], "PostToolUse": [], "Stop": [] },
22
+ "skills": [],
23
+ "commands": [],
24
+ "subagents": [],
25
+ "plugins": [],
26
+ "mcpServers": []
27
+ },
28
+
29
+ "cliTools": [],
30
+
31
+ "scripts": {
32
+ "preflight": [
33
+ { "script": "runFlow" },
34
+ { "script": "loadTaskState" },
35
+ { "script": "loadConventions" },
36
+ { "script": "composePrompt" }
37
+ ],
38
+ "postflight": [
39
+ { "script": "parseAgentResult" },
40
+ { "script": "postIssueComment" },
41
+ { "script": "writeRunSummary" },
42
+ { "script": "saveTaskState" }
43
+ ]
44
+ },
45
+
46
+ "output": {
47
+ "actionTypes": ["PLAN_COMPLETED", "PLAN_FAILED"]
48
+ }
49
+ }
@@ -0,0 +1,42 @@
1
+ You are a senior engineer producing an **implementation plan** for the GitHub issue below. You will NOT write code. You will NOT run git or gh commands. You will NOT modify files. Your only outputs are:
2
+
3
+ 1. Use Read / Grep / Glob / Bash (read-only) to study the codebase as much as needed.
4
+ 2. Emit a final message with the plan wrapped in the required markers (see "Required output").
5
+
6
+ ---
7
+
8
+ # Repo
9
+ - {{repoOwner}}/{{repoName}}, default branch: {{defaultBranch}}
10
+
11
+ # Issue #{{issue.number}}: {{issue.title}}
12
+
13
+ {{issue.body}}
14
+
15
+ Recent comments (most recent first, truncated):
16
+ {{issue.commentsFormatted}}
17
+
18
+ {{conventionsBlock}}
19
+
20
+ ---
21
+
22
+ # Required output
23
+
24
+ Your FINAL message must be exactly this shape (no extra text before or after):
25
+
26
+ ```
27
+ DONE
28
+ COMMIT_MSG: plan: <very short title>
29
+ PR_SUMMARY:
30
+ <A concrete implementation plan in markdown. Include:
31
+ - Files to change (with paths), and the change in each.
32
+ - New files to create, with their purpose and rough shape.
33
+ - Any ambiguities that need the human to resolve first.
34
+ - Verification checklist (typecheck / tests / lint expectations).
35
+ Keep to ~60 lines or less. No filler. No marketing language.>
36
+ ```
37
+
38
+ # Rules
39
+ - Read-only. Do NOT modify any file.
40
+ - Do NOT run git or gh commands.
41
+ - No speculative scope — plan only what the issue asks for.
42
+ - If the issue is ambiguous and you cannot make progress without input, output `FAILED: <what's unclear>` instead of a plan.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kody-ade/kody-engine",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "kody2 — autonomous development engine. Single-session Claude Code agent behind a generic executor + declarative executable profiles.",
5
5
  "license": "MIT",
6
6
  "type": "module",