@dot-agent/cli 1.0.1 → 1.0.2

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/index.cjs ADDED
@@ -0,0 +1,799 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ init: () => init,
34
+ pack: () => pack,
35
+ run: () => run,
36
+ unpack: () => unpack
37
+ });
38
+ module.exports = __toCommonJS(index_exports);
39
+
40
+ // node_modules/tsup/assets/cjs_shims.js
41
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
42
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
43
+
44
+ // src/commands/init.ts
45
+ var import_promises = require("fs/promises");
46
+ var import_path = require("path");
47
+ var AGENT_DESCRIPTION_TEMPLATE = (name, domain) => `agent ${name}
48
+ domain ${domain}
49
+ license Apache-2.0
50
+
51
+ description
52
+ Describe what this agent does.
53
+
54
+ behavior agent.behavior
55
+
56
+ capabilities
57
+ ActionName "Describe this capability"
58
+ `;
59
+ var AGENT_BEHAVIOR_TEMPLATE = `state init
60
+ transition to responsive
61
+
62
+ state responsive
63
+ goal "Help the user with their task."
64
+ interact
65
+ on intent "start" transition to responsive
66
+ `;
67
+ var SOUL_TEMPLATE = (name) => `# ${name} \u2014 Persona
68
+
69
+ ## Voice and Tone
70
+
71
+ Describe the agent's voice, personality, and communication style.
72
+ `;
73
+ var README_TEMPLATE = (name) => `# ${name}
74
+
75
+ Brief description of what this agent does.
76
+
77
+ ## Usage
78
+
79
+ Example of how to use this agent.
80
+ `;
81
+ var LICENSE = `Apache License
82
+ Version 2.0, January 2004
83
+
84
+ http://www.apache.org/licenses/
85
+
86
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
87
+ `;
88
+ async function init(options = {}) {
89
+ const dir = options.dir || process.cwd();
90
+ const name = options.name || (0, import_path.basename)(dir);
91
+ const domain = options.domain || "example.com";
92
+ try {
93
+ await (0, import_promises.stat)(dir);
94
+ } catch {
95
+ await (0, import_promises.mkdir)(dir, { recursive: true });
96
+ }
97
+ const agentDescriptionPath = (0, import_path.join)(dir, "agent.description");
98
+ try {
99
+ await (0, import_promises.stat)(agentDescriptionPath);
100
+ throw new Error(`agent.description already exists at ${agentDescriptionPath}`);
101
+ } catch (err) {
102
+ if (err.code !== "ENOENT") throw err;
103
+ }
104
+ const files = [];
105
+ await (0, import_promises.writeFile)(agentDescriptionPath, AGENT_DESCRIPTION_TEMPLATE(name, domain));
106
+ files.push("agent.description");
107
+ await (0, import_promises.writeFile)((0, import_path.join)(dir, "agent.behavior"), AGENT_BEHAVIOR_TEMPLATE);
108
+ files.push("agent.behavior");
109
+ await (0, import_promises.writeFile)((0, import_path.join)(dir, "SOUL.md"), SOUL_TEMPLATE(name));
110
+ files.push("SOUL.md");
111
+ await (0, import_promises.writeFile)((0, import_path.join)(dir, "README.md"), README_TEMPLATE(name));
112
+ files.push("README.md");
113
+ await (0, import_promises.writeFile)((0, import_path.join)(dir, "LICENSE"), LICENSE);
114
+ files.push("LICENSE");
115
+ await (0, import_promises.mkdir)((0, import_path.join)(dir, "behaviors"), { recursive: true });
116
+ await (0, import_promises.writeFile)((0, import_path.join)(dir, "behaviors", ".gitkeep"), "");
117
+ files.push("behaviors/.gitkeep");
118
+ await (0, import_promises.mkdir)((0, import_path.join)(dir, "guides"), { recursive: true });
119
+ await (0, import_promises.writeFile)((0, import_path.join)(dir, "guides", ".gitkeep"), "");
120
+ files.push("guides/.gitkeep");
121
+ await (0, import_promises.mkdir)((0, import_path.join)(dir, "knowledge"), { recursive: true });
122
+ await (0, import_promises.writeFile)((0, import_path.join)(dir, "knowledge", ".gitkeep"), "");
123
+ files.push("knowledge/.gitkeep");
124
+ await (0, import_promises.writeFile)((0, import_path.join)(dir, "AGENTS.md"), "");
125
+ files.push("AGENTS.md");
126
+ return { dir, files };
127
+ }
128
+
129
+ // src/commands/pack.ts
130
+ var import_promises3 = require("fs/promises");
131
+ var import_path2 = require("path");
132
+ var import_child_process = require("child_process");
133
+ var import_crypto = require("crypto");
134
+ var import_jszip2 = __toESM(require("jszip"), 1);
135
+
136
+ // src/core/lint.ts
137
+ var import_module = require("module");
138
+ var import_web_tree_sitter = require("web-tree-sitter");
139
+ var import_kernel_dsl = require("@dot-agent/kernel-dsl");
140
+ var require2 = (0, import_module.createRequire)(importMetaUrl);
141
+ var { agentWasmPath, behaviorWasmPath } = require2("@dot-agent/tree-sitter");
142
+ var _initialized = false;
143
+ var _agentParser;
144
+ var _behaviorParser;
145
+ var _agentLang;
146
+ var _behaviorLang;
147
+ async function ensureWasmInit() {
148
+ if (_initialized) return;
149
+ try {
150
+ await import_web_tree_sitter.Parser.init();
151
+ } catch (err) {
152
+ throw err;
153
+ }
154
+ _agentParser = new import_web_tree_sitter.Parser();
155
+ _behaviorParser = new import_web_tree_sitter.Parser();
156
+ try {
157
+ _agentLang = await import_web_tree_sitter.Language.load(agentWasmPath);
158
+ _behaviorLang = await import_web_tree_sitter.Language.load(behaviorWasmPath);
159
+ } catch (err) {
160
+ throw err;
161
+ }
162
+ try {
163
+ await (0, import_kernel_dsl.init)();
164
+ } catch (err) {
165
+ }
166
+ _initialized = true;
167
+ }
168
+ function collectSyntaxErrors(node) {
169
+ const errors = [];
170
+ if (node.isError || node.isMissing) errors.push(node);
171
+ for (const child of node.children) {
172
+ errors.push(...collectSyntaxErrors(child));
173
+ }
174
+ return errors;
175
+ }
176
+ function getLineCol(node) {
177
+ return { line: node.startPosition.row + 1, col: node.startPosition.column + 1 };
178
+ }
179
+ async function lintDescription(text) {
180
+ await ensureWasmInit();
181
+ _agentParser.setLanguage(_agentLang);
182
+ const tree = _agentParser.parse(text);
183
+ const messages = [];
184
+ const syntaxErrors = collectSyntaxErrors(tree.rootNode);
185
+ if (syntaxErrors.length > 0) {
186
+ for (const error of syntaxErrors) {
187
+ const { line, col } = getLineCol(error);
188
+ messages.push({
189
+ file: "agent.description",
190
+ line,
191
+ col,
192
+ severity: "error",
193
+ code: "E004",
194
+ message: "Syntax error in description"
195
+ });
196
+ }
197
+ }
198
+ const walk = (node) => {
199
+ if (node.type === "domain_declaration" && node.childCount > 0) {
200
+ const valueNode = node.child(node.childCount - 1);
201
+ if (valueNode && valueNode.text === "example.com") {
202
+ const { line, col } = getLineCol(valueNode);
203
+ messages.push({
204
+ file: "agent.description",
205
+ line,
206
+ col,
207
+ severity: "warning",
208
+ code: "W003",
209
+ message: 'domain still has default value "example.com"'
210
+ });
211
+ }
212
+ }
213
+ for (const child of node.children) walk(child);
214
+ };
215
+ walk(tree.rootNode);
216
+ return messages;
217
+ }
218
+ async function lintBehavior(text) {
219
+ await ensureWasmInit();
220
+ _behaviorParser.setLanguage(_behaviorLang);
221
+ const tree = _behaviorParser.parse(text);
222
+ const messages = [];
223
+ const syntaxErrors = collectSyntaxErrors(tree.rootNode);
224
+ if (syntaxErrors.length > 0) {
225
+ for (const error of syntaxErrors) {
226
+ const { line, col } = getLineCol(error);
227
+ messages.push({
228
+ file: "agent.behavior",
229
+ line,
230
+ col,
231
+ severity: "error",
232
+ code: "E004",
233
+ message: "Syntax error in behavior DSL"
234
+ });
235
+ }
236
+ }
237
+ const walk = (node) => {
238
+ if (node.type === "text_block") {
239
+ if (node.text.length > 280) {
240
+ const { line, col } = getLineCol(node);
241
+ messages.push({
242
+ file: "agent.behavior",
243
+ line,
244
+ col,
245
+ severity: "warning",
246
+ code: "W002",
247
+ message: `Text block exceeds 280 characters (${node.text.length})`
248
+ });
249
+ }
250
+ }
251
+ for (const child of node.children) walk(child);
252
+ };
253
+ walk(tree.rootNode);
254
+ try {
255
+ const kernel = new import_kernel_dsl.AgentDSLKernel();
256
+ try {
257
+ const effects = kernel.load_behavior(text);
258
+ if (Array.isArray(effects)) {
259
+ for (const effect of effects) {
260
+ if (effect.type === "parse_error") {
261
+ messages.push({
262
+ file: "agent.behavior",
263
+ line: 1,
264
+ col: 1,
265
+ severity: "error",
266
+ code: "E006",
267
+ message: `Parse error: ${effect.message}`
268
+ });
269
+ }
270
+ }
271
+ }
272
+ const graph = kernel.get_graph();
273
+ if (graph?.states) {
274
+ for (const stateName of Object.keys(graph.states)) {
275
+ const state = graph.states[stateName];
276
+ const hasIncoming = graph.transitions?.some((t) => t.to === stateName);
277
+ const hasOutgoing = graph.transitions?.some((t) => t.from === stateName);
278
+ if (!hasIncoming && !hasOutgoing && stateName !== graph.current) {
279
+ messages.push({
280
+ file: "agent.behavior",
281
+ line: 1,
282
+ col: 1,
283
+ severity: "warning",
284
+ code: "W001",
285
+ message: `state "${stateName}" has no transitions`
286
+ });
287
+ }
288
+ }
289
+ }
290
+ } catch (kernelErr) {
291
+ }
292
+ } catch (err) {
293
+ }
294
+ return messages;
295
+ }
296
+ async function createLinter() {
297
+ await ensureWasmInit();
298
+ return {
299
+ lintDescription,
300
+ lintBehavior
301
+ };
302
+ }
303
+
304
+ // src/core/id.ts
305
+ function buildId(parts) {
306
+ const { namespace, name, version, digest } = parts;
307
+ if (!namespace || !name || !version || !digest) {
308
+ throw new Error("Missing required ID parts: namespace, name, version, digest");
309
+ }
310
+ return `${namespace}/${name}:${version}~${digest}`;
311
+ }
312
+
313
+ // src/core/envelope.ts
314
+ function parseAboutme(json) {
315
+ if (!json.schemaVersion) throw new Error("Missing schemaVersion in aboutme.json");
316
+ if (!json.id) throw new Error("Missing id in aboutme.json");
317
+ if (!json.name) throw new Error("Missing name in aboutme.json");
318
+ if (!json.description) throw new Error("Missing description in aboutme.json");
319
+ if (!json.version) throw new Error("Missing version in aboutme.json");
320
+ if (!json.domain) throw new Error("Missing domain in aboutme.json");
321
+ if (!json.license) throw new Error("Missing license in aboutme.json");
322
+ if (!json.persona) throw new Error("Missing persona in aboutme.json");
323
+ if (!json.compiler) throw new Error("Missing compiler in aboutme.json");
324
+ if (!Array.isArray(json.skills)) throw new Error("Missing skills array in aboutme.json");
325
+ if (!Array.isArray(json.requires)) throw new Error("Missing requires array in aboutme.json");
326
+ if (!json.integrity) throw new Error("Missing integrity in aboutme.json");
327
+ return {
328
+ schemaVersion: json.schemaVersion,
329
+ id: json.id,
330
+ name: json.name,
331
+ description: json.description,
332
+ version: json.version,
333
+ domain: json.domain,
334
+ license: json.license,
335
+ persona: json.persona,
336
+ compiler: json.compiler,
337
+ commit: json.commit,
338
+ skills: json.skills,
339
+ requires: json.requires,
340
+ integrity: json.integrity
341
+ };
342
+ }
343
+ function buildAboutme(opts) {
344
+ return {
345
+ schemaVersion: "dot-agent/1.0",
346
+ id: opts.id,
347
+ name: opts.name,
348
+ description: opts.description,
349
+ version: opts.version,
350
+ domain: opts.domain,
351
+ license: opts.license || "Apache-2.0",
352
+ persona: opts.persona,
353
+ compiler: opts.compiler,
354
+ commit: opts.commit,
355
+ skills: opts.skills || [],
356
+ requires: opts.requires || [],
357
+ integrity: opts.integrity
358
+ };
359
+ }
360
+ function aboutmeToJson(aboutme) {
361
+ return JSON.stringify(aboutme, null, 2);
362
+ }
363
+
364
+ // src/core/zip.ts
365
+ var import_jszip = __toESM(require("jszip"), 1);
366
+ var import_promises2 = require("fs/promises");
367
+ var MAX_ZIP_SIZE = 500 * 1024 * 1024;
368
+ var MAX_COMPRESSION_RATIO = 100;
369
+ async function readZip(filePath) {
370
+ const data = await (0, import_promises2.readFile)(filePath);
371
+ return import_jszip.default.loadAsync(data);
372
+ }
373
+ async function validateZipBomb(filePath) {
374
+ const data = await (0, import_promises2.readFile)(filePath);
375
+ const zip = await import_jszip.default.loadAsync(data);
376
+ let totalUncompressed = 0;
377
+ zip.forEach((relativePath, file) => {
378
+ if (!file.dir) {
379
+ totalUncompressed += file._data?.uncompressedSize || 0;
380
+ }
381
+ });
382
+ const compressedSize = data.length;
383
+ const ratio = totalUncompressed / compressedSize;
384
+ if (totalUncompressed > MAX_ZIP_SIZE) {
385
+ throw new Error(`ZIP uncompressed size exceeds 500MB limit: ${totalUncompressed}`);
386
+ }
387
+ if (ratio > MAX_COMPRESSION_RATIO) {
388
+ throw new Error(`ZIP compression ratio exceeds 100x limit: ${ratio.toFixed(1)}x`);
389
+ }
390
+ return true;
391
+ }
392
+ async function extractFiles(zip, filter) {
393
+ const files = /* @__PURE__ */ new Map();
394
+ const promises = [];
395
+ zip.forEach((relativePath, file) => {
396
+ if (file.dir) return;
397
+ if (filter && !filter.some((f) => relativePath.startsWith(f))) return;
398
+ promises.push(
399
+ file.async("text").then((content) => {
400
+ files.set(relativePath, content);
401
+ })
402
+ );
403
+ });
404
+ await Promise.all(promises);
405
+ return files;
406
+ }
407
+ async function writeZip(zip, outPath) {
408
+ const data = await zip.generateAsync({ type: "arraybuffer" });
409
+ await (0, import_promises2.writeFile)(outPath, Buffer.from(data));
410
+ }
411
+ async function validateMagicBytes(filePath) {
412
+ const data = await (0, import_promises2.readFile)(filePath);
413
+ const magicBytes = data.subarray(0, 4);
414
+ const isZip = magicBytes[0] === 80 && magicBytes[1] === 75 && magicBytes[2] === 3 && magicBytes[3] === 4;
415
+ if (!isZip) {
416
+ throw new Error("File is not a valid ZIP (invalid magic bytes)");
417
+ }
418
+ return true;
419
+ }
420
+
421
+ // src/commands/pack.ts
422
+ function gitDescribeTags() {
423
+ try {
424
+ return (0, import_child_process.execSync)("git describe --tags --abbrev=0", {
425
+ stdio: "pipe",
426
+ encoding: "utf-8"
427
+ }).trim();
428
+ } catch {
429
+ return null;
430
+ }
431
+ }
432
+ function gitRevParseShort() {
433
+ try {
434
+ return (0, import_child_process.execSync)("git rev-parse --short HEAD", {
435
+ stdio: "pipe",
436
+ encoding: "utf-8"
437
+ }).trim();
438
+ } catch {
439
+ return null;
440
+ }
441
+ }
442
+ async function resolveVersion(explicit) {
443
+ if (explicit) return explicit;
444
+ const gitTag = gitDescribeTags();
445
+ if (gitTag) return gitTag;
446
+ return "v1.0.0";
447
+ }
448
+ async function resolveCommit(explicit) {
449
+ if (explicit) return explicit;
450
+ return gitRevParseShort() || void 0;
451
+ }
452
+ async function collectFiles(dir) {
453
+ const files = /* @__PURE__ */ new Map();
454
+ async function walk(subdir, prefix = "") {
455
+ try {
456
+ const entries = await (0, import_promises3.readdir)(subdir);
457
+ for (const entry of entries) {
458
+ if (entry === ".gitkeep" || entry.startsWith(".")) continue;
459
+ const fullPath = (0, import_path2.join)(subdir, entry);
460
+ const stats = await (0, import_promises3.stat)(fullPath);
461
+ const relativePath = prefix ? `${prefix}/${entry}` : entry;
462
+ if (stats.isDirectory()) {
463
+ await walk(fullPath, relativePath);
464
+ } else {
465
+ const content = await (0, import_promises3.readFile)(fullPath, "utf-8");
466
+ files.set(relativePath, content);
467
+ }
468
+ }
469
+ } catch {
470
+ }
471
+ }
472
+ const description = await (0, import_promises3.readFile)((0, import_path2.join)(dir, "agent.description"), "utf-8");
473
+ files.set("agent.description", description);
474
+ const behavior = await (0, import_promises3.readFile)((0, import_path2.join)(dir, "agent.behavior"), "utf-8");
475
+ files.set("agent.behavior", behavior);
476
+ try {
477
+ const soul = await (0, import_promises3.readFile)((0, import_path2.join)(dir, "SOUL.md"), "utf-8");
478
+ files.set("SOUL.md", soul);
479
+ } catch {
480
+ }
481
+ await walk((0, import_path2.join)(dir, "behaviors"), "behaviors");
482
+ await walk((0, import_path2.join)(dir, "guides"), "guides");
483
+ await walk((0, import_path2.join)(dir, "knowledge"), "knowledge");
484
+ return files;
485
+ }
486
+ function parseDescription(text) {
487
+ const domain = text.match(/domain\s+([^\n]+)/)?.[1] || "";
488
+ const name = text.match(/agent\s+([^\n]+)/)?.[1] || "";
489
+ const description = text.match(/description\s+(.+?)(?=\n\n|\n[a-z])/s)?.[1] || "";
490
+ return {
491
+ domain: domain.trim(),
492
+ name: name.trim(),
493
+ description: description.trim(),
494
+ capabilities: []
495
+ };
496
+ }
497
+ async function pack(options = {}) {
498
+ const dir = options.dir || process.cwd();
499
+ const outPath = options.out || (0, import_path2.join)(dir, `${(0, import_path2.basename)(dir)}.agent`);
500
+ let descriptionText;
501
+ let behaviorText;
502
+ try {
503
+ descriptionText = await (0, import_promises3.readFile)((0, import_path2.join)(dir, "agent.description"), "utf-8");
504
+ } catch {
505
+ throw new Error("E003: File agent.description not found");
506
+ }
507
+ try {
508
+ behaviorText = await (0, import_promises3.readFile)((0, import_path2.join)(dir, "agent.behavior"), "utf-8");
509
+ } catch {
510
+ throw new Error("E007: File agent.behavior not found");
511
+ }
512
+ const linter = await createLinter();
513
+ const descriptionMessages = await linter.lintDescription(descriptionText);
514
+ const behaviorMessages = await linter.lintBehavior(behaviorText);
515
+ const allMessages = [...descriptionMessages, ...behaviorMessages];
516
+ const errors = allMessages.filter((m) => m.severity === "error");
517
+ const warnings = allMessages.filter((m) => m.severity === "warning");
518
+ if (errors.length > 0) {
519
+ throw new Error(`Lint failed: ${errors.map((e) => `${e.file}:${e.line}:${e.col} ${e.code} ${e.message}`).join("\n")}`);
520
+ }
521
+ const description = parseDescription(descriptionText);
522
+ const version = await resolveVersion(options.version);
523
+ const commit = await resolveCommit(options.commit);
524
+ const allFiles = await collectFiles(dir);
525
+ const contentForHash = Array.from(allFiles.values()).join("");
526
+ const digest = (0, import_crypto.createHash)("sha256").update(contentForHash).digest("hex").substring(0, 8);
527
+ const id = buildId({
528
+ namespace: description.domain,
529
+ name: description.name,
530
+ version,
531
+ digest
532
+ });
533
+ const aboutme = buildAboutme({
534
+ id,
535
+ name: description.name,
536
+ description: description.description,
537
+ version,
538
+ domain: description.domain,
539
+ license: "Apache-2.0",
540
+ persona: "SOUL.md",
541
+ compiler: "dot-agent/1.0.0",
542
+ commit,
543
+ skills: [],
544
+ requires: [],
545
+ integrity: {
546
+ sha256: (0, import_crypto.createHash)("sha256").update(contentForHash).digest("hex"),
547
+ files: ".agent/files.json"
548
+ }
549
+ });
550
+ const zip = new import_jszip2.default();
551
+ zip.folder(".agent").file("aboutme.json", aboutmeToJson(aboutme));
552
+ const filesJson = {
553
+ description: "agent.description",
554
+ behavior: "agent.behavior",
555
+ behaviors: Array.from(allFiles.keys()).filter((f) => f.startsWith("behaviors/") && f !== "behaviors/.gitkeep").map((f) => f),
556
+ guides: Array.from(allFiles.keys()).filter((f) => f.startsWith("guides/") && f !== "guides/.gitkeep").map((f) => f),
557
+ knowledge: Array.from(allFiles.keys()).filter((f) => f.startsWith("knowledge/") && f !== "knowledge/.gitkeep").map((f) => f)
558
+ };
559
+ zip.folder(".agent").file("files.json", JSON.stringify(filesJson, null, 2));
560
+ for (const [path, content] of allFiles) {
561
+ if (path !== "behaviors/.gitkeep" && path !== "guides/.gitkeep" && path !== "knowledge/.gitkeep") {
562
+ zip.file(path, content);
563
+ }
564
+ }
565
+ await writeZip(zip, outPath);
566
+ return {
567
+ path: outPath,
568
+ id,
569
+ warnings
570
+ };
571
+ }
572
+
573
+ // src/commands/unpack.ts
574
+ var import_promises4 = require("fs/promises");
575
+ var import_path3 = require("path");
576
+ async function unpack(options) {
577
+ const { file, out, force = false } = options;
578
+ await validateMagicBytes(file);
579
+ await validateZipBomb(file);
580
+ const zip = await readZip(file);
581
+ const aboutmeFile = zip.file(".agent/aboutme.json");
582
+ if (!aboutmeFile) {
583
+ throw new Error("Missing .agent/aboutme.json in ZIP");
584
+ }
585
+ const aboutmeText = await aboutmeFile.async("text");
586
+ const aboutme = parseAboutme(JSON.parse(aboutmeText));
587
+ const outDir = out || `./${aboutme.name}`;
588
+ try {
589
+ await (0, import_promises4.stat)(outDir);
590
+ if (!force) {
591
+ throw new Error(`Output directory already exists: ${outDir}. Use --force to overwrite.`);
592
+ }
593
+ } catch (err) {
594
+ if (err.code !== "ENOENT") throw err;
595
+ }
596
+ const files = await extractFiles(zip);
597
+ await (0, import_promises4.mkdir)(outDir, { recursive: true });
598
+ const extractedFiles = [];
599
+ for (const [path, content] of files) {
600
+ if (path.startsWith(".agent/")) continue;
601
+ const fullPath = (0, import_path3.join)(outDir, path);
602
+ const dir = fullPath.substring(0, fullPath.lastIndexOf("/"));
603
+ await (0, import_promises4.mkdir)(dir, { recursive: true });
604
+ await (0, import_promises4.writeFile)(fullPath, content);
605
+ extractedFiles.push(path);
606
+ }
607
+ return {
608
+ dir: outDir,
609
+ id: aboutme.id,
610
+ files: extractedFiles,
611
+ aboutme
612
+ };
613
+ }
614
+
615
+ // src/commands/run.ts
616
+ var import_events = require("events");
617
+ var import_promises5 = require("fs/promises");
618
+ var import_kernel_dsl2 = require("@dot-agent/kernel-dsl");
619
+ function isZipFile(source) {
620
+ return source.endsWith(".agent");
621
+ }
622
+ async function run(options) {
623
+ const { source } = options;
624
+ const context = new import_events.EventEmitter();
625
+ try {
626
+ context.emit("progress", { step: "opening", pct: 0 });
627
+ let descriptionText;
628
+ let behaviorText;
629
+ let aboutme = null;
630
+ let id;
631
+ if (isZipFile(source)) {
632
+ await validateMagicBytes(source);
633
+ await validateZipBomb(source);
634
+ const zip = await readZip(source);
635
+ const aboutmeFile = zip.file(".agent/aboutme.json");
636
+ if (!aboutmeFile) {
637
+ throw new Error("Missing .agent/aboutme.json");
638
+ }
639
+ const aboutmeText = await aboutmeFile.async("text");
640
+ aboutme = parseAboutme(JSON.parse(aboutmeText));
641
+ id = aboutme.id;
642
+ const descFile = zip.file("agent.description");
643
+ if (!descFile) throw new Error("Missing agent.description");
644
+ descriptionText = await descFile.async("text");
645
+ const behavFile = zip.file("agent.behavior");
646
+ if (!behavFile) throw new Error("Missing agent.behavior");
647
+ behaviorText = await behavFile.async("text");
648
+ context.emit("progress", { step: "parsing", pct: 30 });
649
+ let kernel;
650
+ try {
651
+ await (0, import_kernel_dsl2.init)();
652
+ kernel = new import_kernel_dsl2.AgentDSLKernel();
653
+ kernel.load_behavior(behaviorText);
654
+ } catch (err) {
655
+ kernel = {
656
+ get_current_state: () => "init",
657
+ get_graph: () => ({}),
658
+ get_memory: () => [],
659
+ get_valid_intents: () => [],
660
+ load_behavior: () => {
661
+ },
662
+ observe: () => {
663
+ },
664
+ send_complete: () => {
665
+ },
666
+ send_event: () => {
667
+ },
668
+ send_failed: () => {
669
+ },
670
+ send_fallback: () => {
671
+ },
672
+ send_intent: () => {
673
+ },
674
+ send_offtopic: () => {
675
+ },
676
+ tick_prompt: () => {
677
+ },
678
+ free: () => {
679
+ }
680
+ };
681
+ }
682
+ context.emit("progress", { step: "loading-files", pct: 60 });
683
+ const soulFile = zip.file("SOUL.md");
684
+ const soul = soulFile ? await soulFile.async("text") : void 0;
685
+ const allFiles = await extractFiles(zip);
686
+ const guides = [];
687
+ const knowledge = [];
688
+ const behaviors = [];
689
+ for (const [path, content] of allFiles) {
690
+ if (path.startsWith("guides/") && path !== "guides/.gitkeep") {
691
+ guides.push({ path, content });
692
+ } else if (path.startsWith("knowledge/") && path !== "knowledge/.gitkeep") {
693
+ knowledge.push({ path, content });
694
+ } else if (path.startsWith("behaviors/") && path !== "behaviors/.gitkeep") {
695
+ behaviors.push({ path, content });
696
+ }
697
+ }
698
+ context.id = id;
699
+ context.description = { domain: "example.com", name: "Agent" };
700
+ context.behavior = {};
701
+ context.kernel = kernel;
702
+ context.files = { soul, guides, knowledge, behaviors };
703
+ context.aboutme = aboutme;
704
+ } else {
705
+ const descPath = `${source}/agent.description`;
706
+ const behavPath = `${source}/agent.behavior`;
707
+ try {
708
+ descriptionText = await (0, import_promises5.readFile)(descPath, "utf-8");
709
+ } catch {
710
+ throw new Error(`Missing agent.description at ${descPath}`);
711
+ }
712
+ try {
713
+ behaviorText = await (0, import_promises5.readFile)(behavPath, "utf-8");
714
+ } catch {
715
+ throw new Error(`Missing agent.behavior at ${behavPath}`);
716
+ }
717
+ context.emit("progress", { step: "parsing", pct: 30 });
718
+ let kernel;
719
+ try {
720
+ await (0, import_kernel_dsl2.init)();
721
+ kernel = new import_kernel_dsl2.AgentDSLKernel();
722
+ kernel.load_behavior(behaviorText);
723
+ } catch (err) {
724
+ kernel = {
725
+ get_current_state: () => "init",
726
+ get_graph: () => ({}),
727
+ get_memory: () => [],
728
+ get_valid_intents: () => [],
729
+ load_behavior: () => {
730
+ },
731
+ observe: () => {
732
+ },
733
+ send_complete: () => {
734
+ },
735
+ send_event: () => {
736
+ },
737
+ send_failed: () => {
738
+ },
739
+ send_fallback: () => {
740
+ },
741
+ send_intent: () => {
742
+ },
743
+ send_offtopic: () => {
744
+ },
745
+ tick_prompt: () => {
746
+ },
747
+ free: () => {
748
+ }
749
+ };
750
+ }
751
+ context.emit("progress", { step: "loading-files", pct: 60 });
752
+ id = "local/agent:v1.0~unknown";
753
+ try {
754
+ const soul = await (0, import_promises5.readFile)(`${source}/SOUL.md`, "utf-8");
755
+ context.files = {
756
+ soul,
757
+ guides: [],
758
+ knowledge: [],
759
+ behaviors: []
760
+ };
761
+ } catch {
762
+ context.files = { guides: [], knowledge: [], behaviors: [] };
763
+ }
764
+ const defaultAboutme = {
765
+ schemaVersion: "dot-agent/1.0",
766
+ id,
767
+ name: "Agent",
768
+ description: "",
769
+ version: "v1.0",
770
+ domain: "local",
771
+ license: "Apache-2.0",
772
+ persona: "SOUL.md",
773
+ compiler: "dot-agent/1.0.0",
774
+ skills: [],
775
+ requires: [],
776
+ integrity: { sha256: "", files: "" }
777
+ };
778
+ context.id = id;
779
+ context.description = { domain: "example.com", name: "Agent" };
780
+ context.behavior = {};
781
+ context.kernel = kernel;
782
+ context.aboutme = defaultAboutme;
783
+ }
784
+ context.emit("progress", { step: "ready", pct: 100 });
785
+ context.emit("ready", context);
786
+ return context;
787
+ } catch (err) {
788
+ context.emit("error", err);
789
+ throw err;
790
+ }
791
+ }
792
+ // Annotate the CommonJS export names for ESM import in node:
793
+ 0 && (module.exports = {
794
+ init,
795
+ pack,
796
+ run,
797
+ unpack
798
+ });
799
+ //# sourceMappingURL=index.cjs.map