@geminixiang/mikan 1.0.0-beta.6 → 1.0.0-beta.8

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 (46) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/adapters/github/bot.d.ts +41 -0
  3. package/dist/adapters/github/bot.d.ts.map +1 -0
  4. package/dist/adapters/github/bot.js +429 -0
  5. package/dist/adapters/github/bot.js.map +1 -0
  6. package/dist/adapters/github/client.d.ts +53 -0
  7. package/dist/adapters/github/client.d.ts.map +1 -0
  8. package/dist/adapters/github/client.js +149 -0
  9. package/dist/adapters/github/client.js.map +1 -0
  10. package/dist/adapters/github/context.d.ts +9 -0
  11. package/dist/adapters/github/context.d.ts.map +1 -0
  12. package/dist/adapters/github/context.js +160 -0
  13. package/dist/adapters/github/context.js.map +1 -0
  14. package/dist/adapters/github/ids.d.ts +25 -0
  15. package/dist/adapters/github/ids.d.ts.map +1 -0
  16. package/dist/adapters/github/ids.js +39 -0
  17. package/dist/adapters/github/ids.js.map +1 -0
  18. package/dist/adapters/github/types.d.ts +79 -0
  19. package/dist/adapters/github/types.d.ts.map +1 -0
  20. package/dist/adapters/github/types.js +2 -0
  21. package/dist/adapters/github/types.js.map +1 -0
  22. package/dist/cli/ext-git.d.ts +22 -0
  23. package/dist/cli/ext-git.d.ts.map +1 -0
  24. package/dist/cli/ext-git.js +76 -0
  25. package/dist/cli/ext-git.js.map +1 -0
  26. package/dist/cli/ext.d.ts +2 -0
  27. package/dist/cli/ext.d.ts.map +1 -0
  28. package/dist/cli/ext.js +217 -0
  29. package/dist/cli/ext.js.map +1 -0
  30. package/dist/harness/extensions/loader.d.ts +28 -4
  31. package/dist/harness/extensions/loader.d.ts.map +1 -1
  32. package/dist/harness/extensions/loader.js +195 -44
  33. package/dist/harness/extensions/loader.js.map +1 -1
  34. package/dist/harness/index.d.ts +1 -1
  35. package/dist/harness/index.d.ts.map +1 -1
  36. package/dist/harness/index.js +1 -1
  37. package/dist/harness/index.js.map +1 -1
  38. package/dist/main.js +50 -2
  39. package/dist/main.js.map +1 -1
  40. package/dist/sessions/policy.d.ts.map +1 -1
  41. package/dist/sessions/policy.js +1 -0
  42. package/dist/sessions/policy.js.map +1 -1
  43. package/dist/types.d.ts +1 -1
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/types.js.map +1 -1
  46. package/package.json +2 -1
@@ -12,22 +12,36 @@
12
12
  * under mikan's state dir.
13
13
  *
14
14
  * Directories are scanned in order; all discovered extensions activate.
15
- * Accepted layouts:
15
+ * Accepted layouts (entrypoint may be .mjs/.js/.ts/.mts — loaded via jiti):
16
16
  *
17
- * - `extensions/<name>.mjs` / `extensions/<name>.js`
18
- * - `extensions/<name>/index.mjs` / `extensions/<name>/index.js`
17
+ * - `extensions/<name>.<ext>` (bare file)
18
+ * - `extensions/<name>/index.<ext>` (directory + index)
19
+ * - `extensions/<name>/package.json` (mikan.extensions entrypoint;
20
+ * may carry npm dependencies in node_modules)
19
21
  *
20
- * Modules are imported with a cache-busting query so edited extensions are
21
- * picked up when a new harness instance is created for a conversation.
22
+ * Modules are imported with a fresh jiti instance (no cache) so edited
23
+ * extensions are picked up when a new harness instance is created.
22
24
  */
23
25
  import { existsSync, mkdirSync, readdirSync, readFileSync, statSync } from "fs";
24
26
  import { homedir } from "os";
25
27
  import { basename, dirname, join } from "path";
26
- import { pathToFileURL } from "url";
28
+ import { createJiti } from "jiti";
27
29
  import * as log from "../../log.js";
28
30
  import { loadSkillsFromDir } from "../skills.js";
29
31
  import { ExtensionRegistry } from "./registry.js";
30
- const EXTENSION_FILE_PATTERN = /\.(mjs|js)$/;
32
+ const EXTENSION_FILE_PATTERN = /\.(mjs|js|ts|mts)$/;
33
+ const INDEX_FILE_PATTERN = /^index\.(mjs|js|ts|mts)$/;
34
+ const INDEX_CANDIDATES = ["index.mjs", "index.js", "index.ts", "index.mts"];
35
+ /**
36
+ * Import an extension entrypoint through jiti so it can be TypeScript and can
37
+ * use node_modules dependencies, transparently compiling on the fly. A fresh
38
+ * jiti instance with caching disabled is used per load so edited extensions
39
+ * are picked up when a new harness instance is created for a conversation.
40
+ */
41
+ async function importExtensionModule(entrypoint) {
42
+ const jiti = createJiti(import.meta.url, { moduleCache: false, fsCache: false });
43
+ return jiti.import(entrypoint);
44
+ }
31
45
  /**
32
46
  * Canonical host-only extension code directories for a conversation, in load
33
47
  * order: `<stateDir>/global/extensions` (all conversations) then
@@ -49,9 +63,9 @@ export function defaultExtensionDirs(conversationId, stateDir = join(homedir(),
49
63
  export function listInstalledExtensions(dirs) {
50
64
  const infos = [];
51
65
  for (const dir of dirs) {
52
- for (const entrypoint of discoverExtensionEntrypoints(dir)) {
53
- const slug = extensionSlug(entrypoint);
54
- const manifest = readManifest(entrypoint);
66
+ for (const { entrypoint, rootDir } of discoverExtensionEntrypoints(dir)) {
67
+ const slug = slugForRoot(rootDir);
68
+ const manifest = readManifest(rootDir);
55
69
  infos.push({
56
70
  name: manifest.name ?? slug,
57
71
  slug,
@@ -59,7 +73,7 @@ export function listInstalledExtensions(dirs) {
59
73
  dir,
60
74
  version: manifest.version,
61
75
  description: manifest.description,
62
- skillNames: loadExtensionSkills(entrypoint, slug).map((skill) => skill.name),
76
+ skillNames: loadExtensionSkills(rootDir, slug).map((skill) => skill.name),
63
77
  });
64
78
  }
65
79
  }
@@ -68,11 +82,11 @@ export function listInstalledExtensions(dirs) {
68
82
  function discoverExtensionEntrypoints(dir) {
69
83
  if (!existsSync(dir))
70
84
  return [];
71
- const entrypoints = [];
85
+ const found = [];
72
86
  for (const name of readdirSync(dir).toSorted()) {
73
87
  if (name.startsWith("."))
74
88
  continue;
75
- if (/^index\.(mjs|js)$/.test(name)) {
89
+ if (INDEX_FILE_PATTERN.test(name)) {
76
90
  // An index file at the scan root means the extension's contents were
77
91
  // copied into the scope directory itself; the slug would degenerate to
78
92
  // the scope name (e.g. the conversation id), mis-keying its data dir,
@@ -89,32 +103,73 @@ function discoverExtensionEntrypoints(dir) {
89
103
  continue;
90
104
  }
91
105
  if (stats.isFile() && EXTENSION_FILE_PATTERN.test(name)) {
92
- entrypoints.push(fullPath);
106
+ // Bare-file form: the file is both entrypoint and (its own) root.
107
+ found.push({ entrypoint: fullPath, rootDir: fullPath });
93
108
  continue;
94
109
  }
95
110
  if (stats.isDirectory()) {
96
- for (const candidate of ["index.mjs", "index.js"]) {
97
- const indexPath = join(fullPath, candidate);
98
- if (existsSync(indexPath)) {
99
- entrypoints.push(indexPath);
100
- break;
101
- }
102
- }
111
+ const entrypoint = resolveDirectoryEntrypoint(fullPath);
112
+ if (entrypoint)
113
+ found.push({ entrypoint, rootDir: fullPath });
103
114
  }
104
115
  }
105
- return entrypoints;
116
+ return found;
106
117
  }
107
118
  /**
108
- * Filesystem-safe identifier for an extension, derived from its install
109
- * location (directory name for `<name>/index.mjs`, file basename otherwise).
110
- * The slug keys the extension's data dir, secrets vault, and schedule
111
- * ownership — installing the same extension globally and per-conversation
112
- * shares one slug and therefore one data dir.
119
+ * Resolve a directory-form extension's entrypoint. A `package.json` with a
120
+ * `mikan.extensions` array (first entry, relative to the dir) wins — this is
121
+ * how an extension declares a TypeScript entry and pulls in npm dependencies.
122
+ * Otherwise fall back to an `index.{mjs,js,ts,mts}` file. Returns undefined
123
+ * when neither is present.
113
124
  */
