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