@kitman-sh/cli 0.14.8 → 0.15.0
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/{chunk-y0y2gg8d.js → chunk-0ws25xvg.js} +2 -2
- package/dist/{chunk-b009hdm0.js → chunk-39ykbhq8.js} +5 -5
- package/dist/{chunk-eytzmdna.js → chunk-3n99j4z0.js} +471 -234
- package/dist/{chunk-bbf0jzsc.js → chunk-3ns4sbfb.js} +1 -1
- package/dist/{chunk-q0x3c0dh.js → chunk-4x7a1qkj.js} +7 -7
- package/dist/{chunk-ya4z1n5p.js → chunk-4zc1g45m.js} +7 -7
- package/dist/{chunk-6dj39qtt.js → chunk-58hehm8d.js} +1133 -115
- package/dist/{chunk-9avbsbvk.js → chunk-5hkdgzh4.js} +1 -1
- package/dist/{chunk-xfs1nf75.js → chunk-8393zths.js} +1626 -388
- package/dist/{chunk-bpx2zjh7.js → chunk-8wpg3rph.js} +2 -2
- package/dist/{chunk-6x43ntsx.js → chunk-b16qxawc.js} +1 -1
- package/dist/chunk-cf1hxp43.js +3080 -0
- package/dist/chunk-csxxwscf.js +39 -0
- package/dist/{chunk-dq21ab8w.js → chunk-djp6t2g6.js} +21 -21
- package/dist/{chunk-zpp4jg4a.js → chunk-dx792s4w.js} +1455 -100
- package/dist/{chunk-5wrhj4cj.js → chunk-fv2zpgh0.js} +7 -7
- package/dist/{chunk-ctpgfdzf.js → chunk-fzaecdgv.js} +3 -3
- package/dist/{chunk-79g5zh2p.js → chunk-k2wd9r6t.js} +4 -4
- package/dist/chunk-mrkrt2hg.js +4345 -0
- package/dist/{chunk-721qyd1a.js → chunk-qkt77rtj.js} +6 -6
- package/dist/{chunk-drp4zdwq.js → chunk-rt0qfdtg.js} +15 -7
- package/dist/{chunk-cf723a2y.js → chunk-snwjv2sd.js} +678 -40
- package/dist/{chunk-bdd62njv.js → chunk-vg78dz3w.js} +259 -57
- package/dist/{chunk-wszvkzg8.js → chunk-vq7caqt2.js} +1828 -130
- package/dist/{chunk-63m3r0k4.js → chunk-wfz64h9p.js} +4 -4
- package/dist/{chunk-hz4t408c.js → chunk-xx711t5r.js} +4 -4
- package/dist/index.js +4 -4
- package/package.json +2 -1
- package/dist/chunk-1rwaetnm.js +0 -526
- package/dist/chunk-hrtr5wfq.js +0 -1166
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-
|
|
2
|
+
import"./chunk-k2wd9r6t.js";
|
|
3
3
|
import {
|
|
4
4
|
HERDR_CORE_GENERATION2,
|
|
5
5
|
HERDR_CORE_INSTALL_COMMAND2,
|
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
herdrCoreLayer2,
|
|
13
13
|
herdrCoreTransportLayer2,
|
|
14
14
|
updateHerdrCore2
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import"./chunk-
|
|
17
|
-
import"./chunk-
|
|
15
|
+
} from "./chunk-8393zths.js";
|
|
16
|
+
import"./chunk-vg78dz3w.js";
|
|
17
|
+
import"./chunk-dx792s4w.js";
|
|
18
18
|
export {
|
|
19
19
|
HERDR_CORE_GENERATION2 as HERDR_CORE_GENERATION,
|
|
20
20
|
HERDR_CORE_INSTALL_COMMAND2 as HERDR_CORE_INSTALL_COMMAND,
|
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
decoded2,
|
|
8
8
|
readOpencode2,
|
|
9
9
|
runOpencodeReader2
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import"./chunk-
|
|
12
|
-
import"./chunk-
|
|
13
|
-
import"./chunk-
|
|
10
|
+
} from "./chunk-39ykbhq8.js";
|
|
11
|
+
import"./chunk-k2wd9r6t.js";
|
|
12
|
+
import"./chunk-vg78dz3w.js";
|
|
13
|
+
import"./chunk-dx792s4w.js";
|
|
14
14
|
export {
|
|
15
15
|
decoded2 as decoded,
|
|
16
16
|
decodedOption2 as decodedOption,
|
package/dist/index.js
CHANGED
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
var args = process.argv.slice(2);
|
|
6
6
|
if (args[0] === "srt") {
|
|
7
7
|
process.argv.splice(2, 1);
|
|
8
|
-
const { runSrtCli } = await import("./chunk-
|
|
8
|
+
const { runSrtCli } = await import("./chunk-8wpg3rph.js");
|
|
9
9
|
await runSrtCli();
|
|
10
10
|
} else if (args[0] === "srt-step") {
|
|
11
|
-
const { runSrtStep } = await import("./chunk-
|
|
11
|
+
const { runSrtStep } = await import("./chunk-fzaecdgv.js");
|
|
12
12
|
await runSrtStep(args.slice(1));
|
|
13
13
|
} else if (args[0] === "opencode-read") {
|
|
14
|
-
const { runOpencodeReader } = await import("./chunk-
|
|
14
|
+
const { runOpencodeReader } = await import("./chunk-xx711t5r.js");
|
|
15
15
|
runOpencodeReader();
|
|
16
16
|
} else {
|
|
17
|
-
const { runCli } = await import("./chunk-
|
|
17
|
+
const { runCli } = await import("./chunk-vq7caqt2.js");
|
|
18
18
|
runCli(args);
|
|
19
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitman-sh/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"bin": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"@babel/parser": "^8.1.0",
|
|
16
16
|
"@babel/types": "^8.1.0",
|
|
17
17
|
"@modelcontextprotocol/server": "^2.4.0",
|
|
18
|
+
"oxc-parser": "^0.157.0",
|
|
18
19
|
"secure-exec": "^0.3.3",
|
|
19
20
|
"typebox": "^1.4.5",
|
|
20
21
|
"uuid": "^14.0.3"
|
package/dist/chunk-1rwaetnm.js
DELETED
|
@@ -1,526 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import {
|
|
3
|
-
isString,
|
|
4
|
-
hasProperty,
|
|
5
|
-
isTagged,
|
|
6
|
-
Reference,
|
|
7
|
-
all3,
|
|
8
|
-
forEach,
|
|
9
|
-
succeed6,
|
|
10
|
-
gen,
|
|
11
|
-
fail7,
|
|
12
|
-
flatMap3,
|
|
13
|
-
map8,
|
|
14
|
-
catchTags,
|
|
15
|
-
mapError2,
|
|
16
|
-
orDie,
|
|
17
|
-
ignore,
|
|
18
|
-
orElseSucceed,
|
|
19
|
-
provide3,
|
|
20
|
-
scoped,
|
|
21
|
-
acquireRelease,
|
|
22
|
-
encode2,
|
|
23
|
-
decodeUnknownEffect2,
|
|
24
|
-
decodeEffect,
|
|
25
|
-
optionalKey,
|
|
26
|
-
String4,
|
|
27
|
-
Struct,
|
|
28
|
-
Record,
|
|
29
|
-
Union,
|
|
30
|
-
fromJsonString,
|
|
31
|
-
TaggedError2,
|
|
32
|
-
toCodecJson,
|
|
33
|
-
Json,
|
|
34
|
-
encodePrettyJsonString
|
|
35
|
-
} from "./chunk-zpp4jg4a.js";
|
|
36
|
-
import {
|
|
37
|
-
SecureRandom,
|
|
38
|
-
layerWebCrypto,
|
|
39
|
-
canonicalJson,
|
|
40
|
-
digestSha256,
|
|
41
|
-
schemaBodyJson,
|
|
42
|
-
filterStatusOk,
|
|
43
|
-
get2,
|
|
44
|
-
layer4,
|
|
45
|
-
kitmanMcpServer,
|
|
46
|
-
RunnerRpcProtocolVersion
|
|
47
|
-
} from "./chunk-xfs1nf75.js";
|
|
48
|
-
import {
|
|
49
|
-
decodeText,
|
|
50
|
-
mkString,
|
|
51
|
-
FileSystem,
|
|
52
|
-
Path,
|
|
53
|
-
withDefault,
|
|
54
|
-
String2
|
|
55
|
-
} from "./chunk-bdd62njv.js";
|
|
56
|
-
import {
|
|
57
|
-
Packument,
|
|
58
|
-
tarballMatches
|
|
59
|
-
} from "./chunk-q0x3c0dh.js";
|
|
60
|
-
import"./chunk-drp4zdwq.js";
|
|
61
|
-
import {
|
|
62
|
-
AgentDeclaration,
|
|
63
|
-
KitDeclarations,
|
|
64
|
-
describeFlag,
|
|
65
|
-
Described
|
|
66
|
-
} from "./chunk-hrtr5wfq.js";
|
|
67
|
-
import {
|
|
68
|
-
ChildProcessSpawner,
|
|
69
|
-
make3
|
|
70
|
-
} from "./chunk-79g5zh2p.js";
|
|
71
|
-
import"./chunk-dq21ab8w.js";
|
|
72
|
-
import"./chunk-9avbsbvk.js";
|
|
73
|
-
|
|
74
|
-
// packages/sdk/src/build/index.ts
|
|
75
|
-
class DependencyInstallFailed extends TaggedError2()("DependencyInstallFailed", {
|
|
76
|
-
reason: String4
|
|
77
|
-
}) {
|
|
78
|
-
get message() {
|
|
79
|
-
return `Dependencies do not install from the lockfile: ${this.reason}`;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
class BundleFailed extends TaggedError2()("BundleFailed", { reason: String4 }) {
|
|
84
|
-
get message() {
|
|
85
|
-
return `The Kit does not bundle: ${this.reason}`;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
class DeclarationsInvalid extends TaggedError2()("DeclarationsInvalid", {
|
|
90
|
-
reason: String4
|
|
91
|
-
}) {
|
|
92
|
-
get message() {
|
|
93
|
-
return `The Kit's declarations are invalid: ${this.reason}`;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
class SourceFetchFailed extends TaggedError2()("SourceFetchFailed", {
|
|
98
|
-
reason: String4
|
|
99
|
-
}) {
|
|
100
|
-
get message() {
|
|
101
|
-
return `A setup source does not fetch: ${this.reason}`;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
var RepositoryText = Union([String4, Struct({ file: String4 })]);
|
|
105
|
-
var ConfigAgents = Record(String4, Struct({
|
|
106
|
-
...AgentDeclaration.fields,
|
|
107
|
-
instructions: optionalKey(RepositoryText)
|
|
108
|
-
}));
|
|
109
|
-
var run = (command, args, cwd) => gen(function* () {
|
|
110
|
-
const spawner = yield* ChildProcessSpawner;
|
|
111
|
-
const handle = yield* spawner.spawn(make3(command, args, { cwd, stdin: "ignore" }));
|
|
112
|
-
const [stdout, stderr, exitCode] = yield* all3([
|
|
113
|
-
mkString(decodeText(handle.stdout)),
|
|
114
|
-
mkString(decodeText(handle.stderr)),
|
|
115
|
-
handle.exitCode
|
|
116
|
-
], { concurrency: 3 });
|
|
117
|
-
return { stdout, stderr, ok: exitCode === 0 };
|
|
118
|
-
}).pipe(scoped);
|
|
119
|
-
var failure = (result) => (result.stderr.trim() || result.stdout.trim()).slice(-2000);
|
|
120
|
-
var provenance = (directory) => gen(function* () {
|
|
121
|
-
const git = (...args) => run("git", args, directory).pipe(map8((result) => result.ok ? result.stdout.trim() : undefined), orElseSucceed(() => {
|
|
122
|
-
return;
|
|
123
|
-
}));
|
|
124
|
-
const repository = yield* git("remote", "get-url", "origin");
|
|
125
|
-
const commit = yield* git("rev-parse", "HEAD");
|
|
126
|
-
const status = yield* git("status", "--porcelain");
|
|
127
|
-
return {
|
|
128
|
-
...repository ? { repository } : undefined,
|
|
129
|
-
...commit ? { commit } : undefined,
|
|
130
|
-
clean: commit !== undefined && status === ""
|
|
131
|
-
};
|
|
132
|
-
});
|
|
133
|
-
var inKit = (directory, file, what) => gen(function* () {
|
|
134
|
-
const path = yield* Path;
|
|
135
|
-
const resolved = path.resolve(directory, file);
|
|
136
|
-
if (path.relative(directory, resolved).startsWith(".."))
|
|
137
|
-
return yield* new DeclarationsInvalid({ reason: `${what} ${file} is outside the Kit` });
|
|
138
|
-
return resolved;
|
|
139
|
-
});
|
|
140
|
-
var readText = (directory, text, what) => gen(function* () {
|
|
141
|
-
if (isString(text))
|
|
142
|
-
return text;
|
|
143
|
-
const fs = yield* FileSystem;
|
|
144
|
-
const file = yield* inKit(directory, text.file, what);
|
|
145
|
-
return yield* fs.readFileString(file).pipe(mapError2(() => new DeclarationsInvalid({ reason: `${what} ${text.file} does not read` })));
|
|
146
|
-
});
|
|
147
|
-
var readAgents = (directory, agents) => forEach(Object.entries(agents), ([id, { instructions, ...agent }]) => instructions === undefined ? succeed6([id, agent]) : map8(readText(directory, instructions, `Agent "${id}" instructions`), (text) => [id, { ...agent, instructions: text.trim() }])).pipe(map8(Object.fromEntries));
|
|
148
|
-
var utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
149
|
-
var setupFile = (bytes) => {
|
|
150
|
-
try {
|
|
151
|
-
const text = utf8.decode(bytes);
|
|
152
|
-
return text.includes("\x00") ? { base64: encode2(bytes) } : { utf8: text };
|
|
153
|
-
} catch {
|
|
154
|
-
return { base64: encode2(bytes) };
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
var confined = (boundary, file, what) => gen(function* () {
|
|
158
|
-
const fs = yield* FileSystem;
|
|
159
|
-
const path = yield* Path;
|
|
160
|
-
const unreadable = () => new DeclarationsInvalid({ reason: `${what} does not read` });
|
|
161
|
-
const real = yield* fs.realPath(path.join(boundary, file)).pipe(mapError2(unreadable));
|
|
162
|
-
if (path.relative(yield* fs.realPath(boundary).pipe(mapError2(unreadable)), real).startsWith(".."))
|
|
163
|
-
return yield* new DeclarationsInvalid({ reason: `${what}: ${file} links outside its source` });
|
|
164
|
-
return real;
|
|
165
|
-
});
|
|
166
|
-
var readTree = (root, what, fetched = false) => gen(function* () {
|
|
167
|
-
const fs = yield* FileSystem;
|
|
168
|
-
const path = yield* Path;
|
|
169
|
-
const unreadable = () => new DeclarationsInvalid({ reason: `${what} does not read` });
|
|
170
|
-
const entries = yield* fs.readDirectory(root, { recursive: true }).pipe(mapError2(unreadable));
|
|
171
|
-
const files = {};
|
|
172
|
-
for (const entry of entries.toSorted()) {
|
|
173
|
-
const relative = entry.split(path.sep).join("/");
|
|
174
|
-
if (relative === ".git" || relative.startsWith(".git/"))
|
|
175
|
-
continue;
|
|
176
|
-
const file = fetched ? yield* confined(root, entry, what) : path.join(root, entry);
|
|
177
|
-
if ((yield* fs.stat(file).pipe(mapError2(unreadable))).type !== "File")
|
|
178
|
-
continue;
|
|
179
|
-
files[relative] = yield* fs.readFile(file).pipe(mapError2(unreadable));
|
|
180
|
-
}
|
|
181
|
-
return files;
|
|
182
|
-
});
|
|
183
|
-
var licenseFiles = ["LICENSE", "LICENSE.md", "LICENSE.txt", "COPYING"];
|
|
184
|
-
var fetchedTree = (root, path, what) => gen(function* () {
|
|
185
|
-
const fs = yield* FileSystem;
|
|
186
|
-
const paths = yield* Path;
|
|
187
|
-
const tree = yield* readTree(path === undefined ? root : yield* confined(root, path, what), what, true);
|
|
188
|
-
if (path === undefined)
|
|
189
|
-
return tree;
|
|
190
|
-
for (const license of licenseFiles)
|
|
191
|
-
if (tree[license] === undefined && (yield* fs.exists(paths.join(root, license))))
|
|
192
|
-
return { ...tree, [license]: yield* fs.readFile(yield* confined(root, license, what)).pipe(orDie) };
|
|
193
|
-
return tree;
|
|
194
|
-
});
|
|
195
|
-
var GitSourceLocation = Reference("kitman/sdk/build/GitSourceLocation", { defaultValue: () => (declared) => declared });
|
|
196
|
-
var fetchGit = (declared, what) => gen(function* () {
|
|
197
|
-
const fs = yield* FileSystem;
|
|
198
|
-
const { url, ref } = (yield* GitSourceLocation)(declared);
|
|
199
|
-
const checkout = yield* fs.makeTempDirectoryScoped({ prefix: "kitman-git-" });
|
|
200
|
-
for (const args of [
|
|
201
|
-
["init", "--quiet"],
|
|
202
|
-
["fetch", "--quiet", "--depth", "1", "--", url, ref ?? "HEAD"],
|
|
203
|
-
["checkout", "--quiet", "FETCH_HEAD"]
|
|
204
|
-
]) {
|
|
205
|
-
const result = yield* run("git", args, checkout);
|
|
206
|
-
if (!result.ok)
|
|
207
|
-
return yield* new SourceFetchFailed({
|
|
208
|
-
reason: `${what}: git ${url}${ref === undefined ? "" : ` at ${ref}`}: ${failure(result)}`
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
return checkout;
|
|
212
|
-
});
|
|
213
|
-
var fetchNpm = (name, wanted, what) => gen(function* () {
|
|
214
|
-
const fs = yield* FileSystem;
|
|
215
|
-
const path = yield* Path;
|
|
216
|
-
const registry = yield* String2("NPM_CONFIG_REGISTRY").pipe(withDefault("https://registry.npmjs.org"), orDie);
|
|
217
|
-
const failed = (reason) => new SourceFetchFailed({ reason: `${what}: npm ${name}@${wanted}: ${reason}` });
|
|
218
|
-
const packument = yield* get2(`${registry.replace(/\/+$/, "")}/${name.replace("/", "%2F")}`).pipe(flatMap3(filterStatusOk), flatMap3(schemaBodyJson(Packument)), mapError2((error) => failed(error.message)));
|
|
219
|
-
const dist = packument.versions[packument["dist-tags"][wanted] ?? wanted]?.dist;
|
|
220
|
-
if (dist === undefined)
|
|
221
|
-
return yield* failed("npm has no such version or dist-tag");
|
|
222
|
-
const tarball = yield* get2(dist.tarball).pipe(flatMap3(filterStatusOk), flatMap3((response) => response.arrayBuffer), map8((buffer) => new Uint8Array(buffer)), mapError2((error) => failed(error.message)));
|
|
223
|
-
if (!tarballMatches(tarball, dist))
|
|
224
|
-
return yield* failed(`the tarball does not match its integrity ${dist.integrity ?? `sha1 ${dist.shasum}`}`);
|
|
225
|
-
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "kitman-npm-" });
|
|
226
|
-
yield* fs.writeFile(path.join(directory, "package.tgz"), tarball).pipe(orDie);
|
|
227
|
-
const extracted = yield* run("tar", ["-xzf", "package.tgz"], directory);
|
|
228
|
-
if (!extracted.ok)
|
|
229
|
-
return yield* failed(`the tarball does not extract: ${failure(extracted)}`);
|
|
230
|
-
return yield* confined(directory, "package", what);
|
|
231
|
-
}).pipe(provide3(layer4));
|
|
232
|
-
var sourceTree = (directory, source, what, checkouts) => gen(function* () {
|
|
233
|
-
switch (source.kind) {
|
|
234
|
-
case "local_path":
|
|
235
|
-
return yield* readTree(yield* inKit(directory, source.path, what), what);
|
|
236
|
-
case "git": {
|
|
237
|
-
const key = `${source.url}#${source.ref ?? ""}`;
|
|
238
|
-
const checkout = checkouts.get(key) ?? (yield* fetchGit({ url: source.url, ref: source.ref }, what));
|
|
239
|
-
checkouts.set(key, checkout);
|
|
240
|
-
return yield* fetchedTree(checkout, "path" in source ? source.path : undefined, what);
|
|
241
|
-
}
|
|
242
|
-
case "package":
|
|
243
|
-
return yield* fetchedTree(yield* fetchNpm(source.packageName, source.version ?? "latest", what), "path" in source ? source.path : undefined, what);
|
|
244
|
-
default:
|
|
245
|
-
return yield* new DeclarationsInvalid({
|
|
246
|
-
reason: `${what} comes from a ${source.kind} source, which a build cannot copy in; use a local path, git or npm`
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
var setupArchive = (directory, kit, setup, checkouts) => gen(function* () {
|
|
251
|
-
const fs = yield* FileSystem;
|
|
252
|
-
const files = {};
|
|
253
|
-
const place = (prefix, tree) => {
|
|
254
|
-
for (const [file, bytes] of Object.entries(tree))
|
|
255
|
-
files[`${prefix}/${file}`] = setupFile(bytes);
|
|
256
|
-
return { kind: "local_path", path: prefix };
|
|
257
|
-
};
|
|
258
|
-
if (setup.instructions !== undefined) {
|
|
259
|
-
const what = `Kit ${kit} instructions`;
|
|
260
|
-
const file = yield* inKit(directory, setup.instructions, what);
|
|
261
|
-
files["instructions.md"] = setupFile(yield* fs.readFile(file).pipe(mapError2(() => new DeclarationsInvalid({ reason: `${what} do not read` }))));
|
|
262
|
-
}
|
|
263
|
-
const skills = setup.skills === undefined ? undefined : yield* forEach(setup.skills, (skill) => map8(sourceTree(directory, skill.source, `Kit ${kit} skill ${skill.name}`, checkouts), (tree) => ({
|
|
264
|
-
...skill,
|
|
265
|
-
source: place(`skills/${skill.name}`, tree)
|
|
266
|
-
})));
|
|
267
|
-
const plugins = setup.plugins === undefined ? undefined : yield* forEach(setup.plugins, (plugin) => map8(sourceTree(directory, plugin.sources[0], `Kit ${kit} plugin ${plugin.name}`, checkouts), (tree) => ({
|
|
268
|
-
...plugin,
|
|
269
|
-
sources: [place(`plugins/${plugin.name}`, tree)]
|
|
270
|
-
})));
|
|
271
|
-
const archive = {
|
|
272
|
-
setup: {
|
|
273
|
-
...setup,
|
|
274
|
-
...setup.instructions === undefined ? undefined : { instructions: "instructions.md" },
|
|
275
|
-
...skills === undefined ? undefined : { skills },
|
|
276
|
-
...plugins === undefined ? undefined : { plugins }
|
|
277
|
-
},
|
|
278
|
-
files
|
|
279
|
-
};
|
|
280
|
-
const bytes = new TextEncoder().encode(canonicalJson(archive));
|
|
281
|
-
return { digest: digestSha256(bytes, "hex"), archive: bytes };
|
|
282
|
-
});
|
|
283
|
-
var PackageJson = fromJsonString(Struct({
|
|
284
|
-
name: String4,
|
|
285
|
-
version: optionalKey(String4),
|
|
286
|
-
dependencies: optionalKey(Record(String4, String4))
|
|
287
|
-
}));
|
|
288
|
-
var readPackageJson = (directory) => gen(function* () {
|
|
289
|
-
const fs = yield* FileSystem;
|
|
290
|
-
const path = yield* Path;
|
|
291
|
-
return yield* fs.readFileString(path.join(directory, "package.json")).pipe(flatMap3(decodeEffect(PackageJson)), mapError2(() => new DeclarationsInvalid({ reason: `${directory}/package.json has no name` })));
|
|
292
|
-
});
|
|
293
|
-
var identityOf = (manifest) => ({
|
|
294
|
-
name: manifest.name,
|
|
295
|
-
version: manifest.version ?? "0.0.0"
|
|
296
|
-
});
|
|
297
|
-
var installedPackage = (name, directory) => gen(function* () {
|
|
298
|
-
const fs = yield* FileSystem;
|
|
299
|
-
const path = yield* Path;
|
|
300
|
-
for (let at = directory;; at = path.dirname(at)) {
|
|
301
|
-
const candidate = path.join(at, "node_modules", name);
|
|
302
|
-
if (yield* fs.exists(path.join(candidate, "package.json")))
|
|
303
|
-
return yield* fs.realPath(candidate);
|
|
304
|
-
if (path.dirname(at) === at)
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
var importedFile = (file, specifier) => gen(function* () {
|
|
309
|
-
const fs = yield* FileSystem;
|
|
310
|
-
const path = yield* Path;
|
|
311
|
-
const target = path.resolve(path.dirname(file), specifier);
|
|
312
|
-
for (const candidate of [target, `${target}.ts`, path.join(target, "kitman.config.ts")])
|
|
313
|
-
if (yield* fs.stat(candidate).pipe(map8((info) => info.type === "File"), orElseSucceed(() => false)))
|
|
314
|
-
return candidate;
|
|
315
|
-
return;
|
|
316
|
-
});
|
|
317
|
-
var packageDirectory = (file) => gen(function* () {
|
|
318
|
-
const fs = yield* FileSystem;
|
|
319
|
-
const path = yield* Path;
|
|
320
|
-
for (let at = path.dirname(file);; at = path.dirname(at)) {
|
|
321
|
-
if (yield* fs.exists(path.join(at, "package.json")).pipe(orElseSucceed(() => false)))
|
|
322
|
-
return at;
|
|
323
|
-
if (path.dirname(at) === at)
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
var kitModules = (root) => gen(function* () {
|
|
328
|
-
const fs = yield* FileSystem;
|
|
329
|
-
const path = yield* Path;
|
|
330
|
-
const found = [];
|
|
331
|
-
const visited = new Set;
|
|
332
|
-
const packages = new Set([root]);
|
|
333
|
-
const known = (directory) => packages.has(directory);
|
|
334
|
-
const visitPackage = (directory) => gen(function* () {
|
|
335
|
-
for (const name of Object.keys((yield* readPackageJson(directory)).dependencies ?? {})) {
|
|
336
|
-
const installed = yield* installedPackage(name, directory).pipe(orElseSucceed(() => {
|
|
337
|
-
return;
|
|
338
|
-
}));
|
|
339
|
-
const module = installed === undefined ? undefined : path.join(installed, "kitman.config.ts");
|
|
340
|
-
if (installed === undefined || module === undefined || known(installed))
|
|
341
|
-
continue;
|
|
342
|
-
if (!(yield* fs.exists(module).pipe(orElseSucceed(() => false))))
|
|
343
|
-
continue;
|
|
344
|
-
packages.add(installed);
|
|
345
|
-
found.push({ directory: installed, module, identity: identityOf(yield* readPackageJson(installed)) });
|
|
346
|
-
yield* visitPackage(installed);
|
|
347
|
-
yield* visitImports(module);
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
const visitImports = (file) => gen(function* () {
|
|
351
|
-
if (visited.has(file))
|
|
352
|
-
return;
|
|
353
|
-
visited.add(file);
|
|
354
|
-
const transpiled = yield* run("bun", ["build", "--no-bundle", file], root).pipe(map8((result) => result.ok ? result.stdout : ""), orElseSucceed(() => ""));
|
|
355
|
-
for (const [, specifier] of transpiled.matchAll(/\b(?:from|import)\s*"(\.{1,2}\/[^"]+)"/gu)) {
|
|
356
|
-
const module = specifier === undefined ? undefined : yield* importedFile(file, specifier);
|
|
357
|
-
if (module === undefined || visited.has(module))
|
|
358
|
-
continue;
|
|
359
|
-
const directory = yield* packageDirectory(module);
|
|
360
|
-
if (directory !== undefined && directory !== root) {
|
|
361
|
-
found.push({ directory, module, identity: identityOf(yield* readPackageJson(directory)) });
|
|
362
|
-
if (!known(directory)) {
|
|
363
|
-
packages.add(directory);
|
|
364
|
-
yield* visitPackage(directory);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
yield* visitImports(module);
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
yield* visitPackage(root);
|
|
371
|
-
yield* visitImports(path.join(root, "kitman.config.ts"));
|
|
372
|
-
return found;
|
|
373
|
-
});
|
|
374
|
-
var buildEntry = (identity, modules) => [
|
|
375
|
-
"import config from './kitman.config.ts'",
|
|
376
|
-
"import { runKit } from '@kitman-sh/sdk/program'",
|
|
377
|
-
...modules.map((kit, index) => `import * as kit${index} from ${JSON.stringify(kit.module)}`),
|
|
378
|
-
"",
|
|
379
|
-
`runKit(config, ${JSON.stringify(identity)}, [${modules.map((kit, index) => `[kit${index}.default, ${JSON.stringify(kit.identity)}]`).join(", ")}])`,
|
|
380
|
-
""
|
|
381
|
-
].join(`
|
|
382
|
-
`);
|
|
383
|
-
var renamedKey = (declarations, what, from, to) => {
|
|
384
|
-
const key = Object.keys(declarations ?? {}).find((key) => hasProperty(declarations?.[key], from));
|
|
385
|
-
return key === undefined ? undefined : new DeclarationsInvalid({ reason: `${what} "${key}" names \`${from}\`, which is now \`${to}\`` });
|
|
386
|
-
};
|
|
387
|
-
var resolveNames = (names) => {
|
|
388
|
-
const winners = new Map;
|
|
389
|
-
const overrides = [];
|
|
390
|
-
for (const named of names) {
|
|
391
|
-
const key = `${named.what}\x00${named.name}`;
|
|
392
|
-
const winner = winners.get(key);
|
|
393
|
-
if (winner === undefined)
|
|
394
|
-
winners.set(key, named.kit);
|
|
395
|
-
else if (winner === named.kit)
|
|
396
|
-
return new DeclarationsInvalid({ reason: `Kit ${named.kit} names ${named.what} ${named.name} twice` });
|
|
397
|
-
else
|
|
398
|
-
overrides.push({ what: named.what, name: named.name, winner, replaced: named.kit });
|
|
399
|
-
}
|
|
400
|
-
return { wins: (named) => winners.get(`${named.what}\x00${named.name}`) === named.kit, overrides };
|
|
401
|
-
};
|
|
402
|
-
var buildKit = (directory, options = {}) => gen(function* () {
|
|
403
|
-
const fs = yield* FileSystem;
|
|
404
|
-
const path = yield* Path;
|
|
405
|
-
const root = path.resolve(directory);
|
|
406
|
-
const source = yield* provenance(root);
|
|
407
|
-
const identity = { ...identityOf(yield* readPackageJson(root)), ...options };
|
|
408
|
-
const installed = yield* run("bun", ["install", "--frozen-lockfile", "--ignore-scripts"], root).pipe(mapError2((error) => new DependencyInstallFailed({ reason: error.message })));
|
|
409
|
-
if (!installed.ok)
|
|
410
|
-
return yield* new DependencyInstallFailed({ reason: failure(installed) });
|
|
411
|
-
const packages = yield* kitModules(root);
|
|
412
|
-
const id = yield* SecureRandom.pipe(flatMap3((random) => random.uuidV4()), provide3(layerWebCrypto));
|
|
413
|
-
const entryName = `.kitman-build-entry-${id}.ts`;
|
|
414
|
-
const entry = path.join(root, entryName);
|
|
415
|
-
yield* acquireRelease(fs.writeFileString(entry, buildEntry(identity, packages)), () => ignore(fs.remove(entry)));
|
|
416
|
-
const out = yield* fs.makeTempDirectoryScoped({ prefix: "kitman-kit-" });
|
|
417
|
-
const bundleFile = path.join(out, "bundle.js");
|
|
418
|
-
const bundled = yield* run("bun", ["build", entry, "--target=bun", "--format=esm", "--outfile", bundleFile], root);
|
|
419
|
-
if (!bundled.ok)
|
|
420
|
-
return yield* failure(bundled).includes('"defineConfig"') ? new DeclarationsInvalid({
|
|
421
|
-
reason: "defineConfig is now defineKit; import defineKit from @kitman-sh/sdk/loop"
|
|
422
|
-
}) : new BundleFailed({ reason: failure(bundled) });
|
|
423
|
-
const described = yield* run("bun", [bundleFile, describeFlag], out);
|
|
424
|
-
if (!described.ok)
|
|
425
|
-
return yield* new BundleFailed({ reason: `the bundle does not load: ${failure(described)}` });
|
|
426
|
-
const result = yield* decodeEffect(fromJsonString(toCodecJson(Described)))(described.stdout).pipe(mapError2((error) => new BundleFailed({ reason: `the bundle described itself wrongly: ${error.message}` })));
|
|
427
|
-
if (isTagged(result, "Refused"))
|
|
428
|
-
return yield* result.error;
|
|
429
|
-
const [own] = result.kits;
|
|
430
|
-
if (own === undefined)
|
|
431
|
-
return yield* new BundleFailed({ reason: "the bundle described no Kit" });
|
|
432
|
-
const renamed = renamedKey(own.schedules, "Schedule", "project", "team") ?? renamedKey(own.schedules, "Schedule", "codebase", "team");
|
|
433
|
-
if (renamed !== undefined)
|
|
434
|
-
return yield* renamed;
|
|
435
|
-
const directories = new Map([
|
|
436
|
-
[`${identity.name}@${identity.version}`, root],
|
|
437
|
-
...packages.map((kit) => [`${kit.identity.name}@${kit.identity.version}`, kit.directory])
|
|
438
|
-
]);
|
|
439
|
-
const kits = yield* forEach(result.kits, (kit) => gen(function* () {
|
|
440
|
-
const at = directories.get(`${kit.name}@${kit.version}`) ?? root;
|
|
441
|
-
const invalid = (error) => new DeclarationsInvalid({ reason: `Kit ${kit.name}: ${error.message}` });
|
|
442
|
-
const agents = yield* decodeUnknownEffect2(ConfigAgents)(kit.agents).pipe(mapError2(invalid));
|
|
443
|
-
return { ...kit, directory: at, agents: yield* readAgents(at, agents), setup: kit.setup ?? {} };
|
|
444
|
-
}));
|
|
445
|
-
const named = kits.flatMap((kit) => [
|
|
446
|
-
...kit.loops.map((loop) => ({ kit: kit.name, what: "Loop", name: loop.id })),
|
|
447
|
-
...Object.keys(kit.agents).map((agent) => ({ kit: kit.name, what: "Agent", name: agent })),
|
|
448
|
-
...(kit.setup.skills ?? []).map((skill) => ({ kit: kit.name, what: "skill", name: skill.name })),
|
|
449
|
-
...(kit.setup.plugins ?? []).map((plugin) => ({ kit: kit.name, what: "plugin", name: plugin.name })),
|
|
450
|
-
...(kit.setup.mcpServers ?? []).map((server) => ({ kit: kit.name, what: "MCP server", name: server.name }))
|
|
451
|
-
]);
|
|
452
|
-
const kitman = named.find((entry) => entry.what === "MCP server" && entry.name === kitmanMcpServer);
|
|
453
|
-
if (kitman !== undefined)
|
|
454
|
-
return yield* new DeclarationsInvalid({
|
|
455
|
-
reason: `Kit ${kitman.kit} declares an MCP server named ${kitmanMcpServer}, which Kitman provides`
|
|
456
|
-
});
|
|
457
|
-
const names = resolveNames(named);
|
|
458
|
-
if (isTagged(names, "DeclarationsInvalid"))
|
|
459
|
-
return yield* names;
|
|
460
|
-
const winning = kits.map((kit) => ({
|
|
461
|
-
...kit,
|
|
462
|
-
loops: kit.loops.filter((loop) => names.wins({ kit: kit.name, what: "Loop", name: loop.id })),
|
|
463
|
-
agents: Object.fromEntries(Object.entries(kit.agents).filter(([agent]) => names.wins({ kit: kit.name, what: "Agent", name: agent })))
|
|
464
|
-
}));
|
|
465
|
-
const checkouts = new Map;
|
|
466
|
-
const archives = yield* forEach(kits, (kit) => setupArchive(kit.directory, kit.name, kit.setup, checkouts));
|
|
467
|
-
const carried = winning.map((kit, index) => ({
|
|
468
|
-
name: kit.name,
|
|
469
|
-
version: kit.version,
|
|
470
|
-
setup: archives[index]?.digest ?? "",
|
|
471
|
-
loops: kit.loops.map((loop) => loop.id),
|
|
472
|
-
agents: Object.keys(kit.agents)
|
|
473
|
-
}));
|
|
474
|
-
const declarations = yield* decodeUnknownEffect2(KitDeclarations)({
|
|
475
|
-
loops: winning.flatMap((kit) => kit.loops),
|
|
476
|
-
agents: Object.assign({}, ...winning.map((kit) => kit.agents)),
|
|
477
|
-
...own.schedules === undefined ? undefined : { schedules: own.schedules },
|
|
478
|
-
carried
|
|
479
|
-
}).pipe(mapError2((error) => new DeclarationsInvalid({ reason: error.message })));
|
|
480
|
-
const bundle = yield* fs.readFileString(bundleFile).pipe(map8((text) => new TextEncoder().encode(text.replaceAll(entryName, ".kitman-build-entry.ts"))), mapError2((error) => new BundleFailed({ reason: error.message })));
|
|
481
|
-
return {
|
|
482
|
-
...identity,
|
|
483
|
-
bundle,
|
|
484
|
-
digest: digestSha256(bundle, "hex"),
|
|
485
|
-
declarations,
|
|
486
|
-
setupArchives: archives,
|
|
487
|
-
protocolVersion: RunnerRpcProtocolVersion,
|
|
488
|
-
provenance: source,
|
|
489
|
-
overrides: names.overrides
|
|
490
|
-
};
|
|
491
|
-
}).pipe(scoped, catchTags({
|
|
492
|
-
PlatformError: (error) => fail7(new BundleFailed({ reason: error.message }))
|
|
493
|
-
}));
|
|
494
|
-
var writeKit = (directory, built, out) => gen(function* () {
|
|
495
|
-
const fs = yield* FileSystem;
|
|
496
|
-
const path = yield* Path;
|
|
497
|
-
const inKit = (file) => path.relative(directory, path.join(out, file));
|
|
498
|
-
const setup = {};
|
|
499
|
-
yield* fs.makeDirectory(path.join(out, "setup"), { recursive: true });
|
|
500
|
-
yield* fs.writeFile(path.join(out, "bundle.js"), built.bundle);
|
|
501
|
-
yield* fs.writeFileString(path.join(out, "declarations.json"), yield* encodePrettyJsonString(built.declarations));
|
|
502
|
-
for (const { digest, archive } of built.setupArchives) {
|
|
503
|
-
yield* fs.writeFile(path.join(out, "setup", `${digest}.json`), archive);
|
|
504
|
-
setup[digest] = inKit(`setup/${digest}.json`);
|
|
505
|
-
}
|
|
506
|
-
const manifestPath = path.join(directory, "package.json");
|
|
507
|
-
const manifest = yield* fs.readFileString(manifestPath).pipe(flatMap3(decodeEffect(fromJsonString(Record(String4, Json)))));
|
|
508
|
-
const kitman = {
|
|
509
|
-
bundle: inKit("bundle.js"),
|
|
510
|
-
digest: built.digest,
|
|
511
|
-
protocolVersion: built.protocolVersion,
|
|
512
|
-
declarations: inKit("declarations.json"),
|
|
513
|
-
setup
|
|
514
|
-
};
|
|
515
|
-
yield* fs.writeFileString(manifestPath, `${yield* encodePrettyJsonString({ ...manifest, kitman })}
|
|
516
|
-
`);
|
|
517
|
-
});
|
|
518
|
-
export {
|
|
519
|
-
BundleFailed,
|
|
520
|
-
DeclarationsInvalid,
|
|
521
|
-
DependencyInstallFailed,
|
|
522
|
-
GitSourceLocation,
|
|
523
|
-
SourceFetchFailed,
|
|
524
|
-
buildKit,
|
|
525
|
-
writeKit
|
|
526
|
-
};
|