114
- export function extensionSlug(entrypoint) {
115
- const base = /^index\.(mjs|js)$/.test(basename(entrypoint))
116
- ? basename(dirname(entrypoint))
117
- : basename(entrypoint).replace(EXTENSION_FILE_PATTERN, "");
125
+ function resolveDirectoryEntrypoint(dir) {
126
+ const declared = readMikanManifestEntrypoints(dir)[0];
127
+ if (declared) {
128
+ const resolved = join(dir, declared);
129
+ if (existsSync(resolved))
130
+ return resolved;
131
+ log.logWarning(`Extension package.json declares a missing entrypoint: ${resolved}`, "falling back to an index file");
132
+ }
133
+ for (const candidate of INDEX_CANDIDATES) {
134
+ const indexPath = join(dir, candidate);
135
+ if (existsSync(indexPath))
136
+ return indexPath;
137
+ }
138
+ return undefined;
139
+ }
140
+ /** Read and shape a directory's package.json; undefined when absent/malformed. */
141
+ function readPackageJson(dir) {
142
+ const packageJsonPath = join(dir, "package.json");
143
+ if (!existsSync(packageJsonPath))
144
+ return undefined;
145
+ try {
146
+ const parsed = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
147
+ if (!parsed || typeof parsed !== "object")
148
+ return undefined;
149
+ const record = parsed;
150
+ const mikanRaw = record.mikan;
151
+ return {
152
+ name: typeof record.name === "string" ? record.name : undefined,
153
+ version: typeof record.version === "string" ? record.version : undefined,
154
+ description: typeof record.description === "string" ? record.description : undefined,
155
+ mikan: {
156
+ extensions: Array.isArray(mikanRaw?.extensions)
157
+ ? mikanRaw.extensions.filter((entry) => typeof entry === "string")
158
+ : undefined,
159
+ displayName: typeof mikanRaw?.displayName === "string" ? mikanRaw.displayName : undefined,
160
+ },
161
+ };
162
+ }
163
+ catch (err) {
164
+ log.logWarning(`Ignoring malformed package.json: ${packageJsonPath}`, String(err));
165
+ return undefined;
166
+ }
167
+ }
168
+ /** Read the `mikan.extensions` entrypoint list from a directory's package.json. */
169
+ function readMikanManifestEntrypoints(dir) {
170
+ return readPackageJson(dir)?.mikan?.extensions ?? [];
171
+ }
172
+ function sanitizeSlug(base) {
118
173
  const slug = base
119
174
  .toLowerCase()
120
175
  .replace(/[^a-z0-9_-]+/g, "-")
@@ -122,6 +177,28 @@ export function extensionSlug(entrypoint) {
122
177
  .slice(0, 64);
123
178
  return slug || "extension";
124
179
  }
180
+ /**
181
+ * Filesystem-safe identifier for an extension, derived from its install
182
+ * location: the directory name for a directory-form extension, or the file
183
+ * basename for a bare file. The slug keys the extension's data dir, secrets
184
+ * vault, and schedule ownership — installing the same extension globally and
185
+ * per-conversation shares one slug and therefore one shared data dir.
186
+ */
187
+ export function extensionSlug(entrypoint) {
188
+ // Bare-file form (rootDir === entrypoint, a *.mjs/.ts file) → file basename.
189
+ // Directory form → directory name. Detect the directory form structurally:
190
+ // an entrypoint whose parent holds a package.json or is an index file.
191
+ if (INDEX_FILE_PATTERN.test(basename(entrypoint))) {
192
+ return sanitizeSlug(basename(dirname(entrypoint)));
193
+ }
194
+ return sanitizeSlug(basename(entrypoint).replace(EXTENSION_FILE_PATTERN, ""));
195
+ }
196
+ /** Slug from a discovered extension's root dir (directory or bare file path). */
197
+ function slugForRoot(rootDir) {
198
+ return EXTENSION_FILE_PATTERN.test(basename(rootDir))
199
+ ? sanitizeSlug(basename(rootDir).replace(EXTENSION_FILE_PATTERN, ""))
200
+ : sanitizeSlug(basename(rootDir));
201
+ }
125
202
  /** Sanitize an extension-chosen schedule name into a filename segment. */
126
203
  function scheduleNameSegment(name) {
127
204
  const segment = name
@@ -133,11 +210,27 @@ function scheduleNameSegment(name) {
133
210
  throw new Error(`Invalid schedule name: ${JSON.stringify(name)}`);
134
211
  return segment;
135
212
  }
136
- /** Read `manifest.json` next to a directory-form extension's entrypoint. */
137
- function readManifest(entrypoint) {
138
- if (!/^index\.(mjs|js)$/.test(basename(entrypoint)))
213
+ /**
214
+ * Read display metadata (name/version/description) for a directory-form
215
+ * extension. `package.json` is the primary source — its standard `name`,
216
+ * `version`, `description`, plus an optional `mikan.displayName` that
217
+ * overrides the npm name for the user-facing label (npm names are
218
+ * lowercase/scoped; display names can be arbitrary). A `manifest.json` is a
219
+ * fallback for extensions that ship no package.json.
220
+ */
221
+ function readManifest(rootDir) {
222
+ // Bare-file extensions (rootDir is a *.mjs/.ts file) have no manifest.
223
+ if (EXTENSION_FILE_PATTERN.test(basename(rootDir)))
139
224
  return {};
140
- const manifestPath = join(dirname(entrypoint), "manifest.json");
225
+ const pkg = readPackageJson(rootDir);
226
+ if (pkg && (pkg.mikan?.displayName ?? pkg.name ?? pkg.version ?? pkg.description)) {
227
+ return {
228
+ name: pkg.mikan?.displayName ?? pkg.name,
229
+ version: pkg.version,
230
+ description: pkg.description,
231
+ };
232
+ }
233
+ const manifestPath = join(rootDir, "manifest.json");
141
234
  if (!existsSync(manifestPath))
142
235
  return {};
143
236
  try {
@@ -161,10 +254,11 @@ function readManifest(entrypoint) {
161
254
  * Marked inline: extension files live under the host-only state dir, which
162
255
  * sandbox containers cannot read, so skill bodies must ride in the prompt.
163
256
  */
164
- function loadExtensionSkills(entrypoint, slug) {
165
- if (!/^index\.(mjs|js)$/.test(basename(entrypoint)))
257
+ function loadExtensionSkills(rootDir, slug) {
258
+ // Bare-file extensions (rootDir is a *.mjs/.ts file) ship no skills.
259
+ if (EXTENSION_FILE_PATTERN.test(basename(rootDir)))
166
260
  return [];
167
- const skillsDir = join(dirname(entrypoint), "skills");
261
+ const skillsDir = join(rootDir, "skills");
168
262
  if (!existsSync(skillsDir))
169
263
  return [];
170
264
  const result = loadSkillsFromDir({ dir: skillsDir, source: `extension:${slug}` });
@@ -327,10 +421,9 @@ export async function loadExtensions(options) {
327
421
  const skills = [];
328
422
  const services = options.services ?? {};
329
423
  for (const dir of options.dirs) {
330
- for (const entrypoint of discoverExtensionEntrypoints(dir)) {
424
+ for (const { entrypoint, rootDir } of discoverExtensionEntrypoints(dir)) {
331
425
  try {
332
- const moduleUrl = `${pathToFileURL(entrypoint).href}?t=${Date.now()}`;
333
- const moduleExports = await import(moduleUrl);
426
+ const moduleExports = await importExtensionModule(entrypoint);
334
427
  const extension = resolveActivate(moduleExports);
335
428
  if (!extension) {
336
429
  errors.push({
@@ -339,8 +432,8 @@ export async function loadExtensions(options) {
339
432
  });
340
433
  continue;
341
434
  }
342
- const slug = extensionSlug(entrypoint);
343
- const manifest = readManifest(entrypoint);
435
+ const slug = slugForRoot(rootDir);
436
+ const manifest = readManifest(rootDir);
344
437
  const name = manifest.name ?? extension.name ?? slug;
345
438
  const api = buildExtensionApi({
346
439
  name,
@@ -350,7 +443,7 @@ export async function loadExtensions(options) {
350
443
  services,
351
444
  });
352
445
  await extension.activate(api);
353
- const extensionSkills = loadExtensionSkills(entrypoint, slug);
446
+ const extensionSkills = loadExtensionSkills(rootDir, slug);
354
447
  skills.push(...extensionSkills);
355
448
  extensions.push({
356
449
  name,
@@ -371,4 +464,62 @@ export async function loadExtensions(options) {
371
464
  }
372
465
  return { registry, extensions, errors, skills };
373
466
  }
467
+ /**
468
+ * Validate an extension source path (a directory or a single file) WITHOUT
469
+ * activating it: resolves the entrypoint (package.json `mikan.extensions`,
470
+ * index file, or the file itself), imports it, and checks it exports an
471
+ * `activate` function. Used by `mikan ext install` as a preflight and by
472
+ * `mikan ext validate`. Importing runs top-level module code but not
473
+ * `activate`, so there are no schedule/tool side effects.
474
+ */
475
+ export async function validateExtension(sourcePath) {
476
+ const errors = [];
477
+ const warnings = [];
478
+ const rootDir = sourcePath.replace(/[/\\]+$/, "");
479
+ const base = basename(rootDir);
480
+ if (INDEX_FILE_PATTERN.test(base)) {
481
+ warnings.push("Entry is a bare index file; install into a named directory so the slug is stable.");
482
+ }
483
+ let entrypoint;
484
+ if (!existsSync(rootDir)) {
485
+ errors.push(`Path does not exist: ${rootDir}`);
486
+ }
487
+ else if (statSync(rootDir).isDirectory()) {
488
+ entrypoint = resolveDirectoryEntrypoint(rootDir);
489
+ if (!entrypoint) {
490
+ errors.push("No entrypoint found: expected package.json with a mikan.extensions entry, or an index.{mjs,js,ts,mts}.");
491
+ }
492
+ }
493
+ else if (EXTENSION_FILE_PATTERN.test(base)) {
494
+ entrypoint = rootDir;
495
+ }
496
+ else {
497
+ errors.push(`Not an extension file (expected .mjs/.js/.ts/.mts): ${rootDir}`);
498
+ }
499
+ const slug = slugForRoot(rootDir);
500
+ const manifest = readManifest(rootDir);
501
+ const skillNames = loadExtensionSkills(rootDir, slug).map((skill) => skill.name);
502
+ if (entrypoint) {
503
+ try {
504
+ const moduleExports = await importExtensionModule(entrypoint);
505
+ if (!resolveActivate(moduleExports)) {
506
+ errors.push("Module does not export an activate function (default or named).");
507
+ }
508
+ }
509
+ catch (err) {
510
+ errors.push(`Failed to import: ${err instanceof Error ? err.message : String(err)}`);
511
+ }
512
+ }
513
+ return {
514
+ ok: errors.length === 0,
515
+ slug,
516
+ name: manifest.name ?? slug,
517
+ version: manifest.version,
518
+ description: manifest.description,
519
+ entrypoint,
520
+ skillNames,
521
+ errors,
522
+ warnings,
523
+ };
524
+ }
374
525
  //# sourceMappingURL=loader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/harness/extensions/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAGpC,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAmB,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAclD,MAAM,sBAAsB,GAAG,aAAa,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,cAAsB,EACtB,QAAQ,GAAW,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC;IAE5C,OAAO;QACL,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC;QACtC,IAAI,CAAC,QAAQ,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,CAAC;KAC9D,CAAC;AACJ,CAAC;AAgBD;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAc;IACpD,MAAM,KAAK,GAA6B,EAAE,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,KAAK,MAAM,UAAU,IAAI,4BAA4B,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3D,MAAM,IAAI,GAAG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C,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAClD,CAAC","sourcesContent":["/**\n * Extension discovery and activation.\n *\n * Extension modules execute inside the mikan host process with its full\n * privileges (platform tokens, vault, host filesystem). They must therefore\n * only ever load from host-controlled directories: installing an extension\n * is an administrator action. In particular, extension directories must not\n * live under paths mounted into sandbox containers (workspace and\n * conversation dirs in image mode), or code written from inside the sandbox\n * would be imported into the host process — a sandbox escape.\n * {@link defaultExtensionDirs} returns the canonical host-only locations\n * under mikan's state dir.\n *\n * Directories are scanned in order; all discovered extensions activate.\n * Accepted layouts:\n *\n * - `extensions/<name>.mjs` / `extensions/<name>.js`\n * - `extensions/<name>/index.mjs` / `extensions/<name>/index.js`\n *\n * Modules are imported with a cache-busting query so edited extensions are\n * picked up when a new harness instance is created for a conversation.\n */\nimport { existsSync, mkdirSync, readdirSync, readFileSync, statSync } from \"fs\";\nimport { homedir } from \"os\";\nimport { basename, dirname, join } from \"path\";\nimport { pathToFileURL } from \"url\";\nimport type { AgentTool, ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport * as log from \"../../log.js\";\nimport { loadSkillsFromDir, type MikanSkill } from \"../skills.js\";\nimport { ExtensionRegistry } from \"./registry.js\";\nimport type {\n ExtensionHostServices,\n ExtensionLoadError,\n ExtensionManifest,\n ExtensionSchedulePayload,\n ExtensionScheduleInfo,\n ExtensionScheduleSpec,\n LoadedExtension,\n MikanExtensionActivate,\n MikanExtensionApi,\n MikanExtensionModule,\n} from \"./types.js\";\n\nconst EXTENSION_FILE_PATTERN = /\\.(mjs|js)$/;\n\n/**\n * Canonical host-only extension code directories for a conversation, in load\n * order: `<stateDir>/global/extensions` (all conversations) then\n * `<stateDir>/conversations/<conversationId>/extensions` (that conversation\n * only). `global` and `conversations` are the two sibling scopes; see\n * `LAYOUT.md`. Conversation ids are used verbatim (see LAYOUT.md § Casing).\n */\nexport function defaultExtensionDirs(\n conversationId: string,\n stateDir: string = join(homedir(), \".mikan\"),\n): string[] {\n return [\n join(stateDir, \"global\", \"extensions\"),\n join(stateDir, \"conversations\", conversationId, \"extensions\"),\n ];\n}\n\n/** Discovery-only view of an installed extension (module is not imported). */\nexport interface InstalledExtensionInfo {\n /** Display name: manifest name, falling back to the slug. */\n name: string;\n slug: string;\n path: string;\n /** Scan directory the extension was found in. */\n dir: string;\n version?: string;\n description?: string;\n /** Names of skills shipped in the extension's skills/ directory. */\n skillNames: string[];\n}\n\n/**\n * List installed extensions without importing or activating them — safe for\n * inventory surfaces (commands, portal). Activation side effects (schedule\n * upserts, tool registration) only happen in {@link loadExtensions}.\n */\nexport function listInstalledExtensions(dirs: string[]): InstalledExtensionInfo[] {\n const infos: InstalledExtensionInfo[] = [];\n for (const dir of dirs) {\n for (const entrypoint of discoverExtensionEntrypoints(dir)) {\n const slug = extensionSlug(entrypoint);\n const manifest = readManifest(entrypoint);\n infos.push({\n name: manifest.name ?? slug,\n slug,\n path: entrypoint,\n dir,\n version: manifest.version,\n description: manifest.description,\n skillNames: loadExtensionSkills(entrypoint, slug).map((skill) => skill.name),\n });\n }\n }\n return infos;\n}\n\nexport interface LoadExtensionsOptions {\n /** Directories to scan for extensions. Missing directories are skipped. */\n dirs: string[];\n context: {\n conversationId: string;\n workspaceDir: string;\n model: Model<Api>;\n thinkingLevel: ThinkingLevel;\n };\n /** Embedder-provided services backing the v2 api surface. */\n services?: ExtensionHostServices;\n}\n\nexport interface LoadExtensionsResult {\n registry: ExtensionRegistry;\n extensions: LoadedExtension[];\n errors: ExtensionLoadError[];\n /** Skills contributed by extensions (inline: bodies ride in the prompt). */\n skills: MikanSkill[];\n}\n\nfunction discoverExtensionEntrypoints(dir: string): string[] {\n if (!existsSync(dir)) return [];\n const entrypoints: string[] = [];\n for (const name of readdirSync(dir).toSorted()) {\n if (name.startsWith(\".\")) continue;\n if (/^index\\.(mjs|js)$/.test(name)) {\n // An index file at the scan root means the extension's contents were\n // copied into the scope directory itself; the slug would degenerate to\n // the scope name (e.g. the conversation id), mis-keying its data dir,\n // secrets, and schedules. Require a named form instead.\n log.logWarning(\n `Ignoring extension index file at scope root: ${join(dir, name)}`,\n \"install into a named subdirectory (e.g. extensions/<scope>/my-ext/index.mjs)\",\n );\n continue;\n }\n const fullPath = join(dir, name);\n let stats;\n try {\n stats = statSync(fullPath);\n } catch {\n continue;\n }\n if (stats.isFile() && EXTENSION_FILE_PATTERN.test(name)) {\n entrypoints.push(fullPath);\n continue;\n }\n if (stats.isDirectory()) {\n for (const candidate of [\"index.mjs\", \"index.js\"]) {\n const indexPath = join(fullPath, candidate);\n if (existsSync(indexPath)) {\n entrypoints.push(indexPath);\n break;\n }\n }\n }\n }\n return entrypoints;\n}\n\n/**\n * Filesystem-safe identifier for an extension, derived from its install\n * location (directory name for `<name>/index.mjs`, file basename otherwise).\n * The slug keys the extension's data dir, secrets vault, and schedule\n * ownership — installing the same extension globally and per-conversation\n * shares one slug and therefore one data dir.\n */\nexport function extensionSlug(entrypoint: string): string {\n const base = /^index\\.(mjs|js)$/.test(basename(entrypoint))\n ? basename(dirname(entrypoint))\n : basename(entrypoint).replace(EXTENSION_FILE_PATTERN, \"\");\n const slug = base\n .toLowerCase()\n .replace(/[^a-z0-9_-]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .slice(0, 64);\n return slug || \"extension\";\n}\n\n/** Sanitize an extension-chosen schedule name into a filename segment. */\nfunction scheduleNameSegment(name: string): string {\n const segment = name\n .toLowerCase()\n .replace(/[^a-z0-9_-]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .slice(0, 64);\n if (!segment) throw new Error(`Invalid schedule name: ${JSON.stringify(name)}`);\n return segment;\n}\n\n/** Read `manifest.json` next to a directory-form extension's entrypoint. */\nfunction readManifest(entrypoint: string): ExtensionManifest {\n if (!/^index\\.(mjs|js)$/.test(basename(entrypoint))) return {};\n const manifestPath = join(dirname(entrypoint), \"manifest.json\");\n if (!existsSync(manifestPath)) return {};\n try {\n const parsed: unknown = JSON.parse(readFileSync(manifestPath, \"utf-8\"));\n if (!parsed || typeof parsed !== \"object\") return {};\n const record = parsed as Record<string, unknown>;\n return {\n name: typeof record.name === \"string\" ? record.name : undefined,\n version: typeof record.version === \"string\" ? record.version : undefined,\n description: typeof record.description === \"string\" ? record.description : undefined,\n };\n } catch (err) {\n log.logWarning(`Ignoring malformed extension manifest: ${manifestPath}`, String(err));\n return {};\n }\n}\n\n/**\n * Skills shipped inside a directory-form extension (`<dir>/skills/`).\n * Marked inline: extension files live under the host-only state dir, which\n * sandbox containers cannot read, so skill bodies must ride in the prompt.\n */\nfunction loadExtensionSkills(entrypoint: string, slug: string): MikanSkill[] {\n if (!/^index\\.(mjs|js)$/.test(basename(entrypoint))) return [];\n const skillsDir = join(dirname(entrypoint), \"skills\");\n if (!existsSync(skillsDir)) return [];\n const result = loadSkillsFromDir({ dir: skillsDir, source: `extension:${slug}` });\n for (const diagnostic of result.diagnostics) {\n log.logWarning(`Extension skill warning (${slug}): ${diagnostic.message}`, diagnostic.path);\n }\n for (const skill of result.skills) skill.inline = true;\n return result.skills;\n}\n\nconst SCHEDULE_FILE_SUFFIX = \".json\";\n\nfunction schedulePrefix(slug: string, conversationId: string): string {\n return `ext.${slug}.${scheduleNameSegment(conversationId)}.`;\n}\n\nfunction payloadFromSpec(\n spec: ExtensionScheduleSpec,\n conversationId: string,\n): ExtensionSchedulePayload {\n if (spec.type === \"periodic\") {\n if (!spec.schedule || !spec.timezone) {\n throw new Error(\"periodic schedule requires schedule and timezone\");\n }\n return {\n type: \"periodic\",\n conversationId,\n text: spec.text,\n schedule: spec.schedule,\n timezone: spec.timezone,\n ...(spec.platform ? { platform: spec.platform } : {}),\n };\n }\n if (!spec.at) throw new Error(\"one-shot schedule requires at\");\n return {\n type: \"one-shot\",\n conversationId,\n text: spec.text,\n at: spec.at,\n ...(spec.platform ? { platform: spec.platform } : {}),\n };\n}\n\nfunction specFromPayload(payload: ExtensionSchedulePayload): ExtensionScheduleSpec {\n if (payload.type === \"periodic\") {\n return {\n type: \"periodic\",\n schedule: payload.schedule ?? \"\",\n timezone: payload.timezone ?? \"\",\n text: payload.text,\n ...(payload.platform ? { platform: payload.platform } : {}),\n };\n }\n return {\n type: \"one-shot\",\n at: payload.at ?? \"\",\n text: payload.text,\n ...(payload.platform ? { platform: payload.platform } : {}),\n };\n}\n\n/** Build the v2 api surface for one extension over the injected services. */\nfunction buildExtensionApi(params: {\n name: string;\n slug: string;\n registry: ExtensionRegistry;\n context: LoadExtensionsOptions[\"context\"];\n services: ExtensionHostServices;\n}): MikanExtensionApi {\n const { name, slug, registry, context, services } = params;\n const stateDir = services.stateDir ?? join(homedir(), \".mikan\");\n const conversationId = context.conversationId;\n\n const requireScheduleStore = () => {\n if (!services.scheduleStore) {\n throw new Error(\"api.schedules is unavailable: this context provides no schedule store\");\n }\n return services.scheduleStore;\n };\n\n return {\n on: (hook, handler) => registry.register(name, hook, handler),\n registerTool: (tool: AgentTool) => registry.registerTool(tool),\n log: (message: string) => log.logInfo(`[extension:${name}] ${message}`),\n context,\n paths: {\n get dataDir(): string {\n // This conversation's own data, co-located with the conversation's\n // other host-only assets; removed when the conversation is deleted.\n const dir = join(stateDir, \"conversations\", conversationId, \"extension-data\", slug);\n mkdirSync(dir, { recursive: true });\n return dir;\n },\n get sharedDataDir(): string {\n // Cross-conversation data under the sibling `global` scope.\n const dir = join(stateDir, \"global\", \"extension-data\", slug);\n mkdirSync(dir, { recursive: true });\n return dir;\n },\n },\n secrets: {\n get: (key: string) => services.resolveSecrets?.(slug)[key],\n list: () => Object.keys(services.resolveSecrets?.(slug) ?? {}),\n },\n schedules: {\n upsert: async (scheduleName, spec) => {\n const store = requireScheduleStore();\n const filename = `${schedulePrefix(slug, conversationId)}${scheduleNameSegment(scheduleName)}${SCHEDULE_FILE_SUFFIX}`;\n await store.write(filename, payloadFromSpec(spec, conversationId));\n },\n delete: async (scheduleName) => {\n const store = requireScheduleStore();\n const filename = `${schedulePrefix(slug, conversationId)}${scheduleNameSegment(scheduleName)}${SCHEDULE_FILE_SUFFIX}`;\n return store.delete(filename);\n },\n list: async () => {\n const store = requireScheduleStore();\n const prefix = schedulePrefix(slug, conversationId);\n const infos: ExtensionScheduleInfo[] = [];\n for (const entry of await store.list()) {\n if (!entry.filename.startsWith(prefix)) continue;\n if (!entry.filename.endsWith(SCHEDULE_FILE_SUFFIX)) continue;\n infos.push({\n name: entry.filename.slice(prefix.length, -SCHEDULE_FILE_SUFFIX.length),\n spec: specFromPayload(entry.payload),\n });\n }\n return infos;\n },\n },\n notify: async (text: string) => {\n if (!services.postMessage) {\n throw new Error(\"api.notify is unavailable: this context provides no platform messaging\");\n }\n await services.postMessage(conversationId, text);\n },\n react: async (messageTs: string, emoji: string) => {\n if (!services.addReaction) {\n throw new Error(\"api.react is unavailable: this context provides no reaction support\");\n }\n await services.addReaction(conversationId, messageTs, emoji);\n },\n };\n}\n\nfunction resolveActivate(moduleExports: unknown): MikanExtensionModule | undefined {\n if (!moduleExports || typeof moduleExports !== \"object\") return undefined;\n const candidates: unknown[] = [(moduleExports as { default?: unknown }).default, moduleExports];\n for (const candidate of candidates) {\n if (typeof candidate === \"function\") {\n return { activate: candidate as MikanExtensionActivate };\n }\n if (candidate && typeof candidate === \"object\") {\n const activate = (candidate as { activate?: unknown }).activate;\n if (typeof activate === \"function\") {\n return {\n name:\n typeof (candidate as { name?: unknown }).name === \"string\"\n ? (candidate as { name: string }).name\n : undefined,\n activate: activate as MikanExtensionActivate,\n };\n }\n }\n }\n return undefined;\n}\n\n/** Load and activate all extensions found in the given directories. */\nexport async function loadExtensions(\n options: LoadExtensionsOptions,\n): Promise<LoadExtensionsResult> {\n const registry = new ExtensionRegistry();\n const extensions: LoadedExtension[] = [];\n const errors: ExtensionLoadError[] = [];\n const skills: MikanSkill[] = [];\n const services = options.services ?? {};\n\n for (const dir of options.dirs) {\n for (const entrypoint of discoverExtensionEntrypoints(dir)) {\n try {\n const moduleUrl = `${pathToFileURL(entrypoint).href}?t=${Date.now()}`;\n const moduleExports: unknown = await import(moduleUrl);\n const extension = resolveActivate(moduleExports);\n if (!extension) {\n errors.push({\n path: entrypoint,\n error: \"extension must export an activate function (default or named)\",\n });\n continue;\n }\n const slug = extensionSlug(entrypoint);\n const manifest = readManifest(entrypoint);\n const name = manifest.name ?? extension.name ?? slug;\n const api = buildExtensionApi({\n name,\n slug,\n registry,\n context: options.context,\n services,\n });\n await extension.activate(api);\n const extensionSkills = loadExtensionSkills(entrypoint, slug);\n skills.push(...extensionSkills);\n extensions.push({\n name,\n path: entrypoint,\n slug,\n version: manifest.version,\n description: manifest.description,\n skills: extensionSkills,\n });\n } catch (err) {\n errors.push({\n path: entrypoint,\n error: err instanceof Error ? err.message : String(err),\n });\n }\n }\n }\n\n return { registry, extensions, errors, skills };\n}\n"]}
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/harness/extensions/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGlC,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAmB,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAclD,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AACpD,MAAM,kBAAkB,GAAG,0BAA0B,CAAC;AACtD,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAA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CAAC,CAAC;IAEjF,IAAI,UAAU,EAAE,CAAC;QACf,IAAI,CAAC;YACH,MAAM,aAAa,GAAY,MAAM,qBAAqB,CAAC,UAAU,CAAC,CAAC;YACvE,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE,CAAC;gBACpC,MAAM,CAAC,IAAI,CAAC,iEAAiE,CAAC,CAAC;YACjF,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,qBAAqB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACvF,CAAC;IACH,CAAC;IAED,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QACvB,IAAI;QACJ,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,IAAI;QAC3B,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,UAAU;QACV,UAAU;QACV,MAAM;QACN,QAAQ;KACT,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Extension discovery and activation.\n *\n * Extension modules execute inside the mikan host process with its full\n * privileges (platform tokens, vault, host filesystem). They must therefore\n * only ever load from host-controlled directories: installing an extension\n * is an administrator action. In particular, extension directories must not\n * live under paths mounted into sandbox containers (workspace and\n * conversation dirs in image mode), or code written from inside the sandbox\n * would be imported into the host process — a sandbox escape.\n * {@link defaultExtensionDirs} returns the canonical host-only locations\n * under mikan's state dir.\n *\n * Directories are scanned in order; all discovered extensions activate.\n * Accepted layouts (entrypoint may be .mjs/.js/.ts/.mts — loaded via jiti):\n *\n * - `extensions/<name>.<ext>` (bare file)\n * - `extensions/<name>/index.<ext>` (directory + index)\n * - `extensions/<name>/package.json` (mikan.extensions entrypoint;\n * may carry npm dependencies in node_modules)\n *\n * Modules are imported with a fresh jiti instance (no cache) so edited\n * extensions are picked up when a new harness instance is created.\n */\nimport { existsSync, mkdirSync, readdirSync, readFileSync, statSync } from \"fs\";\nimport { homedir } from \"os\";\nimport { basename, dirname, join } from \"path\";\nimport { createJiti } from \"jiti\";\nimport type { AgentTool, ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport * as log from \"../../log.js\";\nimport { loadSkillsFromDir, type MikanSkill } from \"../skills.js\";\nimport { ExtensionRegistry } from \"./registry.js\";\nimport type {\n ExtensionHostServices,\n ExtensionLoadError,\n ExtensionManifest,\n ExtensionSchedulePayload,\n ExtensionScheduleInfo,\n ExtensionScheduleSpec,\n LoadedExtension,\n MikanExtensionActivate,\n MikanExtensionApi,\n MikanExtensionModule,\n} from \"./types.js\";\n\nconst EXTENSION_FILE_PATTERN = /\\.(mjs|js|ts|mts)$/;\nconst INDEX_FILE_PATTERN = /^index\\.(mjs|js|ts|mts)$/;\nconst INDEX_CANDIDATES = [\"index.mjs\", \"index.js\", \"index.ts\", \"index.mts\"];\n\n/**\n * Import an extension entrypoint through jiti so it can be TypeScript and can\n * use node_modules dependencies, transparently compiling on the fly. A fresh\n * jiti instance with caching disabled is used per load so edited extensions\n * are picked up when a new harness instance is created for a conversation.\n */\nasync function importExtensionModule(entrypoint: string): Promise<unknown> {\n const jiti = createJiti(import.meta.url, { moduleCache: false, fsCache: false });\n return jiti.import(entrypoint);\n}\n\n/**\n * Canonical host-only extension code directories for a conversation, in load\n * order: `<stateDir>/global/extensions` (all conversations) then\n * `<stateDir>/conversations/<conversationId>/extensions` (that conversation\n * only). `global` and `conversations` are the two sibling scopes; see\n * `LAYOUT.md`. Conversation ids are used verbatim (see LAYOUT.md § Casing).\n */\nexport function defaultExtensionDirs(\n conversationId: string,\n stateDir: string = join(homedir(), \".mikan\"),\n): string[] {\n return [\n join(stateDir, \"global\", \"extensions\"),\n join(stateDir, \"conversations\", conversationId, \"extensions\"),\n ];\n}\n\n/** Discovery-only view of an installed extension (module is not imported). */\nexport interface InstalledExtensionInfo {\n /** Display name: manifest name, falling back to the slug. */\n name: string;\n slug: string;\n path: string;\n /** Scan directory the extension was found in. */\n dir: string;\n version?: string;\n description?: string;\n /** Names of skills shipped in the extension's skills/ directory. */\n skillNames: string[];\n}\n\n/**\n * List installed extensions without importing or activating them — safe for\n * inventory surfaces (commands, portal). Activation side effects (schedule\n * upserts, tool registration) only happen in {@link loadExtensions}.\n */\nexport function listInstalledExtensions(dirs: string[]): InstalledExtensionInfo[] {\n const infos: InstalledExtensionInfo[] = [];\n for (const dir of dirs) {\n for (const { entrypoint, rootDir } of discoverExtensionEntrypoints(dir)) {\n const slug = slugForRoot(rootDir);\n const manifest = readManifest(rootDir);\n infos.push({\n name: manifest.name ?? slug,\n slug,\n path: entrypoint,\n dir,\n version: manifest.version,\n description: manifest.description,\n skillNames: loadExtensionSkills(rootDir, slug).map((skill) => skill.name),\n });\n }\n }\n return infos;\n}\n\nexport interface LoadExtensionsOptions {\n /** Directories to scan for extensions. Missing directories are skipped. */\n dirs: string[];\n context: {\n conversationId: string;\n workspaceDir: string;\n model: Model<Api>;\n thinkingLevel: ThinkingLevel;\n };\n /** Embedder-provided services backing the v2 api surface. */\n services?: ExtensionHostServices;\n}\n\nexport interface LoadExtensionsResult {\n registry: ExtensionRegistry;\n extensions: LoadedExtension[];\n errors: ExtensionLoadError[];\n /** Skills contributed by extensions (inline: bodies ride in the prompt). */\n skills: MikanSkill[];\n}\n\n/**\n * A discovered extension: its entrypoint (module to import) and root dir\n * (used for slug, manifest.json, and skills/ — which sit at the extension\n * root, not necessarily next to a nested entrypoint).\n */\ninterface DiscoveredExtension {\n entrypoint: string;\n rootDir: string;\n}\n\nfunction discoverExtensionEntrypoints(dir: string): DiscoveredExtension[] {\n if (!existsSync(dir)) return [];\n const found: DiscoveredExtension[] = [];\n for (const name of readdirSync(dir).toSorted()) {\n if (name.startsWith(\".\")) continue;\n if (INDEX_FILE_PATTERN.test(name)) {\n // An index file at the scan root means the extension's contents were\n // copied into the scope directory itself; the slug would degenerate to\n // the scope name (e.g. the conversation id), mis-keying its data dir,\n // secrets, and schedules. Require a named form instead.\n log.logWarning(\n `Ignoring extension index file at scope root: ${join(dir, name)}`,\n \"install into a named subdirectory (e.g. extensions/<scope>/my-ext/index.mjs)\",\n );\n continue;\n }\n const fullPath = join(dir, name);\n let stats;\n try {\n stats = statSync(fullPath);\n } catch {\n continue;\n }\n if (stats.isFile() && EXTENSION_FILE_PATTERN.test(name)) {\n // Bare-file form: the file is both entrypoint and (its own) root.\n found.push({ entrypoint: fullPath, rootDir: fullPath });\n continue;\n }\n if (stats.isDirectory()) {\n const entrypoint = resolveDirectoryEntrypoint(fullPath);\n if (entrypoint) found.push({ entrypoint, rootDir: fullPath });\n }\n }\n return found;\n}\n\n/**\n * Resolve a directory-form extension's entrypoint. A `package.json` with a\n * `mikan.extensions` array (first entry, relative to the dir) wins — this is\n * how an extension declares a TypeScript entry and pulls in npm dependencies.\n * Otherwise fall back to an `index.{mjs,js,ts,mts}` file. Returns undefined\n * when neither is present.\n */\nfunction resolveDirectoryEntrypoint(dir: string): string | undefined {\n const declared = readMikanManifestEntrypoints(dir)[0];\n if (declared) {\n const resolved = join(dir, declared);\n if (existsSync(resolved)) return resolved;\n log.logWarning(\n `Extension package.json declares a missing entrypoint: ${resolved}`,\n \"falling back to an index file\",\n );\n }\n for (const candidate of INDEX_CANDIDATES) {\n const indexPath = join(dir, candidate);\n if (existsSync(indexPath)) return indexPath;\n }\n return undefined;\n}\n\ninterface ExtensionPackageJson {\n name?: string;\n version?: string;\n description?: string;\n mikan?: { extensions?: string[]; displayName?: string };\n}\n\n/** Read and shape a directory's package.json; undefined when absent/malformed. */\nfunction readPackageJson(dir: string): ExtensionPackageJson | undefined {\n const packageJsonPath = join(dir, \"package.json\");\n if (!existsSync(packageJsonPath)) return undefined;\n try {\n const parsed = JSON.parse(readFileSync(packageJsonPath, \"utf-8\")) as unknown;\n if (!parsed || typeof parsed !== \"object\") return undefined;\n const record = parsed as Record<string, unknown>;\n const mikanRaw = record.mikan as { extensions?: unknown; displayName?: unknown } | undefined;\n return {\n name: typeof record.name === \"string\" ? record.name : undefined,\n version: typeof record.version === \"string\" ? record.version : undefined,\n description: typeof record.description === \"string\" ? record.description : undefined,\n mikan: {\n extensions: Array.isArray(mikanRaw?.extensions)\n ? mikanRaw.extensions.filter((entry): entry is string => typeof entry === \"string\")\n : undefined,\n displayName: typeof mikanRaw?.displayName === \"string\" ? mikanRaw.displayName : undefined,\n },\n };\n } catch (err) {\n log.logWarning(`Ignoring malformed package.json: ${packageJsonPath}`, String(err));\n return undefined;\n }\n}\n\n/** Read the `mikan.extensions` entrypoint list from a directory's package.json. */\nfunction readMikanManifestEntrypoints(dir: string): string[] {\n return readPackageJson(dir)?.mikan?.extensions ?? [];\n}\n\nfunction sanitizeSlug(base: string): string {\n const slug = base\n .toLowerCase()\n .replace(/[^a-z0-9_-]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .slice(0, 64);\n return slug || \"extension\";\n}\n\n/**\n * Filesystem-safe identifier for an extension, derived from its install\n * location: the directory name for a directory-form extension, or the file\n * basename for a bare file. The slug keys the extension's data dir, secrets\n * vault, and schedule ownership — installing the same extension globally and\n * per-conversation shares one slug and therefore one shared data dir.\n */\nexport function extensionSlug(entrypoint: string): string {\n // Bare-file form (rootDir === entrypoint, a *.mjs/.ts file) → file basename.\n // Directory form → directory name. Detect the directory form structurally:\n // an entrypoint whose parent holds a package.json or is an index file.\n if (INDEX_FILE_PATTERN.test(basename(entrypoint))) {\n return sanitizeSlug(basename(dirname(entrypoint)));\n }\n return sanitizeSlug(basename(entrypoint).replace(EXTENSION_FILE_PATTERN, \"\"));\n}\n\n/** Slug from a discovered extension's root dir (directory or bare file path). */\nfunction slugForRoot(rootDir: string): string {\n return EXTENSION_FILE_PATTERN.test(basename(rootDir))\n ? sanitizeSlug(basename(rootDir).replace(EXTENSION_FILE_PATTERN, \"\"))\n : sanitizeSlug(basename(rootDir));\n}\n\n/** Sanitize an extension-chosen schedule name into a filename segment. */\nfunction scheduleNameSegment(name: string): string {\n const segment = name\n .toLowerCase()\n .replace(/[^a-z0-9_-]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .slice(0, 64);\n if (!segment) throw new Error(`Invalid schedule name: ${JSON.stringify(name)}`);\n return segment;\n}\n\n/**\n * Read display metadata (name/version/description) for a directory-form\n * extension. `package.json` is the primary source — its standard `name`,\n * `version`, `description`, plus an optional `mikan.displayName` that\n * overrides the npm name for the user-facing label (npm names are\n * lowercase/scoped; display names can be arbitrary). A `manifest.json` is a\n * fallback for extensions that ship no package.json.\n */\nfunction readManifest(rootDir: string): ExtensionManifest {\n // Bare-file extensions (rootDir is a *.mjs/.ts file) have no manifest.\n if (EXTENSION_FILE_PATTERN.test(basename(rootDir))) return {};\n\n const pkg = readPackageJson(rootDir);\n if (pkg && (pkg.mikan?.displayName ?? pkg.name ?? pkg.version ?? pkg.description)) {\n return {\n name: pkg.mikan?.displayName ?? pkg.name,\n version: pkg.version,\n description: pkg.description,\n };\n }\n\n const manifestPath = join(rootDir, \"manifest.json\");\n if (!existsSync(manifestPath)) return {};\n try {\n const parsed: unknown = JSON.parse(readFileSync(manifestPath, \"utf-8\"));\n if (!parsed || typeof parsed !== \"object\") return {};\n const record = parsed as Record<string, unknown>;\n return {\n name: typeof record.name === \"string\" ? record.name : undefined,\n version: typeof record.version === \"string\" ? record.version : undefined,\n description: typeof record.description === \"string\" ? record.description : undefined,\n };\n } catch (err) {\n log.logWarning(`Ignoring malformed extension manifest: ${manifestPath}`, String(err));\n return {};\n }\n}\n\n/**\n * Skills shipped inside a directory-form extension (`<dir>/skills/`).\n * Marked inline: extension files live under the host-only state dir, which\n * sandbox containers cannot read, so skill bodies must ride in the prompt.\n */\nfunction loadExtensionSkills(rootDir: string, slug: string): MikanSkill[] {\n // Bare-file extensions (rootDir is a *.mjs/.ts file) ship no skills.\n if (EXTENSION_FILE_PATTERN.test(basename(rootDir))) return [];\n const skillsDir = join(rootDir, \"skills\");\n if (!existsSync(skillsDir)) return [];\n const result = loadSkillsFromDir({ dir: skillsDir, source: `extension:${slug}` });\n for (const diagnostic of result.diagnostics) {\n log.logWarning(`Extension skill warning (${slug}): ${diagnostic.message}`, diagnostic.path);\n }\n for (const skill of result.skills) skill.inline = true;\n return result.skills;\n}\n\nconst SCHEDULE_FILE_SUFFIX = \".json\";\n\nfunction schedulePrefix(slug: string, conversationId: string): string {\n return `ext.${slug}.${scheduleNameSegment(conversationId)}.`;\n}\n\nfunction payloadFromSpec(\n spec: ExtensionScheduleSpec,\n conversationId: string,\n): ExtensionSchedulePayload {\n if (spec.type === \"periodic\") {\n if (!spec.schedule || !spec.timezone) {\n throw new Error(\"periodic schedule requires schedule and timezone\");\n }\n return {\n type: \"periodic\",\n conversationId,\n text: spec.text,\n schedule: spec.schedule,\n timezone: spec.timezone,\n ...(spec.platform ? { platform: spec.platform } : {}),\n };\n }\n if (!spec.at) throw new Error(\"one-shot schedule requires at\");\n return {\n type: \"one-shot\",\n conversationId,\n text: spec.text,\n at: spec.at,\n ...(spec.platform ? { platform: spec.platform } : {}),\n };\n}\n\nfunction specFromPayload(payload: ExtensionSchedulePayload): ExtensionScheduleSpec {\n if (payload.type === \"periodic\") {\n return {\n type: \"periodic\",\n schedule: payload.schedule ?? \"\",\n timezone: payload.timezone ?? \"\",\n text: payload.text,\n ...(payload.platform ? { platform: payload.platform } : {}),\n };\n }\n return {\n type: \"one-shot\",\n at: payload.at ?? \"\",\n text: payload.text,\n ...(payload.platform ? { platform: payload.platform } : {}),\n };\n}\n\n/** Build the v2 api surface for one extension over the injected services. */\nfunction buildExtensionApi(params: {\n name: string;\n slug: string;\n registry: ExtensionRegistry;\n context: LoadExtensionsOptions[\"context\"];\n services: ExtensionHostServices;\n}): MikanExtensionApi {\n const { name, slug, registry, context, services } = params;\n const stateDir = services.stateDir ?? join(homedir(), \".mikan\");\n const conversationId = context.conversationId;\n\n const requireScheduleStore = () => {\n if (!services.scheduleStore) {\n throw new Error(\"api.schedules is unavailable: this context provides no schedule store\");\n }\n return services.scheduleStore;\n };\n\n return {\n on: (hook, handler) => registry.register(name, hook, handler),\n registerTool: (tool: AgentTool) => registry.registerTool(tool),\n log: (message: string) => log.logInfo(`[extension:${name}] ${message}`),\n context,\n paths: {\n get dataDir(): string {\n // This conversation's own data, co-located with the conversation's\n // other host-only assets; removed when the conversation is deleted.\n const dir = join(stateDir, \"conversations\", conversationId, \"extension-data\", slug);\n mkdirSync(dir, { recursive: true });\n return dir;\n },\n get sharedDataDir(): string {\n // Cross-conversation data under the sibling `global` scope.\n const dir = join(stateDir, \"global\", \"extension-data\", slug);\n mkdirSync(dir, { recursive: true });\n return dir;\n },\n },\n secrets: {\n get: (key: string) => services.resolveSecrets?.(slug)[key],\n list: () => Object.keys(services.resolveSecrets?.(slug) ?? {}),\n },\n schedules: {\n upsert: async (scheduleName, spec) => {\n const store = requireScheduleStore();\n const filename = `${schedulePrefix(slug, conversationId)}${scheduleNameSegment(scheduleName)}${SCHEDULE_FILE_SUFFIX}`;\n await store.write(filename, payloadFromSpec(spec, conversationId));\n },\n delete: async (scheduleName) => {\n const store = requireScheduleStore();\n const filename = `${schedulePrefix(slug, conversationId)}${scheduleNameSegment(scheduleName)}${SCHEDULE_FILE_SUFFIX}`;\n return store.delete(filename);\n },\n list: async () => {\n const store = requireScheduleStore();\n const prefix = schedulePrefix(slug, conversationId);\n const infos: ExtensionScheduleInfo[] = [];\n for (const entry of await store.list()) {\n if (!entry.filename.startsWith(prefix)) continue;\n if (!entry.filename.endsWith(SCHEDULE_FILE_SUFFIX)) continue;\n infos.push({\n name: entry.filename.slice(prefix.length, -SCHEDULE_FILE_SUFFIX.length),\n spec: specFromPayload(entry.payload),\n });\n }\n return infos;\n },\n },\n notify: async (text: string) => {\n if (!services.postMessage) {\n throw new Error(\"api.notify is unavailable: this context provides no platform messaging\");\n }\n await services.postMessage(conversationId, text);\n },\n react: async (messageTs: string, emoji: string) => {\n if (!services.addReaction) {\n throw new Error(\"api.react is unavailable: this context provides no reaction support\");\n }\n await services.addReaction(conversationId, messageTs, emoji);\n },\n };\n}\n\nfunction resolveActivate(moduleExports: unknown): MikanExtensionModule | undefined {\n if (!moduleExports || typeof moduleExports !== \"object\") return undefined;\n const candidates: unknown[] = [(moduleExports as { default?: unknown }).default, moduleExports];\n for (const candidate of candidates) {\n if (typeof candidate === \"function\") {\n return { activate: candidate as MikanExtensionActivate };\n }\n if (candidate && typeof candidate === \"object\") {\n const activate = (candidate as { activate?: unknown }).activate;\n if (typeof activate === \"function\") {\n return {\n name:\n typeof (candidate as { name?: unknown }).name === \"string\"\n ? (candidate as { name: string }).name\n : undefined,\n activate: activate as MikanExtensionActivate,\n };\n }\n }\n }\n return undefined;\n}\n\n/** Load and activate all extensions found in the given directories. */\nexport async function loadExtensions(\n options: LoadExtensionsOptions,\n): Promise<LoadExtensionsResult> {\n const registry = new ExtensionRegistry();\n const extensions: LoadedExtension[] = [];\n const errors: ExtensionLoadError[] = [];\n const skills: MikanSkill[] = [];\n const services = options.services ?? {};\n\n for (const dir of options.dirs) {\n for (const { entrypoint, rootDir } of discoverExtensionEntrypoints(dir)) {\n try {\n const moduleExports: unknown = await importExtensionModule(entrypoint);\n const extension = resolveActivate(moduleExports);\n if (!extension) {\n errors.push({\n path: entrypoint,\n error: \"extension must export an activate function (default or named)\",\n });\n continue;\n }\n const slug = slugForRoot(rootDir);\n const manifest = readManifest(rootDir);\n const name = manifest.name ?? extension.name ?? slug;\n const api = buildExtensionApi({\n name,\n slug,\n registry,\n context: options.context,\n services,\n });\n await extension.activate(api);\n const extensionSkills = loadExtensionSkills(rootDir, slug);\n skills.push(...extensionSkills);\n extensions.push({\n name,\n path: entrypoint,\n slug,\n version: manifest.version,\n description: manifest.description,\n skills: extensionSkills,\n });\n } catch (err) {\n errors.push({\n path: entrypoint,\n error: err instanceof Error ? err.message : String(err),\n });\n }\n }\n }\n\n return { registry, extensions, errors, skills };\n}\n\nexport interface ExtensionValidation {\n ok: boolean;\n /** Slug the extension would install as (from the source dir/file name). */\n slug: string;\n /** Display name (manifest name, else slug). */\n name: string;\n version?: string;\n description?: string;\n /** Resolved entrypoint that would be imported. */\n entrypoint?: string;\n /** Skill names shipped alongside the extension. */\n skillNames: string[];\n errors: string[];\n warnings: string[];\n}\n\n/**\n * Validate an extension source path (a directory or a single file) WITHOUT\n * activating it: resolves the entrypoint (package.json `mikan.extensions`,\n * index file, or the file itself), imports it, and checks it exports an\n * `activate` function. Used by `mikan ext install` as a preflight and by\n * `mikan ext validate`. Importing runs top-level module code but not\n * `activate`, so there are no schedule/tool side effects.\n */\nexport async function validateExtension(sourcePath: string): Promise<ExtensionValidation> {\n const errors: string[] = [];\n const warnings: string[] = [];\n const rootDir = sourcePath.replace(/[/\\\\]+$/, \"\");\n const base = basename(rootDir);\n\n if (INDEX_FILE_PATTERN.test(base)) {\n warnings.push(\n \"Entry is a bare index file; install into a named directory so the slug is stable.\",\n );\n }\n\n let entrypoint: string | undefined;\n if (!existsSync(rootDir)) {\n errors.push(`Path does not exist: ${rootDir}`);\n } else if (statSync(rootDir).isDirectory()) {\n entrypoint = resolveDirectoryEntrypoint(rootDir);\n if (!entrypoint) {\n errors.push(\n \"No entrypoint found: expected package.json with a mikan.extensions entry, or an index.{mjs,js,ts,mts}.\",\n );\n }\n } else if (EXTENSION_FILE_PATTERN.test(base)) {\n entrypoint = rootDir;\n } else {\n errors.push(`Not an extension file (expected .mjs/.js/.ts/.mts): ${rootDir}`);\n }\n\n const slug = slugForRoot(rootDir);\n const manifest = readManifest(rootDir);\n const skillNames = loadExtensionSkills(rootDir, slug).map((skill) => skill.name);\n\n if (entrypoint) {\n try {\n const moduleExports: unknown = await importExtensionModule(entrypoint);\n if (!resolveActivate(moduleExports)) {\n errors.push(\"Module does not export an activate function (default or named).\");\n }\n } catch (err) {\n errors.push(`Failed to import: ${err instanceof Error ? err.message : String(err)}`);\n }\n }\n\n return {\n ok: errors.length === 0,\n slug,\n name: manifest.name ?? slug,\n version: manifest.version,\n description: manifest.description,\n entrypoint,\n skillNames,\n errors,\n warnings,\n };\n}\n"]}
@@ -13,7 +13,7 @@ export { MikanAgentSession, type CompactionReason, type HarnessEvent, type Harne
13
13
  export { formatSkillsForPrompt, loadSkillsFromDir, parseFrontmatter, type LoadSkillsResult, type MikanSkill, type SkillDiagnostic, } from "./skills.js";
14
14
  export { DEFAULT_BUDGET_SETTINGS, DEFAULT_EVENT_BUDGET, DEFAULT_RETRY_SETTINGS, resolveHarnessSettings, type BudgetSettings, type CompactionSettings, type HarnessSettings, type RetrySettings, } from "./settings.js";
15
15
  export { ExtensionRegistry } from "./extensions/registry.js";
16
- export { defaultExtensionDirs, extensionSlug, listInstalledExtensions, loadExtensions, type InstalledExtensionInfo, type LoadExtensionsOptions, type LoadExtensionsResult, } from "./extensions/loader.js";
16
+ export { defaultExtensionDirs, extensionSlug, listInstalledExtensions, loadExtensions, validateExtension, type ExtensionValidation, type InstalledExtensionInfo, type LoadExtensionsOptions, type LoadExtensionsResult, } from "./extensions/loader.js";
17
17
  export type { BeforeAgentStartHookEvent, BeforeAgentStartHookResult, ExtensionHostServices, ExtensionLoadError, ExtensionManifest, ExtensionScheduleInfo, ExtensionSchedulePayload, ExtensionScheduleSpec, ExtensionScheduleStore, LoadedExtension, MessageEndHookEvent, MikanExtensionActivate, MikanExtensionApi, MikanExtensionModule, MikanHookMap, MikanHookName, SessionCompactHookEvent, ToolCallHookEvent, ToolCallHookResult, ToolResultHookEvent, TurnEndHookEvent, } from "./extensions/types.js";
18
18
  export { CURRENT_SESSION_VERSION, type BranchSummaryEntry, type CompactionEntry, type CustomEntry, type CustomMessageEntry, type SessionContext, type SessionEntry, type SessionFileEntry, type SessionHeader, type SessionInfoEntry, type SessionMessageEntry, } from "./types.js";
19
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/harness/index.ts"],"names":[],"mappings":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AkB,EAClB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,uBAAuB,EACvB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/harness/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,KAAK,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EACL,iBAAiB,EACjB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,GAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,uBAAuB,EACvB,cAAc,EACd,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,yBAAyB,EACzB,0BAA0B,EAC1B,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,uBAAuB,EACvB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAC"}
@@ -13,6 +13,6 @@ export { MikanAgentSession, } from "./runner.js";
13
13
  export { formatSkillsForPrompt, loadSkillsFromDir, parseFrontmatter, } from "./skills.js";
14
14
  export { DEFAULT_BUDGET_SETTINGS, DEFAULT_EVENT_BUDGET, DEFAULT_RETRY_SETTINGS, resolveHarnessSettings, } from "./settings.js";
15
15
  export { ExtensionRegistry } from "./extensions/registry.js";
16
- export { defaultExtensionDirs, extensionSlug, listInstalledExtensions, loadExtensions, } from "./extensions/loader.js";
16
+ export { defaultExtensionDirs, extensionSlug, listInstalledExtensions, loadExtensions, validateExtension, } from "./extensions/loader.js";
17
17
  export { CURRENT_SESSION_VERSION, } from "./types.js";
18
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/harness/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAiC,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EACL,iBAAiB,GAKlB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,GAIjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GAKvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,uBAAuB,EACvB,cAAc,GAIf,MAAM,wBAAwB,CAAC;AAwBhC,OAAO,EACL,uBAAuB,GAWxB,MAAM,YAAY,CAAC","sourcesContent":["/**\n * mikan agent harness.\n *\n * mikan's own harness engineering layer, built directly on pi-agent-core\n * (agent loop, compaction, context building) and pi-ai (providers, models,\n * auth). See `src/harness/README.md` for the architecture.\n */\nexport { FileCredentialStore, defaultAuthPath } from \"./auth.js\";\nexport {\n DEFAULT_HTTP_IDLE_TIMEOUT_MS,\n configureHttpDispatcher,\n parseHttpIdleTimeoutMs,\n} from \"./http.js\";\nexport { MikanModels, defaultModelsJsonPath, type CreateMikanModelsOptions } from \"./models.js\";\nexport { SessionStore, loadSessionFileEntries, parseSessionFileEntries } from \"./session-store.js\";\nexport {\n MikanAgentSession,\n type CompactionReason,\n type HarnessEvent,\n type HarnessEventListener,\n type MikanAgentSessionOptions,\n} from \"./runner.js\";\nexport {\n formatSkillsForPrompt,\n loadSkillsFromDir,\n parseFrontmatter,\n type LoadSkillsResult,\n type MikanSkill,\n type SkillDiagnostic,\n} from \"./skills.js\";\nexport {\n DEFAULT_BUDGET_SETTINGS,\n DEFAULT_EVENT_BUDGET,\n DEFAULT_RETRY_SETTINGS,\n resolveHarnessSettings,\n type BudgetSettings,\n type CompactionSettings,\n type HarnessSettings,\n type RetrySettings,\n} from \"./settings.js\";\nexport { ExtensionRegistry } from \"./extensions/registry.js\";\nexport {\n defaultExtensionDirs,\n extensionSlug,\n listInstalledExtensions,\n loadExtensions,\n type InstalledExtensionInfo,\n type LoadExtensionsOptions,\n type LoadExtensionsResult,\n} from \"./extensions/loader.js\";\nexport type {\n BeforeAgentStartHookEvent,\n BeforeAgentStartHookResult,\n ExtensionHostServices,\n ExtensionLoadError,\n ExtensionManifest,\n ExtensionScheduleInfo,\n ExtensionSchedulePayload,\n ExtensionScheduleSpec,\n ExtensionScheduleStore,\n LoadedExtension,\n MessageEndHookEvent,\n MikanExtensionActivate,\n MikanExtensionApi,\n MikanExtensionModule,\n MikanHookMap,\n MikanHookName,\n SessionCompactHookEvent,\n ToolCallHookEvent,\n ToolCallHookResult,\n ToolResultHookEvent,\n TurnEndHookEvent,\n} from \"./extensions/types.js\";\nexport {\n CURRENT_SESSION_VERSION,\n type BranchSummaryEntry,\n type CompactionEntry,\n type CustomEntry,\n type CustomMessageEntry,\n type SessionContext,\n type SessionEntry,\n type SessionFileEntry,\n type SessionHeader,\n type SessionInfoEntry,\n type SessionMessageEntry,\n} from \"./types.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/harness/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAiC,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EACL,iBAAiB,GAKlB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,GAIjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GAKvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,uBAAuB,EACvB,cAAc,EACd,iBAAiB,GAKlB,MAAM,wBAAwB,CAAC;AAwBhC,OAAO,EACL,uBAAuB,GAWxB,MAAM,YAAY,CAAC","sourcesContent":["/**\n * mikan agent harness.\n *\n * mikan's own harness engineering layer, built directly on pi-agent-core\n * (agent loop, compaction, context building) and pi-ai (providers, models,\n * auth). See `src/harness/README.md` for the architecture.\n */\nexport { FileCredentialStore, defaultAuthPath } from \"./auth.js\";\nexport {\n DEFAULT_HTTP_IDLE_TIMEOUT_MS,\n configureHttpDispatcher,\n parseHttpIdleTimeoutMs,\n} from \"./http.js\";\nexport { MikanModels, defaultModelsJsonPath, type CreateMikanModelsOptions } from \"./models.js\";\nexport { SessionStore, loadSessionFileEntries, parseSessionFileEntries } from \"./session-store.js\";\nexport {\n MikanAgentSession,\n type CompactionReason,\n type HarnessEvent,\n type HarnessEventListener,\n type MikanAgentSessionOptions,\n} from \"./runner.js\";\nexport {\n formatSkillsForPrompt,\n loadSkillsFromDir,\n parseFrontmatter,\n type LoadSkillsResult,\n type MikanSkill,\n type SkillDiagnostic,\n} from \"./skills.js\";\nexport {\n DEFAULT_BUDGET_SETTINGS,\n DEFAULT_EVENT_BUDGET,\n DEFAULT_RETRY_SETTINGS,\n resolveHarnessSettings,\n type BudgetSettings,\n type CompactionSettings,\n type HarnessSettings,\n type RetrySettings,\n} from \"./settings.js\";\nexport { ExtensionRegistry } from \"./extensions/registry.js\";\nexport {\n defaultExtensionDirs,\n extensionSlug,\n listInstalledExtensions,\n loadExtensions,\n validateExtension,\n type ExtensionValidation,\n type InstalledExtensionInfo,\n type LoadExtensionsOptions,\n type LoadExtensionsResult,\n} from \"./extensions/loader.js\";\nexport type {\n BeforeAgentStartHookEvent,\n BeforeAgentStartHookResult,\n ExtensionHostServices,\n ExtensionLoadError,\n ExtensionManifest,\n ExtensionScheduleInfo,\n ExtensionSchedulePayload,\n ExtensionScheduleSpec,\n ExtensionScheduleStore,\n LoadedExtension,\n MessageEndHookEvent,\n MikanExtensionActivate,\n MikanExtensionApi,\n MikanExtensionModule,\n MikanHookMap,\n MikanHookName,\n SessionCompactHookEvent,\n ToolCallHookEvent,\n ToolCallHookResult,\n ToolResultHookEvent,\n TurnEndHookEvent,\n} from \"./extensions/types.js\";\nexport {\n CURRENT_SESSION_VERSION,\n type BranchSummaryEntry,\n type CompactionEntry,\n type CustomEntry,\n type CustomMessageEntry,\n type SessionContext,\n type SessionEntry,\n type SessionFileEntry,\n type SessionHeader,\n type SessionInfoEntry,\n type SessionMessageEntry,\n} from \"./types.js\";\n"]}