@kody-ade/kody-engine 0.2.0 → 0.2.1

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
@@ -2105,9 +2105,60 @@ function finish(out) {
2105
2105
  }
2106
2106
 
2107
2107
  // src/kody2-cli.ts
2108
- import * as fs10 from "fs";
2108
+ import * as fs11 from "fs";
2109
2109
  import * as path9 from "path";
2110
2110
  import { execFileSync as execFileSync11 } from "child_process";
2111
+
2112
+ // src/dispatch.ts
2113
+ import * as fs10 from "fs";
2114
+ function autoDispatch(explicit) {
2115
+ if (explicit?.mode && explicit.target) {
2116
+ return {
2117
+ mode: explicit.mode,
2118
+ target: explicit.target
2119
+ };
2120
+ }
2121
+ const eventName = process.env.GITHUB_EVENT_NAME;
2122
+ const eventPath = process.env.GITHUB_EVENT_PATH;
2123
+ if (!eventName || !eventPath || !fs10.existsSync(eventPath)) return null;
2124
+ let event = {};
2125
+ try {
2126
+ event = JSON.parse(fs10.readFileSync(eventPath, "utf-8"));
2127
+ } catch {
2128
+ return null;
2129
+ }
2130
+ if (eventName === "workflow_dispatch") {
2131
+ const n = parseInt(String(event.inputs?.issue_number ?? ""), 10);
2132
+ if (!Number.isNaN(n) && n > 0) return { mode: "run", target: n };
2133
+ return null;
2134
+ }
2135
+ if (eventName === "issue_comment") {
2136
+ const body = String(event.comment?.body ?? "").toLowerCase();
2137
+ const issueNum = Number(event.issue?.number ?? 0);
2138
+ const isPr = !!event.issue?.pull_request;
2139
+ if (!issueNum) return null;
2140
+ const afterTag = extractAfterTag(body);
2141
+ if (isPr) {
2142
+ if (/\bfix-ci\b/.test(afterTag)) return { mode: "fix-ci", target: issueNum };
2143
+ if (/\bresolve\b/.test(afterTag)) return { mode: "resolve", target: issueNum };
2144
+ const feedbackText = extractFeedback(afterTag);
2145
+ return { mode: "fix", target: issueNum, feedback: feedbackText };
2146
+ }
2147
+ return { mode: "run", target: issueNum };
2148
+ }
2149
+ return null;
2150
+ }
2151
+ function extractAfterTag(body) {
2152
+ const idx = body.indexOf("@kody2");
2153
+ if (idx === -1) return body;
2154
+ return body.slice(idx + "@kody2".length).trim();
2155
+ }
2156
+ function extractFeedback(afterTag) {
2157
+ const cleaned = afterTag.replace(/^(fix|please|kindly)[\s:,.-]+/i, "").trim();
2158
+ return cleaned.length > 0 ? cleaned : void 0;
2159
+ }
2160
+
2161
+ // src/kody2-cli.ts
2111
2162
  var CI_HELP = `kody2 ci \u2014 minimal-YAML autonomous engineer (CI preflight + run)
2112
2163
 
2113
2164
  Usage:
@@ -2192,9 +2243,9 @@ function resolveAuthToken(env = process.env) {
2192
2243
  return token;
2193
2244
  }
2194
2245
  function detectPackageManager(cwd) {
2195
- if (fs10.existsSync(path9.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
2196
- if (fs10.existsSync(path9.join(cwd, "yarn.lock"))) return "yarn";
2197
- if (fs10.existsSync(path9.join(cwd, "bun.lockb"))) return "bun";
2246
+ if (fs11.existsSync(path9.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
2247
+ if (fs11.existsSync(path9.join(cwd, "yarn.lock"))) return "yarn";
2248
+ if (fs11.existsSync(path9.join(cwd, "bun.lockb"))) return "bun";
2198
2249
  return "npm";
2199
2250
  }
2200
2251
  function shellOut(cmd, args, cwd, stream = true) {
@@ -2274,8 +2325,8 @@ function postFailureTail(issueNumber, cwd, reason) {
2274
2325
  const logPath = path9.join(cwd, ".kody2", "last-run.jsonl");
2275
2326
  let tail = "";
2276
2327
  try {
2277
- if (fs10.existsSync(logPath)) {
2278
- const content = fs10.readFileSync(logPath, "utf-8");
2328
+ if (fs11.existsSync(logPath)) {
2329
+ const content = fs11.readFileSync(logPath, "utf-8");
2279
2330
  tail = content.slice(-3e3);
2280
2331
  }
2281
2332
  } catch {
@@ -2300,6 +2351,11 @@ async function runCi(argv) {
2300
2351
  return 0;
2301
2352
  }
2302
2353
  const args = parseCiArgs(argv);
2354
+ const autoFallback = !args.issueNumber ? autoDispatch() : null;
2355
+ if (!args.issueNumber && !autoFallback) {
2356
+ } else {
2357
+ args.errors = args.errors.filter((e) => !e.includes("--issue"));
2358
+ }
2303
2359
  if (args.errors.length > 0 && !args.errors.includes("__HELP__")) {
2304
2360
  for (const e of args.errors) process.stderr.write(`error: ${e}
