@kody-ade/kody-engine 0.4.276 → 0.4.277
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/kody.js +46 -4
- package/package.json +1 -1
package/dist/bin/kody.js
CHANGED
|
@@ -15,7 +15,7 @@ var init_package = __esm({
|
|
|
15
15
|
"package.json"() {
|
|
16
16
|
package_default = {
|
|
17
17
|
name: "@kody-ade/kody-engine",
|
|
18
|
-
version: "0.4.
|
|
18
|
+
version: "0.4.277",
|
|
19
19
|
description: "kody \u2014 autonomous development engine. Single-session Claude Code agent behind a generic executor + declarative executable profiles.",
|
|
20
20
|
license: "MIT",
|
|
21
21
|
type: "module",
|
|
@@ -352,12 +352,25 @@ var init_issue = __esm({
|
|
|
352
352
|
}
|
|
353
353
|
});
|
|
354
354
|
|
|
355
|
+
// src/stateBranch.ts
|
|
356
|
+
var STATE_BRANCH;
|
|
357
|
+
var init_stateBranch = __esm({
|
|
358
|
+
"src/stateBranch.ts"() {
|
|
359
|
+
"use strict";
|
|
360
|
+
STATE_BRANCH = "kody-state";
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
355
364
|
// src/stateRepo.ts
|
|
356
365
|
import path2 from "path";
|
|
357
366
|
function is404(err) {
|
|
358
367
|
const msg = err instanceof Error ? err.message : String(err);
|
|
359
368
|
return /HTTP 404/i.test(msg) || /Not Found/i.test(msg);
|
|
360
369
|
}
|
|
370
|
+
function isAlreadyExists(err) {
|
|
371
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
372
|
+
return /HTTP 422/i.test(msg) || /Reference already exists/i.test(msg);
|
|
373
|
+
}
|
|
361
374
|
function parseStateRepoSlug(slug2, field = "stateRepo") {
|
|
362
375
|
const value = slug2.trim();
|
|
363
376
|
let repoPath = value;
|
|
@@ -428,11 +441,37 @@ function apiPath(config, targetPath) {
|
|
|
428
441
|
const parsed = parseStateRepo(config);
|
|
429
442
|
return `/repos/${parsed.owner}/${parsed.repo}/contents/${targetPath}`;
|
|
430
443
|
}
|
|
444
|
+
function branchApiPath(config, targetPath) {
|
|
445
|
+
return `${apiPath(config, targetPath)}?ref=${encodeURIComponent(STATE_BRANCH)}`;
|
|
446
|
+
}
|
|
447
|
+
function ensureStateBranch(config, cwd) {
|
|
448
|
+
const parsed = parseStateRepo(config);
|
|
449
|
+
try {
|
|
450
|
+
gh(["api", `/repos/${parsed.owner}/${parsed.repo}/git/ref/heads/${STATE_BRANCH}`], { cwd });
|
|
451
|
+
return;
|
|
452
|
+
} catch (err) {
|
|
453
|
+
if (!is404(err)) throw err;
|
|
454
|
+
}
|
|
455
|
+
const repoRaw = gh(["api", `/repos/${parsed.owner}/${parsed.repo}`], { cwd });
|
|
456
|
+
const defaultBranch = String(JSON.parse(repoRaw).default_branch ?? "").trim();
|
|
457
|
+
if (!defaultBranch) throw new Error(`stateRepo: ${parsed.owner}/${parsed.repo} default branch missing`);
|
|
458
|
+
const refRaw = gh(["api", `/repos/${parsed.owner}/${parsed.repo}/git/ref/heads/${defaultBranch}`], { cwd });
|
|
459
|
+
const sha = String(JSON.parse(refRaw).object?.sha ?? "").trim();
|
|
460
|
+
if (!sha) throw new Error(`stateRepo: ${parsed.owner}/${parsed.repo} ${defaultBranch} ref sha missing`);
|
|
461
|
+
try {
|
|
462
|
+
gh(["api", "--method", "POST", `/repos/${parsed.owner}/${parsed.repo}/git/refs`, "--input", "-"], {
|
|
463
|
+
cwd,
|
|
464
|
+
input: JSON.stringify({ ref: `refs/heads/${STATE_BRANCH}`, sha })
|
|
465
|
+
});
|
|
466
|
+
} catch (err) {
|
|
467
|
+
if (!isAlreadyExists(err)) throw err;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
431
470
|
function readStateText(config, cwd, filePath) {
|
|
432
471
|
const targetPath = stateRepoPath(config, filePath);
|
|
433
472
|
let raw = "";
|
|
434
473
|
try {
|
|
435
|
-
raw = gh(["api",
|
|
474
|
+
raw = gh(["api", branchApiPath(config, targetPath)], { cwd });
|
|
436
475
|
} catch (err) {
|
|
437
476
|
if (is404(err)) return null;
|
|
438
477
|
throw err;
|
|
@@ -457,9 +496,11 @@ function readStateText(config, cwd, filePath) {
|
|
|
457
496
|
}
|
|
458
497
|
function writeStateText(config, cwd, filePath, content, message, sha) {
|
|
459
498
|
const targetPath = stateRepoPath(config, filePath);
|
|
499
|
+
ensureStateBranch(config, cwd);
|
|
460
500
|
const payload = {
|
|
461
501
|
message,
|
|
462
|
-
content: Buffer.from(content, "utf-8").toString("base64")
|
|
502
|
+
content: Buffer.from(content, "utf-8").toString("base64"),
|
|
503
|
+
branch: STATE_BRANCH
|
|
463
504
|
};
|
|
464
505
|
if (sha) payload.sha = sha;
|
|
465
506
|
gh(["api", "--method", "PUT", apiPath(config, targetPath), "--input", "-"], {
|
|
@@ -490,7 +531,7 @@ function listStateDirectory(config, cwd, dirPath) {
|
|
|
490
531
|
const targetPath = stateRepoPath(config, dirPath);
|
|
491
532
|
let raw = "";
|
|
492
533
|
try {
|
|
493
|
-
raw = gh(["api",
|
|
534
|
+
raw = gh(["api", branchApiPath(config, targetPath)], { cwd });
|
|
494
535
|
} catch (err) {
|
|
495
536
|
if (is404(err)) return [];
|
|
496
537
|
throw err;
|
|
@@ -502,6 +543,7 @@ var init_stateRepo = __esm({
|
|
|
502
543
|
"src/stateRepo.ts"() {
|
|
503
544
|
"use strict";
|
|
504
545
|
init_issue();
|
|
546
|
+
init_stateBranch();
|
|
505
547
|
}
|
|
506
548
|
});
|
|
507
549
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kody-ade/kody-engine",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.277",
|
|
4
4
|
"description": "kody — autonomous development engine. Single-session Claude Code agent behind a generic executor + declarative executable profiles.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|