@kitman-sh/cli 0.9.0 → 0.10.53

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.
Files changed (37) hide show
  1. package/dist/chunk-11p4wf6n.js +3551 -0
  2. package/dist/chunk-1mc9vgcr.js +39 -0
  3. package/dist/chunk-30397r95.js +30 -0
  4. package/dist/chunk-3bj7sc3v.js +389 -0
  5. package/dist/chunk-6vns3ej0.js +23 -0
  6. package/dist/chunk-7thnf14y.js +936 -0
  7. package/dist/chunk-arvwar2c.js +141 -0
  8. package/dist/chunk-b6thzgc9.js +32 -0
  9. package/dist/{chunk-8bvf4fh4.js → chunk-ctasxxz5.js} +26 -11
  10. package/dist/{chunk-5gjpv3ax.js → chunk-dzh9e6n2.js} +824 -651
  11. package/dist/{chunk-snn0e1qb.js → chunk-eg8f5ncv.js} +7 -3
  12. package/dist/chunk-g5bs3f6z.js +173 -0
  13. package/dist/chunk-jafetf7z.js +109 -0
  14. package/dist/chunk-jagzz148.js +527 -0
  15. package/dist/{chunk-1d4316hp.js → chunk-jfvq7s24.js} +38 -25
  16. package/dist/chunk-mbctzx7e.js +11436 -0
  17. package/dist/chunk-mej2bx5n.js +100 -0
  18. package/dist/chunk-p6spvbwq.js +6305 -0
  19. package/dist/chunk-pp1p3g6e.js +133 -0
  20. package/dist/chunk-r8p3nxcp.js +231 -0
  21. package/dist/chunk-txwt6r25.js +1731 -0
  22. package/dist/chunk-v290mf51.js +5242 -0
  23. package/dist/chunk-vjmz23rs.js +13 -0
  24. package/dist/chunk-vyv0p5eq.js +3183 -0
  25. package/dist/chunk-wh1pa2aa.js +15322 -0
  26. package/dist/chunk-x0b92bjb.js +222 -0
  27. package/dist/{chunk-8z5b6fpd.js → chunk-x9dhxfts.js} +216 -152
  28. package/dist/chunk-z821b2gp.js +164 -0
  29. package/dist/index.js +13 -5738
  30. package/dist/opencode-reader.main.ts +4 -0
  31. package/package.json +6 -5
  32. package/dist/chunk-3gxahgnq.js +0 -28495
  33. package/dist/chunk-ehzbtavj.js +0 -247
  34. package/dist/chunk-f5z8tgss.js +0 -1214
  35. package/dist/chunk-kdb1cbnx.js +0 -1273
  36. package/dist/chunk-ke1w0hx7.js +0 -5771
  37. package/dist/chunk-z6hc4ew9.js +0 -13