2305
2361
  `);
@@ -2307,8 +2363,13 @@ async function runCi(argv) {
2307
2363
  return 64;
2308
2364
  }
2309
2365
  const cwd = args.cwd ? path9.resolve(args.cwd) : process.cwd();
2310
- const issueNumber = args.issueNumber;
2311
- process.stdout.write(`\u2192 kody2 preflight (cwd=${cwd}, issue=${issueNumber})
2366
+ const dispatch = autoFallback ?? {
2367
+ mode: "run",
2368
+ target: args.issueNumber,
2369
+ feedback: void 0
2370
+ };
2371
+ const issueNumber = dispatch.target;
2372
+ process.stdout.write(`\u2192 kody2 preflight (cwd=${cwd}, mode=${dispatch.mode}, target=${issueNumber})
2312
2373
  `);
2313
2374
  try {
2314
2375
  const n = unpackAllSecrets();
@@ -2345,11 +2406,17 @@ async function runCi(argv) {
2345
2406
  postFailureTail(issueNumber, cwd, `preflight crashed: ${msg}`);
2346
2407
  return 99;
2347
2408
  }
2348
- process.stdout.write("\u2192 kody2: preflight done, handing off to kody2 run\n\n");
2409
+ process.stdout.write(`\u2192 kody2: preflight done, handing off to kody2 ${dispatch.mode}
2410
+
2411
+ `);
2349
2412
  try {
2350
2413
  const config = loadConfig(cwd);
2414
+ const cliArgs = { mode: dispatch.mode };
2415
+ if (dispatch.mode === "run") cliArgs.issue = issueNumber;
2416
+ else cliArgs.pr = issueNumber;
2417
+ if (dispatch.feedback) cliArgs.feedback = dispatch.feedback;
2351
2418
  const result = await runExecutable("build", {
2352
- cliArgs: { mode: "run", issue: issueNumber },
2419
+ cliArgs,
2353
2420
  cwd,
2354
2421
  config,
2355
2422
  verbose: args.verbose,
@@ -2451,7 +2518,7 @@ async function main(argv = process.argv.slice(2)) {
2451
2518
  return 0;
2452
2519
  }
2453
2520
  if (args.command === "version") {
2454
- process.stdout.write("kody2 0.2.0\n");
2521
+ process.stdout.write("kody2 0.2.1\n");
2455
2522
  return 0;
2456
2523
  }
2457
2524
  if (args.command === "ci") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kody-ade/kody-engine",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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",
@@ -30,7 +30,6 @@ jobs:
30
30
  if: >-
31
31
  ${{ github.event_name == 'workflow_dispatch' ||
32
32
  (github.event_name == 'issue_comment' &&
33
- !github.event.issue.pull_request &&
34
33
  contains(github.event.comment.body, '@kody2')) }}
35
34
  runs-on: ubuntu-latest
36
35
  timeout-minutes: 60
@@ -54,4 +53,4 @@ jobs:
54
53
 
55
54
  - env:
56
55
  ALL_SECRETS: ${{ toJSON(secrets) }}
57
- run: npx -y -p @kody-ade/engine@latest kody2 ci --issue ${{ github.event.inputs.issue_number || github.event.issue.number }}
56
+ run: npx -y -p @kody-ade/kody-engine@latest kody2 ci