wildcrane 0.11.65 → 0.11.66
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/kanban.mjs +1161 -1059
- package/package.json +1 -1
package/dist/kanban.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// ai4kanban 0.11.
|
|
2
|
+
// ai4kanban 0.11.66 — built from the CLI's TypeScript sources by cli/scripts/build.mjs.
|
|
3
3
|
// Do not edit: every change belongs in cli/src/, and a build overwrites this file.
|
|
4
4
|
import { createRequire as __ai4kanbanRequire } from 'node:module'
|
|
5
5
|
const require = __ai4kanbanRequire(import.meta.url)
|
|
@@ -452,13 +452,16 @@ __export(preview_stages_exports, {
|
|
|
452
452
|
previewBaseline: () => previewBaseline,
|
|
453
453
|
previewDisplay: () => previewDisplay,
|
|
454
454
|
previewReady: () => previewReady,
|
|
455
|
+
reportPreviewStage: () => reportPreviewStage,
|
|
455
456
|
resetPreviewSelection: () => resetPreviewSelection,
|
|
456
457
|
selectPreviewStages: () => selectPreviewStages,
|
|
457
|
-
submitPreviewStage: () => submitPreviewStage
|
|
458
|
+
submitPreviewStage: () => submitPreviewStage,
|
|
459
|
+
syncPreviewContent: () => syncPreviewContent
|
|
458
460
|
});
|
|
459
461
|
function selectPreviewStages(progress, ids) {
|
|
460
462
|
const wanted = new Set(ids);
|
|
461
463
|
if (!ids.length || wanted.size !== ids.length || ids.some((id) => !progress.definitions.some((stage) => stage.id === id))) throw Error("Choose a nonempty list of unique known stage IDs.");
|
|
464
|
+
if (progress.stages.some((stage) => stage.artifact || ["awaiting_confirmation", "confirmed"].includes(stage.status)) && JSON.stringify(progress.stages.map((stage) => stage.id)) !== JSON.stringify(ids)) throw Error("Wait for user approval before changing the selected stages.");
|
|
462
465
|
const chosen = ids.map((id) => progress.definitions.find((stage) => stage.id === id));
|
|
463
466
|
if (progress.stages.length) {
|
|
464
467
|
if (JSON.stringify(progress.stages.map((stage) => stage.id)) === JSON.stringify(ids)) return;
|
|
@@ -535,6 +538,7 @@ function choosePreviewRevision(progress, from, execution) {
|
|
|
535
538
|
const saved = progress.revisionBase ?? progress.stages;
|
|
536
539
|
const at2 = saved.findIndex((stage) => stage.id === from);
|
|
537
540
|
if (at2 < 0) throw Error("Unknown stage.");
|
|
541
|
+
if (saved.slice(0, at2).some((stage) => stage.status !== "confirmed")) throw Error("Wait for user approval before starting the next stage.");
|
|
538
542
|
progress.archivedSelections = [...progress.archivedSelections ?? [], structuredClone(saved)];
|
|
539
543
|
progress.stages = structuredClone(saved);
|
|
540
544
|
progress.generation++;
|
|
@@ -556,6 +560,39 @@ function resetPreviewSelection(progress) {
|
|
|
556
560
|
progress.displayedArtifact = null;
|
|
557
561
|
delete progress.revisionBase;
|
|
558
562
|
}
|
|
563
|
+
function syncPreviewContent(progress, body, assets) {
|
|
564
|
+
let stage = progress.stages.find((stage2) => stage2.id === progress.currentStageId);
|
|
565
|
+
if (stage?.status === "queued" && progress.displayedArtifact) stage = progress.stages.find((item) => item.id === progress.displayedArtifact.stageId);
|
|
566
|
+
if (!stage || !stage.artifact && !body.trim() && !Object.keys(assets).length) return;
|
|
567
|
+
if (stage.artifact?.body === body && JSON.stringify(stage.artifact.assets) === JSON.stringify(assets)) return;
|
|
568
|
+
const artifact = { stageId: stage.id, version: (stage.version ?? 0) + 1, body, assets: structuredClone(assets) };
|
|
569
|
+
stage.version = artifact.version;
|
|
570
|
+
stage.artifact = artifact;
|
|
571
|
+
stage.history = [...stage.history ?? [], artifact];
|
|
572
|
+
if (["confirmed", "ready", "awaiting_confirmation"].includes(stage.status)) stage.status = "running";
|
|
573
|
+
delete stage.confirmation;
|
|
574
|
+
const at2 = progress.stages.indexOf(stage);
|
|
575
|
+
if (progress.currentStageId !== stage.id) {
|
|
576
|
+
progress.currentStageId = stage.id;
|
|
577
|
+
progress.execution = null;
|
|
578
|
+
progress.generation++;
|
|
579
|
+
for (const next of progress.stages.slice(at2 + 1)) {
|
|
580
|
+
next.status = "stale";
|
|
581
|
+
delete next.confirmation;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
progress.displayedArtifact = artifact;
|
|
585
|
+
}
|
|
586
|
+
function reportPreviewStage(progress, stageId, status, execution) {
|
|
587
|
+
if (!progress.stages.length) selectPreviewStages(progress, [stageId]);
|
|
588
|
+
if (progress.currentStageId !== stageId) throw Error("Wait for user approval before starting the next stage.");
|
|
589
|
+
const baseline = previewBaseline(progress, stageId, execution);
|
|
590
|
+
const stage = progress.stages.find((stage2) => stage2.id === stageId);
|
|
591
|
+
if (status === "done") {
|
|
592
|
+
if (stage.status !== "confirmed") stage.status = progress.stages.at(-1)?.id === stageId ? "ready" : "awaiting_confirmation";
|
|
593
|
+
} else if (stage.status !== "confirmed") stage.status = "running";
|
|
594
|
+
return baseline;
|
|
595
|
+
}
|
|
559
596
|
var previewReady;
|
|
560
597
|
var init_preview_stages = __esm({
|
|
561
598
|
"src/lib/preview-stages.ts"() {
|
|
@@ -564,15 +601,780 @@ var init_preview_stages = __esm({
|
|
|
564
601
|
}
|
|
565
602
|
});
|
|
566
603
|
|
|
567
|
-
// src/
|
|
568
|
-
|
|
604
|
+
// ../artifact-sdk/src/internal/references.ts
|
|
605
|
+
function bodyReferences(body) {
|
|
606
|
+
const lines = body.replace(/<!--[^]*?-->/g, "").split(/\r?\n/);
|
|
607
|
+
let fence = "";
|
|
608
|
+
let inTag = false;
|
|
609
|
+
const out = [];
|
|
610
|
+
const visible = [];
|
|
611
|
+
for (const line of lines) {
|
|
612
|
+
const delimiter = /^ {0,3}(`{3,}|~{3,})/.exec(line)?.[1];
|
|
613
|
+
if (fence) {
|
|
614
|
+
if (delimiter && delimiter[0] === fence[0] && delimiter.length >= fence.length) fence = "";
|
|
615
|
+
visible.push("");
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
if (delimiter) {
|
|
619
|
+
fence = delimiter;
|
|
620
|
+
visible.push("");
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
const kept2 = inTag || !/^(?: {4}|\t)/.test(line);
|
|
624
|
+
visible.push(kept2 ? line : "");
|
|
625
|
+
if (kept2 && /^ {0,3}<(?:Asset|Mockup|Compare|Storyboard|Studio)\b/.test(line)) inTag = true;
|
|
626
|
+
if (line.includes("/>")) inTag = false;
|
|
627
|
+
}
|
|
628
|
+
const text6 = visible.join("\n").replace(/(`+)[^]*?\1/g, "");
|
|
629
|
+
const tag = /<(Asset|Mockup|Compare|Storyboard|Studio)\b([^<>]*?)\/>/g;
|
|
630
|
+
const blocks = text6.matchAll(/^ {0,3}(?:<(?:Asset|Mockup|Compare|Storyboard|Studio)\b[^<>]*?\/>[ \t]*(?:\n[ \t]*)?)+$/gm);
|
|
631
|
+
for (const block of blocks) {
|
|
632
|
+
const tags = [...block[0].matchAll(tag)];
|
|
633
|
+
for (const m of tags) {
|
|
634
|
+
const a2 = {};
|
|
635
|
+
for (const p2 of m[2].matchAll(/([\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)) a2[p2[1]] = p2[2] ?? p2[3];
|
|
636
|
+
if (m[1] === "Compare") {
|
|
637
|
+
if (!a2.a || !a2.b) continue;
|
|
638
|
+
for (const k2 of ["a", "b", "shots"]) if (a2[k2]) out.push({ src: a2[k2], types: ARRANGED });
|
|
639
|
+
} else if (a2.src) {
|
|
640
|
+
out.push({ src: a2.src, types: m[1] === "Storyboard" ? STORYBOARD : m[1] === "Studio" ? STUDIO : m[1] === "Asset" ? ASSET : [] });
|
|
641
|
+
if (a2.variants) {
|
|
642
|
+
try {
|
|
643
|
+
const v = JSON.parse(a2.variants);
|
|
644
|
+
if (isObject(v)) {
|
|
645
|
+
for (const src of Object.values(v)) if (typeof src === "string" && src) out.push({ src, types: m[1] === "Asset" ? ASSET : [] });
|
|
646
|
+
}
|
|
647
|
+
} catch {
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
for (const m of text6.replace(tag, "").matchAll(/\]\(\s*<?([^\s)>]+)>?(?:\s+["'][^]*?["'])?\s*\)/g)) out.push({ src: m[1], types: [] });
|
|
654
|
+
return out;
|
|
655
|
+
}
|
|
656
|
+
function kindOf(ext) {
|
|
657
|
+
if (ext === ".tsx" || ext === ".html") return "html";
|
|
658
|
+
if (ext === ".md" || ext === ".mdx") return "markdown";
|
|
659
|
+
if (ext === ".tmx" || ext === ".tmj" || ext === ".tsj") return "tiled";
|
|
660
|
+
const type = TYPES[ext] ?? "";
|
|
661
|
+
if (type.startsWith("image/")) return "image";
|
|
662
|
+
return type.startsWith("video/") || type.startsWith("audio/") ? "video" : "asset";
|
|
663
|
+
}
|
|
664
|
+
var STORYBOARD, STUDIO, ARRANGED, ASSET, isObject, bodySources, TYPES;
|
|
665
|
+
var init_references = __esm({
|
|
666
|
+
"../artifact-sdk/src/internal/references.ts"() {
|
|
667
|
+
"use strict";
|
|
668
|
+
STORYBOARD = ["storyboard"];
|
|
669
|
+
STUDIO = ["studio"];
|
|
670
|
+
ARRANGED = ["storyboard", "compare", "spritesheet", "studio"];
|
|
671
|
+
ASSET = ["spritesheet", "asset"];
|
|
672
|
+
isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
673
|
+
bodySources = (body) => [...new Set(bodyReferences(body).map((r2) => r2.src))];
|
|
674
|
+
TYPES = {
|
|
675
|
+
".png": "image/png",
|
|
676
|
+
".jpg": "image/jpeg",
|
|
677
|
+
".jpeg": "image/jpeg",
|
|
678
|
+
".gif": "image/gif",
|
|
679
|
+
".webp": "image/webp",
|
|
680
|
+
".svg": "image/svg+xml",
|
|
681
|
+
".mp4": "video/mp4",
|
|
682
|
+
".webm": "video/webm",
|
|
683
|
+
".mp3": "audio/mpeg",
|
|
684
|
+
".pdf": "application/pdf",
|
|
685
|
+
".html": "text/html",
|
|
686
|
+
".md": "text/markdown",
|
|
687
|
+
".mdx": "text/markdown",
|
|
688
|
+
".mov": "video/quicktime",
|
|
689
|
+
".wav": "audio/wav",
|
|
690
|
+
".m4a": "audio/mp4",
|
|
691
|
+
".json": "application/json",
|
|
692
|
+
".txt": "text/plain",
|
|
693
|
+
".otf": "font/otf",
|
|
694
|
+
".ttf": "font/ttf",
|
|
695
|
+
".woff": "font/woff",
|
|
696
|
+
".woff2": "font/woff2",
|
|
697
|
+
".css": "text/css",
|
|
698
|
+
".tmx": "application/xml",
|
|
699
|
+
".tmj": "application/json",
|
|
700
|
+
".tsj": "application/json"
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
// ../artifact-sdk/src/builtin/compare.json
|
|
706
|
+
var compare_default;
|
|
707
|
+
var init_compare = __esm({
|
|
708
|
+
"../artifact-sdk/src/builtin/compare.json"() {
|
|
709
|
+
compare_default = '{\n "name": "compare",\n "title": { "en": "Compare", "zh": "\u5BF9\u6BD4" },\n "types": ["compare"],\n "schema": {\n "type": "object",\n "required": ["a", "b"],\n "properties": { "a": { "type": "string" }, "b": { "type": "string" } }\n },\n "references": [\n { "json": "/a", "types": ["storyboard", "compare", "spritesheet", "studio"] },\n { "json": "/b", "types": ["storyboard", "compare", "spritesheet", "studio"] },\n { "json": "/shots", "types": ["storyboard", "compare", "spritesheet", "studio"] }\n ]\n}\n';
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
// ../artifact-sdk/src/builtin/html.json
|
|
714
|
+
var html_default;
|
|
715
|
+
var init_html = __esm({
|
|
716
|
+
"../artifact-sdk/src/builtin/html.json"() {
|
|
717
|
+
html_default = `{
|
|
718
|
+
"name": "html",
|
|
719
|
+
"title": { "en": "Page", "zh": "\u9875\u9762" },
|
|
720
|
+
"types": ["html"],
|
|
721
|
+
"references": [
|
|
722
|
+
{ "text": "<[a-z][^<>]*?\\\\ssrc\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
|
|
723
|
+
{ "text": "<[a-z][^<>]*?\\\\sposter\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
|
|
724
|
+
{ "text": "<[a-z][^<>]*?\\\\ssrcset\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']", "list": "," },
|
|
725
|
+
{ "text": "<link\\\\b[^<>]*?\\\\shref\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
|
|
726
|
+
{ "text": "url\\\\(\\\\s*[\\"']?([^\\"')]+?)[\\"']?\\\\s*\\\\)" }
|
|
727
|
+
],
|
|
728
|
+
"skip": ["(?<=<script\\\\b[^<>]*>)[\\\\s\\\\S]*?(?=</script\\\\s*>|$)"]
|
|
729
|
+
}
|
|
730
|
+
`;
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
// ../artifact-sdk/src/builtin/image.json
|
|
735
|
+
var image_default;
|
|
736
|
+
var init_image = __esm({
|
|
737
|
+
"../artifact-sdk/src/builtin/image.json"() {
|
|
738
|
+
image_default = '{ "name": "image", "title": { "en": "Image", "zh": "\u56FE\u7247" }, "types": ["image"] }\n';
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
// ../artifact-sdk/src/builtin/markdown.json
|
|
743
|
+
var markdown_default;
|
|
744
|
+
var init_markdown = __esm({
|
|
745
|
+
"../artifact-sdk/src/builtin/markdown.json"() {
|
|
746
|
+
markdown_default = `{
|
|
747
|
+
"name": "markdown",
|
|
748
|
+
"title": { "en": "Document", "zh": "\u6587\u6863" },
|
|
749
|
+
"types": ["markdown"],
|
|
750
|
+
"references": [
|
|
751
|
+
{ "text": "!\\\\[[^\\\\]\\\\n]*\\\\]\\\\(\\\\s*<?([^\\\\s)>]+)>?(?:\\\\s+[\\"'][^\\"'\\\\n]*[\\"'])?\\\\s*\\\\)" },
|
|
752
|
+
{ "text": "<img\\\\b[^<>]*?\\\\ssrc\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" }
|
|
753
|
+
]
|
|
754
|
+
}
|
|
755
|
+
`;
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
// ../artifact-sdk/src/builtin/spritesheet.json
|
|
760
|
+
var spritesheet_default;
|
|
761
|
+
var init_spritesheet = __esm({
|
|
762
|
+
"../artifact-sdk/src/builtin/spritesheet.json"() {
|
|
763
|
+
spritesheet_default = '{\n "name": "spritesheet",\n "title": { "en": "Sprite animation", "zh": "\u7CBE\u7075\u52A8\u753B" },\n "types": ["spritesheet"],\n "schema": {\n "type": "object",\n "required": ["frames", "meta"],\n "properties": {\n "frames": {\n "anyOf": [\n { "type": "array", "minItems": 1, "items": { "type": "object", "required": ["frame"] } },\n { "type": "object", "additionalProperties": { "type": "object", "required": ["frame"] } }\n ]\n },\n "meta": {\n "type": "object",\n "required": ["app", "image"],\n "properties": { "app": { "type": "string", "pattern": "codeandweb\\\\.com/texturepacker" }, "image": { "type": "string" } }\n }\n }\n },\n "references": [{ "json": "/meta/image" }]\n}\n';
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
// ../artifact-sdk/src/builtin/storyboard.json
|
|
768
|
+
var storyboard_default;
|
|
769
|
+
var init_storyboard = __esm({
|
|
770
|
+
"../artifact-sdk/src/builtin/storyboard.json"() {
|
|
771
|
+
storyboard_default = '{\n "name": "storyboard",\n "title": { "en": "Storyboard", "zh": "\u5206\u955C" },\n "types": ["storyboard"],\n "schema": {\n "type": "object",\n "anyOf": [{ "required": ["shots"] }, { "required": ["slides"] }],\n "properties": {\n "shots": {\n "type": "array",\n "items": {\n "type": "object",\n "properties": { "frames": { "type": "array", "items": { "type": "object", "properties": { "src": { "type": "string" } } } } }\n }\n },\n "slides": {\n "type": "array",\n "items": {\n "type": "object",\n "properties": {\n "preview": { "type": "object", "properties": { "src": { "type": "string" } } },\n "assets": { "type": "array", "items": { "type": "string" } }\n }\n }\n }\n }\n },\n "references": [\n { "json": "/shots/*/frames/*/src", "types": ["storyboard", "compare", "spritesheet", "studio"] },\n { "json": "/slides/*/preview/src", "types": ["storyboard", "compare", "spritesheet", "studio"] },\n { "json": "/slides/*/assets/*" }\n ]\n}\n';
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
// ../artifact-sdk/src/builtin/tiled.json
|
|
776
|
+
var tiled_default;
|
|
777
|
+
var init_tiled = __esm({
|
|
778
|
+
"../artifact-sdk/src/builtin/tiled.json"() {
|
|
779
|
+
tiled_default = `{
|
|
780
|
+
"name": "tiled",
|
|
781
|
+
"title": { "en": "Tiled map", "zh": "Tiled \u5730\u56FE" },
|
|
782
|
+
"types": ["tiled"],
|
|
783
|
+
"references": [
|
|
784
|
+
{ "text": "<tileset\\\\b[^<>]*?\\\\ssource\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']", "types": ["tiled"] },
|
|
785
|
+
{ "text": "<image\\\\b[^<>]*?\\\\ssource\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
|
|
786
|
+
{ "text": "\\"source\\"\\\\s*:\\\\s*\\"([^\\"]+)\\"", "types": ["tiled"] },
|
|
787
|
+
{ "text": "\\"image\\"\\\\s*:\\\\s*\\"([^\\"]+)\\"" }
|
|
788
|
+
]
|
|
789
|
+
}
|
|
790
|
+
`;
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
|
|
794
|
+
// ../artifact-sdk/src/builtin/video.json
|
|
795
|
+
var video_default;
|
|
796
|
+
var init_video = __esm({
|
|
797
|
+
"../artifact-sdk/src/builtin/video.json"() {
|
|
798
|
+
video_default = '{ "name": "video", "title": { "en": "Video", "zh": "\u89C6\u9891" }, "types": ["video"] }\n';
|
|
799
|
+
}
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
// ../artifact-sdk/src/builtin/studio.json
|
|
803
|
+
var studio_default;
|
|
804
|
+
var init_studio = __esm({
|
|
805
|
+
"../artifact-sdk/src/builtin/studio.json"() {
|
|
806
|
+
studio_default = '{\n "name": "studio",\n "title": {\n "en": "Studio",\n "zh": "\u5DE5\u4F5C\u53F0"\n },\n "types": [\n "studio"\n ],\n "schema": {\n "anyOf": [\n {\n "type": "object",\n "required": [\n "rounds",\n "land",\n "scheduled"\n ],\n "properties": {\n "rounds": {\n "type": "array",\n "items": {\n "type": "array",\n "minItems": 1,\n "items": {\n "type": "object",\n "required": [\n "agent",\n "title"\n ],\n "properties": {\n "agent": {\n "type": "string"\n },\n "title": {\n "type": "object",\n "required": [\n "en"\n ]\n }\n }\n }\n }\n },\n "land": {\n "type": "array",\n "items": {\n "type": "object",\n "required": [\n "agent",\n "title"\n ]\n }\n },\n "scheduled": {\n "type": "array",\n "items": {\n "type": "object",\n "required": [\n "agent",\n "title"\n ]\n }\n },\n "version": {\n "enum": [\n 1\n ]\n }\n }\n },\n {\n "type": "object",\n "required": [\n "version",\n "base",\n "fingerprint",\n "agents",\n "files",\n "results"\n ],\n "properties": {\n "version": {\n "const": 2\n },\n "base": {\n "anyOf": [\n {\n "type": "null"\n },\n {\n "type": "object",\n "required": [\n "id",\n "version",\n "fingerprint"\n ],\n "properties": {\n "id": {\n "type": "string",\n "minLength": 1\n },\n "version": {\n "type": "integer",\n "minimum": 1\n },\n "fingerprint": {\n "type": "string",\n "minLength": 1\n }\n }\n }\n ]\n },\n "fingerprint": {\n "type": "string",\n "minLength": 1\n },\n "agents": {\n "type": "array",\n "maxItems": 500,\n "items": {\n "type": "object",\n "required": [\n "agent",\n "title"\n ],\n "properties": {\n "agent": {\n "type": "string",\n "minLength": 1\n },\n "title": {\n "type": "object",\n "required": [\n "en"\n ],\n "properties": {\n "en": {\n "type": "string",\n "minLength": 1\n },\n "zh": {\n "type": "string"\n }\n }\n }\n }\n }\n },\n "files": {\n "type": "array",\n "maxItems": 1000,\n "items": {\n "type": "object",\n "required": [\n "path",\n "before",\n "after"\n ],\n "properties": {\n "path": {\n "type": "string",\n "minLength": 1\n },\n "before": {\n "anyOf": [\n {\n "type": "string",\n "minLength": 1\n },\n {\n "type": "null"\n }\n ]\n },\n "after": {\n "anyOf": [\n {\n "type": "string",\n "minLength": 1\n },\n {\n "type": "null"\n }\n ]\n },\n "diff": {\n "type": "string",\n "minLength": 1\n }\n }\n }\n },\n "results": {\n "type": "array",\n "maxItems": 500,\n "items": {\n "anyOf": [\n {\n "type": "object",\n "required": [\n "agent",\n "component",\n "src"\n ],\n "properties": {\n "agent": {\n "type": "string",\n "minLength": 1\n },\n "component": {\n "const": "Asset"\n },\n "src": {\n "type": "string",\n "minLength": 1\n },\n "label": {\n "type": "string"\n },\n "alt": {\n "type": "string"\n },\n "device": {\n "enum": [\n "mobile",\n "desktop"\n ]\n },\n "loop": {\n "type": "boolean"\n },\n "variants": {\n "type": "object",\n "additionalProperties": {\n "type": "string",\n "minLength": 1\n }\n }\n }\n },\n {\n "type": "object",\n "required": [\n "agent",\n "component",\n "label",\n "items"\n ],\n "properties": {\n "agent": {\n "type": "string",\n "minLength": 1\n },\n "component": {\n "const": "Set"\n },\n "label": {\n "type": "string"\n },\n "items": {\n "type": "array",\n "minItems": 1,\n "maxItems": 500,\n "items": {\n "type": "object",\n "required": [\n "src"\n ],\n "properties": {\n "src": {\n "type": "string",\n "minLength": 1\n },\n "label": {\n "type": "string"\n },\n "alt": {\n "type": "string"\n },\n "device": {\n "enum": [\n "mobile",\n "desktop"\n ]\n },\n "loop": {\n "type": "boolean"\n },\n "variants": {\n "type": "object",\n "additionalProperties": {\n "type": "string",\n "minLength": 1\n }\n }\n }\n }\n }\n }\n },\n {\n "type": "object",\n "required": [\n "agent",\n "component",\n "a",\n "b"\n ],\n "properties": {\n "agent": {\n "type": "string",\n "minLength": 1\n },\n "component": {\n "const": "Compare"\n },\n "a": {\n "type": "string",\n "minLength": 1\n },\n "b": {\n "type": "string",\n "minLength": 1\n },\n "shots": {\n "type": "string",\n "minLength": 1\n },\n "label": {\n "type": "string"\n },\n "a-label": {\n "type": "string"\n },\n "b-label": {\n "type": "string"\n }\n }\n },\n {\n "type": "object",\n "required": [\n "agent",\n "component",\n "src"\n ],\n "properties": {\n "agent": {\n "type": "string",\n "minLength": 1\n },\n "component": {\n "const": "Storyboard"\n },\n "src": {\n "type": "string",\n "minLength": 1\n },\n "label": {\n "type": "string"\n }\n }\n }\n ]\n }\n }\n }\n }\n ]\n },\n "references": [\n {\n "json": "/files/*/before"\n },\n {\n "json": "/files/*/after"\n },\n {\n "json": "/files/*/diff"\n },\n {\n "json": "/results/*/src",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/variants/*",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/a",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/b",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/shots",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/items/*/src",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/items/*/variants/*",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/items/*/a",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/items/*/b",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/items/*/shots",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n }\n ]\n}\n';
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
// ../artifact-sdk/src/builtin/index.ts
|
|
811
|
+
var read, builtin_default;
|
|
812
|
+
var init_builtin = __esm({
|
|
813
|
+
"../artifact-sdk/src/builtin/index.ts"() {
|
|
814
|
+
"use strict";
|
|
815
|
+
init_compare();
|
|
816
|
+
init_html();
|
|
817
|
+
init_image();
|
|
818
|
+
init_markdown();
|
|
819
|
+
init_spritesheet();
|
|
820
|
+
init_storyboard();
|
|
821
|
+
init_tiled();
|
|
822
|
+
init_video();
|
|
823
|
+
init_studio();
|
|
824
|
+
read = (m) => typeof m === "string" ? JSON.parse(m) : m;
|
|
825
|
+
builtin_default = [html_default, image_default, video_default, markdown_default, storyboard_default, compare_default, studio_default, tiled_default, spritesheet_default].map(read);
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
// ../artifact-sdk/src/internal/schema.ts
|
|
830
|
+
function typeOk(type, v) {
|
|
831
|
+
const types = Array.isArray(type) ? type : [type];
|
|
832
|
+
return types.some(
|
|
833
|
+
(t) => t === "null" ? v === null : t === "array" ? Array.isArray(v) : t === "object" ? isObj(v) : t === "integer" ? Number.isInteger(v) : t === "number" ? typeof v === "number" && Number.isFinite(v) : typeof v === t
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
function schemaProblem(schema, value, at2 = "") {
|
|
837
|
+
if (!isObj(schema)) return null;
|
|
838
|
+
const s = schema;
|
|
839
|
+
const here = at2 || "/";
|
|
840
|
+
if (s.type !== void 0 && !typeOk(s.type, value)) return here;
|
|
841
|
+
if (Array.isArray(s.enum) && !s.enum.some((e2) => JSON.stringify(e2) === JSON.stringify(value))) return here;
|
|
842
|
+
if (s.const !== void 0 && JSON.stringify(s.const) !== JSON.stringify(value)) return here;
|
|
843
|
+
if (Array.isArray(s.anyOf) && !s.anyOf.some((x2) => !schemaProblem(x2, value, at2))) return here;
|
|
844
|
+
if (typeof value === "string") {
|
|
845
|
+
if (typeof s.minLength === "number" && value.length < s.minLength) return here;
|
|
846
|
+
if (typeof s.maxLength === "number" && value.length > s.maxLength) return here;
|
|
847
|
+
if (typeof s.pattern === "string") {
|
|
848
|
+
try {
|
|
849
|
+
if (!new RegExp(s.pattern, "u").test(value)) return here;
|
|
850
|
+
} catch {
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
if (typeof value === "number") {
|
|
855
|
+
if (typeof s.minimum === "number" && value < s.minimum) return here;
|
|
856
|
+
if (typeof s.maximum === "number" && value > s.maximum) return here;
|
|
857
|
+
}
|
|
858
|
+
if (Array.isArray(value)) {
|
|
859
|
+
if (typeof s.minItems === "number" && value.length < s.minItems) return here;
|
|
860
|
+
if (typeof s.maxItems === "number" && value.length > s.maxItems) return here;
|
|
861
|
+
if (isObj(s.items)) {
|
|
862
|
+
for (let i = 0; i < value.length; i++) {
|
|
863
|
+
const bad = schemaProblem(s.items, value[i], `${at2}/${i}`);
|
|
864
|
+
if (bad) return bad;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
if (isObj(value)) {
|
|
869
|
+
const props = isObj(s.properties) ? s.properties : {};
|
|
870
|
+
if (Array.isArray(s.required)) {
|
|
871
|
+
for (const k2 of s.required) if (typeof k2 === "string" && !(k2 in value)) return `${at2}/${k2}`;
|
|
872
|
+
}
|
|
873
|
+
for (const [k2, v] of Object.entries(value)) {
|
|
874
|
+
if (k2 in props) {
|
|
875
|
+
const bad = schemaProblem(props[k2], v, `${at2}/${k2}`);
|
|
876
|
+
if (bad) return bad;
|
|
877
|
+
} else if (s.additionalProperties === false) return `${at2}/${k2}`;
|
|
878
|
+
else if (isObj(s.additionalProperties)) {
|
|
879
|
+
const bad = schemaProblem(s.additionalProperties, v, `${at2}/${k2}`);
|
|
880
|
+
if (bad) return bad;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
return null;
|
|
885
|
+
}
|
|
886
|
+
var isObj;
|
|
887
|
+
var init_schema = __esm({
|
|
888
|
+
"../artifact-sdk/src/internal/schema.ts"() {
|
|
889
|
+
"use strict";
|
|
890
|
+
isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
891
|
+
}
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
// ../artifact-sdk/src/internal/format/studio.ts
|
|
895
|
+
function resultProblem(value, agents) {
|
|
896
|
+
if (!Array.isArray(value) || value.length > 500) return "/results";
|
|
897
|
+
for (let i = 0; i < value.length; i++) {
|
|
898
|
+
const r2 = value[i];
|
|
899
|
+
if (!isObject(r2) || !text(r2.agent) || !agents.has(r2.agent) || !optionalText(r2, ["label"])) return `/results/${i}`;
|
|
900
|
+
const valid = r2.component === "Asset" ? asset(r2) : r2.component === "Set" ? typeof r2.label === "string" && Array.isArray(r2.items) && r2.items.length > 0 && r2.items.length <= 500 && r2.items.every(asset) : r2.component === "Compare" ? source(r2.a) && source(r2.b) && (r2.shots === void 0 || source(r2.shots)) && optionalText(r2, ["a-label", "b-label"]) : r2.component === "Storyboard" && source(r2.src);
|
|
901
|
+
if (!valid) return `/results/${i}`;
|
|
902
|
+
}
|
|
903
|
+
return null;
|
|
904
|
+
}
|
|
905
|
+
function reviewProblem(v) {
|
|
906
|
+
if (!isObject(v) || v.version !== 2) return "/version";
|
|
907
|
+
if (!text(v.fingerprint)) return "/fingerprint";
|
|
908
|
+
if (v.base !== null && !(isObject(v.base) && text(v.base.id) && Number.isInteger(v.base.version) && Number(v.base.version) > 0 && text(v.base.fingerprint))) return "/base";
|
|
909
|
+
if (!Array.isArray(v.agents) || v.agents.length > 500) return "/agents";
|
|
910
|
+
const agents = /* @__PURE__ */ new Set();
|
|
911
|
+
for (const a2 of v.agents) {
|
|
912
|
+
if (!isObject(a2) || !text(a2.agent) || !/^[a-z][a-z0-9-]*$/.test(a2.agent) || agents.has(a2.agent) || !isObject(a2.title) || !text(a2.title.en) || !optionalText(a2.title, ["zh"]) || !icon(a2.icon)) return "/agents";
|
|
913
|
+
agents.add(a2.agent);
|
|
914
|
+
}
|
|
915
|
+
if (!Array.isArray(v.files) || v.files.length > 1e3) return "/files";
|
|
916
|
+
const paths = /* @__PURE__ */ new Set();
|
|
917
|
+
for (const f2 of v.files) {
|
|
918
|
+
if (!isObject(f2) || !relativePath(f2.path) || paths.has(f2.path) || !(f2.before === null || source(f2.before)) || !(f2.after === null || source(f2.after)) || f2.before === null && f2.after === null || f2.diff !== void 0 && !source(f2.diff) || (f2.before === null || f2.after === null) && !f2.diff) return "/files";
|
|
919
|
+
if (f2.path.startsWith("agents/") && !agents.has(f2.path.split("/")[1])) return "/files";
|
|
920
|
+
paths.add(f2.path);
|
|
921
|
+
}
|
|
922
|
+
return resultProblem(v.results, agents);
|
|
923
|
+
}
|
|
924
|
+
var text, source, icon, relativePath, optionalText, asset, parseReview, isReview;
|
|
925
|
+
var init_studio2 = __esm({
|
|
926
|
+
"../artifact-sdk/src/internal/format/studio.ts"() {
|
|
927
|
+
"use strict";
|
|
928
|
+
init_references();
|
|
929
|
+
text = (v) => typeof v === "string" && v.length > 0;
|
|
930
|
+
source = (v) => text(v) && !/^(?:[a-z][\w+.-]*:|\/|#)|\\|[\u0000-\u001f]/i.test(v);
|
|
931
|
+
icon = (v) => v === void 0 || typeof v === "string" || Array.isArray(v) && v.length > 0 && v.length <= 12 && v.every((p2) => isObject(p2) && text(p2.d) && /^[MmLlHhVvCcSsQqTtAaZz0-9.,\s-]+$/.test(p2.d) && ["f", "s"].every((k2) => p2[k2] === void 0 || typeof p2[k2] === "string" && /^[kwcgopsmlry]$/.test(p2[k2])) && (p2.o === void 0 || p2.o === true) && (p2.w === void 0 || typeof p2.w === "number" && p2.w > 0 && p2.w <= 3));
|
|
932
|
+
relativePath = (v) => source(v) && v.split("/").every((p2) => p2 && p2 !== "." && p2 !== "..");
|
|
933
|
+
optionalText = (v, keys) => keys.every((k2) => v[k2] === void 0 || typeof v[k2] === "string");
|
|
934
|
+
asset = (v) => isObject(v) && source(v.src) && optionalText(v, ["label", "alt"]) && (v.alt === void 0 || !/[<>]/.test(v.alt)) && (v.device === void 0 || v.device === "desktop" || v.device === "mobile") && (v.loop === void 0 || typeof v.loop === "boolean") && (v.variants === void 0 || isObject(v.variants) && Object.values(v.variants).every(source));
|
|
935
|
+
parseReview = (v) => reviewProblem(v) ? null : v;
|
|
936
|
+
isReview = (v) => isObject(v) && v.version === 2;
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
// ../artifact-sdk/src/internal/manifest.ts
|
|
941
|
+
function typeOf(data, types) {
|
|
942
|
+
const problem = (type) => type === "studio" && isReview(data) ? reviewProblem(data) : schemaProblem(manifestOf(type)?.schema, data);
|
|
943
|
+
for (const type of types) if (!problem(type)) return { type };
|
|
944
|
+
if (types.length !== 1) return { type: null };
|
|
945
|
+
return { type: types[0], problem: `does not match ${types[0]} at ${problem(types[0])}` };
|
|
946
|
+
}
|
|
947
|
+
function mapJson(node, keys, at2, visit) {
|
|
948
|
+
if (!keys.length) return typeof node === "string" && node ? visit(node, at2) : node;
|
|
949
|
+
const [key, ...rest] = keys;
|
|
950
|
+
if (Array.isArray(node)) {
|
|
951
|
+
if (key === "*") return node.map((x2, i2) => mapJson(x2, rest, `${at2}/${i2}`, visit));
|
|
952
|
+
const i = Number(key);
|
|
953
|
+
return Number.isInteger(i) && i in node ? node.map((x2, j2) => j2 === i ? mapJson(x2, rest, `${at2}/${j2}`, visit) : x2) : node;
|
|
954
|
+
}
|
|
955
|
+
if (!isObject2(node)) return node;
|
|
956
|
+
const out = { ...node };
|
|
957
|
+
for (const k2 of key === "*" ? Object.keys(node) : key in node ? [key] : []) out[k2] = mapJson(node[k2], rest, `${at2}/${k2}`, visit);
|
|
958
|
+
return out;
|
|
959
|
+
}
|
|
960
|
+
function mapText(text6, rule, skipped, visit, includeRemote) {
|
|
961
|
+
let out = "";
|
|
962
|
+
let last = 0;
|
|
963
|
+
for (const m of text6.matchAll(new RegExp(rule.text, "gid"))) {
|
|
964
|
+
const span = m.indices?.[1];
|
|
965
|
+
if (!span || m[1] === void 0 || skipped.some(([a2, b2]) => span[0] >= a2 && span[0] < b2)) continue;
|
|
966
|
+
const line = text6.slice(0, span[0]).split("\n").length;
|
|
967
|
+
const one = (src) => remote(src) && !includeRemote ? src : visit(src, line);
|
|
968
|
+
const value = rule.list ? m[1].split(rule.list).map((part) => part.replace(/^(\s*)(\S+)/, (_2, space, src) => space + one(src))).join(rule.list) : one(m[1]);
|
|
969
|
+
out += text6.slice(last, span[0]) + value;
|
|
970
|
+
last = span[1];
|
|
971
|
+
}
|
|
972
|
+
return out + text6.slice(last);
|
|
973
|
+
}
|
|
974
|
+
function mapReferences(manifest, content, map2, includeRemote = false) {
|
|
975
|
+
const skipped = (text6) => (manifest?.skip ?? []).flatMap((re3) => [...text6.matchAll(new RegExp(re3, "gi"))].map((m) => [m.index, m.index + m[0].length]));
|
|
976
|
+
for (const rule of manifest?.references ?? []) {
|
|
977
|
+
const types = rule.types ?? [];
|
|
978
|
+
if ("json" in rule) {
|
|
979
|
+
if (typeof content !== "string") content = mapJson(content, rule.json.split("/").filter(Boolean), "", (src, at2) => map2(src, { src, types, text: false, at: at2 || "/" }));
|
|
980
|
+
} else if (typeof content === "string") {
|
|
981
|
+
content = mapText(content, rule, skipped(content), (src, line) => map2(src, { src, types, text: true, line }), includeRemote);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
return content;
|
|
985
|
+
}
|
|
986
|
+
function referencesOf(manifest, content, includeRemote = false) {
|
|
987
|
+
const found2 = [];
|
|
988
|
+
mapReferences(manifest, content, (src, ref) => (found2.push(ref), src), includeRemote);
|
|
989
|
+
return found2;
|
|
990
|
+
}
|
|
991
|
+
var BUILTINS, manifestOf, isObject2, remote;
|
|
992
|
+
var init_manifest = __esm({
|
|
993
|
+
"../artifact-sdk/src/internal/manifest.ts"() {
|
|
994
|
+
"use strict";
|
|
995
|
+
init_builtin();
|
|
996
|
+
init_schema();
|
|
997
|
+
init_studio2();
|
|
998
|
+
BUILTINS = builtin_default;
|
|
999
|
+
manifestOf = (type) => BUILTINS.find((m) => m.types.includes(type));
|
|
1000
|
+
isObject2 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
1001
|
+
remote = (src) => !src || /^(?:[a-z][\w+.-]*:|\/|#)/i.test(src);
|
|
1002
|
+
}
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
// src/lib/cloud/config.ts
|
|
1006
|
+
function cloudEndpoints() {
|
|
1007
|
+
return {
|
|
1008
|
+
supabaseUrl: trimSlash(process.env.AI4KANBAN_SUPABASE_URL || SUPABASE_URL),
|
|
1009
|
+
anonKey: process.env.AI4KANBAN_SUPABASE_ANON_KEY || SUPABASE_ANON_KEY,
|
|
1010
|
+
api: trimSlash(process.env.AI4KANBAN_CLOUD_URL || API_URL)
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
function cloudConfigured() {
|
|
1014
|
+
const { supabaseUrl, anonKey } = cloudEndpoints();
|
|
1015
|
+
return !!supabaseUrl && !!anonKey;
|
|
1016
|
+
}
|
|
1017
|
+
var SUPABASE_URL, SUPABASE_ANON_KEY, API_URL, trimSlash, NOT_CONFIGURED;
|
|
1018
|
+
var init_config = __esm({
|
|
1019
|
+
"src/lib/cloud/config.ts"() {
|
|
1020
|
+
"use strict";
|
|
1021
|
+
SUPABASE_URL = "https://yajrbpprmdvtkvjjfpbk.supabase.co";
|
|
1022
|
+
SUPABASE_ANON_KEY = "sb_publishable_ioUQ23BTtoj8NKqndp0Jrw_omVR3m4n";
|
|
1023
|
+
API_URL = "https://api.ai4kanban.dev";
|
|
1024
|
+
trimSlash = (url) => url.replace(/\/+$/, "");
|
|
1025
|
+
NOT_CONFIGURED = "This build of WildCrane carries no Cloud project to sign in against.";
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
|
|
1029
|
+
// src/lib/machine/home.ts
|
|
1030
|
+
import os from "node:os";
|
|
569
1031
|
import path3 from "node:path";
|
|
570
|
-
function
|
|
1032
|
+
function machineHome() {
|
|
1033
|
+
return process.env.AI4KANBAN_HOME || path3.join(os.homedir(), ".ai4kanban");
|
|
1034
|
+
}
|
|
1035
|
+
var init_home = __esm({
|
|
1036
|
+
"src/lib/machine/home.ts"() {
|
|
1037
|
+
"use strict";
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
|
|
1041
|
+
// src/lib/cloud/session.ts
|
|
1042
|
+
import fs3 from "node:fs";
|
|
1043
|
+
import { createHash } from "node:crypto";
|
|
1044
|
+
import path4 from "node:path";
|
|
1045
|
+
function readRetry(session) {
|
|
1046
|
+
try {
|
|
1047
|
+
const retry2 = JSON.parse(fs3.readFileSync(retryFile(), "utf8"));
|
|
1048
|
+
if (retry2.key === refreshKey(session) && Number.isFinite(retry2.until) && Number.isInteger(retry2.attempt) && retry2.attempt > 0 && typeof retry2.error === "string") return retry2;
|
|
1049
|
+
} catch {
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
function deferRefresh(session, error, after2) {
|
|
1053
|
+
const current = readSession();
|
|
1054
|
+
if (current?.subject === session.subject && current.refreshToken === session.refreshToken) {
|
|
1055
|
+
const attempt2 = Math.min((readRetry(session)?.attempt ?? 0) + 1, 4);
|
|
1056
|
+
const seconds = after2?.trim() ? Number(after2) : NaN;
|
|
1057
|
+
const serverDelay = Number.isFinite(seconds) ? seconds * 1e3 : Date.parse(after2 ?? "") - Date.now();
|
|
1058
|
+
const delay2 = Math.max(Math.min(REFRESH_BACKOFF_MS * 2 ** (attempt2 - 1), 3e5), Number.isFinite(serverDelay) ? serverDelay : 0);
|
|
1059
|
+
const retry2 = { key: refreshKey(session), until: Date.now() + delay2, attempt: attempt2, error };
|
|
1060
|
+
const temporary = `${retryFile()}.${process.pid}.tmp`;
|
|
1061
|
+
fs3.writeFileSync(temporary, JSON.stringify(retry2), { mode: 384 });
|
|
1062
|
+
fs3.renameSync(temporary, retryFile());
|
|
1063
|
+
}
|
|
1064
|
+
return { ok: false, reason: "unreachable", error };
|
|
1065
|
+
}
|
|
1066
|
+
function readSession() {
|
|
1067
|
+
let raw;
|
|
1068
|
+
try {
|
|
1069
|
+
raw = fs3.readFileSync(sessionFile(), "utf8");
|
|
1070
|
+
} catch {
|
|
1071
|
+
return null;
|
|
1072
|
+
}
|
|
1073
|
+
try {
|
|
1074
|
+
const held4 = JSON.parse(raw);
|
|
1075
|
+
if (!held4.accessToken || !held4.refreshToken || !held4.subject) return null;
|
|
1076
|
+
if (held4.supabaseUrl !== cloudEndpoints().supabaseUrl) return null;
|
|
1077
|
+
return { ...held4, version: 1, expiresAt: Number(held4.expiresAt) || 0 };
|
|
1078
|
+
} catch {
|
|
1079
|
+
return null;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
function writeSession(session) {
|
|
1083
|
+
fs3.mkdirSync(machineHome(), { recursive: true, mode: 448 });
|
|
1084
|
+
const tmp = `${sessionFile()}.${process.pid}.tmp`;
|
|
1085
|
+
fs3.writeFileSync(tmp, `${JSON.stringify(session, null, 2)}
|
|
1086
|
+
`, { mode: 384 });
|
|
1087
|
+
fs3.renameSync(tmp, sessionFile());
|
|
1088
|
+
if (!expiringSoon(session) || !readRetry(session)) fs3.rmSync(retryFile(), { force: true });
|
|
1089
|
+
}
|
|
1090
|
+
function clearSession() {
|
|
1091
|
+
try {
|
|
1092
|
+
fs3.rmSync(sessionFile());
|
|
1093
|
+
fs3.rmSync(retryFile(), { force: true });
|
|
1094
|
+
} catch {
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
async function accessToken() {
|
|
1098
|
+
const held4 = readSession();
|
|
1099
|
+
if (!held4) return { ok: false, reason: "signed-out" };
|
|
1100
|
+
if (!expiringSoon(held4)) return { ok: true, token: held4.accessToken, session: held4 };
|
|
1101
|
+
return refresh();
|
|
1102
|
+
}
|
|
1103
|
+
async function refresh() {
|
|
1104
|
+
const lock = await takeLock();
|
|
1105
|
+
if (!lock) return { ok: false, reason: "unreachable", error: "Cloud sign-in refresh is busy. Try again shortly." };
|
|
1106
|
+
try {
|
|
1107
|
+
const now = readSession();
|
|
1108
|
+
if (!now) return { ok: false, reason: "signed-out" };
|
|
1109
|
+
if (!expiringSoon(now)) return { ok: true, token: now.accessToken, session: now };
|
|
1110
|
+
const retry2 = readRetry(now);
|
|
1111
|
+
if (retry2 && retry2.until > Date.now()) return { ok: false, reason: "unreachable", error: retry2.error };
|
|
1112
|
+
const { api, anonKey } = cloudEndpoints();
|
|
1113
|
+
let response;
|
|
1114
|
+
try {
|
|
1115
|
+
response = await fetch(`${api}/auth/v1/token?grant_type=refresh_token`, {
|
|
1116
|
+
method: "POST",
|
|
1117
|
+
headers: { apikey: anonKey, "content-type": "application/json" },
|
|
1118
|
+
body: JSON.stringify({ refresh_token: now.refreshToken }),
|
|
1119
|
+
signal: AbortSignal.timeout(REFRESH_TIMEOUT_MS)
|
|
1120
|
+
});
|
|
1121
|
+
} catch (e2) {
|
|
1122
|
+
return deferRefresh(now, e2 instanceof Error ? e2.message : String(e2));
|
|
1123
|
+
}
|
|
1124
|
+
if (!response.ok) {
|
|
1125
|
+
const body = await response.json().catch(() => null);
|
|
1126
|
+
const error = body?.error_description ?? body?.msg ?? body?.message;
|
|
1127
|
+
if (![400, 401, 403].includes(response.status)) return deferRefresh(now, error ?? `Cloud answered ${response.status}`, response.headers.get("retry-after"));
|
|
1128
|
+
return { ok: false, reason: "expired", error };
|
|
1129
|
+
}
|
|
1130
|
+
const fresh = sessionFrom(await response.json().catch(() => null), now);
|
|
1131
|
+
if (!fresh) return deferRefresh(now, "Cloud returned an invalid sign-in refresh response.");
|
|
1132
|
+
const current = readSession();
|
|
1133
|
+
if (!current || current.subject !== now.subject) return { ok: false, reason: "expired" };
|
|
1134
|
+
if (current.refreshToken !== now.refreshToken) return { ok: true, token: current.accessToken, session: current };
|
|
1135
|
+
writeSession(fresh);
|
|
1136
|
+
return { ok: true, token: fresh.accessToken, session: fresh };
|
|
1137
|
+
} finally {
|
|
1138
|
+
lock();
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
function sessionFrom(body, previous) {
|
|
1142
|
+
if (!body || typeof body !== "object") return null;
|
|
1143
|
+
const token2 = body;
|
|
1144
|
+
const subject = token2.user?.id ?? previous?.subject;
|
|
1145
|
+
if (!token2.access_token || !token2.refresh_token || !subject) return null;
|
|
1146
|
+
const expiresAt = token2.expires_at ? token2.expires_at * 1e3 : Date.now() + (token2.expires_in ?? 3600) * 1e3;
|
|
1147
|
+
return {
|
|
1148
|
+
version: 1,
|
|
1149
|
+
supabaseUrl: cloudEndpoints().supabaseUrl,
|
|
1150
|
+
accessToken: token2.access_token,
|
|
1151
|
+
refreshToken: token2.refresh_token,
|
|
1152
|
+
expiresAt,
|
|
1153
|
+
subject,
|
|
1154
|
+
email: token2.user?.email ?? previous?.email,
|
|
1155
|
+
handle: previous?.handle,
|
|
1156
|
+
name: previous?.name,
|
|
1157
|
+
avatarUrl: previous?.avatarUrl,
|
|
1158
|
+
avatar: previous?.avatar
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
async function takeLock() {
|
|
1162
|
+
const until = Date.now() + LOCK_WAIT_MS;
|
|
1163
|
+
for (; ; ) {
|
|
1164
|
+
try {
|
|
1165
|
+
fs3.mkdirSync(machineHome(), { recursive: true, mode: 448 });
|
|
1166
|
+
fs3.mkdirSync(lockDir());
|
|
1167
|
+
try {
|
|
1168
|
+
fs3.writeFileSync(lockOwner(), `${process.pid}
|
|
1169
|
+
`);
|
|
1170
|
+
} catch {
|
|
1171
|
+
}
|
|
1172
|
+
return () => {
|
|
1173
|
+
try {
|
|
1174
|
+
fs3.rmSync(lockDir(), { recursive: true, force: true });
|
|
1175
|
+
} catch {
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
} catch (err) {
|
|
1179
|
+
if (err.code !== "EEXIST") throw err;
|
|
1180
|
+
if (stale()) {
|
|
1181
|
+
fs3.rmSync(lockDir(), { recursive: true, force: true });
|
|
1182
|
+
continue;
|
|
1183
|
+
}
|
|
1184
|
+
if (Date.now() > until) return null;
|
|
1185
|
+
await sleep(LOCK_RETRY_MS);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
function stale() {
|
|
1190
|
+
let held4;
|
|
1191
|
+
try {
|
|
1192
|
+
const pid = Number(fs3.readFileSync(lockOwner(), "utf8").trim());
|
|
1193
|
+
held4 = Number.isInteger(pid) && pid > 0 ? pid : void 0;
|
|
1194
|
+
} catch {
|
|
1195
|
+
held4 = void 0;
|
|
1196
|
+
}
|
|
1197
|
+
if (held4 !== void 0) return !alive(held4);
|
|
1198
|
+
try {
|
|
1199
|
+
return Date.now() - fs3.statSync(lockDir()).mtimeMs > LOCK_STALE_MS;
|
|
1200
|
+
} catch {
|
|
1201
|
+
return false;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
function alive(pid) {
|
|
1205
|
+
try {
|
|
1206
|
+
process.kill(pid, 0);
|
|
1207
|
+
return true;
|
|
1208
|
+
} catch (e2) {
|
|
1209
|
+
return e2.code === "EPERM";
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
var REFRESH_MARGIN_MS, LOCK_STALE_MS, LOCK_WAIT_MS, LOCK_RETRY_MS, REFRESH_TIMEOUT_MS, REFRESH_BACKOFF_MS, sessionFile, lockDir, lockOwner, retryFile, refreshKey, expiringSoon, sleep;
|
|
1213
|
+
var init_session = __esm({
|
|
1214
|
+
"src/lib/cloud/session.ts"() {
|
|
1215
|
+
"use strict";
|
|
1216
|
+
init_home();
|
|
1217
|
+
init_config();
|
|
1218
|
+
REFRESH_MARGIN_MS = 6e4;
|
|
1219
|
+
LOCK_STALE_MS = 3e4;
|
|
1220
|
+
LOCK_WAIT_MS = 2e4;
|
|
1221
|
+
LOCK_RETRY_MS = 50;
|
|
1222
|
+
REFRESH_TIMEOUT_MS = 15e3;
|
|
1223
|
+
REFRESH_BACKOFF_MS = 6e4;
|
|
1224
|
+
sessionFile = () => path4.join(machineHome(), "session.json");
|
|
1225
|
+
lockDir = () => path4.join(machineHome(), "session.lock");
|
|
1226
|
+
lockOwner = () => path4.join(lockDir(), "owner");
|
|
1227
|
+
retryFile = () => path4.join(machineHome(), "session-refresh.json");
|
|
1228
|
+
refreshKey = (session) => createHash("sha256").update(JSON.stringify([cloudEndpoints().api, session.subject, session.refreshToken])).digest("hex");
|
|
1229
|
+
expiringSoon = (session) => session.expiresAt - REFRESH_MARGIN_MS <= Date.now();
|
|
1230
|
+
sleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
|
|
1234
|
+
// src/lib/cloud/tasks.ts
|
|
1235
|
+
import crypto from "node:crypto";
|
|
1236
|
+
import fs4 from "node:fs";
|
|
1237
|
+
import path5 from "node:path";
|
|
1238
|
+
function workspaceTask() {
|
|
1239
|
+
const id = process.env[TASK_ENV];
|
|
1240
|
+
return id && id.trim() ? id.trim() : null;
|
|
1241
|
+
}
|
|
1242
|
+
function cloudStudio(name) {
|
|
1243
|
+
if (/^wf-/.test(name)) return name.replace("-", "_");
|
|
1244
|
+
return `wf_builtin_${name.replace(/-/g, "_")}`;
|
|
1245
|
+
}
|
|
1246
|
+
async function call(method, route2, body, key) {
|
|
1247
|
+
if (!cloudConfigured()) return { ok: false, error: NOT_CONFIGURED, code: "bad_request" };
|
|
1248
|
+
const token2 = await accessToken();
|
|
1249
|
+
if (!token2.ok) {
|
|
1250
|
+
return token2.reason === "unreachable" ? { ok: false, error: `Cloud could not be reached: ${token2.error}` } : { ok: false, error: token2.reason === "expired" ? "Cloud sign-in has expired. Sign in again." : "This machine is not signed in to Cloud.", code: "unauthenticated" };
|
|
1251
|
+
}
|
|
1252
|
+
let response;
|
|
1253
|
+
try {
|
|
1254
|
+
response = await fetch(`${cloudEndpoints().api}${route2}`, {
|
|
1255
|
+
method,
|
|
1256
|
+
headers: {
|
|
1257
|
+
authorization: `Bearer ${token2.token}`,
|
|
1258
|
+
...body ? { "content-type": "application/json" } : {},
|
|
1259
|
+
...key ? { "idempotency-key": key } : {}
|
|
1260
|
+
},
|
|
1261
|
+
...body ? { body: JSON.stringify(body) } : {},
|
|
1262
|
+
signal: AbortSignal.timeout(2e4)
|
|
1263
|
+
});
|
|
1264
|
+
} catch (e2) {
|
|
1265
|
+
return { ok: false, error: `Cloud could not be reached: ${e2 instanceof Error ? e2.message : String(e2)}` };
|
|
1266
|
+
}
|
|
1267
|
+
const parsed = await response.json().catch(() => ({}));
|
|
1268
|
+
if (!response.ok) return { ok: false, code: parsed.error?.code ?? "refused", error: parsed.error?.message ?? `Cloud answered ${response.status}.` };
|
|
1269
|
+
return { ok: true, value: parsed, replayed: response.headers.get("idempotent-replayed") === "true" };
|
|
1270
|
+
}
|
|
1271
|
+
async function createTask(from, said2) {
|
|
1272
|
+
const source2 = await call("GET", `/v1/tasks/${encodeURIComponent(from)}`);
|
|
1273
|
+
if (!source2.ok) return source2;
|
|
1274
|
+
const studio = said2.studio ? cloudStudio(said2.studio) : source2.value.studio?.id;
|
|
1275
|
+
const body = {
|
|
1276
|
+
title: said2.title,
|
|
1277
|
+
project: source2.value.project,
|
|
1278
|
+
...studio ? { studio } : {},
|
|
1279
|
+
...said2.request?.trim() ? { request: said2.request.trim() } : {},
|
|
1280
|
+
source: "api",
|
|
1281
|
+
source_context: { task: from, ...said2.agent ? { agent: said2.agent } : {} },
|
|
1282
|
+
...said2.run ? { run: true } : {},
|
|
1283
|
+
...said2.metadata && Object.keys(said2.metadata).length ? { metadata: said2.metadata } : {},
|
|
1284
|
+
...said2.triage ? { triage: `tri_${source2.value.project.replace(/^prj_/, "")}_${said2.triage}` } : {}
|
|
1285
|
+
};
|
|
1286
|
+
const key = `akb-${crypto.createHash("sha256").update(`${from}
|
|
1287
|
+
${said2.slug?.trim() || said2.title}`).digest("hex").slice(0, 40)}`;
|
|
1288
|
+
const made = await call("POST", "/v1/tasks", body, key);
|
|
1289
|
+
if (!made.ok) return made;
|
|
1290
|
+
const number = numberOf(made.value.key);
|
|
1291
|
+
if (!Number.isInteger(number)) return { ok: false, error: `Cloud answered a task with no number: ${made.value.key}`, code: "refused" };
|
|
1292
|
+
return { ok: true, value: { task: made.value, number, from: source2.value, replayed: made.replayed === true } };
|
|
1293
|
+
}
|
|
1294
|
+
function runnerProject(board2) {
|
|
1295
|
+
if (path5.basename(board2) !== "kanban" || path5.basename(path5.dirname(board2)) !== ".akb") return null;
|
|
1296
|
+
const linked2 = linkedProject(board2, path5.dirname(path5.dirname(board2)));
|
|
1297
|
+
return linked2.ok ? linked2.value : null;
|
|
1298
|
+
}
|
|
1299
|
+
function linkedProject(board2, root2) {
|
|
1300
|
+
const file2 = path5.join(root2, ".akb", "base.json");
|
|
1301
|
+
if (!fs4.existsSync(file2)) return { ok: true, value: null };
|
|
1302
|
+
try {
|
|
1303
|
+
const base = JSON.parse(fs4.readFileSync(file2, "utf8"));
|
|
1304
|
+
if (!base || typeof base !== "object" || base.project !== void 0 && (typeof base.project !== "string" || !base.project.trim()) || base.files !== void 0 && (!base.files || typeof base.files !== "object" || Array.isArray(base.files))) throw new Error();
|
|
1305
|
+
const projects = new Set(Object.keys(base.files ?? {}).flatMap((p2) => /^projects\/([^/]+)\//.exec(p2)?.[1] ?? []));
|
|
1306
|
+
if (typeof base.project === "string") projects.add(base.project);
|
|
1307
|
+
if (projects.size !== 1) throw new Error();
|
|
1308
|
+
return { ok: true, value: [...projects][0] };
|
|
1309
|
+
} catch {
|
|
1310
|
+
return { ok: false, error: "The project link is invalid or names multiple projects.", code: "invalid-link" };
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
async function creationProject(board2, root2, task = workspaceTask()) {
|
|
1314
|
+
const link2 = linkedProject(board2, root2);
|
|
1315
|
+
if (!link2.ok) return link2;
|
|
1316
|
+
let project2 = link2.value;
|
|
1317
|
+
if (task) {
|
|
1318
|
+
const source2 = await call("GET", `/v1/tasks/${encodeURIComponent(task)}`);
|
|
1319
|
+
if (!source2.ok) return {
|
|
1320
|
+
...source2,
|
|
1321
|
+
error: source2.code === "forbidden" ? "Cannot access this task. Check your account and task access in WildCrane, then try again." : source2.code === "not_found" ? "This task does not exist. Start a new task from the WildCrane web app." : source2.error
|
|
1322
|
+
};
|
|
1323
|
+
if (project2 && project2 !== source2.value.project) return { ok: false, error: "The source task conflicts with this board\u2019s project link.", code: "invalid-link" };
|
|
1324
|
+
project2 = source2.value.project;
|
|
1325
|
+
}
|
|
1326
|
+
if (!project2) return { ok: false, error: "This board is not linked to a Cloud project.", code: "unlinked" };
|
|
1327
|
+
const checked = await call("GET", `/v1/projects/${encodeURIComponent(project2)}`);
|
|
1328
|
+
return checked.ok ? { ok: true, value: project2 } : checked;
|
|
1329
|
+
}
|
|
1330
|
+
async function createProjectTask(project2, said2, key) {
|
|
1331
|
+
const made = await call("POST", "/v1/tasks", {
|
|
1332
|
+
title: said2.title,
|
|
1333
|
+
project: project2,
|
|
1334
|
+
source: "api",
|
|
1335
|
+
...said2.studio ? { studio: cloudStudio(said2.studio) } : {},
|
|
1336
|
+
...said2.request?.trim() ? { request: said2.request.trim() } : {},
|
|
1337
|
+
...said2.agent ? { source_context: { agent: said2.agent } } : {},
|
|
1338
|
+
...said2.triage ? { triage: `tri_${project2.replace(/^prj_/, "")}_${said2.triage}` } : {}
|
|
1339
|
+
}, key);
|
|
1340
|
+
if (!made.ok) return made;
|
|
1341
|
+
const number = numberOf(made.value.key);
|
|
1342
|
+
if (!Number.isInteger(number)) return { ok: false, error: `Cloud answered a task with no number: ${made.value.key}`, code: "refused" };
|
|
1343
|
+
return { ok: true, value: { task: made.value, number } };
|
|
1344
|
+
}
|
|
1345
|
+
async function approveTask(project2, number) {
|
|
1346
|
+
const held4 = await call("GET", `/v1/projects/${encodeURIComponent(project2)}`);
|
|
1347
|
+
if (!held4.ok) return held4;
|
|
1348
|
+
const key = `${held4.value.prefix}-${number}`;
|
|
1349
|
+
const task = await call("GET", `/v1/tasks/${encodeURIComponent(key)}`);
|
|
1350
|
+
if (!task.ok) return task;
|
|
1351
|
+
const revision = task.value.review?.revision;
|
|
1352
|
+
const decided = await call("POST", `/v1/tasks/${encodeURIComponent(key)}/decisions`, {
|
|
1353
|
+
decision: "approve",
|
|
1354
|
+
...revision !== void 0 ? { review_revision: revision } : {}
|
|
1355
|
+
});
|
|
1356
|
+
return decided.ok ? { ok: true, value: { key } } : decided;
|
|
1357
|
+
}
|
|
1358
|
+
var TASK_ENV, numberOf;
|
|
1359
|
+
var init_tasks = __esm({
|
|
1360
|
+
"src/lib/cloud/tasks.ts"() {
|
|
1361
|
+
"use strict";
|
|
1362
|
+
init_config();
|
|
1363
|
+
init_session();
|
|
1364
|
+
TASK_ENV = "AI4KANBAN_TASK";
|
|
1365
|
+
numberOf = (key) => Number(/-(\d+)$/.exec(key)?.[1] ?? NaN);
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
|
|
1369
|
+
// src/lib/lock.ts
|
|
1370
|
+
import fs5 from "node:fs";
|
|
1371
|
+
import path6 from "node:path";
|
|
1372
|
+
function sleep2(ms) {
|
|
571
1373
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
572
1374
|
}
|
|
573
1375
|
function ageOf(dir) {
|
|
574
1376
|
try {
|
|
575
|
-
return Date.now() -
|
|
1377
|
+
return Date.now() - fs5.statSync(dir).mtimeMs;
|
|
576
1378
|
} catch {
|
|
577
1379
|
return 0;
|
|
578
1380
|
}
|
|
@@ -588,7 +1390,7 @@ function pidAlive(pid) {
|
|
|
588
1390
|
}
|
|
589
1391
|
function ownerOf(dir) {
|
|
590
1392
|
try {
|
|
591
|
-
const pid = Number(
|
|
1393
|
+
const pid = Number(fs5.readFileSync(path6.join(dir, OWNER), "utf8").trim());
|
|
592
1394
|
return Number.isInteger(pid) && pid > 0 ? pid : void 0;
|
|
593
1395
|
} catch {
|
|
594
1396
|
return void 0;
|
|
@@ -596,7 +1398,7 @@ function ownerOf(dir) {
|
|
|
596
1398
|
}
|
|
597
1399
|
function claimBreak(dir) {
|
|
598
1400
|
try {
|
|
599
|
-
|
|
1401
|
+
fs5.mkdirSync(path6.join(dir, BREAKING));
|
|
600
1402
|
return true;
|
|
601
1403
|
} catch {
|
|
602
1404
|
return false;
|
|
@@ -607,9 +1409,9 @@ function withLock(dir, what, fn2) {
|
|
|
607
1409
|
let held4;
|
|
608
1410
|
for (; ; ) {
|
|
609
1411
|
try {
|
|
610
|
-
|
|
1412
|
+
fs5.mkdirSync(dir, { recursive: false });
|
|
611
1413
|
try {
|
|
612
|
-
|
|
1414
|
+
fs5.writeFileSync(path6.join(dir, OWNER), `${process.pid}
|
|
613
1415
|
`);
|
|
614
1416
|
} catch {
|
|
615
1417
|
}
|
|
@@ -617,17 +1419,17 @@ function withLock(dir, what, fn2) {
|
|
|
617
1419
|
} catch (err) {
|
|
618
1420
|
const code = err.code;
|
|
619
1421
|
if (code === "ENOENT") {
|
|
620
|
-
|
|
1422
|
+
fs5.mkdirSync(path6.dirname(dir), { recursive: true });
|
|
621
1423
|
continue;
|
|
622
1424
|
}
|
|
623
1425
|
if (code !== "EEXIST") throw err;
|
|
624
1426
|
if (ageOf(dir) > STALE_MS) {
|
|
625
|
-
|
|
1427
|
+
fs5.rmSync(dir, { recursive: true, force: true });
|
|
626
1428
|
continue;
|
|
627
1429
|
}
|
|
628
1430
|
held4 = ownerOf(dir);
|
|
629
1431
|
if (held4 !== void 0 && !pidAlive(held4) && claimBreak(dir)) {
|
|
630
|
-
|
|
1432
|
+
fs5.rmSync(dir, { recursive: true, force: true });
|
|
631
1433
|
continue;
|
|
632
1434
|
}
|
|
633
1435
|
if (Date.now() > until) {
|
|
@@ -636,18 +1438,18 @@ function withLock(dir, what, fn2) {
|
|
|
636
1438
|
"board-busy"
|
|
637
1439
|
);
|
|
638
1440
|
}
|
|
639
|
-
|
|
1441
|
+
sleep2(RETRY_MS);
|
|
640
1442
|
}
|
|
641
1443
|
}
|
|
642
1444
|
try {
|
|
643
1445
|
return fn2();
|
|
644
1446
|
} finally {
|
|
645
1447
|
const owner = ownerOf(dir);
|
|
646
|
-
if (owner === void 0 || owner === process.pid)
|
|
1448
|
+
if (owner === void 0 || owner === process.pid) fs5.rmSync(dir, { recursive: true, force: true });
|
|
647
1449
|
}
|
|
648
1450
|
}
|
|
649
1451
|
function withBoardLock(fn2) {
|
|
650
|
-
if (!
|
|
1452
|
+
if (!fs5.existsSync(KANBAN)) return fn2();
|
|
651
1453
|
if (depth > 0) return fn2();
|
|
652
1454
|
try {
|
|
653
1455
|
ensureAkbDir();
|
|
@@ -713,8 +1515,8 @@ var init_argv = __esm({
|
|
|
713
1515
|
});
|
|
714
1516
|
|
|
715
1517
|
// src/lib/agent/installed.ts
|
|
716
|
-
import
|
|
717
|
-
import
|
|
1518
|
+
import fs6 from "node:fs";
|
|
1519
|
+
import path7 from "node:path";
|
|
718
1520
|
function windowsExtensions() {
|
|
719
1521
|
const raw = process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD";
|
|
720
1522
|
return raw.split(";").map((ext) => ext.trim().toLowerCase()).filter(Boolean);
|
|
@@ -725,21 +1527,21 @@ function commandBinary(command) {
|
|
|
725
1527
|
function binaryOnPath(binary) {
|
|
726
1528
|
if (!binary) return false;
|
|
727
1529
|
const extensions = WINDOWS ? ["", ...windowsExtensions()] : [""];
|
|
728
|
-
for (const dir of (process.env.PATH ?? "").split(
|
|
1530
|
+
for (const dir of (process.env.PATH ?? "").split(path7.delimiter)) {
|
|
729
1531
|
if (!dir) continue;
|
|
730
1532
|
for (const ext of extensions) {
|
|
731
|
-
if (
|
|
1533
|
+
if (fs6.existsSync(path7.join(dir, `${binary}${ext}`))) return true;
|
|
732
1534
|
}
|
|
733
1535
|
}
|
|
734
1536
|
return false;
|
|
735
1537
|
}
|
|
736
1538
|
function pathLookup() {
|
|
737
1539
|
const names3 = /* @__PURE__ */ new Set();
|
|
738
|
-
for (const dir of (process.env.PATH ?? "").split(
|
|
1540
|
+
for (const dir of (process.env.PATH ?? "").split(path7.delimiter)) {
|
|
739
1541
|
if (!dir) continue;
|
|
740
1542
|
let entries;
|
|
741
1543
|
try {
|
|
742
|
-
entries =
|
|
1544
|
+
entries = fs6.readdirSync(dir);
|
|
743
1545
|
} catch {
|
|
744
1546
|
continue;
|
|
745
1547
|
}
|
|
@@ -749,7 +1551,7 @@ function pathLookup() {
|
|
|
749
1551
|
return (command) => {
|
|
750
1552
|
const binary = commandBinary(command);
|
|
751
1553
|
if (!binary) return false;
|
|
752
|
-
if (binary.includes("/") || binary.includes("\\")) return
|
|
1554
|
+
if (binary.includes("/") || binary.includes("\\")) return fs6.existsSync(binary);
|
|
753
1555
|
if (!WINDOWS) return names3.has(binary);
|
|
754
1556
|
const lower = binary.toLowerCase();
|
|
755
1557
|
return names3.has(lower) || extensions.some((ext) => names3.has(`${lower}${ext}`));
|
|
@@ -766,11 +1568,11 @@ var init_installed = __esm({
|
|
|
766
1568
|
|
|
767
1569
|
// src/lib/agent/launch.ts
|
|
768
1570
|
import { spawn } from "node:child_process";
|
|
769
|
-
import
|
|
770
|
-
import
|
|
1571
|
+
import fs7 from "node:fs";
|
|
1572
|
+
import path8 from "node:path";
|
|
771
1573
|
import { fileURLToPath } from "node:url";
|
|
772
1574
|
function boardArgs() {
|
|
773
|
-
const standard =
|
|
1575
|
+
const standard = path8.join(REPO_ROOT, "docs", "kanban");
|
|
774
1576
|
return KANBAN === standard ? ["--dir", REPO_ROOT] : ["--board", KANBAN];
|
|
775
1577
|
}
|
|
776
1578
|
function watcherEnv(env2 = process.env) {
|
|
@@ -779,8 +1581,8 @@ function watcherEnv(env2 = process.env) {
|
|
|
779
1581
|
}
|
|
780
1582
|
function spawnWatcher(sessionId) {
|
|
781
1583
|
if (!BUILT) return void 0;
|
|
782
|
-
|
|
783
|
-
const out =
|
|
1584
|
+
fs7.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
1585
|
+
const out = fs7.openSync(path8.join(SESSIONS_DIR, `${sessionId}.watch.log`), "a");
|
|
784
1586
|
try {
|
|
785
1587
|
const child = spawn(process.execPath, [SELF, "__watch", sessionId, ...boardArgs()], {
|
|
786
1588
|
cwd: REPO_ROOT,
|
|
@@ -796,7 +1598,7 @@ function spawnWatcher(sessionId) {
|
|
|
796
1598
|
return void 0;
|
|
797
1599
|
} finally {
|
|
798
1600
|
try {
|
|
799
|
-
|
|
1601
|
+
fs7.closeSync(out);
|
|
800
1602
|
} catch {
|
|
801
1603
|
}
|
|
802
1604
|
}
|
|
@@ -813,13 +1615,13 @@ var init_launch = __esm({
|
|
|
813
1615
|
});
|
|
814
1616
|
|
|
815
1617
|
// src/lib/agent/command.ts
|
|
816
|
-
import
|
|
817
|
-
import
|
|
1618
|
+
import fs8 from "node:fs";
|
|
1619
|
+
import path9 from "node:path";
|
|
818
1620
|
function selfCommand() {
|
|
819
|
-
const bin =
|
|
820
|
-
const file2 =
|
|
1621
|
+
const bin = path9.resolve(path9.dirname(SELF), "..", "bin", "ai4kanban.mjs");
|
|
1622
|
+
const file2 = fs8.existsSync(bin) ? bin : SELF;
|
|
821
1623
|
const inside2 = rel(file2);
|
|
822
|
-
const shortHop = !inside2.startsWith("..") && !
|
|
1624
|
+
const shortHop = !inside2.startsWith("..") && !path9.isAbsolute(inside2) && inside2.split(/[\\/]/).length <= 3;
|
|
823
1625
|
return `node ${shortHop ? inside2 : file2}`;
|
|
824
1626
|
}
|
|
825
1627
|
function boardCommand() {
|
|
@@ -834,8 +1636,8 @@ function rawMove(words) {
|
|
|
834
1636
|
return `${command} raw ${words}${BOARD_FLAG || ` --dir ${REPO_ROOT}`}`;
|
|
835
1637
|
}
|
|
836
1638
|
function absoluteSelf() {
|
|
837
|
-
const bin =
|
|
838
|
-
return
|
|
1639
|
+
const bin = path9.resolve(path9.dirname(SELF), "..", "bin", "ai4kanban.mjs");
|
|
1640
|
+
return fs8.existsSync(bin) ? bin : SELF;
|
|
839
1641
|
}
|
|
840
1642
|
function commandNote(command) {
|
|
841
1643
|
if (command === "akb") return "";
|
|
@@ -851,9 +1653,9 @@ var init_command = __esm({
|
|
|
851
1653
|
});
|
|
852
1654
|
|
|
853
1655
|
// src/lib/machine/identity.ts
|
|
854
|
-
import
|
|
1656
|
+
import os2 from "node:os";
|
|
855
1657
|
function machineName() {
|
|
856
|
-
const raw =
|
|
1658
|
+
const raw = os2.hostname().trim();
|
|
857
1659
|
return raw.replace(/\.local$/i, "") || "this machine";
|
|
858
1660
|
}
|
|
859
1661
|
var init_identity = __esm({
|
|
@@ -932,21 +1734,9 @@ var init_capabilities = __esm({
|
|
|
932
1734
|
}
|
|
933
1735
|
});
|
|
934
1736
|
|
|
935
|
-
// src/lib/machine/home.ts
|
|
936
|
-
import os2 from "node:os";
|
|
937
|
-
import path7 from "node:path";
|
|
938
|
-
function machineHome() {
|
|
939
|
-
return process.env.AI4KANBAN_HOME || path7.join(os2.homedir(), ".ai4kanban");
|
|
940
|
-
}
|
|
941
|
-
var init_home = __esm({
|
|
942
|
-
"src/lib/machine/home.ts"() {
|
|
943
|
-
"use strict";
|
|
944
|
-
}
|
|
945
|
-
});
|
|
946
|
-
|
|
947
1737
|
// src/lib/agent/spawnable.ts
|
|
948
|
-
import
|
|
949
|
-
import
|
|
1738
|
+
import fs9 from "node:fs";
|
|
1739
|
+
import path10 from "node:path";
|
|
950
1740
|
function cmdArg(arg) {
|
|
951
1741
|
const quoted = `"${arg.replace(/\r?\n|\r/g, " ").replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1")}"`;
|
|
952
1742
|
return quoted.replace(META, "^$1").replace(META, "^$1");
|
|
@@ -955,21 +1745,21 @@ function cmdLine(file2, args2) {
|
|
|
955
1745
|
return `"${[file2.replace(META, "^$1"), ...args2.map(cmdArg)].join(" ")}"`;
|
|
956
1746
|
}
|
|
957
1747
|
function shimTarget(text6, file2) {
|
|
958
|
-
const dir =
|
|
1748
|
+
const dir = path10.win32.dirname(file2);
|
|
959
1749
|
const found2 = /"%(?:~dp0|dp0%)\\?([^"%]+)"\s+%\*/i.exec(text6);
|
|
960
1750
|
if (!found2 || !/\\node\.exe"/i.test(text6)) return null;
|
|
961
|
-
const script =
|
|
962
|
-
const local =
|
|
1751
|
+
const script = path10.win32.resolve(dir, found2[1].replace(/\//g, "\\"));
|
|
1752
|
+
const local = path10.win32.join(dir, "node.exe");
|
|
963
1753
|
const nodePath = /SET "NODE_PATH=([^"]*)"/i.exec(text6)?.[1];
|
|
964
|
-
return { script, node:
|
|
1754
|
+
return { script, node: fs9.existsSync(local) ? local : "node", env: nodePath ? { NODE_PATH: nodePath } : {} };
|
|
965
1755
|
}
|
|
966
1756
|
function onWindowsPath(name, env2) {
|
|
967
1757
|
const exts = (env2.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
|
|
968
1758
|
const key = Object.keys(env2).find((k2) => k2.toUpperCase() === "PATH") ?? "PATH";
|
|
969
1759
|
for (const dir of (env2[key] ?? "").split(";").filter(Boolean)) {
|
|
970
1760
|
for (const ext of exts) {
|
|
971
|
-
const file2 =
|
|
972
|
-
if (
|
|
1761
|
+
const file2 = path10.win32.join(dir, `${name}${ext.toLowerCase()}`);
|
|
1762
|
+
if (fs9.existsSync(file2)) return file2;
|
|
973
1763
|
}
|
|
974
1764
|
}
|
|
975
1765
|
return void 0;
|
|
@@ -977,13 +1767,13 @@ function onWindowsPath(name, env2) {
|
|
|
977
1767
|
function spawnable(command, args2, options = {}, platform = process.platform) {
|
|
978
1768
|
if (platform !== "win32") return { command, args: args2, options };
|
|
979
1769
|
const env2 = options.env ?? process.env;
|
|
980
|
-
const file2 =
|
|
981
|
-
const ext =
|
|
1770
|
+
const file2 = path10.extname(command) || /[\\/]/.test(command) ? command : onWindowsPath(command, env2) ?? command;
|
|
1771
|
+
const ext = path10.extname(file2).toLowerCase();
|
|
982
1772
|
const hidden = { ...options, windowsHide: true, shell: false };
|
|
983
1773
|
if (ext !== ".cmd" && ext !== ".bat") return { command: file2, args: args2, options: hidden };
|
|
984
1774
|
let text6 = "";
|
|
985
1775
|
try {
|
|
986
|
-
text6 =
|
|
1776
|
+
text6 = fs9.readFileSync(file2, "utf8");
|
|
987
1777
|
} catch {
|
|
988
1778
|
}
|
|
989
1779
|
const shim = shimTarget(text6, file2);
|
|
@@ -1006,9 +1796,9 @@ var init_spawnable = __esm({
|
|
|
1006
1796
|
|
|
1007
1797
|
// src/lib/agent/locate.ts
|
|
1008
1798
|
import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
1009
|
-
import
|
|
1799
|
+
import fs10 from "node:fs";
|
|
1010
1800
|
import os3 from "node:os";
|
|
1011
|
-
import
|
|
1801
|
+
import path11 from "node:path";
|
|
1012
1802
|
function versionIn(output) {
|
|
1013
1803
|
const plain = output.replace(/\x1b\[[0-9;]*m/g, "");
|
|
1014
1804
|
return /(?<![\w.-])v?(\d+(?:\.\d+)+(?:-[0-9A-Za-z.-]+)?)/.exec(plain)?.[1] ?? null;
|
|
@@ -1053,7 +1843,7 @@ function pick(copies) {
|
|
|
1053
1843
|
}
|
|
1054
1844
|
function folders(parent) {
|
|
1055
1845
|
try {
|
|
1056
|
-
return
|
|
1846
|
+
return fs10.readdirSync(parent, { withFileTypes: true }).filter((one) => one.isDirectory()).map((one) => one.name);
|
|
1057
1847
|
} catch {
|
|
1058
1848
|
return [];
|
|
1059
1849
|
}
|
|
@@ -1072,28 +1862,28 @@ function byVersion(names3) {
|
|
|
1072
1862
|
function latestIn(parent, tail = "") {
|
|
1073
1863
|
let names3;
|
|
1074
1864
|
try {
|
|
1075
|
-
names3 =
|
|
1865
|
+
names3 = fs10.readdirSync(parent);
|
|
1076
1866
|
} catch {
|
|
1077
1867
|
return [];
|
|
1078
1868
|
}
|
|
1079
|
-
return byVersion(names3.filter((name) => !name.startsWith("."))).slice(0, 2).map((name) =>
|
|
1869
|
+
return byVersion(names3.filter((name) => !name.startsWith("."))).slice(0, 2).map((name) => path11.join(parent, name, tail));
|
|
1080
1870
|
}
|
|
1081
1871
|
function commonDirs() {
|
|
1082
1872
|
const home3 = os3.homedir();
|
|
1083
|
-
const under = (...parts) =>
|
|
1084
|
-
const nodes = (root2, tail = []) => root2 ? folders(root2).map((version) =>
|
|
1873
|
+
const under = (...parts) => path11.join(home3, ...parts);
|
|
1874
|
+
const nodes = (root2, tail = []) => root2 ? folders(root2).map((version) => path11.join(root2, version, ...tail)) : [];
|
|
1085
1875
|
if (WINDOWS2) {
|
|
1086
1876
|
const [app, local, data, programs] = [env("APPDATA"), env("LOCALAPPDATA"), env("ProgramData"), env("ProgramFiles")];
|
|
1087
1877
|
return [
|
|
1088
1878
|
under(".local", "bin"),
|
|
1089
1879
|
under(".bun", "bin"),
|
|
1090
1880
|
under("scoop", "shims"),
|
|
1091
|
-
...app ? [
|
|
1092
|
-
...local ? [
|
|
1093
|
-
...data ? [
|
|
1094
|
-
...programs ? [
|
|
1881
|
+
...app ? [path11.join(app, "npm")] : [],
|
|
1882
|
+
...local ? [path11.join(local, "pnpm"), path11.join(local, "Volta", "bin"), path11.join(local, "Microsoft", "WinGet", "Links")] : [],
|
|
1883
|
+
...data ? [path11.join(data, "chocolatey", "bin")] : [],
|
|
1884
|
+
...programs ? [path11.join(programs, "nodejs")] : [],
|
|
1095
1885
|
...nodes(env("NVM_HOME")),
|
|
1096
|
-
...app ? nodes(
|
|
1886
|
+
...app ? nodes(path11.join(app, "fnm", "node-versions"), ["installation"]) : []
|
|
1097
1887
|
];
|
|
1098
1888
|
}
|
|
1099
1889
|
const support = process.platform === "darwin" ? under("Library", "Application Support") : under(".local", "share");
|
|
@@ -1110,10 +1900,10 @@ function commonDirs() {
|
|
|
1110
1900
|
...env("PNPM_HOME") ? [env("PNPM_HOME")] : [],
|
|
1111
1901
|
under("Library", "pnpm"),
|
|
1112
1902
|
under(".local", "share", "pnpm"),
|
|
1113
|
-
|
|
1114
|
-
...nodes(
|
|
1115
|
-
...nodes(
|
|
1116
|
-
...nodes(
|
|
1903
|
+
path11.join(env("VOLTA_HOME") || under(".volta"), "bin"),
|
|
1904
|
+
...nodes(path11.join(env("NVM_DIR") || under(".nvm"), "versions", "node"), ["bin"]),
|
|
1905
|
+
...nodes(path11.join(env("FNM_DIR") || path11.join(support, "fnm"), "node-versions"), ["installation", "bin"]),
|
|
1906
|
+
...nodes(path11.join(env("ASDF_DATA_DIR") || under(".asdf"), "installs", "nodejs"), ["bin"]),
|
|
1117
1907
|
...nodes(under(".local", "share", "mise", "installs", "node"), ["bin"]),
|
|
1118
1908
|
...nodes(under(".nodenv", "versions"), ["bin"]),
|
|
1119
1909
|
...nodes("/usr/local/n/versions/node", ["bin"])
|
|
@@ -1121,19 +1911,19 @@ function commonDirs() {
|
|
|
1121
1911
|
}
|
|
1122
1912
|
function onPath(binary) {
|
|
1123
1913
|
const names3 = WINDOWS2 ? (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean).map((ext) => `${binary}${ext.toLowerCase()}`) : [binary];
|
|
1124
|
-
return (process.env.PATH ?? "").split(
|
|
1914
|
+
return (process.env.PATH ?? "").split(path11.delimiter).filter(Boolean).flatMap((dir) => names3.map((name) => path11.join(dir, name)));
|
|
1125
1915
|
}
|
|
1126
1916
|
function copyFiles(harness) {
|
|
1127
1917
|
const pinned2 = harness.pinned?.();
|
|
1128
1918
|
if (pinned2 && isFile(pinned2)) return [{ file: pinned2, entry: false }];
|
|
1129
1919
|
const binary = commandBinary(harness.command);
|
|
1130
|
-
const exe = (file2) => WINDOWS2 && !
|
|
1920
|
+
const exe = (file2) => WINDOWS2 && !path11.extname(file2) ? [`${file2}.exe`, `${file2}.cmd`] : [file2];
|
|
1131
1921
|
const path_ = onPath(binary).filter(isFile);
|
|
1132
|
-
const elsewhere = process.env.AI4KANBAN_PATH_ONLY ? [] : [...harness.installs?.() ?? [], ...commonDirs().map((dir) =>
|
|
1922
|
+
const elsewhere = process.env.AI4KANBAN_PATH_ONLY ? [] : [...harness.installs?.() ?? [], ...commonDirs().map((dir) => path11.join(dir, binary))];
|
|
1133
1923
|
const others = elsewhere.flatMap(exe).filter(isFile);
|
|
1134
1924
|
const seen = /* @__PURE__ */ new Set();
|
|
1135
1925
|
return [...path_, ...others].flatMap((file2, i) => {
|
|
1136
|
-
const real2 =
|
|
1926
|
+
const real2 = fs10.realpathSync.native(file2);
|
|
1137
1927
|
if (seen.has(real2)) return [];
|
|
1138
1928
|
seen.add(real2);
|
|
1139
1929
|
return [{ file: file2, entry: i === 0 && path_.length > 0 }];
|
|
@@ -1142,7 +1932,7 @@ function copyFiles(harness) {
|
|
|
1142
1932
|
function kept() {
|
|
1143
1933
|
if (answers) return answers;
|
|
1144
1934
|
try {
|
|
1145
|
-
answers = JSON.parse(
|
|
1935
|
+
answers = JSON.parse(fs10.readFileSync(answersFile(), "utf8"));
|
|
1146
1936
|
} catch {
|
|
1147
1937
|
answers = {};
|
|
1148
1938
|
}
|
|
@@ -1151,16 +1941,16 @@ function kept() {
|
|
|
1151
1941
|
function keep(file2, answer2) {
|
|
1152
1942
|
kept()[file2] = answer2;
|
|
1153
1943
|
try {
|
|
1154
|
-
|
|
1944
|
+
fs10.mkdirSync(machineHome(), { recursive: true });
|
|
1155
1945
|
const staged = `${answersFile()}.${process.pid}`;
|
|
1156
|
-
|
|
1157
|
-
|
|
1946
|
+
fs10.writeFileSync(staged, JSON.stringify(answers));
|
|
1947
|
+
fs10.renameSync(staged, answersFile());
|
|
1158
1948
|
} catch {
|
|
1159
1949
|
}
|
|
1160
1950
|
}
|
|
1161
1951
|
function keyOf(file2) {
|
|
1162
|
-
const real2 =
|
|
1163
|
-
const stat =
|
|
1952
|
+
const real2 = fs10.realpathSync.native(file2);
|
|
1953
|
+
const stat = fs10.statSync(real2);
|
|
1164
1954
|
return `${real2}|${stat.size}|${stat.mtimeMs}`;
|
|
1165
1955
|
}
|
|
1166
1956
|
function known(file2, maxAge) {
|
|
@@ -1173,8 +1963,8 @@ function judge(code, status, stdout, stderr) {
|
|
|
1173
1963
|
return { starts: true, version: status === 0 ? versionIn(stdout) ?? versionIn(stderr) : null };
|
|
1174
1964
|
}
|
|
1175
1965
|
function copyEnv(file2, given = process.env) {
|
|
1176
|
-
if (!
|
|
1177
|
-
return { ...given, PATH: [
|
|
1966
|
+
if (!path11.isAbsolute(file2)) return given;
|
|
1967
|
+
return { ...given, PATH: [path11.dirname(file2), given.PATH].filter(Boolean).join(path11.delimiter) };
|
|
1178
1968
|
}
|
|
1179
1969
|
function probe(file2) {
|
|
1180
1970
|
const key = keyOf(file2);
|
|
@@ -1225,13 +2015,13 @@ var init_locate = __esm({
|
|
|
1225
2015
|
env = (name) => process.env[name]?.trim() ?? "";
|
|
1226
2016
|
isFile = (file2) => {
|
|
1227
2017
|
try {
|
|
1228
|
-
return
|
|
2018
|
+
return fs10.statSync(file2).isFile();
|
|
1229
2019
|
} catch {
|
|
1230
2020
|
return false;
|
|
1231
2021
|
}
|
|
1232
2022
|
};
|
|
1233
2023
|
isCopy = (harness, file2) => copyFiles(harness).some((one) => one.file === file2);
|
|
1234
|
-
answersFile = () =>
|
|
2024
|
+
answersFile = () => path11.join(machineHome(), "agent-copies.json");
|
|
1235
2025
|
probeOptions = (file2) => ({ cwd: os3.tmpdir(), env: copyEnv(file2), windowsHide: true, shell: false });
|
|
1236
2026
|
spawnName = (copy2, binary) => copy2 && (!copy2.entry || /\.(cmd|bat)$/i.test(copy2.file)) ? copy2.file : binary;
|
|
1237
2027
|
}
|
|
@@ -1288,21 +2078,21 @@ var init_models = __esm({
|
|
|
1288
2078
|
});
|
|
1289
2079
|
|
|
1290
2080
|
// src/lib/agent/harnesses/types.ts
|
|
1291
|
-
import { createHash } from "node:crypto";
|
|
1292
|
-
import
|
|
1293
|
-
import
|
|
2081
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
2082
|
+
import fs11 from "node:fs";
|
|
2083
|
+
import path12 from "node:path";
|
|
1294
2084
|
function namesFlag(argv, flags) {
|
|
1295
2085
|
return argv.some((tok) => flags.some((flag) => tok === flag || tok.startsWith(`${flag}=`)));
|
|
1296
2086
|
}
|
|
1297
2087
|
function machineFile(name, text6) {
|
|
1298
|
-
const suffix =
|
|
1299
|
-
const file2 =
|
|
2088
|
+
const suffix = createHash2("sha256").update(text6).digest("hex").slice(0, 16);
|
|
2089
|
+
const file2 = path12.join(machineHome(), "prompts", `${path12.parse(name).name}-${suffix}${path12.extname(name)}`);
|
|
1300
2090
|
try {
|
|
1301
|
-
if (
|
|
2091
|
+
if (fs11.readFileSync(file2, "utf8") === text6) return file2;
|
|
1302
2092
|
} catch {
|
|
1303
2093
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
2094
|
+
fs11.mkdirSync(path12.dirname(file2), { recursive: true });
|
|
2095
|
+
fs11.writeFileSync(file2, text6);
|
|
1306
2096
|
return file2;
|
|
1307
2097
|
}
|
|
1308
2098
|
var RAW_ARGS_KEY, MODEL_KEY, RAW_ARGS, MCP_CONFIG;
|
|
@@ -1343,12 +2133,12 @@ var init_types2 = __esm({
|
|
|
1343
2133
|
});
|
|
1344
2134
|
|
|
1345
2135
|
// src/lib/machine/settings.ts
|
|
1346
|
-
import
|
|
1347
|
-
import
|
|
2136
|
+
import fs12 from "node:fs";
|
|
2137
|
+
import path13 from "node:path";
|
|
1348
2138
|
function heldSettings() {
|
|
1349
2139
|
let text6;
|
|
1350
2140
|
try {
|
|
1351
|
-
text6 =
|
|
2141
|
+
text6 = fs12.readFileSync(settingsFile(), "utf8");
|
|
1352
2142
|
} catch (err) {
|
|
1353
2143
|
if (err.code === "ENOENT") return { unreadable: false, values: {} };
|
|
1354
2144
|
return { unreadable: true, values: {} };
|
|
@@ -1371,12 +2161,12 @@ function saveSettings(patch2) {
|
|
|
1371
2161
|
const next = { ...values, ...patch2 };
|
|
1372
2162
|
for (const [key, value] of Object.entries(patch2)) if (value === void 0) delete next[key];
|
|
1373
2163
|
try {
|
|
1374
|
-
|
|
2164
|
+
fs12.mkdirSync(machineHome(), { recursive: true, mode: 448 });
|
|
1375
2165
|
const file2 = settingsFile();
|
|
1376
2166
|
const tmp = `${file2}.${process.pid}.tmp`;
|
|
1377
|
-
|
|
2167
|
+
fs12.writeFileSync(tmp, `${JSON.stringify(next, null, 2)}
|
|
1378
2168
|
`);
|
|
1379
|
-
|
|
2169
|
+
fs12.renameSync(tmp, file2);
|
|
1380
2170
|
return { ok: true };
|
|
1381
2171
|
} catch (err) {
|
|
1382
2172
|
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
@@ -1388,7 +2178,7 @@ var init_settings = __esm({
|
|
|
1388
2178
|
"use strict";
|
|
1389
2179
|
init_home();
|
|
1390
2180
|
init_types2();
|
|
1391
|
-
settingsFile = () =>
|
|
2181
|
+
settingsFile = () => path13.join(machineHome(), "settings.json");
|
|
1392
2182
|
held = () => heldSettings().values;
|
|
1393
2183
|
}
|
|
1394
2184
|
});
|
|
@@ -1822,9 +2612,9 @@ var init_antigravity = __esm({
|
|
|
1822
2612
|
});
|
|
1823
2613
|
|
|
1824
2614
|
// src/lib/agent/harnesses/antigravity.ts
|
|
1825
|
-
import
|
|
1826
|
-
import
|
|
1827
|
-
import { createHash as
|
|
2615
|
+
import fs13 from "node:fs";
|
|
2616
|
+
import path14 from "node:path";
|
|
2617
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
1828
2618
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
1829
2619
|
function antigravityModels(output) {
|
|
1830
2620
|
return output.split("\n").flatMap((line) => {
|
|
@@ -1834,7 +2624,7 @@ function antigravityModels(output) {
|
|
|
1834
2624
|
}
|
|
1835
2625
|
function args(argv, resume) {
|
|
1836
2626
|
if (namesFlag(argv, ["--continue", "-c", "--conversation", "--remote-agent"])) throw new Error(translating() ? "\u8BF7\u901A\u8FC7 WildCrane \u9009\u62E9 Antigravity \u4F1A\u8BDD\uFF0C\u4E0D\u8981\u5728\u989D\u5916\u53C2\u6570\u4E2D\u6307\u5B9A\u4F1A\u8BDD\u6216\u8FDC\u7A0B\u6267\u884C\u3002" : "Antigravity: select a session through WildCrane, not extra arguments.");
|
|
1837
|
-
if (resume && (!/^[a-f0-9-]{36}$/i.test(resume) || !
|
|
2627
|
+
if (resume && (!/^[a-f0-9-]{36}$/i.test(resume) || !fs13.existsSync(home(".gemini", "antigravity-cli", "conversations", `${resume}.db`)))) throw new Error(translating() ? "Antigravity \u4F1A\u8BDD\u4E0D\u5B58\u5728\u3002\u8BF7\u5728\u672C\u673A\u6062\u590D\u539F\u4F1A\u8BDD\u540E\u7EED\u63A5\u3002" : "Antigravity session not found. Restore the original conversation on this computer before resuming.");
|
|
1838
2628
|
const extra = resume ? ["--conversation", resume] : [];
|
|
1839
2629
|
if (!namesFlag(argv, ["--output-format"])) extra.push("--output-format", "stream-json");
|
|
1840
2630
|
if (!namesFlag(argv, ["--dangerously-skip-permissions"])) extra.push("--dangerously-skip-permissions");
|
|
@@ -1885,11 +2675,11 @@ var init_antigravity2 = __esm({
|
|
|
1885
2675
|
const rule = `${text6}
|
|
1886
2676
|
|
|
1887
2677
|
The task working directory is ${env2.PWD ?? process.cwd()}. Use it as the base for project files and commands. This additional workspace contains only language rules; do not write task output here.`;
|
|
1888
|
-
const hash2 =
|
|
1889
|
-
const root2 =
|
|
1890
|
-
const file2 =
|
|
1891
|
-
|
|
1892
|
-
|
|
2678
|
+
const hash2 = createHash3("sha256").update(rule).digest("hex").slice(0, 16);
|
|
2679
|
+
const root2 = path14.join(machineHome(), "prompts", `antigravity-${hash2}`);
|
|
2680
|
+
const file2 = path14.join(root2, ".agents", "rules", "language.md");
|
|
2681
|
+
fs13.mkdirSync(path14.dirname(file2), { recursive: true });
|
|
2682
|
+
fs13.writeFileSync(file2, `---
|
|
1893
2683
|
trigger: always_on
|
|
1894
2684
|
---
|
|
1895
2685
|
|
|
@@ -2310,7 +3100,7 @@ var init_prices = __esm({
|
|
|
2310
3100
|
import { readFileSync as readFileSync2, readdirSync, statSync as statSync2 } from "node:fs";
|
|
2311
3101
|
import { homedir as homedir2 } from "node:os";
|
|
2312
3102
|
import { join as join2 } from "node:path";
|
|
2313
|
-
function
|
|
3103
|
+
function text2(value) {
|
|
2314
3104
|
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
2315
3105
|
}
|
|
2316
3106
|
function count(value) {
|
|
@@ -2408,8 +3198,8 @@ function readCodexRunFacts(threadId) {
|
|
|
2408
3198
|
} catch {
|
|
2409
3199
|
}
|
|
2410
3200
|
}
|
|
2411
|
-
if (entry.type === "session_meta") facts.provider ??=
|
|
2412
|
-
if (entry.type === "turn_context") facts.model =
|
|
3201
|
+
if (entry.type === "session_meta") facts.provider ??= text2(payload.model_provider);
|
|
3202
|
+
if (entry.type === "turn_context") facts.model = text2(payload.model) ?? facts.model;
|
|
2413
3203
|
if (payload.type === "token_count") {
|
|
2414
3204
|
facts.context = contextIn(payload.info) ?? facts.context;
|
|
2415
3205
|
const info = payload.info && typeof payload.info === "object" ? payload.info : {};
|
|
@@ -2943,7 +3733,7 @@ function createKimiStreamRenderer(cwd, resumeId) {
|
|
|
2943
3733
|
subagents.add(str2(call2.id));
|
|
2944
3734
|
events.subagent(str2(call2.id), str2(args2.description) || name);
|
|
2945
3735
|
} else {
|
|
2946
|
-
events.toolCall(str2(call2.id), name,
|
|
3736
|
+
events.toolCall(str2(call2.id), name, kindOf2(name), ARG_KEYS2.map((k2) => str2(args2[k2])).find((v) => v.trim()));
|
|
2947
3737
|
}
|
|
2948
3738
|
}
|
|
2949
3739
|
return `${said2 ? `${said2}
|
|
@@ -2992,7 +3782,7 @@ function createKimiStreamRenderer(cwd, resumeId) {
|
|
|
2992
3782
|
}
|
|
2993
3783
|
};
|
|
2994
3784
|
}
|
|
2995
|
-
var ARG_KEYS2, TOOL_KINDS3,
|
|
3785
|
+
var ARG_KEYS2, TOOL_KINDS3, kindOf2, LOOK_EVERY_MS2;
|
|
2996
3786
|
var init_kimi_stream = __esm({
|
|
2997
3787
|
"src/lib/agent/wire/kimi-stream.ts"() {
|
|
2998
3788
|
"use strict";
|
|
@@ -3009,22 +3799,22 @@ var init_kimi_stream = __esm({
|
|
|
3009
3799
|
[/bash|shell/i, "execute"],
|
|
3010
3800
|
[/write|edit|replace/i, "edit"]
|
|
3011
3801
|
];
|
|
3012
|
-
|
|
3802
|
+
kindOf2 = (name) => TOOL_KINDS3.find(([re3]) => re3.test(name))?.[1] ?? "other";
|
|
3013
3803
|
LOOK_EVERY_MS2 = 3e3;
|
|
3014
3804
|
}
|
|
3015
3805
|
});
|
|
3016
3806
|
|
|
3017
3807
|
// src/lib/agent/wire/acp-cost.ts
|
|
3018
|
-
import
|
|
3019
|
-
import
|
|
3020
|
-
import { createHash as
|
|
3808
|
+
import fs14 from "node:fs";
|
|
3809
|
+
import path15 from "node:path";
|
|
3810
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
3021
3811
|
function acpCostFile(tool, cwd, session) {
|
|
3022
|
-
const key =
|
|
3023
|
-
return
|
|
3812
|
+
const key = createHash4("sha256").update(JSON.stringify([tool, cwd, session])).digest("hex");
|
|
3813
|
+
return path15.join(machineHome(), "usage", "acp", `${key}.json`);
|
|
3024
3814
|
}
|
|
3025
3815
|
function readAcpCost(file2) {
|
|
3026
3816
|
try {
|
|
3027
|
-
const n = JSON.parse(
|
|
3817
|
+
const n = JSON.parse(fs14.readFileSync(file2, "utf8"));
|
|
3028
3818
|
return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : void 0;
|
|
3029
3819
|
} catch {
|
|
3030
3820
|
return void 0;
|
|
@@ -3033,10 +3823,10 @@ function readAcpCost(file2) {
|
|
|
3033
3823
|
function saveAcpCost(file2, cost) {
|
|
3034
3824
|
if (cost === void 0) return;
|
|
3035
3825
|
try {
|
|
3036
|
-
|
|
3826
|
+
fs14.mkdirSync(path15.dirname(file2), { recursive: true, mode: 448 });
|
|
3037
3827
|
const tmp = `${file2}.${process.pid}.tmp`;
|
|
3038
|
-
|
|
3039
|
-
|
|
3828
|
+
fs14.writeFileSync(tmp, JSON.stringify(cost), { mode: 384 });
|
|
3829
|
+
fs14.renameSync(tmp, file2);
|
|
3040
3830
|
} catch {
|
|
3041
3831
|
}
|
|
3042
3832
|
}
|
|
@@ -3215,7 +4005,7 @@ var init_package = __esm({
|
|
|
3215
4005
|
"package.json"() {
|
|
3216
4006
|
package_default = {
|
|
3217
4007
|
name: "wildcrane",
|
|
3218
|
-
version: "0.11.
|
|
4008
|
+
version: "0.11.66",
|
|
3219
4009
|
akbContract: 17,
|
|
3220
4010
|
description: "WildCrane's `akb` command \u2014 scaffold the Markdown board under docs/kanban/, put an agent on a card, and carry the flows the agent works by.",
|
|
3221
4011
|
keywords: [
|
|
@@ -3291,7 +4081,7 @@ var init_version = __esm({
|
|
|
3291
4081
|
});
|
|
3292
4082
|
|
|
3293
4083
|
// src/lib/agent/wire/acp.ts
|
|
3294
|
-
import
|
|
4084
|
+
import fs15 from "node:fs";
|
|
3295
4085
|
function whereHint(update2, title) {
|
|
3296
4086
|
const locations = Array.isArray(update2.locations) ? update2.locations : [];
|
|
3297
4087
|
const path88 = str2(obj2(locations[0]).path);
|
|
@@ -3356,7 +4146,7 @@ function ticksUsd(value) {
|
|
|
3356
4146
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? ticks / TICKS_PER_USD : void 0;
|
|
3357
4147
|
}
|
|
3358
4148
|
function mcpServersIn(file2) {
|
|
3359
|
-
const servers = obj2(obj2(JSON.parse(
|
|
4149
|
+
const servers = obj2(obj2(JSON.parse(fs15.readFileSync(file2, "utf8"))).mcpServers);
|
|
3360
4150
|
return Object.entries(servers).map(([name, raw]) => {
|
|
3361
4151
|
const s = obj2(raw);
|
|
3362
4152
|
return {
|
|
@@ -3586,7 +4376,7 @@ var init_acp = __esm({
|
|
|
3586
4376
|
});
|
|
3587
4377
|
|
|
3588
4378
|
// src/lib/agent/wire/zcode.ts
|
|
3589
|
-
import
|
|
4379
|
+
import path16 from "node:path";
|
|
3590
4380
|
function whereHint2(input, title) {
|
|
3591
4381
|
const named2 = obj2(input);
|
|
3592
4382
|
for (const key of ["command", "file_path", "path", "url", "pattern"]) {
|
|
@@ -3737,7 +4527,7 @@ async function oneTurn2(io, options) {
|
|
|
3737
4527
|
{ stringIds: true }
|
|
3738
4528
|
);
|
|
3739
4529
|
try {
|
|
3740
|
-
const workspacePath =
|
|
4530
|
+
const workspacePath = path16.resolve(io.cwd);
|
|
3741
4531
|
const workspace2 = { workspacePath, workspaceKey: workspacePath };
|
|
3742
4532
|
let opened;
|
|
3743
4533
|
if (io.resumeId) {
|
|
@@ -3875,14 +4665,14 @@ var init_zcode = __esm({
|
|
|
3875
4665
|
});
|
|
3876
4666
|
|
|
3877
4667
|
// src/lib/file-memo.ts
|
|
3878
|
-
import
|
|
3879
|
-
import
|
|
4668
|
+
import fs16 from "node:fs";
|
|
4669
|
+
import path17 from "node:path";
|
|
3880
4670
|
function stamp(paths) {
|
|
3881
4671
|
const parts = [];
|
|
3882
4672
|
const visit = (p2) => {
|
|
3883
4673
|
let st2;
|
|
3884
4674
|
try {
|
|
3885
|
-
st2 =
|
|
4675
|
+
st2 = fs16.statSync(p2, { bigint: true });
|
|
3886
4676
|
} catch {
|
|
3887
4677
|
parts.push(`${p2}:-`);
|
|
3888
4678
|
return;
|
|
@@ -3894,11 +4684,11 @@ function stamp(paths) {
|
|
|
3894
4684
|
parts.push(`${p2}/`);
|
|
3895
4685
|
let names3;
|
|
3896
4686
|
try {
|
|
3897
|
-
names3 =
|
|
4687
|
+
names3 = fs16.readdirSync(p2).sort();
|
|
3898
4688
|
} catch {
|
|
3899
4689
|
return;
|
|
3900
4690
|
}
|
|
3901
|
-
for (const name of names3) if (name !== "node_modules" && name !== ".git") visit(
|
|
4691
|
+
for (const name of names3) if (name !== "node_modules" && name !== ".git") visit(path17.join(p2, name));
|
|
3902
4692
|
};
|
|
3903
4693
|
for (const p2 of paths) visit(p2);
|
|
3904
4694
|
return parts.join("\n");
|
|
@@ -4008,15 +4798,15 @@ var init_types3 = __esm({
|
|
|
4008
4798
|
});
|
|
4009
4799
|
|
|
4010
4800
|
// src/lib/agent/settings.ts
|
|
4011
|
-
import
|
|
4012
|
-
import
|
|
4801
|
+
import fs17 from "node:fs";
|
|
4802
|
+
import path18 from "node:path";
|
|
4013
4803
|
function configBlock(value) {
|
|
4014
4804
|
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
4015
4805
|
return value;
|
|
4016
4806
|
}
|
|
4017
4807
|
function readConfigRaw() {
|
|
4018
|
-
if (!
|
|
4019
|
-
return JSON.parse(
|
|
4808
|
+
if (!fs17.existsSync(UI_CONFIG)) return {};
|
|
4809
|
+
return JSON.parse(fs17.readFileSync(UI_CONFIG, "utf8"));
|
|
4020
4810
|
}
|
|
4021
4811
|
function safeConfig() {
|
|
4022
4812
|
try {
|
|
@@ -4073,8 +4863,8 @@ function writeConfig(change2) {
|
|
|
4073
4863
|
}
|
|
4074
4864
|
change2(cfg);
|
|
4075
4865
|
try {
|
|
4076
|
-
|
|
4077
|
-
|
|
4866
|
+
fs17.mkdirSync(path18.dirname(UI_CONFIG), { recursive: true });
|
|
4867
|
+
fs17.writeFileSync(UI_CONFIG, JSON.stringify(cfg, null, 2) + "\n");
|
|
4078
4868
|
forgetFileMemos();
|
|
4079
4869
|
return { ok: true };
|
|
4080
4870
|
} catch (e2) {
|
|
@@ -4101,7 +4891,7 @@ function unquote(value) {
|
|
|
4101
4891
|
function readEnvFile() {
|
|
4102
4892
|
let text6;
|
|
4103
4893
|
try {
|
|
4104
|
-
text6 =
|
|
4894
|
+
text6 = fs17.readFileSync(ENV_FILE, "utf8");
|
|
4105
4895
|
} catch {
|
|
4106
4896
|
return {};
|
|
4107
4897
|
}
|
|
@@ -4114,15 +4904,15 @@ function readEnvFile() {
|
|
|
4114
4904
|
}
|
|
4115
4905
|
function ensureIgnored() {
|
|
4116
4906
|
try {
|
|
4117
|
-
if (!
|
|
4118
|
-
|
|
4119
|
-
|
|
4907
|
+
if (!fs17.existsSync(KANBAN_GITIGNORE)) {
|
|
4908
|
+
fs17.mkdirSync(path18.dirname(KANBAN_GITIGNORE), { recursive: true });
|
|
4909
|
+
fs17.writeFileSync(KANBAN_GITIGNORE, IGNORE_BLOCK);
|
|
4120
4910
|
return { ok: true };
|
|
4121
4911
|
}
|
|
4122
|
-
const text6 =
|
|
4912
|
+
const text6 = fs17.readFileSync(KANBAN_GITIGNORE, "utf8");
|
|
4123
4913
|
if (text6.split("\n").some((line) => line.trim() === ".env")) return { ok: true };
|
|
4124
4914
|
const separator = !text6 || text6.endsWith("\n") ? "" : "\n";
|
|
4125
|
-
|
|
4915
|
+
fs17.writeFileSync(KANBAN_GITIGNORE, `${text6}${separator}${IGNORE_BLOCK}`);
|
|
4126
4916
|
return { ok: true };
|
|
4127
4917
|
} catch (e2) {
|
|
4128
4918
|
const why2 = e2 instanceof Error ? e2.message : String(e2);
|
|
@@ -4140,7 +4930,7 @@ function setSecret(name, value) {
|
|
|
4140
4930
|
if (!ignored.ok) return ignored;
|
|
4141
4931
|
let lines;
|
|
4142
4932
|
try {
|
|
4143
|
-
lines =
|
|
4933
|
+
lines = fs17.existsSync(ENV_FILE) ? fs17.readFileSync(ENV_FILE, "utf8").split("\n") : [];
|
|
4144
4934
|
} catch (e2) {
|
|
4145
4935
|
const why2 = e2 instanceof Error ? e2.message : String(e2);
|
|
4146
4936
|
return { ok: false, ...refusal("fileRead", `couldn't read ${ENV_FILE}: ${why2}`, { path: ENV_FILE, details: why2 }) };
|
|
@@ -4163,7 +4953,7 @@ function setSecret(name, value) {
|
|
|
4163
4953
|
if (next && !written) text6 += `${name}=${next}
|
|
4164
4954
|
`;
|
|
4165
4955
|
try {
|
|
4166
|
-
|
|
4956
|
+
fs17.writeFileSync(ENV_FILE, text6, { mode: 384 });
|
|
4167
4957
|
return { ok: true };
|
|
4168
4958
|
} catch (e2) {
|
|
4169
4959
|
const why2 = e2 instanceof Error ? e2.message : String(e2);
|
|
@@ -4958,22 +5748,22 @@ var init_transient = __esm({
|
|
|
4958
5748
|
});
|
|
4959
5749
|
|
|
4960
5750
|
// src/lib/agent/harnesses/claude-code.ts
|
|
4961
|
-
import
|
|
5751
|
+
import path19 from "node:path";
|
|
4962
5752
|
function claudeStreamArgs(argv) {
|
|
4963
5753
|
if (argv.includes("--output-format")) return [];
|
|
4964
5754
|
return ["--output-format", "stream-json", "--verbose", ...argv.includes("--input-format") ? [] : ["--input-format", "stream-json"]];
|
|
4965
5755
|
}
|
|
4966
5756
|
function claudeOnWindows() {
|
|
4967
5757
|
const [local, roaming] = [process.env.LOCALAPPDATA?.trim(), process.env.APPDATA?.trim()];
|
|
4968
|
-
const packages = local ?
|
|
5758
|
+
const packages = local ? path19.join(local, "Packages") : "";
|
|
4969
5759
|
const data = [
|
|
4970
|
-
...folders(packages).filter((name) => /^(\w+\.)?Claude_/i.test(name)).sort().map((name) =>
|
|
4971
|
-
...roaming ? [
|
|
5760
|
+
...folders(packages).filter((name) => /^(\w+\.)?Claude_/i.test(name)).sort().map((name) => path19.join(packages, name, "LocalCache", "Roaming", "Claude")),
|
|
5761
|
+
...roaming ? [path19.join(roaming, "Claude")] : []
|
|
4972
5762
|
];
|
|
4973
5763
|
return data.flatMap(
|
|
4974
|
-
(dir) => latestIn(
|
|
4975
|
-
|
|
4976
|
-
...folders(version).map((build) =>
|
|
5764
|
+
(dir) => latestIn(path19.join(dir, "claude-code")).flatMap((version) => [
|
|
5765
|
+
path19.join(version, "claude.exe"),
|
|
5766
|
+
...folders(version).map((build) => path19.join(version, build, "claude.exe"))
|
|
4977
5767
|
])
|
|
4978
5768
|
);
|
|
4979
5769
|
}
|
|
@@ -5243,7 +6033,7 @@ var init_claude_code = __esm({
|
|
|
5243
6033
|
...latestIn(home(".local", "share", "claude", "versions")),
|
|
5244
6034
|
// The copy Claude Desktop carries.
|
|
5245
6035
|
...process.platform === "win32" ? claudeOnWindows() : latestIn(home("Library", "Application Support", "Claude", "claude-code")).flatMap(
|
|
5246
|
-
(version) => folders(version).map((build) =>
|
|
6036
|
+
(version) => folders(version).map((build) => path19.join(version, build, "claude.app", "Contents", "MacOS", "claude"))
|
|
5247
6037
|
)
|
|
5248
6038
|
],
|
|
5249
6039
|
install: "npm install -g @anthropic-ai/claude-code"
|
|
@@ -5253,8 +6043,8 @@ var init_claude_code = __esm({
|
|
|
5253
6043
|
|
|
5254
6044
|
// src/lib/agent/worktree.ts
|
|
5255
6045
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
5256
|
-
import
|
|
5257
|
-
import
|
|
6046
|
+
import fs18 from "node:fs";
|
|
6047
|
+
import path20 from "node:path";
|
|
5258
6048
|
function spawnGit(args2, options) {
|
|
5259
6049
|
const out = spawnSync4("git", args2, {
|
|
5260
6050
|
...options,
|
|
@@ -5289,15 +6079,15 @@ var init_worktree = __esm({
|
|
|
5289
6079
|
gitLimits = { timeoutMs: 3e4 };
|
|
5290
6080
|
GitTimeoutError = class extends Error {
|
|
5291
6081
|
};
|
|
5292
|
-
worktreeDir = (relPath) =>
|
|
6082
|
+
worktreeDir = (relPath) => path20.resolve(REPO_ROOT, relPath);
|
|
5293
6083
|
headCommit = (cwd = REPO_ROOT) => git(["rev-parse", "HEAD"], cwd)?.trim() || null;
|
|
5294
|
-
worktreeExists = (relPath) => !!relPath &&
|
|
6084
|
+
worktreeExists = (relPath) => !!relPath && fs18.existsSync(path20.join(worktreeDir(relPath), ".git"));
|
|
5295
6085
|
}
|
|
5296
6086
|
});
|
|
5297
6087
|
|
|
5298
6088
|
// src/lib/agent/harnesses/codex.ts
|
|
5299
|
-
import
|
|
5300
|
-
import
|
|
6089
|
+
import fs19 from "node:fs";
|
|
6090
|
+
import path21 from "node:path";
|
|
5301
6091
|
function codexExtraArgs(argv, cwd = REPO_ROOT) {
|
|
5302
6092
|
const extra = [];
|
|
5303
6093
|
if (!namesFlag(argv, ["--json", "--experimental-json"])) extra.push("--json");
|
|
@@ -5313,10 +6103,10 @@ function codexExtraArgs(argv, cwd = REPO_ROOT) {
|
|
|
5313
6103
|
}
|
|
5314
6104
|
const flags = [...argv, ...extra];
|
|
5315
6105
|
const workspaceWrite = flags.some((arg, i) => arg === "--full-auto" || arg === "--sandbox=workspace-write" || (arg === "--sandbox" || arg === "-s") && flags[i + 1] === "workspace-write");
|
|
5316
|
-
if (workspaceWrite &&
|
|
6106
|
+
if (workspaceWrite && path21.resolve(cwd) !== path21.resolve(REPO_ROOT)) {
|
|
5317
6107
|
for (const dir of [KANBAN, AKB_DIR]) {
|
|
5318
|
-
const relative =
|
|
5319
|
-
if (relative === ".." || relative.startsWith(`..${
|
|
6108
|
+
const relative = path21.relative(cwd, dir);
|
|
6109
|
+
if (relative === ".." || relative.startsWith(`..${path21.sep}`) || path21.isAbsolute(relative)) {
|
|
5320
6110
|
extra.push("--add-dir", dir);
|
|
5321
6111
|
}
|
|
5322
6112
|
}
|
|
@@ -5339,7 +6129,7 @@ function envRoot(name) {
|
|
|
5339
6129
|
}
|
|
5340
6130
|
function modified(file2) {
|
|
5341
6131
|
try {
|
|
5342
|
-
return
|
|
6132
|
+
return fs19.statSync(file2).mtimeMs;
|
|
5343
6133
|
} catch {
|
|
5344
6134
|
return 0;
|
|
5345
6135
|
}
|
|
@@ -5364,28 +6154,28 @@ function codexOnWindows() {
|
|
|
5364
6154
|
const local = envRoot("LOCALAPPDATA");
|
|
5365
6155
|
const profile = envRoot("USERPROFILE");
|
|
5366
6156
|
const programs = envRoot("ProgramFiles");
|
|
5367
|
-
const cache = local ?
|
|
5368
|
-
const releases = profile ?
|
|
5369
|
-
const packages = programs ?
|
|
6157
|
+
const cache = local ? path21.join(local, "OpenAI", "Codex", "bin") : "";
|
|
6158
|
+
const releases = profile ? path21.join(profile, ".codex", "packages", "standalone", "releases") : "";
|
|
6159
|
+
const packages = programs ? path21.join(programs, "WindowsApps") : "";
|
|
5370
6160
|
return [
|
|
5371
6161
|
// Desktop's relocated CLI cache: a folder per build hash, newest file first.
|
|
5372
|
-
...byNewest(folders(cache).map((name) =>
|
|
6162
|
+
...byNewest(folders(cache).map((name) => path21.join(cache, name, "codex.exe"))),
|
|
5373
6163
|
// The separate standalone launcher, at a path with nothing variable in it.
|
|
5374
|
-
...local ? [
|
|
6164
|
+
...local ? [path21.join(local, "Programs", "OpenAI", "Codex", "bin", "codex.exe")] : [],
|
|
5375
6165
|
// That launcher's release payload: a folder per version and target.
|
|
5376
6166
|
...byVersion(folders(releases).filter(ourArch)).map(
|
|
5377
|
-
(name) =>
|
|
6167
|
+
(name) => path21.join(releases, name, "bin", "codex.exe")
|
|
5378
6168
|
),
|
|
5379
6169
|
// Desktop's own MSIX package.
|
|
5380
6170
|
...byVersion(folders(packages).filter((name) => name.startsWith("OpenAI.Codex_")).filter(ourArch)).map(
|
|
5381
|
-
(name) =>
|
|
6171
|
+
(name) => path21.join(packages, name, "app", "resources", "codex.exe")
|
|
5382
6172
|
)
|
|
5383
6173
|
];
|
|
5384
6174
|
}
|
|
5385
6175
|
function codexInstalls() {
|
|
5386
6176
|
const chosen = process.env.CODEX_INSTALL_DIR?.trim();
|
|
5387
6177
|
return [
|
|
5388
|
-
...chosen ? [
|
|
6178
|
+
...chosen ? [path21.join(chosen, "codex")] : [],
|
|
5389
6179
|
...process.platform === "win32" ? codexOnWindows() : [
|
|
5390
6180
|
// macOS, where Codex now lives in the merged app — `codex-cli/bin/` since 26.928…
|
|
5391
6181
|
"/Applications/ChatGPT.app/Contents/Resources/codex-cli/bin/codex",
|
|
@@ -5444,7 +6234,7 @@ var init_codex2 = __esm({
|
|
|
5444
6234
|
systemPrompt(text6, argv) {
|
|
5445
6235
|
if (namesFlag(argv, ["developer_instructions", "model_instructions_file"])) return {};
|
|
5446
6236
|
try {
|
|
5447
|
-
const config =
|
|
6237
|
+
const config = fs19.readFileSync(path21.join(process.env.CODEX_HOME || home(".codex"), "config.toml"), "utf8");
|
|
5448
6238
|
if (/^\s*(?:developer_instructions|model_instructions_file)\s*=/m.test(config)) return {};
|
|
5449
6239
|
} catch {
|
|
5450
6240
|
}
|
|
@@ -5697,24 +6487,24 @@ var init_cursor = __esm({
|
|
|
5697
6487
|
});
|
|
5698
6488
|
|
|
5699
6489
|
// src/lib/agent/harnesses/dsh.ts
|
|
5700
|
-
import
|
|
5701
|
-
import
|
|
6490
|
+
import fs20 from "node:fs";
|
|
6491
|
+
import path22 from "node:path";
|
|
5702
6492
|
function dshHome(argv) {
|
|
5703
6493
|
const binary = argv[0];
|
|
5704
6494
|
if (!binary) return void 0;
|
|
5705
|
-
const names3 = process.platform === "win32" && !
|
|
5706
|
-
const candidates = binary.includes("/") || binary.includes("\\") ? names3 : (process.env.PATH ?? "").split(
|
|
6495
|
+
const names3 = process.platform === "win32" && !path22.extname(binary) ? [".exe", ".cmd"].map((ext) => binary + ext) : [binary];
|
|
6496
|
+
const candidates = binary.includes("/") || binary.includes("\\") ? names3 : (process.env.PATH ?? "").split(path22.delimiter).filter(Boolean).flatMap((dir2) => names3.map((name) => path22.join(dir2, name)));
|
|
5707
6497
|
let dir;
|
|
5708
6498
|
try {
|
|
5709
|
-
const found2 = candidates.find((candidate) =>
|
|
6499
|
+
const found2 = candidates.find((candidate) => fs20.existsSync(candidate));
|
|
5710
6500
|
if (!found2) return void 0;
|
|
5711
|
-
const script = /\.cmd$/i.test(found2) ? shimTarget(
|
|
5712
|
-
dir =
|
|
6501
|
+
const script = /\.cmd$/i.test(found2) ? shimTarget(fs20.readFileSync(found2, "utf8"), found2)?.script : void 0;
|
|
6502
|
+
dir = path22.dirname(fs20.realpathSync(script ?? found2));
|
|
5713
6503
|
} catch {
|
|
5714
6504
|
return void 0;
|
|
5715
6505
|
}
|
|
5716
|
-
for (let up =
|
|
5717
|
-
if (
|
|
6506
|
+
for (let up = path22.dirname(dir); dir !== up; up = path22.dirname(dir)) {
|
|
6507
|
+
if (fs20.existsSync(path22.join(dir, "package.json"))) return dir;
|
|
5718
6508
|
dir = up;
|
|
5719
6509
|
}
|
|
5720
6510
|
return void 0;
|
|
@@ -5722,7 +6512,7 @@ function dshHome(argv) {
|
|
|
5722
6512
|
function dshFound(binary, onPath2) {
|
|
5723
6513
|
const home3 = dshHome([binary]);
|
|
5724
6514
|
const exts = process.platform === "win32" ? [".cmd", ".exe"] : [""];
|
|
5725
|
-
return !!home3 && exts.some((ext) =>
|
|
6515
|
+
return !!home3 && exts.some((ext) => fs20.existsSync(path22.join(home3, "node_modules", ".bin", `dsh${ext}`))) || onPath2("dsh");
|
|
5726
6516
|
}
|
|
5727
6517
|
function dshExtraArgs(argv) {
|
|
5728
6518
|
const args2 = namesFlag(argv, ["--permission-mode"]) ? [] : ["--permission-mode", "workspace-write"];
|
|
@@ -6442,7 +7232,7 @@ var init_providers = __esm({
|
|
|
6442
7232
|
});
|
|
6443
7233
|
|
|
6444
7234
|
// src/lib/agent/run-settings.ts
|
|
6445
|
-
import
|
|
7235
|
+
import path23 from "node:path";
|
|
6446
7236
|
function isFilled(harness, { values, secretsSet }) {
|
|
6447
7237
|
return (key) => {
|
|
6448
7238
|
const setting = harness.settings.find((s) => s.key === key);
|
|
@@ -6522,7 +7312,7 @@ function languageEnv(given) {
|
|
|
6522
7312
|
try {
|
|
6523
7313
|
const config = JSON.parse(env2.OPENCODE_CONFIG_CONTENT ?? "{}");
|
|
6524
7314
|
if (Array.isArray(config.instructions)) {
|
|
6525
|
-
config.instructions = config.instructions.filter((file2) => typeof file2 !== "string" ||
|
|
7315
|
+
config.instructions = config.instructions.filter((file2) => typeof file2 !== "string" || path23.dirname(file2) !== path23.join(machineHome(), "prompts") || !/^opencode-language(?:-[a-f0-9]{16})?\.md$/.test(path23.basename(file2)));
|
|
6526
7316
|
env2.OPENCODE_CONFIG_CONTENT = JSON.stringify(config);
|
|
6527
7317
|
}
|
|
6528
7318
|
} catch {
|
|
@@ -6538,7 +7328,7 @@ function withSystemLanguage(harness, argv, env2, language) {
|
|
|
6538
7328
|
const note = language === "zh" ? "\u8BED\u8A00\u89C4\u5219\u672A\u80FD\u66F4\u65B0\uFF1A\u8FDE\u63A5\u5668\u3001\u5DF2\u6709\u4F1A\u8BDD\u6216\u81EA\u8BBE\u7CFB\u7EDF\u63D0\u793A\u8BCD\u4E0D\u652F\u6301\u6CE8\u5165\u3002\u8BF7\u81EA\u884C\u53E6\u5F00\u652F\u6301\u7684\u4F1A\u8BDD\u4EE5\u91C7\u7528\u65B0\u89C4\u5219\u3002" : "Language rules could not be updated: the connector, existing session, or custom system prompt prevents injection. Open a supported new session to apply them.";
|
|
6539
7329
|
return { argv, env: env2, note };
|
|
6540
7330
|
}
|
|
6541
|
-
const at2 = /^node(?:\.exe)?$/.test(
|
|
7331
|
+
const at2 = /^node(?:\.exe)?$/.test(path23.basename(argv[0])) && argv[1] && !argv[1].startsWith("-") ? 2 : 1;
|
|
6542
7332
|
return { argv: [...argv.slice(0, at2), ...added?.args ?? [], ...argv.slice(at2)], env: { ...env2, ...added?.env } };
|
|
6543
7333
|
}
|
|
6544
7334
|
var init_run_settings = __esm({
|
|
@@ -6554,223 +7344,6 @@ var init_run_settings = __esm({
|
|
|
6554
7344
|
}
|
|
6555
7345
|
});
|
|
6556
7346
|
|
|
6557
|
-
// src/lib/cloud/config.ts
|
|
6558
|
-
function cloudEndpoints() {
|
|
6559
|
-
return {
|
|
6560
|
-
supabaseUrl: trimSlash(process.env.AI4KANBAN_SUPABASE_URL || SUPABASE_URL),
|
|
6561
|
-
anonKey: process.env.AI4KANBAN_SUPABASE_ANON_KEY || SUPABASE_ANON_KEY,
|
|
6562
|
-
api: trimSlash(process.env.AI4KANBAN_CLOUD_URL || API_URL)
|
|
6563
|
-
};
|
|
6564
|
-
}
|
|
6565
|
-
function cloudConfigured() {
|
|
6566
|
-
const { supabaseUrl, anonKey } = cloudEndpoints();
|
|
6567
|
-
return !!supabaseUrl && !!anonKey;
|
|
6568
|
-
}
|
|
6569
|
-
var SUPABASE_URL, SUPABASE_ANON_KEY, API_URL, trimSlash, NOT_CONFIGURED;
|
|
6570
|
-
var init_config = __esm({
|
|
6571
|
-
"src/lib/cloud/config.ts"() {
|
|
6572
|
-
"use strict";
|
|
6573
|
-
SUPABASE_URL = "https://yajrbpprmdvtkvjjfpbk.supabase.co";
|
|
6574
|
-
SUPABASE_ANON_KEY = "sb_publishable_ioUQ23BTtoj8NKqndp0Jrw_omVR3m4n";
|
|
6575
|
-
API_URL = "https://api.ai4kanban.dev";
|
|
6576
|
-
trimSlash = (url) => url.replace(/\/+$/, "");
|
|
6577
|
-
NOT_CONFIGURED = "This build of WildCrane carries no Cloud project to sign in against.";
|
|
6578
|
-
}
|
|
6579
|
-
});
|
|
6580
|
-
|
|
6581
|
-
// src/lib/cloud/session.ts
|
|
6582
|
-
import fs19 from "node:fs";
|
|
6583
|
-
import { createHash as createHash4 } from "node:crypto";
|
|
6584
|
-
import path22 from "node:path";
|
|
6585
|
-
function readRetry(session) {
|
|
6586
|
-
try {
|
|
6587
|
-
const retry2 = JSON.parse(fs19.readFileSync(retryFile(), "utf8"));
|
|
6588
|
-
if (retry2.key === refreshKey(session) && Number.isFinite(retry2.until) && Number.isInteger(retry2.attempt) && retry2.attempt > 0 && typeof retry2.error === "string") return retry2;
|
|
6589
|
-
} catch {
|
|
6590
|
-
}
|
|
6591
|
-
}
|
|
6592
|
-
function deferRefresh(session, error, after2) {
|
|
6593
|
-
const current = readSession();
|
|
6594
|
-
if (current?.subject === session.subject && current.refreshToken === session.refreshToken) {
|
|
6595
|
-
const attempt2 = Math.min((readRetry(session)?.attempt ?? 0) + 1, 4);
|
|
6596
|
-
const seconds = after2?.trim() ? Number(after2) : NaN;
|
|
6597
|
-
const serverDelay = Number.isFinite(seconds) ? seconds * 1e3 : Date.parse(after2 ?? "") - Date.now();
|
|
6598
|
-
const delay2 = Math.max(Math.min(REFRESH_BACKOFF_MS * 2 ** (attempt2 - 1), 3e5), Number.isFinite(serverDelay) ? serverDelay : 0);
|
|
6599
|
-
const retry2 = { key: refreshKey(session), until: Date.now() + delay2, attempt: attempt2, error };
|
|
6600
|
-
const temporary = `${retryFile()}.${process.pid}.tmp`;
|
|
6601
|
-
fs19.writeFileSync(temporary, JSON.stringify(retry2), { mode: 384 });
|
|
6602
|
-
fs19.renameSync(temporary, retryFile());
|
|
6603
|
-
}
|
|
6604
|
-
return { ok: false, reason: "unreachable", error };
|
|
6605
|
-
}
|
|
6606
|
-
function readSession() {
|
|
6607
|
-
let raw;
|
|
6608
|
-
try {
|
|
6609
|
-
raw = fs19.readFileSync(sessionFile(), "utf8");
|
|
6610
|
-
} catch {
|
|
6611
|
-
return null;
|
|
6612
|
-
}
|
|
6613
|
-
try {
|
|
6614
|
-
const held4 = JSON.parse(raw);
|
|
6615
|
-
if (!held4.accessToken || !held4.refreshToken || !held4.subject) return null;
|
|
6616
|
-
if (held4.supabaseUrl !== cloudEndpoints().supabaseUrl) return null;
|
|
6617
|
-
return { ...held4, version: 1, expiresAt: Number(held4.expiresAt) || 0 };
|
|
6618
|
-
} catch {
|
|
6619
|
-
return null;
|
|
6620
|
-
}
|
|
6621
|
-
}
|
|
6622
|
-
function writeSession(session) {
|
|
6623
|
-
fs19.mkdirSync(machineHome(), { recursive: true, mode: 448 });
|
|
6624
|
-
const tmp = `${sessionFile()}.${process.pid}.tmp`;
|
|
6625
|
-
fs19.writeFileSync(tmp, `${JSON.stringify(session, null, 2)}
|
|
6626
|
-
`, { mode: 384 });
|
|
6627
|
-
fs19.renameSync(tmp, sessionFile());
|
|
6628
|
-
if (!expiringSoon(session) || !readRetry(session)) fs19.rmSync(retryFile(), { force: true });
|
|
6629
|
-
}
|
|
6630
|
-
function clearSession() {
|
|
6631
|
-
try {
|
|
6632
|
-
fs19.rmSync(sessionFile());
|
|
6633
|
-
fs19.rmSync(retryFile(), { force: true });
|
|
6634
|
-
} catch {
|
|
6635
|
-
}
|
|
6636
|
-
}
|
|
6637
|
-
async function accessToken() {
|
|
6638
|
-
const held4 = readSession();
|
|
6639
|
-
if (!held4) return { ok: false, reason: "signed-out" };
|
|
6640
|
-
if (!expiringSoon(held4)) return { ok: true, token: held4.accessToken, session: held4 };
|
|
6641
|
-
return refresh();
|
|
6642
|
-
}
|
|
6643
|
-
async function refresh() {
|
|
6644
|
-
const lock = await takeLock();
|
|
6645
|
-
if (!lock) return { ok: false, reason: "unreachable", error: "Cloud sign-in refresh is busy. Try again shortly." };
|
|
6646
|
-
try {
|
|
6647
|
-
const now = readSession();
|
|
6648
|
-
if (!now) return { ok: false, reason: "signed-out" };
|
|
6649
|
-
if (!expiringSoon(now)) return { ok: true, token: now.accessToken, session: now };
|
|
6650
|
-
const retry2 = readRetry(now);
|
|
6651
|
-
if (retry2 && retry2.until > Date.now()) return { ok: false, reason: "unreachable", error: retry2.error };
|
|
6652
|
-
const { api, anonKey } = cloudEndpoints();
|
|
6653
|
-
let response;
|
|
6654
|
-
try {
|
|
6655
|
-
response = await fetch(`${api}/auth/v1/token?grant_type=refresh_token`, {
|
|
6656
|
-
method: "POST",
|
|
6657
|
-
headers: { apikey: anonKey, "content-type": "application/json" },
|
|
6658
|
-
body: JSON.stringify({ refresh_token: now.refreshToken }),
|
|
6659
|
-
signal: AbortSignal.timeout(REFRESH_TIMEOUT_MS)
|
|
6660
|
-
});
|
|
6661
|
-
} catch (e2) {
|
|
6662
|
-
return deferRefresh(now, e2 instanceof Error ? e2.message : String(e2));
|
|
6663
|
-
}
|
|
6664
|
-
if (!response.ok) {
|
|
6665
|
-
const body = await response.json().catch(() => null);
|
|
6666
|
-
const error = body?.error_description ?? body?.msg ?? body?.message;
|
|
6667
|
-
if (![400, 401, 403].includes(response.status)) return deferRefresh(now, error ?? `Cloud answered ${response.status}`, response.headers.get("retry-after"));
|
|
6668
|
-
return { ok: false, reason: "expired", error };
|
|
6669
|
-
}
|
|
6670
|
-
const fresh = sessionFrom(await response.json().catch(() => null), now);
|
|
6671
|
-
if (!fresh) return deferRefresh(now, "Cloud returned an invalid sign-in refresh response.");
|
|
6672
|
-
const current = readSession();
|
|
6673
|
-
if (!current || current.subject !== now.subject) return { ok: false, reason: "expired" };
|
|
6674
|
-
if (current.refreshToken !== now.refreshToken) return { ok: true, token: current.accessToken, session: current };
|
|
6675
|
-
writeSession(fresh);
|
|
6676
|
-
return { ok: true, token: fresh.accessToken, session: fresh };
|
|
6677
|
-
} finally {
|
|
6678
|
-
lock();
|
|
6679
|
-
}
|
|
6680
|
-
}
|
|
6681
|
-
function sessionFrom(body, previous) {
|
|
6682
|
-
if (!body || typeof body !== "object") return null;
|
|
6683
|
-
const token2 = body;
|
|
6684
|
-
const subject = token2.user?.id ?? previous?.subject;
|
|
6685
|
-
if (!token2.access_token || !token2.refresh_token || !subject) return null;
|
|
6686
|
-
const expiresAt = token2.expires_at ? token2.expires_at * 1e3 : Date.now() + (token2.expires_in ?? 3600) * 1e3;
|
|
6687
|
-
return {
|
|
6688
|
-
version: 1,
|
|
6689
|
-
supabaseUrl: cloudEndpoints().supabaseUrl,
|
|
6690
|
-
accessToken: token2.access_token,
|
|
6691
|
-
refreshToken: token2.refresh_token,
|
|
6692
|
-
expiresAt,
|
|
6693
|
-
subject,
|
|
6694
|
-
email: token2.user?.email ?? previous?.email,
|
|
6695
|
-
handle: previous?.handle,
|
|
6696
|
-
name: previous?.name,
|
|
6697
|
-
avatarUrl: previous?.avatarUrl,
|
|
6698
|
-
avatar: previous?.avatar
|
|
6699
|
-
};
|
|
6700
|
-
}
|
|
6701
|
-
async function takeLock() {
|
|
6702
|
-
const until = Date.now() + LOCK_WAIT_MS;
|
|
6703
|
-
for (; ; ) {
|
|
6704
|
-
try {
|
|
6705
|
-
fs19.mkdirSync(machineHome(), { recursive: true, mode: 448 });
|
|
6706
|
-
fs19.mkdirSync(lockDir());
|
|
6707
|
-
try {
|
|
6708
|
-
fs19.writeFileSync(lockOwner(), `${process.pid}
|
|
6709
|
-
`);
|
|
6710
|
-
} catch {
|
|
6711
|
-
}
|
|
6712
|
-
return () => {
|
|
6713
|
-
try {
|
|
6714
|
-
fs19.rmSync(lockDir(), { recursive: true, force: true });
|
|
6715
|
-
} catch {
|
|
6716
|
-
}
|
|
6717
|
-
};
|
|
6718
|
-
} catch (err) {
|
|
6719
|
-
if (err.code !== "EEXIST") throw err;
|
|
6720
|
-
if (stale()) {
|
|
6721
|
-
fs19.rmSync(lockDir(), { recursive: true, force: true });
|
|
6722
|
-
continue;
|
|
6723
|
-
}
|
|
6724
|
-
if (Date.now() > until) return null;
|
|
6725
|
-
await sleep2(LOCK_RETRY_MS);
|
|
6726
|
-
}
|
|
6727
|
-
}
|
|
6728
|
-
}
|
|
6729
|
-
function stale() {
|
|
6730
|
-
let held4;
|
|
6731
|
-
try {
|
|
6732
|
-
const pid = Number(fs19.readFileSync(lockOwner(), "utf8").trim());
|
|
6733
|
-
held4 = Number.isInteger(pid) && pid > 0 ? pid : void 0;
|
|
6734
|
-
} catch {
|
|
6735
|
-
held4 = void 0;
|
|
6736
|
-
}
|
|
6737
|
-
if (held4 !== void 0) return !alive(held4);
|
|
6738
|
-
try {
|
|
6739
|
-
return Date.now() - fs19.statSync(lockDir()).mtimeMs > LOCK_STALE_MS;
|
|
6740
|
-
} catch {
|
|
6741
|
-
return false;
|
|
6742
|
-
}
|
|
6743
|
-
}
|
|
6744
|
-
function alive(pid) {
|
|
6745
|
-
try {
|
|
6746
|
-
process.kill(pid, 0);
|
|
6747
|
-
return true;
|
|
6748
|
-
} catch (e2) {
|
|
6749
|
-
return e2.code === "EPERM";
|
|
6750
|
-
}
|
|
6751
|
-
}
|
|
6752
|
-
var REFRESH_MARGIN_MS, LOCK_STALE_MS, LOCK_WAIT_MS, LOCK_RETRY_MS, REFRESH_TIMEOUT_MS, REFRESH_BACKOFF_MS, sessionFile, lockDir, lockOwner, retryFile, refreshKey, expiringSoon, sleep2;
|
|
6753
|
-
var init_session = __esm({
|
|
6754
|
-
"src/lib/cloud/session.ts"() {
|
|
6755
|
-
"use strict";
|
|
6756
|
-
init_home();
|
|
6757
|
-
init_config();
|
|
6758
|
-
REFRESH_MARGIN_MS = 6e4;
|
|
6759
|
-
LOCK_STALE_MS = 3e4;
|
|
6760
|
-
LOCK_WAIT_MS = 2e4;
|
|
6761
|
-
LOCK_RETRY_MS = 50;
|
|
6762
|
-
REFRESH_TIMEOUT_MS = 15e3;
|
|
6763
|
-
REFRESH_BACKOFF_MS = 6e4;
|
|
6764
|
-
sessionFile = () => path22.join(machineHome(), "session.json");
|
|
6765
|
-
lockDir = () => path22.join(machineHome(), "session.lock");
|
|
6766
|
-
lockOwner = () => path22.join(lockDir(), "owner");
|
|
6767
|
-
retryFile = () => path22.join(machineHome(), "session-refresh.json");
|
|
6768
|
-
refreshKey = (session) => createHash4("sha256").update(JSON.stringify([cloudEndpoints().api, session.subject, session.refreshToken])).digest("hex");
|
|
6769
|
-
expiringSoon = (session) => session.expiresAt - REFRESH_MARGIN_MS <= Date.now();
|
|
6770
|
-
sleep2 = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
6771
|
-
}
|
|
6772
|
-
});
|
|
6773
|
-
|
|
6774
7347
|
// src/lib/cloud/execution.ts
|
|
6775
7348
|
function executionOf(value = process.env.AI4KANBAN_EXECUTION) {
|
|
6776
7349
|
try {
|
|
@@ -6809,20 +7382,20 @@ var init_execution = __esm({
|
|
|
6809
7382
|
});
|
|
6810
7383
|
|
|
6811
7384
|
// src/lib/agent/log.ts
|
|
6812
|
-
import
|
|
6813
|
-
import
|
|
7385
|
+
import fs21 from "node:fs";
|
|
7386
|
+
import path24 from "node:path";
|
|
6814
7387
|
function pruneLogs() {
|
|
6815
7388
|
try {
|
|
6816
|
-
const runs =
|
|
7389
|
+
const runs = fs21.readdirSync(SESSIONS_DIR).filter((f2) => f2.endsWith(".log") && !f2.endsWith(".watch.log")).map((f2) => ({ id: f2.slice(0, -".log".length), t: fs21.statSync(path24.join(SESSIONS_DIR, f2)).mtimeMs })).sort((a2, b2) => b2.t - a2.t);
|
|
6817
7390
|
const kept2 = new Set(runs.slice(0, KEEP_LOGS).map((r2) => r2.id));
|
|
6818
7391
|
const drop = new Set(runs.slice(KEEP_LOGS).map((r2) => r2.id));
|
|
6819
|
-
for (const f2 of
|
|
7392
|
+
for (const f2 of fs21.readdirSync(SESSIONS_DIR)) {
|
|
6820
7393
|
const dot = f2.indexOf(".");
|
|
6821
7394
|
const id = dot === -1 ? f2 : f2.slice(0, dot);
|
|
6822
7395
|
const stray = f2.endsWith(".images") && !kept2.has(id) && !drop.has(id) && stale2(f2);
|
|
6823
7396
|
if (!stray && !drop.has(id)) continue;
|
|
6824
7397
|
try {
|
|
6825
|
-
|
|
7398
|
+
fs21.rmSync(path24.join(SESSIONS_DIR, f2), { recursive: true, force: true });
|
|
6826
7399
|
} catch {
|
|
6827
7400
|
}
|
|
6828
7401
|
}
|
|
@@ -6831,7 +7404,7 @@ function pruneLogs() {
|
|
|
6831
7404
|
}
|
|
6832
7405
|
function stale2(name) {
|
|
6833
7406
|
try {
|
|
6834
|
-
return Date.now() -
|
|
7407
|
+
return Date.now() - fs21.statSync(path24.join(SESSIONS_DIR, name)).mtimeMs > STRAY_MS;
|
|
6835
7408
|
} catch {
|
|
6836
7409
|
return false;
|
|
6837
7410
|
}
|
|
@@ -6858,13 +7431,13 @@ function asContext(v) {
|
|
|
6858
7431
|
function readLogTail(logPath, maxBytes = TAIL_BYTES) {
|
|
6859
7432
|
let fd;
|
|
6860
7433
|
try {
|
|
6861
|
-
const size =
|
|
7434
|
+
const size = fs21.statSync(logPath).size;
|
|
6862
7435
|
const start = Math.max(0, size - maxBytes);
|
|
6863
7436
|
const len = size - start;
|
|
6864
7437
|
if (len === 0) return "";
|
|
6865
|
-
fd =
|
|
7438
|
+
fd = fs21.openSync(logPath, "r");
|
|
6866
7439
|
const buf = Buffer.alloc(len);
|
|
6867
|
-
|
|
7440
|
+
fs21.readSync(fd, buf, 0, len, start);
|
|
6868
7441
|
let text6 = buf.toString("utf8");
|
|
6869
7442
|
if (start > 0) {
|
|
6870
7443
|
const nl2 = text6.indexOf("\n");
|
|
@@ -6876,7 +7449,7 @@ function readLogTail(logPath, maxBytes = TAIL_BYTES) {
|
|
|
6876
7449
|
} finally {
|
|
6877
7450
|
if (fd !== void 0) {
|
|
6878
7451
|
try {
|
|
6879
|
-
|
|
7452
|
+
fs21.closeSync(fd);
|
|
6880
7453
|
} catch {
|
|
6881
7454
|
}
|
|
6882
7455
|
}
|
|
@@ -6987,15 +7560,15 @@ __export(store_exports, {
|
|
|
6987
7560
|
withRuns: () => withRuns,
|
|
6988
7561
|
withStore: () => withStore
|
|
6989
7562
|
});
|
|
6990
|
-
import
|
|
6991
|
-
import
|
|
7563
|
+
import fs22 from "node:fs";
|
|
7564
|
+
import path25 from "node:path";
|
|
6992
7565
|
function logPathIn(held4, sessionId) {
|
|
6993
|
-
return typeof held4 === "string" && held4.startsWith(SESSIONS_DIR +
|
|
7566
|
+
return typeof held4 === "string" && held4.startsWith(SESSIONS_DIR + path25.sep) ? held4 : logPathOf(sessionId);
|
|
6994
7567
|
}
|
|
6995
7568
|
function parseStore() {
|
|
6996
7569
|
let data;
|
|
6997
7570
|
try {
|
|
6998
|
-
data = JSON.parse(
|
|
7571
|
+
data = JSON.parse(fs22.readFileSync(SESSIONS, "utf8"));
|
|
6999
7572
|
} catch {
|
|
7000
7573
|
return { runs: [], deliveries: [], marks: {} };
|
|
7001
7574
|
}
|
|
@@ -7161,7 +7734,7 @@ function readDeliveryRow(raw) {
|
|
|
7161
7734
|
cloudExecution: executionOf(entry.cloudExecution ?? null),
|
|
7162
7735
|
approved: typeof entry.approved === "string" ? entry.approved : "",
|
|
7163
7736
|
// The plan a card-less build was started from (#481), where it was one.
|
|
7164
|
-
plan:
|
|
7737
|
+
plan: text3(entry.plan),
|
|
7165
7738
|
initialQuestions: typeof entry.initialQuestions === "number" && entry.initialQuestions >= 0 ? Math.floor(entry.initialQuestions) : void 0,
|
|
7166
7739
|
steps: readSteps(entry.steps),
|
|
7167
7740
|
completions: Array.isArray(entry.completions) ? entry.completions.filter((c2) => c2 && typeof c2.sessionId === "string" && Number.isInteger(c2.step) && typeof c2.at === "number") : void 0,
|
|
@@ -7174,10 +7747,10 @@ function readDeliveryRow(raw) {
|
|
|
7174
7747
|
commitMode: entry.commitMode === "auto" || entry.commitMode === "manual" || entry.commitMode === "files" ? entry.commitMode : void 0,
|
|
7175
7748
|
touched: readTouched(entry.touched),
|
|
7176
7749
|
planned: Array.isArray(entry.planned) ? entry.planned.filter((t) => typeof t === "string") : void 0,
|
|
7177
|
-
manualWhy:
|
|
7178
|
-
targetBranch:
|
|
7179
|
-
worktree:
|
|
7180
|
-
branch:
|
|
7750
|
+
manualWhy: text3(entry.manualWhy),
|
|
7751
|
+
targetBranch: text3(entry.targetBranch),
|
|
7752
|
+
worktree: text3(entry.worktree),
|
|
7753
|
+
branch: text3(entry.branch),
|
|
7181
7754
|
reviewed: readReviewed(entry.reviewed),
|
|
7182
7755
|
landing: readLanding(entry.landing),
|
|
7183
7756
|
// The flow rules this delivery froze (#306). A delivery written down before they
|
|
@@ -7192,16 +7765,16 @@ function readDeliveryRow(raw) {
|
|
|
7192
7765
|
function readStudio(raw) {
|
|
7193
7766
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
7194
7767
|
const box2 = raw;
|
|
7195
|
-
const id =
|
|
7768
|
+
const id = text3(box2.id);
|
|
7196
7769
|
if (!id) return void 0;
|
|
7197
7770
|
const rows = (value) => (Array.isArray(value) ? value : []).flatMap((one) => {
|
|
7198
7771
|
if (!one || typeof one !== "object" || Array.isArray(one)) return [];
|
|
7199
7772
|
const row = one;
|
|
7200
|
-
const agent =
|
|
7773
|
+
const agent = text3(row.agent);
|
|
7201
7774
|
return agent ? [{ agent, extra: typeof row.extra === "string" ? row.extra : "" }] : [];
|
|
7202
7775
|
});
|
|
7203
7776
|
const stages = box2.stages && typeof box2.stages === "object" ? box2.stages : {};
|
|
7204
|
-
const lead =
|
|
7777
|
+
const lead = text3(stages.execute?.lead);
|
|
7205
7778
|
const previews = Array.isArray(box2.previews) ? rows(box2.previews.flat()) : stages.plan ? rows(stages.plan.helpers) : [];
|
|
7206
7779
|
const land = Array.isArray(box2.land) ? rows(box2.land) : lead ? [{ agent: lead, extra: "" }] : [];
|
|
7207
7780
|
return {
|
|
@@ -7224,9 +7797,9 @@ function readPictures(raw) {
|
|
|
7224
7797
|
function readBlocker(raw) {
|
|
7225
7798
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
7226
7799
|
const box2 = raw;
|
|
7227
|
-
const step =
|
|
7228
|
-
const cause =
|
|
7229
|
-
const unblock =
|
|
7800
|
+
const step = text3(box2.step);
|
|
7801
|
+
const cause = text3(box2.cause);
|
|
7802
|
+
const unblock = text3(box2.unblock);
|
|
7230
7803
|
return step && cause && unblock ? { step, cause, unblock } : void 0;
|
|
7231
7804
|
}
|
|
7232
7805
|
function readRules(raw) {
|
|
@@ -7240,9 +7813,9 @@ function readRules(raw) {
|
|
|
7240
7813
|
function readReviewed(raw) {
|
|
7241
7814
|
if (!raw || typeof raw !== "object") return void 0;
|
|
7242
7815
|
const box2 = raw;
|
|
7243
|
-
const mark =
|
|
7816
|
+
const mark = text3(box2.mark);
|
|
7244
7817
|
if (!mark) return void 0;
|
|
7245
|
-
return { mark, diff:
|
|
7818
|
+
return { mark, diff: text3(box2.diff), at: typeof box2.at === "number" ? box2.at : 0 };
|
|
7246
7819
|
}
|
|
7247
7820
|
function readLanding(raw) {
|
|
7248
7821
|
if (!raw || typeof raw !== "object") return void 0;
|
|
@@ -7250,14 +7823,14 @@ function readLanding(raw) {
|
|
|
7250
7823
|
const num3 = (value) => typeof value === "number" ? value : void 0;
|
|
7251
7824
|
return {
|
|
7252
7825
|
status: asLandingStatus(box2.status),
|
|
7253
|
-
why:
|
|
7826
|
+
why: text3(box2.why),
|
|
7254
7827
|
attempts: typeof box2.attempts === "number" && box2.attempts > 0 ? Math.floor(box2.attempts) : 0,
|
|
7255
7828
|
rebasedAt: num3(box2.rebasedAt),
|
|
7256
|
-
rebasedFrom:
|
|
7257
|
-
originalBase:
|
|
7829
|
+
rebasedFrom: text3(box2.rebasedFrom),
|
|
7830
|
+
originalBase: text3(box2.originalBase),
|
|
7258
7831
|
rebaseKind: box2.rebaseKind === "disjoint" || box2.rebaseKind === "overlap" || box2.rebaseKind === "conflict" ? box2.rebaseKind : void 0,
|
|
7259
|
-
commit:
|
|
7260
|
-
onto:
|
|
7832
|
+
commit: text3(box2.commit),
|
|
7833
|
+
onto: text3(box2.onto),
|
|
7261
7834
|
overlap: Array.isArray(box2.overlap) ? box2.overlap.filter((n) => Number.isInteger(n)) : void 0,
|
|
7262
7835
|
wait: readLandingWait(box2.wait),
|
|
7263
7836
|
reason: readLandingReason(box2.reason),
|
|
@@ -7286,7 +7859,7 @@ function readLandingReason(raw) {
|
|
|
7286
7859
|
const files = Array.isArray(box2.files) ? box2.files.filter((f2) => typeof f2 === "string") : [];
|
|
7287
7860
|
return {
|
|
7288
7861
|
kind: box2.kind,
|
|
7289
|
-
...
|
|
7862
|
+
...text3(box2.behind) ? { behind: text3(box2.behind) } : {},
|
|
7290
7863
|
...files.length ? { files } : {}
|
|
7291
7864
|
};
|
|
7292
7865
|
}
|
|
@@ -7294,7 +7867,7 @@ function readAnswers(raw) {
|
|
|
7294
7867
|
if (!Array.isArray(raw)) return void 0;
|
|
7295
7868
|
const answers2 = raw.flatMap((entry) => {
|
|
7296
7869
|
if (!entry || entry.outcome !== "changed" && entry.outcome !== "unchanged") return [];
|
|
7297
|
-
const why2 =
|
|
7870
|
+
const why2 = text3(entry.why);
|
|
7298
7871
|
if (!why2) return [];
|
|
7299
7872
|
return [
|
|
7300
7873
|
{
|
|
@@ -7356,16 +7929,16 @@ function writeStore(store) {
|
|
|
7356
7929
|
marks: store.marks,
|
|
7357
7930
|
...store.refined ? { refined: store.refined } : {}
|
|
7358
7931
|
};
|
|
7359
|
-
|
|
7932
|
+
fs22.mkdirSync(path25.dirname(SESSIONS), { recursive: true });
|
|
7360
7933
|
const tmp = `${SESSIONS}.tmp`;
|
|
7361
|
-
|
|
7362
|
-
|
|
7934
|
+
fs22.writeFileSync(tmp, JSON.stringify(kept2, null, 2) + "\n");
|
|
7935
|
+
fs22.renameSync(tmp, SESSIONS);
|
|
7363
7936
|
forgetFileMemos();
|
|
7364
7937
|
}
|
|
7365
7938
|
function prune(runs, deliveries) {
|
|
7366
7939
|
const held4 = new Set(deliveries.filter(holdsCheckout).map((d2) => d2.deliveryId));
|
|
7367
7940
|
const live = runs.filter((r2) => r2.status === "running");
|
|
7368
|
-
const finished = runs.filter((r2) => r2.status !== "running" && (
|
|
7941
|
+
const finished = runs.filter((r2) => r2.status !== "running" && (fs22.existsSync(r2.logPath) || r2.deliveryId && held4.has(r2.deliveryId))).sort((a2, b2) => b2.startedAt - a2.startedAt).slice(0, KEEP_RUNS);
|
|
7369
7942
|
const spared = runs.filter(
|
|
7370
7943
|
(r2) => r2.status !== "running" && !finished.includes(r2) && (!!r2.discardedCards?.length || r2.deliveryId && held4.has(r2.deliveryId))
|
|
7371
7944
|
);
|
|
@@ -7410,7 +7983,7 @@ function handoffOf(value) {
|
|
|
7410
7983
|
cwd: typeof h3.cwd === "string" && h3.cwd ? h3.cwd : void 0
|
|
7411
7984
|
};
|
|
7412
7985
|
}
|
|
7413
|
-
var KEEP_RUNS, KEEP_DELIVERIES, logPathOf, eventsPathOf, WAS_CLARIFY, RETIRED_ACTIONS, knownAction, readAction, readStore, strings, stringRecord, readRuns, PENDING_MS, runIsLive, creationOf, cardCreation,
|
|
7986
|
+
var KEEP_RUNS, KEEP_DELIVERIES, logPathOf, eventsPathOf, WAS_CLARIFY, RETIRED_ACTIONS, knownAction, readAction, readStore, strings, stringRecord, readRuns, PENDING_MS, runIsLive, creationOf, cardCreation, text3, LANDING_REASONS, asLandingStatus, isVerdict, holdsCheckout;
|
|
7414
7987
|
var init_store = __esm({
|
|
7415
7988
|
"src/lib/agent/store.ts"() {
|
|
7416
7989
|
"use strict";
|
|
@@ -7422,8 +7995,8 @@ var init_store = __esm({
|
|
|
7422
7995
|
init_log();
|
|
7423
7996
|
KEEP_RUNS = 100;
|
|
7424
7997
|
KEEP_DELIVERIES = 30;
|
|
7425
|
-
logPathOf = (sessionId) =>
|
|
7426
|
-
eventsPathOf = (sessionId) =>
|
|
7998
|
+
logPathOf = (sessionId) => path25.join(SESSIONS_DIR, `${sessionId}.log`);
|
|
7999
|
+
eventsPathOf = (sessionId) => path25.join(SESSIONS_DIR, `${sessionId}.events.jsonl`);
|
|
7427
8000
|
WAS_CLARIFY = /* @__PURE__ */ new Set(["auto-refine", "refine", "raise-questions"]);
|
|
7428
8001
|
RETIRED_ACTIONS = /* @__PURE__ */ new Set([
|
|
7429
8002
|
"channel",
|
|
@@ -7457,7 +8030,7 @@ var init_store = __esm({
|
|
|
7457
8030
|
if (strict) return state;
|
|
7458
8031
|
return state && state.runId === insideRun() ? void 0 : state;
|
|
7459
8032
|
};
|
|
7460
|
-
|
|
8033
|
+
text3 = (value) => typeof value === "string" && value ? value : void 0;
|
|
7461
8034
|
LANDING_REASONS = /* @__PURE__ */ new Set([
|
|
7462
8035
|
"queued",
|
|
7463
8036
|
"worktree-gone",
|
|
@@ -7997,9 +8570,9 @@ var init_parse = __esm({
|
|
|
7997
8570
|
// src/lib/agent/studio-def.ts
|
|
7998
8571
|
function readAgent(item) {
|
|
7999
8572
|
const row = typeof item === "string" ? { agent: item } : box(item);
|
|
8000
|
-
const agent =
|
|
8573
|
+
const agent = text4(row.agent);
|
|
8001
8574
|
if (!agent) return null;
|
|
8002
|
-
return { agent, extra: typeof row.extra === "string" ? row.extra : "", ...
|
|
8575
|
+
return { agent, extra: typeof row.extra === "string" ? row.extra : "", ...text4(row.off) === "true" ? { off: true } : {} };
|
|
8003
8576
|
}
|
|
8004
8577
|
function readPreviews(value) {
|
|
8005
8578
|
if (value === void 0 || value === "") return [];
|
|
@@ -8028,7 +8601,7 @@ function parseStudioFile(id, source2, from) {
|
|
|
8028
8601
|
const { meta, body } = splitFrontmatter(source2);
|
|
8029
8602
|
if (meta === null) return { problem: `${from}: no \`---\` frontmatter` };
|
|
8030
8603
|
const raw = parseYamlBlock(meta);
|
|
8031
|
-
const name =
|
|
8604
|
+
const name = text4(raw.name).replace(/\s+/g, " ");
|
|
8032
8605
|
if (!name) return { problem: `${from}: its frontmatter has no \`name\`` };
|
|
8033
8606
|
const old = OLD_KEYS.filter((key) => key in raw);
|
|
8034
8607
|
if (old.length) {
|
|
@@ -8053,21 +8626,21 @@ function parseStudioFile(id, source2, from) {
|
|
|
8053
8626
|
const scheduled = [];
|
|
8054
8627
|
for (const item of Array.isArray(raw.scheduled) ? raw.scheduled : []) {
|
|
8055
8628
|
const row = typeof item === "string" ? { agent: item } : box(item);
|
|
8056
|
-
const agent =
|
|
8629
|
+
const agent = text4(row.agent);
|
|
8057
8630
|
if (!agent || scheduled.some((s) => s.agent === agent)) continue;
|
|
8058
|
-
scheduled.push({ agent, ...
|
|
8631
|
+
scheduled.push({ agent, ...text4(row.cadence) ? { cadence: text4(row.cadence) } : {} });
|
|
8059
8632
|
}
|
|
8060
8633
|
const workspace2 = memoryPaths(raw.memoryFiles, `memory/studios/${id}/`);
|
|
8061
8634
|
if (typeof workspace2 === "string") return { problem: `${from}: declares ${workspace2}` };
|
|
8062
|
-
const names3 = Object.fromEntries(Object.entries(box(raw.names)).map(([lang, said2]) => [lang,
|
|
8635
|
+
const names3 = Object.fromEntries(Object.entries(box(raw.names)).map(([lang, said2]) => [lang, text4(said2)]).filter(([, said2]) => said2));
|
|
8063
8636
|
return {
|
|
8064
8637
|
def: {
|
|
8065
8638
|
id,
|
|
8066
8639
|
name,
|
|
8067
8640
|
...Object.keys(names3).length ? { names: names3 } : {},
|
|
8068
|
-
description:
|
|
8069
|
-
when:
|
|
8070
|
-
needsArtifact:
|
|
8641
|
+
description: text4(raw.description),
|
|
8642
|
+
when: text4(raw.when),
|
|
8643
|
+
needsArtifact: text4(raw.needsArtifact) === "true",
|
|
8071
8644
|
...icon2 ? { icon: icon2 } : {},
|
|
8072
8645
|
previews,
|
|
8073
8646
|
land,
|
|
@@ -8077,7 +8650,7 @@ function parseStudioFile(id, source2, from) {
|
|
|
8077
8650
|
}
|
|
8078
8651
|
};
|
|
8079
8652
|
}
|
|
8080
|
-
var STUDIO_ID, OLD_KEYS, box,
|
|
8653
|
+
var STUDIO_ID, OLD_KEYS, box, text4, readGroup;
|
|
8081
8654
|
var init_studio_def = __esm({
|
|
8082
8655
|
"src/lib/agent/studio-def.ts"() {
|
|
8083
8656
|
"use strict";
|
|
@@ -8088,7 +8661,7 @@ var init_studio_def = __esm({
|
|
|
8088
8661
|
STUDIO_ID = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
8089
8662
|
OLD_KEYS = ["stages", "delivers", "helpers", "every"];
|
|
8090
8663
|
box = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
8091
|
-
|
|
8664
|
+
text4 = (value) => typeof value === "string" ? value.trim() : "";
|
|
8092
8665
|
readGroup = (value) => (Array.isArray(value) ? value : []).map(readAgent).filter((h3) => !!h3);
|
|
8093
8666
|
}
|
|
8094
8667
|
});
|
|
@@ -8279,17 +8852,17 @@ var init_studio_files = __esm({
|
|
|
8279
8852
|
});
|
|
8280
8853
|
|
|
8281
8854
|
// src/lib/agent/studio-folder.ts
|
|
8282
|
-
import
|
|
8283
|
-
import
|
|
8855
|
+
import fs23 from "node:fs";
|
|
8856
|
+
import path26 from "node:path";
|
|
8284
8857
|
function filesOf(dir, base = dir) {
|
|
8285
|
-
return
|
|
8286
|
-
const full =
|
|
8287
|
-
return e2.isDirectory() ? filesOf(full, base) : [
|
|
8858
|
+
return fs23.readdirSync(dir, { withFileTypes: true }).filter((e2) => !e2.name.startsWith(".")).flatMap((e2) => {
|
|
8859
|
+
const full = path26.join(dir, e2.name);
|
|
8860
|
+
return e2.isDirectory() ? filesOf(full, base) : [path26.relative(base, full).split(path26.sep).join("/")];
|
|
8288
8861
|
});
|
|
8289
8862
|
}
|
|
8290
8863
|
function readStudioFile(dir, file2) {
|
|
8291
|
-
const full =
|
|
8292
|
-
return isAboutFile(file2) && !file2.endsWith(".md") ? `data:${MIME[
|
|
8864
|
+
const full = path26.join(dir, file2);
|
|
8865
|
+
return isAboutFile(file2) && !file2.endsWith(".md") ? `data:${MIME[path26.extname(file2)]};base64,${fs23.readFileSync(full).toString("base64")}` : fs23.readFileSync(full, "utf8");
|
|
8293
8866
|
}
|
|
8294
8867
|
var MIME, readStudioFolder;
|
|
8295
8868
|
var init_studio_folder = __esm({
|
|
@@ -8302,23 +8875,23 @@ var init_studio_folder = __esm({
|
|
|
8302
8875
|
});
|
|
8303
8876
|
|
|
8304
8877
|
// ../official/pack.ts
|
|
8305
|
-
import
|
|
8306
|
-
import
|
|
8307
|
-
import
|
|
8878
|
+
import crypto2 from "node:crypto";
|
|
8879
|
+
import fs24 from "node:fs";
|
|
8880
|
+
import path27 from "node:path";
|
|
8308
8881
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
8309
8882
|
function packOfficial(root2 = OFFICIAL, loose = false) {
|
|
8310
|
-
const agentsDir =
|
|
8883
|
+
const agentsDir = path27.join(root2, "agents");
|
|
8311
8884
|
const agentFiles = Object.fromEntries(dirs(agentsDir).map((name) => {
|
|
8312
|
-
const dir =
|
|
8885
|
+
const dir = path27.join(agentsDir, name);
|
|
8313
8886
|
return [name, readStudioFolder(dir)];
|
|
8314
8887
|
}));
|
|
8315
8888
|
for (const [name, own] of Object.entries(loose ? {} : agentFiles)) {
|
|
8316
8889
|
const read4 = parseSpecAgent(own["AGENT.md"] ?? "", `official/agents/${name}/AGENT.md`, (p2) => own[p2] ?? null, true);
|
|
8317
8890
|
if ("problem" in read4) throw new Error(read4.problem);
|
|
8318
8891
|
}
|
|
8319
|
-
const studiosDir =
|
|
8892
|
+
const studiosDir = path27.join(root2, "studios");
|
|
8320
8893
|
return dirs(studiosDir).map((folder) => {
|
|
8321
|
-
const dir =
|
|
8894
|
+
const dir = path27.join(studiosDir, folder);
|
|
8322
8895
|
const files = {};
|
|
8323
8896
|
for (const f2 of filesOf(dir).sort()) {
|
|
8324
8897
|
if (f2 === STUDIO_FILE || f2 === CARD_TEMPLATE_FILE || f2 === MCP_FILE || f2.startsWith("skills/") || f2.startsWith(SHARED_DIR) || isAboutFile(f2)) files[f2] = readStudioFile(dir, f2);
|
|
@@ -8355,144 +8928,9 @@ var init_pack = __esm({
|
|
|
8355
8928
|
init_studio_def();
|
|
8356
8929
|
init_studio_folder();
|
|
8357
8930
|
init_studio_files();
|
|
8358
|
-
OFFICIAL =
|
|
8359
|
-
dirs = (dir) =>
|
|
8360
|
-
hashOf = (files) =>
|
|
8361
|
-
}
|
|
8362
|
-
});
|
|
8363
|
-
|
|
8364
|
-
// src/lib/cloud/tasks.ts
|
|
8365
|
-
import crypto2 from "node:crypto";
|
|
8366
|
-
import fs24 from "node:fs";
|
|
8367
|
-
import path27 from "node:path";
|
|
8368
|
-
function workspaceTask() {
|
|
8369
|
-
const id = process.env[TASK_ENV];
|
|
8370
|
-
return id && id.trim() ? id.trim() : null;
|
|
8371
|
-
}
|
|
8372
|
-
function cloudStudio(name) {
|
|
8373
|
-
if (/^wf-/.test(name)) return name.replace("-", "_");
|
|
8374
|
-
return `wf_builtin_${name.replace(/-/g, "_")}`;
|
|
8375
|
-
}
|
|
8376
|
-
async function call(method, route2, body, key) {
|
|
8377
|
-
if (!cloudConfigured()) return { ok: false, error: NOT_CONFIGURED, code: "bad_request" };
|
|
8378
|
-
const token2 = await accessToken();
|
|
8379
|
-
if (!token2.ok) {
|
|
8380
|
-
return token2.reason === "unreachable" ? { ok: false, error: `Cloud could not be reached: ${token2.error}` } : { ok: false, error: token2.reason === "expired" ? "Cloud sign-in has expired. Sign in again." : "This machine is not signed in to Cloud.", code: "unauthenticated" };
|
|
8381
|
-
}
|
|
8382
|
-
let response;
|
|
8383
|
-
try {
|
|
8384
|
-
response = await fetch(`${cloudEndpoints().api}${route2}`, {
|
|
8385
|
-
method,
|
|
8386
|
-
headers: {
|
|
8387
|
-
authorization: `Bearer ${token2.token}`,
|
|
8388
|
-
...body ? { "content-type": "application/json" } : {},
|
|
8389
|
-
...key ? { "idempotency-key": key } : {}
|
|
8390
|
-
},
|
|
8391
|
-
...body ? { body: JSON.stringify(body) } : {},
|
|
8392
|
-
signal: AbortSignal.timeout(2e4)
|
|
8393
|
-
});
|
|
8394
|
-
} catch (e2) {
|
|
8395
|
-
return { ok: false, error: `Cloud could not be reached: ${e2 instanceof Error ? e2.message : String(e2)}` };
|
|
8396
|
-
}
|
|
8397
|
-
const parsed = await response.json().catch(() => ({}));
|
|
8398
|
-
if (!response.ok) return { ok: false, code: parsed.error?.code ?? "refused", error: parsed.error?.message ?? `Cloud answered ${response.status}.` };
|
|
8399
|
-
return { ok: true, value: parsed, replayed: response.headers.get("idempotent-replayed") === "true" };
|
|
8400
|
-
}
|
|
8401
|
-
async function createTask(from, said2) {
|
|
8402
|
-
const source2 = await call("GET", `/v1/tasks/${encodeURIComponent(from)}`);
|
|
8403
|
-
if (!source2.ok) return source2;
|
|
8404
|
-
const studio = said2.studio ? cloudStudio(said2.studio) : source2.value.studio?.id;
|
|
8405
|
-
const body = {
|
|
8406
|
-
title: said2.title,
|
|
8407
|
-
project: source2.value.project,
|
|
8408
|
-
...studio ? { studio } : {},
|
|
8409
|
-
...said2.request?.trim() ? { request: said2.request.trim() } : {},
|
|
8410
|
-
source: "api",
|
|
8411
|
-
source_context: { task: from, ...said2.agent ? { agent: said2.agent } : {} },
|
|
8412
|
-
...said2.run ? { run: true } : {},
|
|
8413
|
-
...said2.metadata && Object.keys(said2.metadata).length ? { metadata: said2.metadata } : {},
|
|
8414
|
-
...said2.triage ? { triage: `tri_${source2.value.project.replace(/^prj_/, "")}_${said2.triage}` } : {}
|
|
8415
|
-
};
|
|
8416
|
-
const key = `akb-${crypto2.createHash("sha256").update(`${from}
|
|
8417
|
-
${said2.slug?.trim() || said2.title}`).digest("hex").slice(0, 40)}`;
|
|
8418
|
-
const made = await call("POST", "/v1/tasks", body, key);
|
|
8419
|
-
if (!made.ok) return made;
|
|
8420
|
-
const number = numberOf(made.value.key);
|
|
8421
|
-
if (!Number.isInteger(number)) return { ok: false, error: `Cloud answered a task with no number: ${made.value.key}`, code: "refused" };
|
|
8422
|
-
return { ok: true, value: { task: made.value, number, from: source2.value, replayed: made.replayed === true } };
|
|
8423
|
-
}
|
|
8424
|
-
function runnerProject(board2) {
|
|
8425
|
-
if (path27.basename(board2) !== "kanban" || path27.basename(path27.dirname(board2)) !== ".akb") return null;
|
|
8426
|
-
const linked2 = linkedProject(board2, path27.dirname(path27.dirname(board2)));
|
|
8427
|
-
return linked2.ok ? linked2.value : null;
|
|
8428
|
-
}
|
|
8429
|
-
function linkedProject(board2, root2) {
|
|
8430
|
-
const file2 = path27.join(root2, ".akb", "base.json");
|
|
8431
|
-
if (!fs24.existsSync(file2)) return { ok: true, value: null };
|
|
8432
|
-
try {
|
|
8433
|
-
const base = JSON.parse(fs24.readFileSync(file2, "utf8"));
|
|
8434
|
-
if (!base || typeof base !== "object" || base.project !== void 0 && (typeof base.project !== "string" || !base.project.trim()) || base.files !== void 0 && (!base.files || typeof base.files !== "object" || Array.isArray(base.files))) throw new Error();
|
|
8435
|
-
const projects = new Set(Object.keys(base.files ?? {}).flatMap((p2) => /^projects\/([^/]+)\//.exec(p2)?.[1] ?? []));
|
|
8436
|
-
if (typeof base.project === "string") projects.add(base.project);
|
|
8437
|
-
if (projects.size !== 1) throw new Error();
|
|
8438
|
-
return { ok: true, value: [...projects][0] };
|
|
8439
|
-
} catch {
|
|
8440
|
-
return { ok: false, error: "The project link is invalid or names multiple projects.", code: "invalid-link" };
|
|
8441
|
-
}
|
|
8442
|
-
}
|
|
8443
|
-
async function creationProject(board2, root2, task = workspaceTask()) {
|
|
8444
|
-
const link2 = linkedProject(board2, root2);
|
|
8445
|
-
if (!link2.ok) return link2;
|
|
8446
|
-
let project2 = link2.value;
|
|
8447
|
-
if (task) {
|
|
8448
|
-
const source2 = await call("GET", `/v1/tasks/${encodeURIComponent(task)}`);
|
|
8449
|
-
if (!source2.ok) return {
|
|
8450
|
-
...source2,
|
|
8451
|
-
error: source2.code === "forbidden" ? "Cannot access this task. Check your account and task access in WildCrane, then try again." : source2.code === "not_found" ? "This task does not exist. Start a new task from the WildCrane web app." : source2.error
|
|
8452
|
-
};
|
|
8453
|
-
if (project2 && project2 !== source2.value.project) return { ok: false, error: "The source task conflicts with this board\u2019s project link.", code: "invalid-link" };
|
|
8454
|
-
project2 = source2.value.project;
|
|
8455
|
-
}
|
|
8456
|
-
if (!project2) return { ok: false, error: "This board is not linked to a Cloud project.", code: "unlinked" };
|
|
8457
|
-
const checked = await call("GET", `/v1/projects/${encodeURIComponent(project2)}`);
|
|
8458
|
-
return checked.ok ? { ok: true, value: project2 } : checked;
|
|
8459
|
-
}
|
|
8460
|
-
async function createProjectTask(project2, said2, key) {
|
|
8461
|
-
const made = await call("POST", "/v1/tasks", {
|
|
8462
|
-
title: said2.title,
|
|
8463
|
-
project: project2,
|
|
8464
|
-
source: "api",
|
|
8465
|
-
...said2.studio ? { studio: cloudStudio(said2.studio) } : {},
|
|
8466
|
-
...said2.request?.trim() ? { request: said2.request.trim() } : {},
|
|
8467
|
-
...said2.agent ? { source_context: { agent: said2.agent } } : {},
|
|
8468
|
-
...said2.triage ? { triage: `tri_${project2.replace(/^prj_/, "")}_${said2.triage}` } : {}
|
|
8469
|
-
}, key);
|
|
8470
|
-
if (!made.ok) return made;
|
|
8471
|
-
const number = numberOf(made.value.key);
|
|
8472
|
-
if (!Number.isInteger(number)) return { ok: false, error: `Cloud answered a task with no number: ${made.value.key}`, code: "refused" };
|
|
8473
|
-
return { ok: true, value: { task: made.value, number } };
|
|
8474
|
-
}
|
|
8475
|
-
async function approveTask(project2, number) {
|
|
8476
|
-
const held4 = await call("GET", `/v1/projects/${encodeURIComponent(project2)}`);
|
|
8477
|
-
if (!held4.ok) return held4;
|
|
8478
|
-
const key = `${held4.value.prefix}-${number}`;
|
|
8479
|
-
const task = await call("GET", `/v1/tasks/${encodeURIComponent(key)}`);
|
|
8480
|
-
if (!task.ok) return task;
|
|
8481
|
-
const revision = task.value.review?.revision;
|
|
8482
|
-
const decided = await call("POST", `/v1/tasks/${encodeURIComponent(key)}/decisions`, {
|
|
8483
|
-
decision: "approve",
|
|
8484
|
-
...revision !== void 0 ? { review_revision: revision } : {}
|
|
8485
|
-
});
|
|
8486
|
-
return decided.ok ? { ok: true, value: { key } } : decided;
|
|
8487
|
-
}
|
|
8488
|
-
var TASK_ENV, numberOf;
|
|
8489
|
-
var init_tasks = __esm({
|
|
8490
|
-
"src/lib/cloud/tasks.ts"() {
|
|
8491
|
-
"use strict";
|
|
8492
|
-
init_config();
|
|
8493
|
-
init_session();
|
|
8494
|
-
TASK_ENV = "AI4KANBAN_TASK";
|
|
8495
|
-
numberOf = (key) => Number(/-(\d+)$/.exec(key)?.[1] ?? NaN);
|
|
8931
|
+
OFFICIAL = path27.dirname(fileURLToPath2(import.meta.url));
|
|
8932
|
+
dirs = (dir) => fs24.readdirSync(dir, { withFileTypes: true }).filter((e2) => e2.isDirectory()).map((e2) => e2.name).sort();
|
|
8933
|
+
hashOf = (files) => crypto2.createHash("sha256").update(hashInput(files)).digest("hex");
|
|
8496
8934
|
}
|
|
8497
8935
|
});
|
|
8498
8936
|
|
|
@@ -12714,7 +13152,7 @@ function storyboardProblem(data) {
|
|
|
12714
13152
|
return null;
|
|
12715
13153
|
}
|
|
12716
13154
|
var COMPARE_IMAGES, COMPARE_VIDEOS, TAG, ATTR;
|
|
12717
|
-
var
|
|
13155
|
+
var init_compare2 = __esm({
|
|
12718
13156
|
"src/lib/compare.ts"() {
|
|
12719
13157
|
"use strict";
|
|
12720
13158
|
COMPARE_IMAGES = ["png", "jpg", "jpeg", "webp", "gif", "svg"];
|
|
@@ -12766,7 +13204,7 @@ function assetName(src, cardId2, exts, nested = false) {
|
|
|
12766
13204
|
return { name };
|
|
12767
13205
|
}
|
|
12768
13206
|
var TAG2, attr, SRC_ATTR, LABEL_ATTR, SEGMENT2, storyboardTag, studioTag;
|
|
12769
|
-
var
|
|
13207
|
+
var init_storyboard2 = __esm({
|
|
12770
13208
|
"src/lib/storyboard.ts"() {
|
|
12771
13209
|
"use strict";
|
|
12772
13210
|
TAG2 = /^<Storyboard\b([^<>]*?)\/>$/;
|
|
@@ -12783,407 +13221,6 @@ var init_storyboard = __esm({
|
|
|
12783
13221
|
}
|
|
12784
13222
|
});
|
|
12785
13223
|
|
|
12786
|
-
// ../artifact-sdk/src/builtin/compare.json
|
|
12787
|
-
var compare_default;
|
|
12788
|
-
var init_compare2 = __esm({
|
|
12789
|
-
"../artifact-sdk/src/builtin/compare.json"() {
|
|
12790
|
-
compare_default = '{\n "name": "compare",\n "title": { "en": "Compare", "zh": "\u5BF9\u6BD4" },\n "types": ["compare"],\n "schema": {\n "type": "object",\n "required": ["a", "b"],\n "properties": { "a": { "type": "string" }, "b": { "type": "string" } }\n },\n "references": [\n { "json": "/a", "types": ["storyboard", "compare", "spritesheet", "studio"] },\n { "json": "/b", "types": ["storyboard", "compare", "spritesheet", "studio"] },\n { "json": "/shots", "types": ["storyboard", "compare", "spritesheet", "studio"] }\n ]\n}\n';
|
|
12791
|
-
}
|
|
12792
|
-
});
|
|
12793
|
-
|
|
12794
|
-
// ../artifact-sdk/src/builtin/html.json
|
|
12795
|
-
var html_default;
|
|
12796
|
-
var init_html = __esm({
|
|
12797
|
-
"../artifact-sdk/src/builtin/html.json"() {
|
|
12798
|
-
html_default = `{
|
|
12799
|
-
"name": "html",
|
|
12800
|
-
"title": { "en": "Page", "zh": "\u9875\u9762" },
|
|
12801
|
-
"types": ["html"],
|
|
12802
|
-
"references": [
|
|
12803
|
-
{ "text": "<[a-z][^<>]*?\\\\ssrc\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
|
|
12804
|
-
{ "text": "<[a-z][^<>]*?\\\\sposter\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
|
|
12805
|
-
{ "text": "<[a-z][^<>]*?\\\\ssrcset\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']", "list": "," },
|
|
12806
|
-
{ "text": "<link\\\\b[^<>]*?\\\\shref\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
|
|
12807
|
-
{ "text": "url\\\\(\\\\s*[\\"']?([^\\"')]+?)[\\"']?\\\\s*\\\\)" }
|
|
12808
|
-
],
|
|
12809
|
-
"skip": ["(?<=<script\\\\b[^<>]*>)[\\\\s\\\\S]*?(?=</script\\\\s*>|$)"]
|
|
12810
|
-
}
|
|
12811
|
-
`;
|
|
12812
|
-
}
|
|
12813
|
-
});
|
|
12814
|
-
|
|
12815
|
-
// ../artifact-sdk/src/builtin/image.json
|
|
12816
|
-
var image_default;
|
|
12817
|
-
var init_image = __esm({
|
|
12818
|
-
"../artifact-sdk/src/builtin/image.json"() {
|
|
12819
|
-
image_default = '{ "name": "image", "title": { "en": "Image", "zh": "\u56FE\u7247" }, "types": ["image"] }\n';
|
|
12820
|
-
}
|
|
12821
|
-
});
|
|
12822
|
-
|
|
12823
|
-
// ../artifact-sdk/src/builtin/markdown.json
|
|
12824
|
-
var markdown_default;
|
|
12825
|
-
var init_markdown = __esm({
|
|
12826
|
-
"../artifact-sdk/src/builtin/markdown.json"() {
|
|
12827
|
-
markdown_default = `{
|
|
12828
|
-
"name": "markdown",
|
|
12829
|
-
"title": { "en": "Document", "zh": "\u6587\u6863" },
|
|
12830
|
-
"types": ["markdown"],
|
|
12831
|
-
"references": [
|
|
12832
|
-
{ "text": "!\\\\[[^\\\\]\\\\n]*\\\\]\\\\(\\\\s*<?([^\\\\s)>]+)>?(?:\\\\s+[\\"'][^\\"'\\\\n]*[\\"'])?\\\\s*\\\\)" },
|
|
12833
|
-
{ "text": "<img\\\\b[^<>]*?\\\\ssrc\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" }
|
|
12834
|
-
]
|
|
12835
|
-
}
|
|
12836
|
-
`;
|
|
12837
|
-
}
|
|
12838
|
-
});
|
|
12839
|
-
|
|
12840
|
-
// ../artifact-sdk/src/builtin/spritesheet.json
|
|
12841
|
-
var spritesheet_default;
|
|
12842
|
-
var init_spritesheet = __esm({
|
|
12843
|
-
"../artifact-sdk/src/builtin/spritesheet.json"() {
|
|
12844
|
-
spritesheet_default = '{\n "name": "spritesheet",\n "title": { "en": "Sprite animation", "zh": "\u7CBE\u7075\u52A8\u753B" },\n "types": ["spritesheet"],\n "schema": {\n "type": "object",\n "required": ["frames", "meta"],\n "properties": {\n "frames": {\n "anyOf": [\n { "type": "array", "minItems": 1, "items": { "type": "object", "required": ["frame"] } },\n { "type": "object", "additionalProperties": { "type": "object", "required": ["frame"] } }\n ]\n },\n "meta": {\n "type": "object",\n "required": ["app", "image"],\n "properties": { "app": { "type": "string", "pattern": "codeandweb\\\\.com/texturepacker" }, "image": { "type": "string" } }\n }\n }\n },\n "references": [{ "json": "/meta/image" }]\n}\n';
|
|
12845
|
-
}
|
|
12846
|
-
});
|
|
12847
|
-
|
|
12848
|
-
// ../artifact-sdk/src/builtin/storyboard.json
|
|
12849
|
-
var storyboard_default;
|
|
12850
|
-
var init_storyboard2 = __esm({
|
|
12851
|
-
"../artifact-sdk/src/builtin/storyboard.json"() {
|
|
12852
|
-
storyboard_default = '{\n "name": "storyboard",\n "title": { "en": "Storyboard", "zh": "\u5206\u955C" },\n "types": ["storyboard"],\n "schema": {\n "type": "object",\n "anyOf": [{ "required": ["shots"] }, { "required": ["slides"] }],\n "properties": {\n "shots": {\n "type": "array",\n "items": {\n "type": "object",\n "properties": { "frames": { "type": "array", "items": { "type": "object", "properties": { "src": { "type": "string" } } } } }\n }\n },\n "slides": {\n "type": "array",\n "items": {\n "type": "object",\n "properties": {\n "preview": { "type": "object", "properties": { "src": { "type": "string" } } },\n "assets": { "type": "array", "items": { "type": "string" } }\n }\n }\n }\n }\n },\n "references": [\n { "json": "/shots/*/frames/*/src", "types": ["storyboard", "compare", "spritesheet", "studio"] },\n { "json": "/slides/*/preview/src", "types": ["storyboard", "compare", "spritesheet", "studio"] },\n { "json": "/slides/*/assets/*" }\n ]\n}\n';
|
|
12853
|
-
}
|
|
12854
|
-
});
|
|
12855
|
-
|
|
12856
|
-
// ../artifact-sdk/src/builtin/tiled.json
|
|
12857
|
-
var tiled_default;
|
|
12858
|
-
var init_tiled = __esm({
|
|
12859
|
-
"../artifact-sdk/src/builtin/tiled.json"() {
|
|
12860
|
-
tiled_default = `{
|
|
12861
|
-
"name": "tiled",
|
|
12862
|
-
"title": { "en": "Tiled map", "zh": "Tiled \u5730\u56FE" },
|
|
12863
|
-
"types": ["tiled"],
|
|
12864
|
-
"references": [
|
|
12865
|
-
{ "text": "<tileset\\\\b[^<>]*?\\\\ssource\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']", "types": ["tiled"] },
|
|
12866
|
-
{ "text": "<image\\\\b[^<>]*?\\\\ssource\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
|
|
12867
|
-
{ "text": "\\"source\\"\\\\s*:\\\\s*\\"([^\\"]+)\\"", "types": ["tiled"] },
|
|
12868
|
-
{ "text": "\\"image\\"\\\\s*:\\\\s*\\"([^\\"]+)\\"" }
|
|
12869
|
-
]
|
|
12870
|
-
}
|
|
12871
|
-
`;
|
|
12872
|
-
}
|
|
12873
|
-
});
|
|
12874
|
-
|
|
12875
|
-
// ../artifact-sdk/src/builtin/video.json
|
|
12876
|
-
var video_default;
|
|
12877
|
-
var init_video = __esm({
|
|
12878
|
-
"../artifact-sdk/src/builtin/video.json"() {
|
|
12879
|
-
video_default = '{ "name": "video", "title": { "en": "Video", "zh": "\u89C6\u9891" }, "types": ["video"] }\n';
|
|
12880
|
-
}
|
|
12881
|
-
});
|
|
12882
|
-
|
|
12883
|
-
// ../artifact-sdk/src/builtin/studio.json
|
|
12884
|
-
var studio_default;
|
|
12885
|
-
var init_studio = __esm({
|
|
12886
|
-
"../artifact-sdk/src/builtin/studio.json"() {
|
|
12887
|
-
studio_default = '{\n "name": "studio",\n "title": {\n "en": "Studio",\n "zh": "\u5DE5\u4F5C\u53F0"\n },\n "types": [\n "studio"\n ],\n "schema": {\n "anyOf": [\n {\n "type": "object",\n "required": [\n "rounds",\n "land",\n "scheduled"\n ],\n "properties": {\n "rounds": {\n "type": "array",\n "items": {\n "type": "array",\n "minItems": 1,\n "items": {\n "type": "object",\n "required": [\n "agent",\n "title"\n ],\n "properties": {\n "agent": {\n "type": "string"\n },\n "title": {\n "type": "object",\n "required": [\n "en"\n ]\n }\n }\n }\n }\n },\n "land": {\n "type": "array",\n "items": {\n "type": "object",\n "required": [\n "agent",\n "title"\n ]\n }\n },\n "scheduled": {\n "type": "array",\n "items": {\n "type": "object",\n "required": [\n "agent",\n "title"\n ]\n }\n },\n "version": {\n "enum": [\n 1\n ]\n }\n }\n },\n {\n "type": "object",\n "required": [\n "version",\n "base",\n "fingerprint",\n "agents",\n "files",\n "results"\n ],\n "properties": {\n "version": {\n "const": 2\n },\n "base": {\n "anyOf": [\n {\n "type": "null"\n },\n {\n "type": "object",\n "required": [\n "id",\n "version",\n "fingerprint"\n ],\n "properties": {\n "id": {\n "type": "string",\n "minLength": 1\n },\n "version": {\n "type": "integer",\n "minimum": 1\n },\n "fingerprint": {\n "type": "string",\n "minLength": 1\n }\n }\n }\n ]\n },\n "fingerprint": {\n "type": "string",\n "minLength": 1\n },\n "agents": {\n "type": "array",\n "maxItems": 500,\n "items": {\n "type": "object",\n "required": [\n "agent",\n "title"\n ],\n "properties": {\n "agent": {\n "type": "string",\n "minLength": 1\n },\n "title": {\n "type": "object",\n "required": [\n "en"\n ],\n "properties": {\n "en": {\n "type": "string",\n "minLength": 1\n },\n "zh": {\n "type": "string"\n }\n }\n }\n }\n }\n },\n "files": {\n "type": "array",\n "maxItems": 1000,\n "items": {\n "type": "object",\n "required": [\n "path",\n "before",\n "after"\n ],\n "properties": {\n "path": {\n "type": "string",\n "minLength": 1\n },\n "before": {\n "anyOf": [\n {\n "type": "string",\n "minLength": 1\n },\n {\n "type": "null"\n }\n ]\n },\n "after": {\n "anyOf": [\n {\n "type": "string",\n "minLength": 1\n },\n {\n "type": "null"\n }\n ]\n },\n "diff": {\n "type": "string",\n "minLength": 1\n }\n }\n }\n },\n "results": {\n "type": "array",\n "maxItems": 500,\n "items": {\n "anyOf": [\n {\n "type": "object",\n "required": [\n "agent",\n "component",\n "src"\n ],\n "properties": {\n "agent": {\n "type": "string",\n "minLength": 1\n },\n "component": {\n "const": "Asset"\n },\n "src": {\n "type": "string",\n "minLength": 1\n },\n "label": {\n "type": "string"\n },\n "alt": {\n "type": "string"\n },\n "device": {\n "enum": [\n "mobile",\n "desktop"\n ]\n },\n "loop": {\n "type": "boolean"\n },\n "variants": {\n "type": "object",\n "additionalProperties": {\n "type": "string",\n "minLength": 1\n }\n }\n }\n },\n {\n "type": "object",\n "required": [\n "agent",\n "component",\n "label",\n "items"\n ],\n "properties": {\n "agent": {\n "type": "string",\n "minLength": 1\n },\n "component": {\n "const": "Set"\n },\n "label": {\n "type": "string"\n },\n "items": {\n "type": "array",\n "minItems": 1,\n "maxItems": 500,\n "items": {\n "type": "object",\n "required": [\n "src"\n ],\n "properties": {\n "src": {\n "type": "string",\n "minLength": 1\n },\n "label": {\n "type": "string"\n },\n "alt": {\n "type": "string"\n },\n "device": {\n "enum": [\n "mobile",\n "desktop"\n ]\n },\n "loop": {\n "type": "boolean"\n },\n "variants": {\n "type": "object",\n "additionalProperties": {\n "type": "string",\n "minLength": 1\n }\n }\n }\n }\n }\n }\n },\n {\n "type": "object",\n "required": [\n "agent",\n "component",\n "a",\n "b"\n ],\n "properties": {\n "agent": {\n "type": "string",\n "minLength": 1\n },\n "component": {\n "const": "Compare"\n },\n "a": {\n "type": "string",\n "minLength": 1\n },\n "b": {\n "type": "string",\n "minLength": 1\n },\n "shots": {\n "type": "string",\n "minLength": 1\n },\n "label": {\n "type": "string"\n },\n "a-label": {\n "type": "string"\n },\n "b-label": {\n "type": "string"\n }\n }\n },\n {\n "type": "object",\n "required": [\n "agent",\n "component",\n "src"\n ],\n "properties": {\n "agent": {\n "type": "string",\n "minLength": 1\n },\n "component": {\n "const": "Storyboard"\n },\n "src": {\n "type": "string",\n "minLength": 1\n },\n "label": {\n "type": "string"\n }\n }\n }\n ]\n }\n }\n }\n }\n ]\n },\n "references": [\n {\n "json": "/files/*/before"\n },\n {\n "json": "/files/*/after"\n },\n {\n "json": "/files/*/diff"\n },\n {\n "json": "/results/*/src",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/variants/*",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/a",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/b",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/shots",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/items/*/src",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/items/*/variants/*",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/items/*/a",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/items/*/b",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n },\n {\n "json": "/results/*/items/*/shots",\n "types": [\n "storyboard",\n "compare",\n "spritesheet",\n "studio",\n "asset"\n ]\n }\n ]\n}\n';
|
|
12888
|
-
}
|
|
12889
|
-
});
|
|
12890
|
-
|
|
12891
|
-
// ../artifact-sdk/src/builtin/index.ts
|
|
12892
|
-
var read, builtin_default;
|
|
12893
|
-
var init_builtin = __esm({
|
|
12894
|
-
"../artifact-sdk/src/builtin/index.ts"() {
|
|
12895
|
-
"use strict";
|
|
12896
|
-
init_compare2();
|
|
12897
|
-
init_html();
|
|
12898
|
-
init_image();
|
|
12899
|
-
init_markdown();
|
|
12900
|
-
init_spritesheet();
|
|
12901
|
-
init_storyboard2();
|
|
12902
|
-
init_tiled();
|
|
12903
|
-
init_video();
|
|
12904
|
-
init_studio();
|
|
12905
|
-
read = (m) => typeof m === "string" ? JSON.parse(m) : m;
|
|
12906
|
-
builtin_default = [html_default, image_default, video_default, markdown_default, storyboard_default, compare_default, studio_default, tiled_default, spritesheet_default].map(read);
|
|
12907
|
-
}
|
|
12908
|
-
});
|
|
12909
|
-
|
|
12910
|
-
// ../artifact-sdk/src/internal/schema.ts
|
|
12911
|
-
function typeOk(type, v) {
|
|
12912
|
-
const types = Array.isArray(type) ? type : [type];
|
|
12913
|
-
return types.some(
|
|
12914
|
-
(t) => t === "null" ? v === null : t === "array" ? Array.isArray(v) : t === "object" ? isObj(v) : t === "integer" ? Number.isInteger(v) : t === "number" ? typeof v === "number" && Number.isFinite(v) : typeof v === t
|
|
12915
|
-
);
|
|
12916
|
-
}
|
|
12917
|
-
function schemaProblem(schema, value, at2 = "") {
|
|
12918
|
-
if (!isObj(schema)) return null;
|
|
12919
|
-
const s = schema;
|
|
12920
|
-
const here = at2 || "/";
|
|
12921
|
-
if (s.type !== void 0 && !typeOk(s.type, value)) return here;
|
|
12922
|
-
if (Array.isArray(s.enum) && !s.enum.some((e2) => JSON.stringify(e2) === JSON.stringify(value))) return here;
|
|
12923
|
-
if (s.const !== void 0 && JSON.stringify(s.const) !== JSON.stringify(value)) return here;
|
|
12924
|
-
if (Array.isArray(s.anyOf) && !s.anyOf.some((x2) => !schemaProblem(x2, value, at2))) return here;
|
|
12925
|
-
if (typeof value === "string") {
|
|
12926
|
-
if (typeof s.minLength === "number" && value.length < s.minLength) return here;
|
|
12927
|
-
if (typeof s.maxLength === "number" && value.length > s.maxLength) return here;
|
|
12928
|
-
if (typeof s.pattern === "string") {
|
|
12929
|
-
try {
|
|
12930
|
-
if (!new RegExp(s.pattern, "u").test(value)) return here;
|
|
12931
|
-
} catch {
|
|
12932
|
-
}
|
|
12933
|
-
}
|
|
12934
|
-
}
|
|
12935
|
-
if (typeof value === "number") {
|
|
12936
|
-
if (typeof s.minimum === "number" && value < s.minimum) return here;
|
|
12937
|
-
if (typeof s.maximum === "number" && value > s.maximum) return here;
|
|
12938
|
-
}
|
|
12939
|
-
if (Array.isArray(value)) {
|
|
12940
|
-
if (typeof s.minItems === "number" && value.length < s.minItems) return here;
|
|
12941
|
-
if (typeof s.maxItems === "number" && value.length > s.maxItems) return here;
|
|
12942
|
-
if (isObj(s.items)) {
|
|
12943
|
-
for (let i = 0; i < value.length; i++) {
|
|
12944
|
-
const bad = schemaProblem(s.items, value[i], `${at2}/${i}`);
|
|
12945
|
-
if (bad) return bad;
|
|
12946
|
-
}
|
|
12947
|
-
}
|
|
12948
|
-
}
|
|
12949
|
-
if (isObj(value)) {
|
|
12950
|
-
const props = isObj(s.properties) ? s.properties : {};
|
|
12951
|
-
if (Array.isArray(s.required)) {
|
|
12952
|
-
for (const k2 of s.required) if (typeof k2 === "string" && !(k2 in value)) return `${at2}/${k2}`;
|
|
12953
|
-
}
|
|
12954
|
-
for (const [k2, v] of Object.entries(value)) {
|
|
12955
|
-
if (k2 in props) {
|
|
12956
|
-
const bad = schemaProblem(props[k2], v, `${at2}/${k2}`);
|
|
12957
|
-
if (bad) return bad;
|
|
12958
|
-
} else if (s.additionalProperties === false) return `${at2}/${k2}`;
|
|
12959
|
-
else if (isObj(s.additionalProperties)) {
|
|
12960
|
-
const bad = schemaProblem(s.additionalProperties, v, `${at2}/${k2}`);
|
|
12961
|
-
if (bad) return bad;
|
|
12962
|
-
}
|
|
12963
|
-
}
|
|
12964
|
-
}
|
|
12965
|
-
return null;
|
|
12966
|
-
}
|
|
12967
|
-
var isObj;
|
|
12968
|
-
var init_schema = __esm({
|
|
12969
|
-
"../artifact-sdk/src/internal/schema.ts"() {
|
|
12970
|
-
"use strict";
|
|
12971
|
-
isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
12972
|
-
}
|
|
12973
|
-
});
|
|
12974
|
-
|
|
12975
|
-
// ../artifact-sdk/src/internal/references.ts
|
|
12976
|
-
function bodyReferences(body) {
|
|
12977
|
-
const lines = body.replace(/<!--[^]*?-->/g, "").split(/\r?\n/);
|
|
12978
|
-
let fence = "";
|
|
12979
|
-
let inTag = false;
|
|
12980
|
-
const out = [];
|
|
12981
|
-
const visible = [];
|
|
12982
|
-
for (const line of lines) {
|
|
12983
|
-
const delimiter = /^ {0,3}(`{3,}|~{3,})/.exec(line)?.[1];
|
|
12984
|
-
if (fence) {
|
|
12985
|
-
if (delimiter && delimiter[0] === fence[0] && delimiter.length >= fence.length) fence = "";
|
|
12986
|
-
visible.push("");
|
|
12987
|
-
continue;
|
|
12988
|
-
}
|
|
12989
|
-
if (delimiter) {
|
|
12990
|
-
fence = delimiter;
|
|
12991
|
-
visible.push("");
|
|
12992
|
-
continue;
|
|
12993
|
-
}
|
|
12994
|
-
const kept2 = inTag || !/^(?: {4}|\t)/.test(line);
|
|
12995
|
-
visible.push(kept2 ? line : "");
|
|
12996
|
-
if (kept2 && /^ {0,3}<(?:Asset|Mockup|Compare|Storyboard|Studio)\b/.test(line)) inTag = true;
|
|
12997
|
-
if (line.includes("/>")) inTag = false;
|
|
12998
|
-
}
|
|
12999
|
-
const text6 = visible.join("\n").replace(/(`+)[^]*?\1/g, "");
|
|
13000
|
-
const tag = /<(Asset|Mockup|Compare|Storyboard|Studio)\b([^<>]*?)\/>/g;
|
|
13001
|
-
const blocks = text6.matchAll(/^ {0,3}(?:<(?:Asset|Mockup|Compare|Storyboard|Studio)\b[^<>]*?\/>[ \t]*(?:\n[ \t]*)?)+$/gm);
|
|
13002
|
-
for (const block of blocks) {
|
|
13003
|
-
const tags = [...block[0].matchAll(tag)];
|
|
13004
|
-
for (const m of tags) {
|
|
13005
|
-
const a2 = {};
|
|
13006
|
-
for (const p2 of m[2].matchAll(/([\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)) a2[p2[1]] = p2[2] ?? p2[3];
|
|
13007
|
-
if (m[1] === "Compare") {
|
|
13008
|
-
if (!a2.a || !a2.b) continue;
|
|
13009
|
-
for (const k2 of ["a", "b", "shots"]) if (a2[k2]) out.push({ src: a2[k2], types: ARRANGED });
|
|
13010
|
-
} else if (a2.src) {
|
|
13011
|
-
out.push({ src: a2.src, types: m[1] === "Storyboard" ? STORYBOARD : m[1] === "Studio" ? STUDIO : m[1] === "Asset" ? ASSET : [] });
|
|
13012
|
-
if (a2.variants) {
|
|
13013
|
-
try {
|
|
13014
|
-
const v = JSON.parse(a2.variants);
|
|
13015
|
-
if (isObject(v)) {
|
|
13016
|
-
for (const src of Object.values(v)) if (typeof src === "string" && src) out.push({ src, types: m[1] === "Asset" ? ASSET : [] });
|
|
13017
|
-
}
|
|
13018
|
-
} catch {
|
|
13019
|
-
}
|
|
13020
|
-
}
|
|
13021
|
-
}
|
|
13022
|
-
}
|
|
13023
|
-
}
|
|
13024
|
-
for (const m of text6.replace(tag, "").matchAll(/\]\(\s*<?([^\s)>]+)>?(?:\s+["'][^]*?["'])?\s*\)/g)) out.push({ src: m[1], types: [] });
|
|
13025
|
-
return out;
|
|
13026
|
-
}
|
|
13027
|
-
function kindOf2(ext) {
|
|
13028
|
-
if (ext === ".tsx" || ext === ".html") return "html";
|
|
13029
|
-
if (ext === ".md" || ext === ".mdx") return "markdown";
|
|
13030
|
-
if (ext === ".tmx" || ext === ".tmj" || ext === ".tsj") return "tiled";
|
|
13031
|
-
const type = TYPES[ext] ?? "";
|
|
13032
|
-
if (type.startsWith("image/")) return "image";
|
|
13033
|
-
return type.startsWith("video/") || type.startsWith("audio/") ? "video" : "asset";
|
|
13034
|
-
}
|
|
13035
|
-
var STORYBOARD, STUDIO, ARRANGED, ASSET, isObject, bodySources, TYPES;
|
|
13036
|
-
var init_references = __esm({
|
|
13037
|
-
"../artifact-sdk/src/internal/references.ts"() {
|
|
13038
|
-
"use strict";
|
|
13039
|
-
STORYBOARD = ["storyboard"];
|
|
13040
|
-
STUDIO = ["studio"];
|
|
13041
|
-
ARRANGED = ["storyboard", "compare", "spritesheet", "studio"];
|
|
13042
|
-
ASSET = ["spritesheet", "asset"];
|
|
13043
|
-
isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
13044
|
-
bodySources = (body) => [...new Set(bodyReferences(body).map((r2) => r2.src))];
|
|
13045
|
-
TYPES = {
|
|
13046
|
-
".png": "image/png",
|
|
13047
|
-
".jpg": "image/jpeg",
|
|
13048
|
-
".jpeg": "image/jpeg",
|
|
13049
|
-
".gif": "image/gif",
|
|
13050
|
-
".webp": "image/webp",
|
|
13051
|
-
".svg": "image/svg+xml",
|
|
13052
|
-
".mp4": "video/mp4",
|
|
13053
|
-
".webm": "video/webm",
|
|
13054
|
-
".mp3": "audio/mpeg",
|
|
13055
|
-
".pdf": "application/pdf",
|
|
13056
|
-
".html": "text/html",
|
|
13057
|
-
".md": "text/markdown",
|
|
13058
|
-
".mdx": "text/markdown",
|
|
13059
|
-
".mov": "video/quicktime",
|
|
13060
|
-
".wav": "audio/wav",
|
|
13061
|
-
".m4a": "audio/mp4",
|
|
13062
|
-
".json": "application/json",
|
|
13063
|
-
".txt": "text/plain",
|
|
13064
|
-
".otf": "font/otf",
|
|
13065
|
-
".ttf": "font/ttf",
|
|
13066
|
-
".woff": "font/woff",
|
|
13067
|
-
".woff2": "font/woff2",
|
|
13068
|
-
".css": "text/css",
|
|
13069
|
-
".tmx": "application/xml",
|
|
13070
|
-
".tmj": "application/json",
|
|
13071
|
-
".tsj": "application/json"
|
|
13072
|
-
};
|
|
13073
|
-
}
|
|
13074
|
-
});
|
|
13075
|
-
|
|
13076
|
-
// ../artifact-sdk/src/internal/format/studio.ts
|
|
13077
|
-
function resultProblem(value, agents) {
|
|
13078
|
-
if (!Array.isArray(value) || value.length > 500) return "/results";
|
|
13079
|
-
for (let i = 0; i < value.length; i++) {
|
|
13080
|
-
const r2 = value[i];
|
|
13081
|
-
if (!isObject(r2) || !text4(r2.agent) || !agents.has(r2.agent) || !optionalText(r2, ["label"])) return `/results/${i}`;
|
|
13082
|
-
const valid = r2.component === "Asset" ? asset(r2) : r2.component === "Set" ? typeof r2.label === "string" && Array.isArray(r2.items) && r2.items.length > 0 && r2.items.length <= 500 && r2.items.every(asset) : r2.component === "Compare" ? source(r2.a) && source(r2.b) && (r2.shots === void 0 || source(r2.shots)) && optionalText(r2, ["a-label", "b-label"]) : r2.component === "Storyboard" && source(r2.src);
|
|
13083
|
-
if (!valid) return `/results/${i}`;
|
|
13084
|
-
}
|
|
13085
|
-
return null;
|
|
13086
|
-
}
|
|
13087
|
-
function reviewProblem(v) {
|
|
13088
|
-
if (!isObject(v) || v.version !== 2) return "/version";
|
|
13089
|
-
if (!text4(v.fingerprint)) return "/fingerprint";
|
|
13090
|
-
if (v.base !== null && !(isObject(v.base) && text4(v.base.id) && Number.isInteger(v.base.version) && Number(v.base.version) > 0 && text4(v.base.fingerprint))) return "/base";
|
|
13091
|
-
if (!Array.isArray(v.agents) || v.agents.length > 500) return "/agents";
|
|
13092
|
-
const agents = /* @__PURE__ */ new Set();
|
|
13093
|
-
for (const a2 of v.agents) {
|
|
13094
|
-
if (!isObject(a2) || !text4(a2.agent) || !/^[a-z][a-z0-9-]*$/.test(a2.agent) || agents.has(a2.agent) || !isObject(a2.title) || !text4(a2.title.en) || !optionalText(a2.title, ["zh"]) || !icon(a2.icon)) return "/agents";
|
|
13095
|
-
agents.add(a2.agent);
|
|
13096
|
-
}
|
|
13097
|
-
if (!Array.isArray(v.files) || v.files.length > 1e3) return "/files";
|
|
13098
|
-
const paths = /* @__PURE__ */ new Set();
|
|
13099
|
-
for (const f2 of v.files) {
|
|
13100
|
-
if (!isObject(f2) || !relativePath(f2.path) || paths.has(f2.path) || !(f2.before === null || source(f2.before)) || !(f2.after === null || source(f2.after)) || f2.before === null && f2.after === null || f2.diff !== void 0 && !source(f2.diff) || (f2.before === null || f2.after === null) && !f2.diff) return "/files";
|
|
13101
|
-
if (f2.path.startsWith("agents/") && !agents.has(f2.path.split("/")[1])) return "/files";
|
|
13102
|
-
paths.add(f2.path);
|
|
13103
|
-
}
|
|
13104
|
-
return resultProblem(v.results, agents);
|
|
13105
|
-
}
|
|
13106
|
-
var text4, source, icon, relativePath, optionalText, asset, parseReview, isReview;
|
|
13107
|
-
var init_studio2 = __esm({
|
|
13108
|
-
"../artifact-sdk/src/internal/format/studio.ts"() {
|
|
13109
|
-
"use strict";
|
|
13110
|
-
init_references();
|
|
13111
|
-
text4 = (v) => typeof v === "string" && v.length > 0;
|
|
13112
|
-
source = (v) => text4(v) && !/^(?:[a-z][\w+.-]*:|\/|#)|\\|[\u0000-\u001f]/i.test(v);
|
|
13113
|
-
icon = (v) => v === void 0 || typeof v === "string" || Array.isArray(v) && v.length > 0 && v.length <= 12 && v.every((p2) => isObject(p2) && text4(p2.d) && /^[MmLlHhVvCcSsQqTtAaZz0-9.,\s-]+$/.test(p2.d) && ["f", "s"].every((k2) => p2[k2] === void 0 || typeof p2[k2] === "string" && /^[kwcgopsmlry]$/.test(p2[k2])) && (p2.o === void 0 || p2.o === true) && (p2.w === void 0 || typeof p2.w === "number" && p2.w > 0 && p2.w <= 3));
|
|
13114
|
-
relativePath = (v) => source(v) && v.split("/").every((p2) => p2 && p2 !== "." && p2 !== "..");
|
|
13115
|
-
optionalText = (v, keys) => keys.every((k2) => v[k2] === void 0 || typeof v[k2] === "string");
|
|
13116
|
-
asset = (v) => isObject(v) && source(v.src) && optionalText(v, ["label", "alt"]) && (v.alt === void 0 || !/[<>]/.test(v.alt)) && (v.device === void 0 || v.device === "desktop" || v.device === "mobile") && (v.loop === void 0 || typeof v.loop === "boolean") && (v.variants === void 0 || isObject(v.variants) && Object.values(v.variants).every(source));
|
|
13117
|
-
parseReview = (v) => reviewProblem(v) ? null : v;
|
|
13118
|
-
isReview = (v) => isObject(v) && v.version === 2;
|
|
13119
|
-
}
|
|
13120
|
-
});
|
|
13121
|
-
|
|
13122
|
-
// ../artifact-sdk/src/internal/manifest.ts
|
|
13123
|
-
function typeOf(data, types) {
|
|
13124
|
-
const problem = (type) => type === "studio" && isReview(data) ? reviewProblem(data) : schemaProblem(manifestOf(type)?.schema, data);
|
|
13125
|
-
for (const type of types) if (!problem(type)) return { type };
|
|
13126
|
-
if (types.length !== 1) return { type: null };
|
|
13127
|
-
return { type: types[0], problem: `does not match ${types[0]} at ${problem(types[0])}` };
|
|
13128
|
-
}
|
|
13129
|
-
function mapJson(node, keys, at2, visit) {
|
|
13130
|
-
if (!keys.length) return typeof node === "string" && node ? visit(node, at2) : node;
|
|
13131
|
-
const [key, ...rest] = keys;
|
|
13132
|
-
if (Array.isArray(node)) {
|
|
13133
|
-
if (key === "*") return node.map((x2, i2) => mapJson(x2, rest, `${at2}/${i2}`, visit));
|
|
13134
|
-
const i = Number(key);
|
|
13135
|
-
return Number.isInteger(i) && i in node ? node.map((x2, j2) => j2 === i ? mapJson(x2, rest, `${at2}/${j2}`, visit) : x2) : node;
|
|
13136
|
-
}
|
|
13137
|
-
if (!isObject2(node)) return node;
|
|
13138
|
-
const out = { ...node };
|
|
13139
|
-
for (const k2 of key === "*" ? Object.keys(node) : key in node ? [key] : []) out[k2] = mapJson(node[k2], rest, `${at2}/${k2}`, visit);
|
|
13140
|
-
return out;
|
|
13141
|
-
}
|
|
13142
|
-
function mapText(text6, rule, skipped, visit, includeRemote) {
|
|
13143
|
-
let out = "";
|
|
13144
|
-
let last = 0;
|
|
13145
|
-
for (const m of text6.matchAll(new RegExp(rule.text, "gid"))) {
|
|
13146
|
-
const span = m.indices?.[1];
|
|
13147
|
-
if (!span || m[1] === void 0 || skipped.some(([a2, b2]) => span[0] >= a2 && span[0] < b2)) continue;
|
|
13148
|
-
const line = text6.slice(0, span[0]).split("\n").length;
|
|
13149
|
-
const one = (src) => remote(src) && !includeRemote ? src : visit(src, line);
|
|
13150
|
-
const value = rule.list ? m[1].split(rule.list).map((part) => part.replace(/^(\s*)(\S+)/, (_2, space, src) => space + one(src))).join(rule.list) : one(m[1]);
|
|
13151
|
-
out += text6.slice(last, span[0]) + value;
|
|
13152
|
-
last = span[1];
|
|
13153
|
-
}
|
|
13154
|
-
return out + text6.slice(last);
|
|
13155
|
-
}
|
|
13156
|
-
function mapReferences(manifest, content, map2, includeRemote = false) {
|
|
13157
|
-
const skipped = (text6) => (manifest?.skip ?? []).flatMap((re3) => [...text6.matchAll(new RegExp(re3, "gi"))].map((m) => [m.index, m.index + m[0].length]));
|
|
13158
|
-
for (const rule of manifest?.references ?? []) {
|
|
13159
|
-
const types = rule.types ?? [];
|
|
13160
|
-
if ("json" in rule) {
|
|
13161
|
-
if (typeof content !== "string") content = mapJson(content, rule.json.split("/").filter(Boolean), "", (src, at2) => map2(src, { src, types, text: false, at: at2 || "/" }));
|
|
13162
|
-
} else if (typeof content === "string") {
|
|
13163
|
-
content = mapText(content, rule, skipped(content), (src, line) => map2(src, { src, types, text: true, line }), includeRemote);
|
|
13164
|
-
}
|
|
13165
|
-
}
|
|
13166
|
-
return content;
|
|
13167
|
-
}
|
|
13168
|
-
function referencesOf(manifest, content, includeRemote = false) {
|
|
13169
|
-
const found2 = [];
|
|
13170
|
-
mapReferences(manifest, content, (src, ref) => (found2.push(ref), src), includeRemote);
|
|
13171
|
-
return found2;
|
|
13172
|
-
}
|
|
13173
|
-
var BUILTINS, manifestOf, isObject2, remote;
|
|
13174
|
-
var init_manifest = __esm({
|
|
13175
|
-
"../artifact-sdk/src/internal/manifest.ts"() {
|
|
13176
|
-
"use strict";
|
|
13177
|
-
init_builtin();
|
|
13178
|
-
init_schema();
|
|
13179
|
-
init_studio2();
|
|
13180
|
-
BUILTINS = builtin_default;
|
|
13181
|
-
manifestOf = (type) => BUILTINS.find((m) => m.types.includes(type));
|
|
13182
|
-
isObject2 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
13183
|
-
remote = (src) => !src || /^(?:[a-z][\w+.-]*:|\/|#)/i.test(src);
|
|
13184
|
-
}
|
|
13185
|
-
});
|
|
13186
|
-
|
|
13187
13224
|
// ../artifact-sdk/src/internal/collect.ts
|
|
13188
13225
|
function collect(body, card, host2) {
|
|
13189
13226
|
return collectSources(bodyReferences(body), card, host2);
|
|
@@ -13283,7 +13320,7 @@ var init_collect = __esm({
|
|
|
13283
13320
|
textKind = (ext, types) => types.find((t) => {
|
|
13284
13321
|
const m = manifestOf(t);
|
|
13285
13322
|
return m && !m.schema;
|
|
13286
|
-
}) ??
|
|
13323
|
+
}) ?? kindOf(ext);
|
|
13287
13324
|
kindAt = (src, types) => extOf(src) === ".json" ? types.includes("asset") ? "asset" : types[0] ?? "asset" : textKind(extOf(src), types);
|
|
13288
13325
|
}
|
|
13289
13326
|
});
|
|
@@ -13693,8 +13730,8 @@ var init_spec_contract = __esm({
|
|
|
13693
13730
|
init_cards();
|
|
13694
13731
|
init_frontmatter();
|
|
13695
13732
|
init_paths();
|
|
13696
|
-
|
|
13697
|
-
|
|
13733
|
+
init_compare2();
|
|
13734
|
+
init_storyboard2();
|
|
13698
13735
|
init_preview_files();
|
|
13699
13736
|
init_validate();
|
|
13700
13737
|
ASSET_LINE = /^\s*<(?:Asset|Mockup)\b[^<>]*\/>\s*$/;
|
|
@@ -17918,7 +17955,18 @@ import path65 from "node:path";
|
|
|
17918
17955
|
import { createHash as createHash5, randomUUID as randomUUID6 } from "node:crypto";
|
|
17919
17956
|
function readPreviewProgress(id) {
|
|
17920
17957
|
try {
|
|
17921
|
-
|
|
17958
|
+
const all2 = JSON.parse(fs62.readFileSync(file(id), "utf8"));
|
|
17959
|
+
if (!runnerProject(KANBAN) && !process.env[PREVIEW_BRIDGE_ENV]) {
|
|
17960
|
+
const body = findCard(id)?.body ?? "";
|
|
17961
|
+
for (const [name, progress] of Object.entries(all2)) {
|
|
17962
|
+
const section = previewSection(body, name);
|
|
17963
|
+
try {
|
|
17964
|
+
syncPreviewContent(progress, section, localPreviewAssets(id, section));
|
|
17965
|
+
} catch {
|
|
17966
|
+
}
|
|
17967
|
+
}
|
|
17968
|
+
}
|
|
17969
|
+
return all2;
|
|
17922
17970
|
} catch (error) {
|
|
17923
17971
|
if (error.code === "ENOENT") return {};
|
|
17924
17972
|
throw error;
|
|
@@ -17929,6 +17977,7 @@ function updatePreviewProgress(id, change2) {
|
|
|
17929
17977
|
return withLock(`${file(id)}.lock`, "updating preview progress", () => {
|
|
17930
17978
|
const all2 = readPreviewProgress(id);
|
|
17931
17979
|
const result = change2(all2);
|
|
17980
|
+
if (!runnerProject(KANBAN) && !process.env[PREVIEW_BRIDGE_ENV]) freezeLocalAssets(id, all2);
|
|
17932
17981
|
const temp = `${file(id)}.${process.pid}.tmp`;
|
|
17933
17982
|
fs62.writeFileSync(temp, JSON.stringify(all2) + "\n");
|
|
17934
17983
|
fs62.renameSync(temp, file(id));
|
|
@@ -17962,13 +18011,13 @@ Select with: ${command} raw previews ${name} ${id} --stages <id,...>.`;
|
|
|
17962
18011
|
const current = progress.stages.find((stage) => stage.id === progress.currentStageId);
|
|
17963
18012
|
if (!current) return `Saved stages: ${JSON.stringify(progress.stages)}
|
|
17964
18013
|
Select with: ${command} raw previews ${name} ${id} --stages <id,...>.`;
|
|
17965
|
-
if (
|
|
18014
|
+
if (["awaiting_confirmation", "ready", "confirmed"].includes(current.status)) return "The current preview is awaiting user review. Stop and wait for approval before starting the next stage; do not poll.";
|
|
17966
18015
|
return [
|
|
17967
18016
|
`Selected stages: ${progress.stages.map((stage) => stage.id).join(", ")}. Current stage: ${current.id}.`,
|
|
17968
18017
|
progress.files[current.instructions] === progress.body ? "" : progress.files[current.instructions],
|
|
17969
18018
|
...progress.stages.filter((stage) => stage.status === "confirmed").map((stage) => `Confirmed ${stage.id} v${stage.version}:
|
|
17970
18019
|
${stage.artifact?.body ?? ""}`),
|
|
17971
|
-
`
|
|
18020
|
+
`Report completion with: ${command} raw previews ${name} ${id} --stage ${current.id} --status done. Stop and wait for user approval before starting the next stage.`
|
|
17972
18021
|
].join("\n\n");
|
|
17973
18022
|
}
|
|
17974
18023
|
function previewOwner(id, name, inside2 = insideRun()) {
|
|
@@ -18026,28 +18075,6 @@ function previewSection(body, name) {
|
|
|
18026
18075
|
const end2 = lines.findIndex((line, index) => index > start && (/^## /.test(line) || line.trim() === "<!-- agent -->"));
|
|
18027
18076
|
return lines.slice(start + 1, end2 < 0 ? void 0 : end2).join("\n").trim();
|
|
18028
18077
|
}
|
|
18029
|
-
function submitLocalPreview(id, name, stage, baseline) {
|
|
18030
|
-
const run4 = previewRun(id, name);
|
|
18031
|
-
const card = findCard(id);
|
|
18032
|
-
if (!card) throw Error("The task is no longer open.");
|
|
18033
|
-
const body = previewSection(card.body, name);
|
|
18034
|
-
const snapshot2 = randomUUID6();
|
|
18035
|
-
const source2 = path65.join(ASSETS, String(id));
|
|
18036
|
-
const dest = path65.join(BOARD_STATE, "previews", "assets", String(id), snapshot2);
|
|
18037
|
-
if (fs62.existsSync(source2) && fs62.lstatSync(source2).isSymbolicLink()) throw Error("Preview assets must stay inside this task\u2019s asset folder.");
|
|
18038
|
-
if (fs62.existsSync(source2)) fs62.cpSync(source2, dest, { recursive: true, dereference: true, filter: (file2) => {
|
|
18039
|
-
const real2 = fs62.realpathSync(file2);
|
|
18040
|
-
if (real2 !== fs62.realpathSync(source2) && !real2.startsWith(fs62.realpathSync(source2) + path65.sep)) throw Error("Preview assets must stay inside this task\u2019s asset folder.");
|
|
18041
|
-
return true;
|
|
18042
|
-
} });
|
|
18043
|
-
return updatePreviewProgress(id, (all2) => {
|
|
18044
|
-
const progress = all2[name];
|
|
18045
|
-
if (!progress) throw Error("Select the stages first.");
|
|
18046
|
-
const base = baseline ?? readPreviewBaseline(id, name, run4.sessionId);
|
|
18047
|
-
if (base.stageId !== stage) throw Error("Wrong stage.");
|
|
18048
|
-
return submitPreviewStage(progress, base, body, { folder: dest });
|
|
18049
|
-
});
|
|
18050
|
-
}
|
|
18051
18078
|
function savePreviewBaseline(id, name, run4, baseline) {
|
|
18052
18079
|
writeJson2(baselineFile(id, name, run4), baseline);
|
|
18053
18080
|
}
|
|
@@ -18084,10 +18111,83 @@ function frozenPreviewFile(agent, relative) {
|
|
|
18084
18111
|
if (run4?.action !== "spec" || run4.specAgent !== agent || run4.cardId === null) return void 0;
|
|
18085
18112
|
return readPreviewProgress(run4.cardId)[agent]?.files[relative];
|
|
18086
18113
|
}
|
|
18114
|
+
function reportLocalPreview(id, name, stage, status) {
|
|
18115
|
+
const run4 = previewRun(id, name);
|
|
18116
|
+
return updatePreviewProgress(id, (all2) => {
|
|
18117
|
+
const progress = all2[name];
|
|
18118
|
+
if (!progress || progress.execution !== run4.sessionId) throw Error("This execution is outdated. Reload the task.");
|
|
18119
|
+
const baseline = reportPreviewStage(progress, stage, "running", run4.sessionId);
|
|
18120
|
+
const body = previewSection(findCard(id)?.body ?? "", name);
|
|
18121
|
+
const assets = localPreviewAssets(id, body);
|
|
18122
|
+
syncPreviewContent(progress, body, assets);
|
|
18123
|
+
reportPreviewStage(progress, stage, status, run4.sessionId);
|
|
18124
|
+
savePreviewBaseline(id, name, run4.sessionId, baseline);
|
|
18125
|
+
return progress;
|
|
18126
|
+
});
|
|
18127
|
+
}
|
|
18128
|
+
function localPreviewAssets(id, body) {
|
|
18129
|
+
const assets = {};
|
|
18130
|
+
const taskRoot = path65.join(ASSETS, String(id));
|
|
18131
|
+
const visit = (src) => {
|
|
18132
|
+
if (src in assets || /^[a-z][\w+.-]*:/i.test(src)) return;
|
|
18133
|
+
const file2 = path65.resolve(ASSETS, src.replace(/^\.assets\//, ""));
|
|
18134
|
+
if (!file2.startsWith(taskRoot + path65.sep)) throw Error("Preview assets must stay inside this task\u2019s asset folder.");
|
|
18135
|
+
if (!fs62.existsSync(file2)) {
|
|
18136
|
+
assets[src] = null;
|
|
18137
|
+
return;
|
|
18138
|
+
}
|
|
18139
|
+
if (fs62.lstatSync(taskRoot).isSymbolicLink()) throw Error("Preview assets must stay inside this task\u2019s asset folder.");
|
|
18140
|
+
const real2 = fs62.realpathSync(file2);
|
|
18141
|
+
if (!real2.startsWith(fs62.realpathSync(taskRoot) + path65.sep)) throw Error("Preview assets must stay inside this task\u2019s asset folder.");
|
|
18142
|
+
const bytes2 = fs62.readFileSync(real2);
|
|
18143
|
+
assets[src] = createHash5("sha256").update(bytes2).digest("hex");
|
|
18144
|
+
const manifest = manifestOf(kindOf(path65.extname(file2)));
|
|
18145
|
+
let content = bytes2.toString();
|
|
18146
|
+
if (manifest?.references?.some((ref) => "json" in ref)) {
|
|
18147
|
+
try {
|
|
18148
|
+
content = JSON.parse(content);
|
|
18149
|
+
} catch {
|
|
18150
|
+
return;
|
|
18151
|
+
}
|
|
18152
|
+
}
|
|
18153
|
+
for (const ref of referencesOf(manifest, content)) {
|
|
18154
|
+
if (/^[a-z][\w+.-]*:/i.test(ref.src)) continue;
|
|
18155
|
+
visit(path65.posix.normalize(path65.posix.join(path65.posix.dirname(src), ref.src)));
|
|
18156
|
+
}
|
|
18157
|
+
};
|
|
18158
|
+
for (const ref of bodyReferences(body)) if (ref.src.startsWith(".assets/") || fs62.existsSync(path65.join(ASSETS, ref.src))) visit(ref.src);
|
|
18159
|
+
return assets;
|
|
18160
|
+
}
|
|
18161
|
+
function freezeLocalAssets(id, all2) {
|
|
18162
|
+
for (const progress of Object.values(all2)) for (const stage of progress.stages) {
|
|
18163
|
+
const artifact = stage.artifact;
|
|
18164
|
+
if (!artifact || artifact.localAssets) continue;
|
|
18165
|
+
const pinned2 = {};
|
|
18166
|
+
for (const [src, hash2] of Object.entries(artifact.assets)) {
|
|
18167
|
+
if (typeof hash2 !== "string") continue;
|
|
18168
|
+
const file2 = path65.join(ASSETS, src.replace(/^\.assets\//, ""));
|
|
18169
|
+
if (!fs62.existsSync(file2)) continue;
|
|
18170
|
+
const root2 = path65.join(ASSETS, String(id));
|
|
18171
|
+
if (fs62.lstatSync(root2).isSymbolicLink() || !fs62.realpathSync(file2).startsWith(fs62.realpathSync(root2) + path65.sep)) throw Error("Preview assets must stay inside this task\u2019s asset folder.");
|
|
18172
|
+
if (createHash5("sha256").update(fs62.readFileSync(file2)).digest("hex") !== hash2) continue;
|
|
18173
|
+
const frozen = path65.join(BOARD_STATE, "previews", "assets", String(id), stage.id, String(progress.generation), String(artifact.version), hash2, src.replace(/^\.assets\//, ""));
|
|
18174
|
+
fs62.mkdirSync(path65.dirname(frozen), { recursive: true });
|
|
18175
|
+
if (!fs62.existsSync(frozen)) fs62.copyFileSync(file2, frozen, fs62.constants.COPYFILE_EXCL);
|
|
18176
|
+
pinned2[src] = frozen;
|
|
18177
|
+
}
|
|
18178
|
+
artifact.localAssets = pinned2;
|
|
18179
|
+
for (const saved of stage.history ?? []) if (saved.version === artifact.version) saved.localAssets = pinned2;
|
|
18180
|
+
if (progress.displayedArtifact?.stageId === stage.id && progress.displayedArtifact.version === artifact.version) progress.displayedArtifact.localAssets = pinned2;
|
|
18181
|
+
}
|
|
18182
|
+
}
|
|
18087
18183
|
var file, contextFile, PreviewContextMissing, baselineFile;
|
|
18088
18184
|
var init_preview_progress = __esm({
|
|
18089
18185
|
"src/lib/agent/preview-progress.ts"() {
|
|
18090
18186
|
"use strict";
|
|
18187
|
+
init_references();
|
|
18188
|
+
init_manifest();
|
|
18189
|
+
init_tasks();
|
|
18190
|
+
init_paths();
|
|
18091
18191
|
init_paths();
|
|
18092
18192
|
init_lock();
|
|
18093
18193
|
init_agents();
|
|
@@ -18099,6 +18199,7 @@ var init_preview_progress = __esm({
|
|
|
18099
18199
|
init_cards();
|
|
18100
18200
|
init_frontmatter();
|
|
18101
18201
|
init_execution();
|
|
18202
|
+
init_preview();
|
|
18102
18203
|
init_preview_stages();
|
|
18103
18204
|
file = (id) => path65.join(BOARD_STATE, "previews", `${id}.json`);
|
|
18104
18205
|
contextFile = (id, name, owner) => path65.join(BOARD_STATE, "previews", "contexts", String(id), name, `${createHash5("sha256").update(owner).digest("hex")}.json`);
|
|
@@ -30981,8 +31082,8 @@ async function cmdSpec(opts, program2 = "akb") {
|
|
|
30981
31082
|
say(specAgentList(program2, !insideRun()));
|
|
30982
31083
|
return { agents: specAgentNamesOnBoard(), problems: specAgentProblems() };
|
|
30983
31084
|
}
|
|
30984
|
-
if ([opts.
|
|
30985
|
-
if (opts.submit && !opts.stage || opts.
|
|
31085
|
+
if ([opts.stage !== void 0, opts.stages !== void 0, opts.reviseFrom, opts.resetStages].filter(Boolean).length > 1) die("Choose one stage operation.", { kind: "invalid-usage" });
|
|
31086
|
+
if (opts.submit && !opts.stage || opts.status && !opts.stage || opts.status && !["running", "done"].includes(opts.status)) die("Use --stage <id> [--status running|done].", { kind: "invalid-usage" });
|
|
30986
31087
|
const askedName = opts.agent.trim();
|
|
30987
31088
|
const agent = findSpecAgent(askedName);
|
|
30988
31089
|
if (!agent) die(notAnAgent(askedName), { kind: "no-such-spec-agent", specAgent: askedName });
|
|
@@ -30992,7 +31093,7 @@ async function cmdSpec(opts, program2 = "akb") {
|
|
|
30992
31093
|
die(`say which card: ${program2} raw previews ${name} <id> [note]`, { kind: "needs-input" });
|
|
30993
31094
|
}
|
|
30994
31095
|
if (!locate2(id)) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
|
|
30995
|
-
if (opts.stages !== void 0 || opts.
|
|
31096
|
+
if (opts.stages !== void 0 || opts.stage || opts.reviseFrom) {
|
|
30996
31097
|
try {
|
|
30997
31098
|
let run5;
|
|
30998
31099
|
try {
|
|
@@ -31003,7 +31104,7 @@ async function cmdSpec(opts, program2 = "akb") {
|
|
|
31003
31104
|
run5 = previewRun(id, name);
|
|
31004
31105
|
}
|
|
31005
31106
|
const ids = opts.stages?.split(",").map((id2) => id2.trim());
|
|
31006
|
-
const result = await previewBridge(name, ids ? "select" : opts.reviseFrom ? "revise" : "submit", { run: run5.sessionId, cardId: id, ...ids ? { stages: ids } : opts.reviseFrom ? { stageId: opts.reviseFrom } : { baseline: readPreviewBaseline(id, name, run5.sessionId), stageId: opts.stage } });
|
|
31107
|
+
const result = await previewBridge(name, ids ? "select" : opts.reviseFrom ? "revise" : opts.submit ? "submit" : "status", { run: run5.sessionId, cardId: id, ...ids ? { stages: ids } : opts.reviseFrom ? { stageId: opts.reviseFrom } : { ...opts.submit ? { baseline: readPreviewBaseline(id, name, run5.sessionId) } : {}, stageId: opts.stage, status: opts.submit ? "done" : opts.status ?? "running" } });
|
|
31007
31108
|
if (result?.progress) {
|
|
31008
31109
|
updatePreviewProgress(id, (all2) => {
|
|
31009
31110
|
all2[name] = result.progress;
|
|
@@ -31011,17 +31112,18 @@ async function cmdSpec(opts, program2 = "akb") {
|
|
|
31011
31112
|
if (result.baseline) savePreviewBaseline(id, name, run5.sessionId, result.baseline);
|
|
31012
31113
|
} else if (opts.reviseFrom) {
|
|
31013
31114
|
updatePreviewProgress(id, (all2) => {
|
|
31014
|
-
const
|
|
31015
|
-
choosePreviewRevision(
|
|
31016
|
-
savePreviewBaseline(id, name, run5.sessionId, previewBaseline(
|
|
31115
|
+
const progress2 = all2[name];
|
|
31116
|
+
choosePreviewRevision(progress2, opts.reviseFrom, run5.sessionId);
|
|
31117
|
+
savePreviewBaseline(id, name, run5.sessionId, previewBaseline(progress2, opts.reviseFrom, run5.sessionId));
|
|
31017
31118
|
});
|
|
31018
31119
|
} else if (ids) {
|
|
31019
31120
|
const selected = selectLocalPreview(id, name, ids);
|
|
31020
31121
|
savePreviewBaseline(id, name, run5.sessionId, selected.baseline);
|
|
31021
|
-
} else
|
|
31022
|
-
|
|
31023
|
-
|
|
31024
|
-
|
|
31122
|
+
} else reportLocalPreview(id, name, opts.stage, opts.submit ? "done" : opts.status ?? "running");
|
|
31123
|
+
say(previewStagePrompt(id, name, boardCommandFor(id)));
|
|
31124
|
+
const progress = readPreviewProgress(id)[name];
|
|
31125
|
+
const at2 = progress.stages.findIndex((stage) => stage.id === progress.currentStageId);
|
|
31126
|
+
return { specAgent: name, cardId: id, currentStageId: progress.currentStageId, status: ["awaiting_confirmation", "ready", "confirmed"].includes(progress.stages[at2]?.status) ? "done" : "running", position: at2 + 1, title: progress.stages[at2]?.title, instructions: progress.stages[at2]?.status === "running" ? progress.files[progress.stages[at2].instructions] : void 0, submitted: !!opts.submit };
|
|
31025
31127
|
} catch (error) {
|
|
31026
31128
|
die(error instanceof Error ? error.message : "Preview submission failed.", { kind: "preview-refused" });
|
|
31027
31129
|
}
|
|
@@ -115754,7 +115856,7 @@ function declareRaw(program2, cli) {
|
|
|
115754
115856
|
groups.delivery.addHelpText("after", HELP_AFTER.deliveries(cli.program));
|
|
115755
115857
|
withShared(program2.command("previews")).argument("[agent]", "which preview agent; left off, the agents this board has are listed").argument("[id]", "the card to put it on", cardId).argument("[note...]", "what the flow wants looked at").summary("put a preview agent on a card; bare, list the preview agents this board has").description(
|
|
115756
115858
|
"Fill one part of a card spec. Use --print to follow the specialist instructions in the current session. Without --print, start a separate run; inside a board run, queue it until that run ends."
|
|
115757
|
-
).option("-f, --follow", "watch its log instead of returning").option("--notes <text>", "what the flow wants looked at, for a caller building a command").option("--print", "print specialist instructions and work in this session").option("--reset-stages", "explicitly change the preview scope and choose its stages again").option("--revise-from <id>", "start the requested revision at its earliest affected stage").option("--stages <ids>", "save this preview agent\u2019s ordered stage selection").option("--
|
|
115859
|
+
).option("-f, --follow", "watch its log instead of returning").option("--notes <text>", "what the flow wants looked at, for a caller building a command").option("--print", "print specialist instructions and work in this session").option("--reset-stages", "explicitly change the preview scope and choose its stages again").option("--revise-from <id>", "start the requested revision at its earliest affected stage").option("--stages <ids>", "save this preview agent\u2019s ordered stage selection").option("--status <status>", "report running or done for the current stage").addOption(new Option("--submit").hideHelp()).option("--stage <id>", "the authorized stage to work on").option("--events", "with --follow: print structured events").option("--continue", "continue the saved preview stage").option("--triggers", "list agent names and trigger conditions without starting a run").option("--studio <id>", "only enabled preview agents of this studio").option("--workspace <id>", "the workspace whose studios to query").addHelpText("after", `
|
|
115758
115860
|
List trigger conditions: ${raw} previews --triggers --json`).action(async function(...vals) {
|
|
115759
115861
|
const [agent, id, note] = positional(vals);
|
|
115760
115862
|
const opts = this.opts();
|