@@ -1,247 +0,0 @@
1
- // @bun
2
- import {
3
- isString,
4
- hasProperty,
5
- isTagged,
6
- all,
7
- forEach,
8
- succeed5,
9
- gen,
10
- fail4,
11
- try_,
12
- flatMap2,
13
- map3,
14
- catchTags,
15
- mapError,
16
- ignore,
17
- orElseSucceed,
18
- scoped,
19
- acquireRelease,
20
- decodeText,
21
- mkString,
22
- FileSystem,
23
- Path,
24
- ChildProcessSpawner,
25
- make8,
26
- decodeUnknownEffect,
27
- decodeEffect,
28
- optionalKey,
29
- Literal,
30
- String2,
31
- Struct,
32
- Record,
33
- ArraySchema,
34
- Union,
35
- Literals,
36
- fromJsonString,
37
- TaggedError2,
38
- toCodecJson,
39
- digestSha256,
40
- RunnerRpcProtocolVersion
41
- } from "./chunk-3gxahgnq.js";
42
- import"./chunk-8bvf4fh4.js";
43
- import {
44
- AgentDeclaration,
45
- KitInstallationDeclaration,
46
- KitAssignmentDeclaration,
47
- PackageDeclarations
48
- } from "./chunk-kdb1cbnx.js";
49
- import {
50
- describeFlag,
51
- Described
52
- } from "./chunk-1d4316hp.js";
53
- import"./chunk-8z5b6fpd.js";
54
-
55
- // packages/sdk/src/build/index.ts
56
- class DependencyInstallFailed extends TaggedError2()("DependencyInstallFailed", {
57
- reason: String2
58
- }) {
59
- get message() {
60
- return `Dependencies do not install from the lockfile: ${this.reason}`;
61
- }
62
- }
63
-
64
- class BundleFailed extends TaggedError2()("BundleFailed", { reason: String2 }) {
65
- get message() {
66
- return `The Package does not bundle: ${this.reason}`;
67
- }
68
- }
69
-
70
- class DeclarationsInvalid extends TaggedError2()("DeclarationsInvalid", {
71
- reason: String2
72
- }) {
73
- get message() {
74
- return `The Package's declarations are invalid: ${this.reason}`;
75
- }
76
- }
77
- var RepositoryText = Union([String2, Struct({ file: String2 })]);
78
- var ConfigAgents = Record(String2, Struct({
79
- extends: optionalKey(String2),
80
- instructions: optionalKey(RepositoryText),
81
- harness: optionalKey(String2),
82
- model: optionalKey(String2),
83
- effort: AgentDeclaration.fields.effort,
84
- kits: optionalKey(ArraySchema(String2)),
85
- network: optionalKey(Union([Struct({ hosts: ArraySchema(String2) }), Literal("open")])),
86
- sandbox: optionalKey(Literal("docker"))
87
- }));
88
- var ConfigKits = Record(String2, Union([
89
- KitInstallationDeclaration,
90
- KitAssignmentDeclaration,
91
- Struct({
92
- name: String2,
93
- kind: optionalKey(Literals(["technology", "brand", "domain", "process", "other"])),
94
- description: optionalKey(String2),
95
- context: RepositoryText,
96
- skills: optionalKey(ArraySchema(String2))
97
- })
98
- ]));
99
- var run = (command, args, cwd) => gen(function* () {
100
- const spawner = yield* ChildProcessSpawner;
101
- const handle = yield* spawner.spawn(make8(command, args, { cwd, stdin: "ignore" }));
102
- const [stdout, stderr, exitCode] = yield* all([
103
- mkString(decodeText(handle.stdout)),
104
- mkString(decodeText(handle.stderr)),
105
- handle.exitCode
106
- ], { concurrency: 3 });
107
- return { stdout, stderr, ok: exitCode === 0 };
108
- }).pipe(scoped);
109
- var failure = (result) => (result.stderr.trim() || result.stdout.trim()).slice(-2000);
110
- var provenance = (directory) => gen(function* () {
111
- const git = (...args) => run("git", args, directory).pipe(map3((result) => result.ok ? result.stdout.trim() : undefined), orElseSucceed(() => {
112
- return;
113
- }));
114
- const repository = yield* git("remote", "get-url", "origin");
115
- const commit = yield* git("rev-parse", "HEAD");
116
- const status = yield* git("status", "--porcelain");
117
- return {
118
- ...repository ? { repository } : undefined,
119
- ...commit ? { commit } : undefined,
120
- clean: commit !== undefined && status === ""
121
- };
122
- });
123
- var inRepository = (directory, file, what) => gen(function* () {
124
- const path = yield* Path;
125
- const resolved = path.resolve(directory, file);
126
- if (path.relative(directory, resolved).startsWith(".."))
127
- return yield* new DeclarationsInvalid({ reason: `${what} ${file} is outside the repository` });
128
- return resolved;
129
- });
130
- var readText = (directory, text, what) => gen(function* () {
131
- if (isString(text))
132
- return text;
133
- const fs = yield* FileSystem;
134
- const file = yield* inRepository(directory, text.file, what);
135
- return yield* fs.readFileString(file).pipe(mapError(() => new DeclarationsInvalid({ reason: `${what} ${text.file} does not read` })));
136
- });
137
- var readAgents = (directory, agents) => forEach(Object.entries(agents), ([id, { instructions, ...agent }]) => instructions === undefined ? succeed5([id, agent]) : map3(readText(directory, instructions, `Agent "${id}" instructions`), (text) => [id, { ...agent, instructions: text.trim() }])).pipe(map3(Object.fromEntries));
138
- var utf8 = new TextDecoder("utf-8", { fatal: true });
139
- var readSkill = (directory, skill, what) => gen(function* () {
140
- const fs = yield* FileSystem;
141
- const path = yield* Path;
142
- const root = yield* inRepository(directory, skill, what);
143
- const unreadable = () => new DeclarationsInvalid({ reason: `${what} ${skill} does not read` });
144
- const entries = yield* fs.readDirectory(root, { recursive: true }).pipe(mapError(unreadable));
145
- const files = {};
146
- for (const entry of entries.toSorted()) {
147
- const file = path.join(root, entry);
148
- if ((yield* fs.stat(file).pipe(mapError(unreadable))).type !== "File")
149
- continue;
150
- const bytes = yield* fs.readFile(file).pipe(mapError(unreadable));
151
- const text = yield* try_({
152
- try: () => utf8.decode(bytes),
153
- catch: () => new DeclarationsInvalid({ reason: `${what} ${skill} holds a binary file, ${entry}` })
154
- });
155
- if (text.includes("\x00"))
156
- return yield* new DeclarationsInvalid({ reason: `${what} ${skill} holds a binary file, ${entry}` });
157
- files[entry.split(path.sep).join("/")] = text;
158
- }
159
- if (files["SKILL.md"] === undefined)
160
- return yield* new DeclarationsInvalid({ reason: `${what} ${skill} has no SKILL.md` });
161
- return [path.basename(root), files];
162
- });
163
- var readKits = (directory, kits) => forEach(Object.entries(kits), ([key, kit]) => gen(function* () {
164
- if (!("context" in kit))
165
- return [key, kit];
166
- const { context, skills, ...authored } = kit;
167
- const what = `Kit "${key}"`;
168
- return [
169
- key,
170
- {
171
- ...authored,
172
- context: yield* readText(directory, context, `${what} context`),
173
- ...skills === undefined ? undefined : {
174
- skills: Object.fromEntries(yield* forEach(skills, (skill) => readSkill(directory, skill, `${what} skill`)))
175
- }
176
- }
177
- ];
178
- })).pipe(map3(Object.fromEntries));
179
- var PackageJson = fromJsonString(Struct({ name: String2 }));
180
- var packageName = (root) => gen(function* () {
181
- const fs = yield* FileSystem;
182
- const path = yield* Path;
183
- return yield* fs.readFileString(path.join(root, "package.json")).pipe(flatMap2(decodeEffect(PackageJson)), map3((manifest) => manifest.name), mapError(() => new DeclarationsInvalid({ reason: "package.json has no name" })));
184
- });
185
- var renamedKey = (declarations, what, from, to) => {
186
- const key = Object.keys(declarations ?? {}).find((key) => hasProperty(declarations?.[key], from));
187
- return key === undefined ? undefined : new DeclarationsInvalid({ reason: `${what} "${key}" names \`${from}\`, which is now \`${to}\`` });
188
- };
189
- var duplicateLoopId = (loops) => loops.map((loop) => loop.id).find((id, index, ids) => ids.indexOf(id) !== index);
190
- var buildPackage = (directory) => gen(function* () {
191
- const fs = yield* FileSystem;
192
- const path = yield* Path;
193
- const root = path.resolve(directory);
194
- const source = yield* provenance(root);
195
- const name = yield* packageName(root);
196
- const installed = yield* run("bun", ["install", "--frozen-lockfile", "--ignore-scripts"], root).pipe(mapError((error) => new DependencyInstallFailed({ reason: error.message })));
197
- if (!installed.ok)
198
- return yield* new DependencyInstallFailed({ reason: failure(installed) });
199
- const entry = path.join(root, ".kitman-build-entry.ts");
200
- yield* acquireRelease(fs.writeFileString(entry, `import config from './kitman.config.ts'
201
- import { runPackage } from '@kitman-sh/sdk/program'
202
-
203
- runPackage(config)
204
- `), () => ignore(fs.remove(entry)));
205
- const out = yield* fs.makeTempDirectoryScoped({ prefix: "kitman-package-" });
206
- const bundleFile = path.join(out, "bundle.js");
207
- const bundled = yield* run("bun", ["build", entry, "--target=bun", "--format=esm", "--outfile", bundleFile], root);
208
- if (!bundled.ok)
209
- return yield* new BundleFailed({ reason: failure(bundled) });
210
- const described = yield* run("bun", [bundleFile, describeFlag], out);
211
- if (!described.ok)
212
- return yield* new BundleFailed({ reason: `the bundle does not load: ${failure(described)}` });
213
- const result = yield* decodeEffect(fromJsonString(toCodecJson(Described)))(described.stdout).pipe(mapError((error) => new BundleFailed({ reason: `the bundle described itself wrongly: ${error.message}` })));
214
- if (isTagged(result, "Refused"))
215
- return yield* result.error;
216
- const duplicate = duplicateLoopId(result.loops);
217
- if (duplicate !== undefined)
218
- return yield* new DeclarationsInvalid({ reason: `Loop "${duplicate}" is declared twice` });
219
- const renamed = renamedKey(result.schedules, "Schedule", "project", "team") ?? renamedKey(result.schedules, "Schedule", "codebase", "team") ?? renamedKey(result.kits, "Kit", "projects", "teams") ?? renamedKey(result.kits, "Kit", "codebases", "teams");
220
- if (renamed !== undefined)
221
- return yield* renamed;
222
- const agents = yield* decodeUnknownEffect(ConfigAgents)(result.agents).pipe(mapError((error) => new DeclarationsInvalid({ reason: error.message })));
223
- const kits = result.kits === undefined ? undefined : yield* decodeUnknownEffect(ConfigKits)(result.kits).pipe(mapError((error) => new DeclarationsInvalid({ reason: error.message })));
224
- const declarations = yield* decodeUnknownEffect(PackageDeclarations)({
225
- loops: result.loops,
226
- agents: yield* readAgents(root, agents),
227
- ...result.schedules === undefined ? undefined : { schedules: result.schedules },
228
- ...kits === undefined ? undefined : { kits: yield* readKits(root, kits) }
229
- }).pipe(mapError((error) => new DeclarationsInvalid({ reason: error.message })));
230
- const bundle = yield* fs.readFile(bundleFile).pipe(mapError((error) => new BundleFailed({ reason: error.message })));
231
- return {
232
- name,
233
- bundle,
234
- digest: digestSha256(bundle, "hex"),
235
- declarations,
236
- protocolVersion: RunnerRpcProtocolVersion,
237
- provenance: source
238
- };
239
- }).pipe(scoped, catchTags({
240
- PlatformError: (error) => fail4(new BundleFailed({ reason: error.message }))
241
- }));
242
- export {
243
- BundleFailed,
244
- DeclarationsInvalid,
245
- DependencyInstallFailed,
246
- buildPackage
247
- };