@geminixiang/mikan 1.0.0-beta.37 → 1.0.0-beta.39

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 (201) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +1 -1
  3. package/dist/adapter.js +1 -1
  4. package/dist/adapter.js.map +1 -1
  5. package/dist/adapters/discord/bot.d.ts +3 -6
  6. package/dist/adapters/discord/bot.d.ts.map +1 -1
  7. package/dist/adapters/discord/bot.js +16 -39
  8. package/dist/adapters/discord/bot.js.map +1 -1
  9. package/dist/adapters/github/bot.d.ts +2 -0
  10. package/dist/adapters/github/bot.d.ts.map +1 -1
  11. package/dist/adapters/github/bot.js +15 -11
  12. package/dist/adapters/github/bot.js.map +1 -1
  13. package/dist/adapters/github/github-ops.d.ts +1 -1
  14. package/dist/adapters/github/github-ops.d.ts.map +1 -1
  15. package/dist/adapters/github/github-ops.js +2 -1
  16. package/dist/adapters/github/github-ops.js.map +1 -1
  17. package/dist/adapters/github/repo.d.ts +2 -1
  18. package/dist/adapters/github/repo.d.ts.map +1 -1
  19. package/dist/adapters/github/repo.js +2 -3
  20. package/dist/adapters/github/repo.js.map +1 -1
  21. package/dist/adapters/github/types.d.ts +1 -1
  22. package/dist/adapters/github/types.d.ts.map +1 -1
  23. package/dist/adapters/github/types.js.map +1 -1
  24. package/dist/adapters/intake.js +1 -1
  25. package/dist/adapters/intake.js.map +1 -1
  26. package/dist/adapters/shared.d.ts +17 -5
  27. package/dist/adapters/shared.d.ts.map +1 -1
  28. package/dist/adapters/shared.js +44 -8
  29. package/dist/adapters/shared.js.map +1 -1
  30. package/dist/adapters/slack/blocks.d.ts +14 -0
  31. package/dist/adapters/slack/blocks.d.ts.map +1 -1
  32. package/dist/adapters/slack/blocks.js +34 -0
  33. package/dist/adapters/slack/blocks.js.map +1 -1
  34. package/dist/adapters/slack/bot.d.ts +19 -6
  35. package/dist/adapters/slack/bot.d.ts.map +1 -1
  36. package/dist/adapters/slack/bot.js +88 -21
  37. package/dist/adapters/slack/bot.js.map +1 -1
  38. package/dist/adapters/slack/types.d.ts +1 -1
  39. package/dist/adapters/slack/types.js.map +1 -1
  40. package/dist/adapters/telegram/bot.d.ts +5 -6
  41. package/dist/adapters/telegram/bot.d.ts.map +1 -1
  42. package/dist/adapters/telegram/bot.js +29 -51
  43. package/dist/adapters/telegram/bot.js.map +1 -1
  44. package/dist/adapters/types.d.ts +19 -1
  45. package/dist/adapters/types.d.ts.map +1 -1
  46. package/dist/adapters/types.js.map +1 -1
  47. package/dist/agent.d.ts +0 -1
  48. package/dist/agent.d.ts.map +1 -1
  49. package/dist/agent.js +79 -101
  50. package/dist/agent.js.map +1 -1
  51. package/dist/cli/ext-dev.d.ts.map +1 -1
  52. package/dist/cli/ext-dev.js +8 -8
  53. package/dist/cli/ext-dev.js.map +1 -1
  54. package/dist/cli/ext.js +3 -3
  55. package/dist/cli/ext.js.map +1 -1
  56. package/dist/cli/office.js +2 -2
  57. package/dist/cli/office.js.map +1 -1
  58. package/dist/commands/auto-reply.d.ts.map +1 -1
  59. package/dist/commands/auto-reply.js +1 -2
  60. package/dist/commands/auto-reply.js.map +1 -1
  61. package/dist/commands/login.js +1 -1
  62. package/dist/commands/login.js.map +1 -1
  63. package/dist/commands/manifest.d.ts.map +1 -1
  64. package/dist/commands/manifest.js +3 -1
  65. package/dist/commands/manifest.js.map +1 -1
  66. package/dist/commands/model.d.ts.map +1 -1
  67. package/dist/commands/model.js +3 -7
  68. package/dist/commands/model.js.map +1 -1
  69. package/dist/commands/sandbox.d.ts.map +1 -1
  70. package/dist/commands/sandbox.js +7 -7
  71. package/dist/commands/sandbox.js.map +1 -1
  72. package/dist/commands/session-view.d.ts.map +1 -1
  73. package/dist/commands/session-view.js +1 -2
  74. package/dist/commands/session-view.js.map +1 -1
  75. package/dist/commands/types.d.ts +2 -1
  76. package/dist/commands/types.d.ts.map +1 -1
  77. package/dist/commands/types.js.map +1 -1
  78. package/dist/config.d.ts +10 -18
  79. package/dist/config.d.ts.map +1 -1
  80. package/dist/config.js +16 -15
  81. package/dist/config.js.map +1 -1
  82. package/dist/execution-resolver.d.ts +4 -6
  83. package/dist/execution-resolver.d.ts.map +1 -1
  84. package/dist/execution-resolver.js +10 -19
  85. package/dist/execution-resolver.js.map +1 -1
  86. package/dist/harness/extensions/loader.js +1 -1
  87. package/dist/harness/extensions/loader.js.map +1 -1
  88. package/dist/harness/skills.d.ts +8 -0
  89. package/dist/harness/skills.d.ts.map +1 -1
  90. package/dist/harness/skills.js +46 -4
  91. package/dist/harness/skills.js.map +1 -1
  92. package/dist/harness/types.d.ts +2 -0
  93. package/dist/harness/types.d.ts.map +1 -1
  94. package/dist/harness/types.js.map +1 -1
  95. package/dist/index.d.ts +2 -0
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +1 -0
  98. package/dist/index.js.map +1 -1
  99. package/dist/main.js +16 -16
  100. package/dist/main.js.map +1 -1
  101. package/dist/{office-address.d.ts → office/address.d.ts} +13 -14
  102. package/dist/office/address.d.ts.map +1 -0
  103. package/dist/{office-address.js → office/address.js} +13 -18
  104. package/dist/office/address.js.map +1 -0
  105. package/dist/office/index.d.ts +11 -0
  106. package/dist/office/index.d.ts.map +1 -0
  107. package/dist/office/index.js +11 -0
  108. package/dist/office/index.js.map +1 -0
  109. package/dist/office/layout.d.ts +20 -0
  110. package/dist/office/layout.d.ts.map +1 -0
  111. package/dist/office/layout.js +88 -0
  112. package/dist/office/layout.js.map +1 -0
  113. package/dist/{office-migration.d.ts → office/migration.d.ts} +3 -3
  114. package/dist/office/migration.d.ts.map +1 -0
  115. package/dist/{office-migration.js → office/migration.js} +8 -12
  116. package/dist/office/migration.js.map +1 -0
  117. package/dist/{office-registry.d.ts → office/registry.d.ts} +18 -24
  118. package/dist/office/registry.d.ts.map +1 -0
  119. package/dist/{office-registry.js → office/registry.js} +22 -83
  120. package/dist/office/registry.js.map +1 -0
  121. package/dist/office/types.d.ts +71 -0
  122. package/dist/office/types.d.ts.map +1 -0
  123. package/dist/office/types.js +2 -0
  124. package/dist/office/types.js.map +1 -0
  125. package/dist/packages/admin.js +5 -5
  126. package/dist/packages/admin.js.map +1 -1
  127. package/dist/packages/inspect.d.ts.map +1 -1
  128. package/dist/packages/inspect.js +3 -8
  129. package/dist/packages/inspect.js.map +1 -1
  130. package/dist/packages/materialize.js +1 -1
  131. package/dist/packages/materialize.js.map +1 -1
  132. package/dist/packages/resolve.js +5 -8
  133. package/dist/packages/resolve.js.map +1 -1
  134. package/dist/packages/types.d.ts +2 -5
  135. package/dist/packages/types.d.ts.map +1 -1
  136. package/dist/packages/types.js.map +1 -1
  137. package/dist/runtime/conversation-runtime.d.ts.map +1 -1
  138. package/dist/runtime/conversation-runtime.js +13 -15
  139. package/dist/runtime/conversation-runtime.js.map +1 -1
  140. package/dist/runtime/session-lifecycle.js +1 -1
  141. package/dist/runtime/session-lifecycle.js.map +1 -1
  142. package/dist/runtime/types.d.ts +3 -2
  143. package/dist/runtime/types.d.ts.map +1 -1
  144. package/dist/runtime/types.js.map +1 -1
  145. package/dist/sandbox/identity.js +1 -1
  146. package/dist/sandbox/identity.js.map +1 -1
  147. package/dist/settings-mutation.d.ts +3 -2
  148. package/dist/settings-mutation.d.ts.map +1 -1
  149. package/dist/settings-mutation.js +6 -7
  150. package/dist/settings-mutation.js.map +1 -1
  151. package/dist/tools/generate-image.d.ts +8 -2
  152. package/dist/tools/generate-image.d.ts.map +1 -1
  153. package/dist/tools/generate-image.js +5 -3
  154. package/dist/tools/generate-image.js.map +1 -1
  155. package/dist/tools/index.d.ts +5 -0
  156. package/dist/tools/index.d.ts.map +1 -1
  157. package/dist/tools/index.js +3 -5
  158. package/dist/tools/index.js.map +1 -1
  159. package/dist/trigger.d.ts +1 -1
  160. package/dist/trigger.d.ts.map +1 -1
  161. package/dist/trigger.js +5 -10
  162. package/dist/trigger.js.map +1 -1
  163. package/dist/types.d.ts +3 -22
  164. package/dist/types.d.ts.map +1 -1
  165. package/dist/types.js.map +1 -1
  166. package/dist/vault/index.js +1 -1
  167. package/dist/vault/index.js.map +1 -1
  168. package/dist/vault/injection.d.ts +3 -1
  169. package/dist/vault/injection.d.ts.map +1 -1
  170. package/dist/vault/injection.js +2 -2
  171. package/dist/vault/injection.js.map +1 -1
  172. package/dist/web/admin/portal.d.ts.map +1 -1
  173. package/dist/web/admin/portal.js +67 -80
  174. package/dist/web/admin/portal.js.map +1 -1
  175. package/dist/web/admin/types.d.ts +2 -1
  176. package/dist/web/admin/types.d.ts.map +1 -1
  177. package/dist/web/admin/types.js.map +1 -1
  178. package/dist/web/server.d.ts +1 -1
  179. package/dist/web/server.d.ts.map +1 -1
  180. package/dist/web/server.js +3 -3
  181. package/dist/web/server.js.map +1 -1
  182. package/dist/web/session-view/portal.js +1 -1
  183. package/dist/web/session-view/portal.js.map +1 -1
  184. package/dist/workspace-projection/index.d.ts +2 -4
  185. package/dist/workspace-projection/index.d.ts.map +1 -1
  186. package/dist/workspace-projection/index.js +21 -56
  187. package/dist/workspace-projection/index.js.map +1 -1
  188. package/dist/workspace-projection/types.d.ts +0 -2
  189. package/dist/workspace-projection/types.d.ts.map +1 -1
  190. package/dist/workspace-projection/types.js.map +1 -1
  191. package/package.json +41 -16
  192. package/dist/office-address.d.ts.map +0 -1
  193. package/dist/office-address.js.map +0 -1
  194. package/dist/office-migration.d.ts.map +0 -1
  195. package/dist/office-migration.js.map +0 -1
  196. package/dist/office-registry.d.ts.map +0 -1
  197. package/dist/office-registry.js.map +0 -1
  198. package/dist/store.d.ts +0 -51
  199. package/dist/store.d.ts.map +0 -1
  200. package/dist/store.js +0 -185
  201. package/dist/store.js.map +0 -1
@@ -0,0 +1,88 @@
1
+ import { lstatSync, mkdirSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { officeKey, validateOfficeAddress } from "./address.js";
4
+ import { OfficeRegistry } from "./registry.js";
5
+ /**
6
+ * Workspace-root entries that are shared infrastructure, never office dirs.
7
+ * The single definition behind boot-time directory setup, the events
8
+ * watcher, the workspace projection, and the migration's legacy-dir scan.
9
+ */
10
+ export const RESERVED_WORKSPACE_NAMES = Object.freeze(new Set(["skills", "events", "agents", "MEMORY.md"]));
11
+ /**
12
+ * Construct the Workspace value for a deployment. One construction site per
13
+ * process (main.ts for the daemon; CLI subcommands and tests build their
14
+ * own). The value owns the registry instance and the recorded-office cache
15
+ * that office materialization uses on hot paths, so there is no process-wide
16
+ * registry state.
17
+ */
18
+ export function createWorkspace(options) {
19
+ // Paths are joined as given (no resolve) so values match what callers
20
+ // passing the same root/stateDir strings computed before this module.
21
+ const { root, stateDir } = options;
22
+ // Lazy: CLI surfaces construct a Workspace for path math without paying
23
+ // for (or being allowed to create) the registry journal.
24
+ let registry;
25
+ const recorded = new Set();
26
+ const offices = new Map();
27
+ const workspace = Object.freeze({
28
+ root,
29
+ stateDir,
30
+ memoryPath: join(root, "MEMORY.md"),
31
+ skillsDir: join(root, "skills"),
32
+ eventsDir: join(root, "events"),
33
+ agentsDir: join(root, "agents"),
34
+ reservedNames: RESERVED_WORKSPACE_NAMES,
35
+ office(address) {
36
+ const normalized = validateOfficeAddress(address);
37
+ const key = officeKey(normalized);
38
+ const existing = offices.get(key);
39
+ if (existing)
40
+ return existing;
41
+ const dir = join(root, key);
42
+ const office = Object.freeze({
43
+ address: normalized,
44
+ key,
45
+ dir,
46
+ memoryPath: join(dir, "MEMORY.md"),
47
+ skillsDir: join(dir, "skills"),
48
+ sessionsDir: join(dir, "sessions"),
49
+ attachmentsDir: join(dir, "attachments"),
50
+ logPath: join(dir, "log.jsonl"),
51
+ stateDir: join(stateDir, "conversations", key),
52
+ workspace,
53
+ ensure() {
54
+ // Record-first ordering: a crash can leave a record without a
55
+ // directory (harmless; recreated on the next message) but never an
56
+ // anonymous office directory the registry cannot enumerate.
57
+ if (!recorded.has(key)) {
58
+ registry ??= new OfficeRegistry(stateDir);
59
+ registry.recordOffice(normalized);
60
+ recorded.add(key);
61
+ }
62
+ ensureRegularOfficeDirectory(dir);
63
+ return dir;
64
+ },
65
+ });
66
+ offices.set(key, office);
67
+ return office;
68
+ },
69
+ });
70
+ return workspace;
71
+ }
72
+ /** mkdir-if-missing with the same fail-closed type guard as projection roots. */
73
+ function ensureRegularOfficeDirectory(dir) {
74
+ let stats;
75
+ try {
76
+ stats = lstatSync(dir);
77
+ }
78
+ catch (err) {
79
+ if (err.code !== "ENOENT")
80
+ throw err;
81
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
82
+ return;
83
+ }
84
+ if (stats.isSymbolicLink() || !stats.isDirectory()) {
85
+ throw new Error(`Office directory must be a regular non-symlink directory: ${dir}`);
86
+ }
87
+ }
88
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.js","sourceRoot":"","sources":["../../src/office/layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAI/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAwB,MAAM,CAAC,MAAM,CACxE,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CACrD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,OAA2C;IACzE,sEAAsE;IACtE,sEAAsE;IACtE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACnC,wEAAwE;IACxE,yDAAyD;IACzD,IAAI,QAAoC,CAAC;IACzC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE1C,MAAM,SAAS,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AK,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC;wBAC1C,QAAQ,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;wBAClC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;oBACpB,CAAC;oBACD,4BAA4B,CAAC,GAAG,CAAC,CAAC;oBAClC,OAAO,GAAG,CAAC;gBACb,CAAC;aACF,CAAC,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YACzB,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,iFAAiF;AACjF,SAAS,4BAA4B,CAAC,GAAW;IAC/C,IAAI,KAAK,CAAC;IACV,IAAI,CAAC;QACH,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAK,GAA6B,CAAC,IAAI,KAAK,QAAQ;YAAE,MAAM,GAAG,CAAC;QAChE,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACjD,OAAO;IACT,CAAC;IACD,IAAI,KAAK,CAAC,cAAc,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,6DAA6D,GAAG,EAAE,CAAC,CAAC;IACtF,CAAC;AACH,CAAC","sourcesContent":["import { lstatSync, mkdirSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { OfficeAddress } from \"../types.js\";\nimport type { Office, Workspace } from \"./types.js\";\nimport { officeKey, validateOfficeAddress } from \"./address.js\";\nimport { OfficeRegistry } from \"./registry.js\";\n\nexport type { Office, Workspace } from \"./types.js\";\n\n/**\n * Workspace-root entries that are shared infrastructure, never office dirs.\n * The single definition behind boot-time directory setup, the events\n * watcher, the workspace projection, and the migration's legacy-dir scan.\n */\nexport const RESERVED_WORKSPACE_NAMES: ReadonlySet<string> = Object.freeze(\n new Set([\"skills\", \"events\", \"agents\", \"MEMORY.md\"]),\n);\n\n/**\n * Construct the Workspace value for a deployment. One construction site per\n * process (main.ts for the daemon; CLI subcommands and tests build their\n * own). The value owns the registry instance and the recorded-office cache\n * that office materialization uses on hot paths, so there is no process-wide\n * registry state.\n */\nexport function createWorkspace(options: { root: string; stateDir: string }): Workspace {\n // Paths are joined as given (no resolve) so values match what callers\n // passing the same root/stateDir strings computed before this module.\n const { root, stateDir } = options;\n // Lazy: CLI surfaces construct a Workspace for path math without paying\n // for (or being allowed to create) the registry journal.\n let registry: OfficeRegistry | undefined;\n const recorded = new Set<string>();\n const offices = new Map<string, Office>();\n\n const workspace: Workspace = Object.freeze({\n root,\n stateDir,\n memoryPath: join(root, \"MEMORY.md\"),\n skillsDir: join(root, \"skills\"),\n eventsDir: join(root, \"events\"),\n agentsDir: join(root, \"agents\"),\n reservedNames: RESERVED_WORKSPACE_NAMES,\n office(address: OfficeAddress): Office {\n const normalized = validateOfficeAddress(address);\n const key = officeKey(normalized);\n const existing = offices.get(key);\n if (existing) return existing;\n\n const dir = join(root, key);\n const office: Office = Object.freeze({\n address: normalized,\n key,\n dir,\n memoryPath: join(dir, \"MEMORY.md\"),\n skillsDir: join(dir, \"skills\"),\n sessionsDir: join(dir, \"sessions\"),\n attachmentsDir: join(dir, \"attachments\"),\n logPath: join(dir, \"log.jsonl\"),\n stateDir: join(stateDir, \"conversations\", key),\n workspace,\n ensure(): string {\n // Record-first ordering: a crash can leave a record without a\n // directory (harmless; recreated on the next message) but never an\n // anonymous office directory the registry cannot enumerate.\n if (!recorded.has(key)) {\n registry ??= new OfficeRegistry(stateDir);\n registry.recordOffice(normalized);\n recorded.add(key);\n }\n ensureRegularOfficeDirectory(dir);\n return dir;\n },\n });\n offices.set(key, office);\n return office;\n },\n });\n return workspace;\n}\n\n/** mkdir-if-missing with the same fail-closed type guard as projection roots. */\nfunction ensureRegularOfficeDirectory(dir: string): void {\n let stats;\n try {\n stats = lstatSync(dir);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== \"ENOENT\") throw err;\n mkdirSync(dir, { recursive: true, mode: 0o700 });\n return;\n }\n if (stats.isSymbolicLink() || !stats.isDirectory()) {\n throw new Error(`Office directory must be a regular non-symlink directory: ${dir}`);\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { OfficeRecord } from "./types.js";
2
- import type { PlatformName } from "./types.js";
1
+ import type { OfficeRecord } from "../types.js";
2
+ import type { PlatformName } from "../types.js";
3
3
  export interface OfficeMigrationRunSummary {
4
4
  /** Raw ids whose directories moved to the office-key layout this run. */
5
5
  migrated: string[];
@@ -41,4 +41,4 @@ export declare function buildContainerBindTranslator(options: {
41
41
  workspaceRoot: string;
42
42
  stateDir: string;
43
43
  }): (bindSpec: string) => string;
44
- //# sourceMappingURL=office-migration.d.ts.map
44
+ //# sourceMappingURL=migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../src/office/migration.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,KAAK,EAAyB,YAAY,EAAE,MAAM,aAAa,CAAC;AAEvE,MAAM,WAAW,yBAAyB;IACxC,yEAAyE;IACzE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,uEAAuE;IACvE,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,wEAAwE;IACxE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,iEAAiE;IACjE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,yEAAyE;IACzE,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,gFAAgF;IAChF,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,wEAAwE;IACxE,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,gFAAgF;IAChF,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE;IAC5C,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,SAAS,YAAY,EAAE,CAAC;CAC3C,GAAG,yBAAyB,CAqC5B;AA4JD,+EAA+E;AAC/E,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,yBAAyB,GAAG,MAAM,CAsCvF;AAkBD,wBAAgB,4BAA4B,CAAC,OAAO,EAAE;IACpD,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CA2B/B"}
@@ -1,15 +1,11 @@
1
1
  import { existsSync, lstatSync, readdirSync, renameSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import * as log from "./log.js";
4
- import { isOfficeKey, officeKey, officeStateDir } from "./office-address.js";
5
- import { legacyConversationCredentialKey } from "./sandbox/identity.js";
6
- import { OfficeRegistry } from "./office-registry.js";
7
- import { migrateConversationVaultKeys } from "./vault/index.js";
8
- /**
9
- * Workspace-root entries that are shared infrastructure, never office dirs.
10
- * Mirrors the boot-time directory setup in main.ts.
11
- */
12
- const RESERVED_WORKSPACE_ENTRIES = new Set(["skills", "events", "agents"]);
3
+ import * as log from "../log.js";
4
+ import { isOfficeKey, officeKey, officeStateDir } from "./address.js";
5
+ import { RESERVED_WORKSPACE_NAMES } from "./layout.js";
6
+ import { legacyConversationCredentialKey } from "../sandbox/identity.js";
7
+ import { OfficeRegistry } from "./registry.js";
8
+ import { migrateConversationVaultKeys } from "../vault/index.js";
13
9
  /**
14
10
  * Move every legacy raw-id office directory under the workspace root to the
15
11
  * canonical office-key layout, journaling each move through the office
@@ -163,7 +159,7 @@ function listLegacyOfficeDirs(workspaceRoot) {
163
159
  for (const entry of readdirSync(workspaceRoot, { withFileTypes: true })) {
164
160
  if (entry.name.startsWith("."))
165
161
  continue;
166
- if (RESERVED_WORKSPACE_ENTRIES.has(entry.name))
162
+ if (RESERVED_WORKSPACE_NAMES.has(entry.name))
167
163
  continue;
168
164
  if (isOfficeKey(entry.name))
169
165
  continue;
@@ -256,4 +252,4 @@ export function buildContainerBindTranslator(options) {
256
252
  return `${source}:${target}${readOnly ? ":ro" : ""}`;
257
253
  };
258
254
  }
259
- //# sourceMappingURL=office-migration.js.map
255
+ //# sourceMappingURL=migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.js","sourceRoot":"","sources":["../../src/office/migration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AAsBjE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAIpC;IACC,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACtD,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,gBAAgB;QAAE,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAEnF,MAAM,OAAO,GAA8B;QACzC,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,EAAE;QACX,MAAM,EAAE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,CAAC,QAAQ,CAAC;QACzD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,SAAS,KAAK,CAAC,CAAC;YAAE,OAAO,QAAQ,CAAC;QACtC,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC;QAClE,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;QACpE,OAAO,GAAG,MAAM,IAAI,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACvD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { existsSync, lstatSync, readdirSync, renameSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport * as log from \"../log.js\";\nimport { isOfficeKey, officeKey, officeStateDir } from \"./address.js\";\nimport { RESERVED_WORKSPACE_NAMES } from \"./layout.js\";\nimport { legacyConversationCredentialKey } from \"../sandbox/identity.js\";\nimport type { OfficeRecord } from \"../types.js\";\nimport { OfficeRegistry } from \"./registry.js\";\nimport { migrateConversationVaultKeys } from \"../vault/index.js\";\nimport type { OfficeMigrationRecord, PlatformName } from \"../types.js\";\n\nexport interface OfficeMigrationRunSummary {\n /** Raw ids whose directories moved to the office-key layout this run. */\n migrated: string[];\n /** Raw ids whose interrupted moves were completed from the journal. */\n recovered: string[];\n /** Raw ids that still need an explicit owner (`mikan office claim`). */\n unowned: string[];\n /** Raw ids whose records are failed and need operator repair. */\n failed: string[];\n /** Raw ids whose conversation vault directories moved to office keys. */\n vaultKeysMigrated: string[];\n /** Raw ids whose legacy and office-key vault dirs both exist (manual merge). */\n vaultConflicts: string[];\n /** Raw ids whose host state dirs (settings, extensions, data) moved. */\n stateDirsMigrated: string[];\n /** Raw ids whose legacy and office-key state dirs both exist (manual merge). */\n stateDirConflicts: string[];\n}\n\n/**\n * Move every legacy raw-id office directory under the workspace root to the\n * canonical office-key layout, journaling each move through the office\n * registry so an interrupted run resumes instead of losing offices.\n *\n * The engine never guesses: with several enabled platforms an unowned raw\n * directory stays in place and is reported for `mikan office claim`. Callers\n * must treat a non-empty `unowned`/`failed` as fatal for daemon boot — after\n * the layout flip, an unmigrated legacy directory is invisible to the\n * runtime, which would silently present the conversation as empty.\n */\nexport function migrateLegacyOffices(options: {\n workspaceRoot: string;\n stateDir: string;\n enabledPlatforms: readonly PlatformName[];\n}): OfficeMigrationRunSummary {\n const registry = new OfficeRegistry(options.stateDir);\n for (const platform of options.enabledPlatforms) registry.enablePlatform(platform);\n\n const summary: OfficeMigrationRunSummary = {\n migrated: [],\n recovered: [],\n unowned: [],\n failed: [],\n vaultKeysMigrated: [],\n vaultConflicts: [],\n stateDirsMigrated: [],\n stateDirConflicts: [],\n };\n\n recoverInterruptedMoves(registry, summary);\n claimAndMoveLegacyDirs(registry, options.workspaceRoot, summary);\n\n // Credential vaults are keyed by office too; the registry inventory (which\n // the directory moves above just extended) drives the same rename.\n const vaults = migrateConversationVaultKeys({\n stateDir: options.stateDir,\n offices: registry.getOffices(),\n });\n summary.vaultKeysMigrated = vaults.migrated;\n summary.vaultConflicts = vaults.conflicts;\n for (const rawConversationId of vaults.migrated) {\n log.logInfo(`[office] Migrated vault key to office key: ${rawConversationId}`);\n }\n\n migrateConversationStateDirs(registry, options.stateDir, summary);\n\n for (const record of registry.getState().migrations) {\n if (record.status === \"needs-owner\") summary.unowned.push(record.rawConversationId);\n else if (record.status === \"failed\") summary.failed.push(record.rawConversationId);\n }\n return summary;\n}\n\n/** Complete or fail every move the journal says was interrupted mid-rename. */\nfunction recoverInterruptedMoves(\n registry: OfficeRegistry,\n summary: OfficeMigrationRunSummary,\n): void {\n for (const record of registry.getState().migrations) {\n if (record.status !== \"moving\") continue;\n const targetDir = record.targetDir;\n if (!targetDir) {\n registry.markFailed(record.rawConversationId, \"Moving record has no target directory\");\n continue;\n }\n const sourceExists = pathExists(record.sourceDir);\n const targetExists = pathExists(targetDir);\n if (sourceExists && targetExists) {\n registry.markFailed(\n record.rawConversationId,\n \"Both legacy source and office target exist; merge them manually\",\n );\n continue;\n }\n if (!sourceExists && !targetExists) {\n registry.markFailed(\n record.rawConversationId,\n \"Neither legacy source nor office target exists\",\n );\n continue;\n }\n if (sourceExists) renameSync(record.sourceDir, targetDir);\n registry.markCommitted(record.rawConversationId);\n recordMigratedOffice(registry, record);\n summary.recovered.push(record.rawConversationId);\n log.logInfo(`[office] Recovered interrupted migration: ${record.rawConversationId}`);\n }\n}\n\n/** Scan the workspace root and move every claimable legacy office directory. */\nfunction claimAndMoveLegacyDirs(\n registry: OfficeRegistry,\n workspaceRoot: string,\n summary: OfficeMigrationRunSummary,\n): void {\n for (const rawConversationId of listLegacyOfficeDirs(workspaceRoot)) {\n const existing = registry.getMigration(rawConversationId);\n if (existing?.status === \"committed\") {\n // The move already happened; a raw-id dir with this name reappearing\n // afterwards is a different (or resurrected) office the runtime can no\n // longer see. Refusing to boot beats silently ignoring its data.\n throw new Error(\n `Legacy office directory reappeared after migration: ${join(workspaceRoot, rawConversationId)}`,\n );\n }\n if (existing?.status === \"failed\") continue; // reported via summary.failed\n\n const record = registry.prepareLegacyMigration({\n rawConversationId,\n sourceDir: join(workspaceRoot, rawConversationId),\n workspaceRoot,\n });\n if (record.status === \"needs-owner\") continue; // reported via summary.unowned\n\n const moving = registry.markMoving(rawConversationId);\n const targetDir = moving.targetDir;\n if (!targetDir) throw new Error(\"Moving office migration has no target directory\");\n renameSync(moving.sourceDir, targetDir);\n registry.markCommitted(rawConversationId);\n recordMigratedOffice(registry, moving);\n summary.migrated.push(rawConversationId);\n log.logInfo(`[office] Migrated office directory: ${rawConversationId} -> ${targetDir}`);\n }\n}\n\n/**\n * Move each registered office's host state tree — settings.json, extensions,\n * extension-data, git checkouts — from `conversations/<rawId>` to\n * `conversations/<officeKey>` in one rename. Conflicts are reported for\n * manual merge, never clobbered.\n */\nfunction migrateConversationStateDirs(\n registry: OfficeRegistry,\n stateDir: string,\n summary: OfficeMigrationRunSummary,\n): void {\n for (const office of registry.getOffices()) {\n const legacyDir = join(stateDir, \"conversations\", office.conversationId);\n if (!existsSync(legacyDir)) continue;\n const targetDir = officeStateDir(stateDir, office);\n if (existsSync(targetDir)) {\n summary.stateDirConflicts.push(office.conversationId);\n continue;\n }\n renameSync(legacyDir, targetDir);\n summary.stateDirsMigrated.push(office.conversationId);\n log.logInfo(`[office] Migrated host state dir to office key: ${office.conversationId}`);\n }\n}\n\n/** A migrated office is an existing office; keep the directory enumerable. */\nfunction recordMigratedOffice(registry: OfficeRegistry, record: OfficeMigrationRecord): void {\n if (!record.ownerPlatform) return;\n registry.recordOffice({\n platform: record.ownerPlatform,\n conversationId: record.rawConversationId,\n });\n}\n\n/**\n * Legacy office candidates: regular directories that are not reserved\n * infrastructure, not hidden, and not already office-key named. A symlink in\n * office position is refused outright — following it could move data from\n * outside the workspace root.\n *\n * A candidate must also look like a conversation office: every office that\n * ever saw a message has a `log.jsonl`, and every office that ran the agent\n * has `sessions/`. Trusted workspace roots legitimately accumulate other\n * directories — repos the agent cloned, build output — which are not offices\n * and must be neither renamed nor reported as unowned; they stay where they\n * are (an operator can still claim one explicitly via `mikan office claim`).\n */\nfunction listLegacyOfficeDirs(workspaceRoot: string): string[] {\n const candidates: string[] = [];\n for (const entry of readdirSync(workspaceRoot, { withFileTypes: true })) {\n if (entry.name.startsWith(\".\")) continue;\n if (RESERVED_WORKSPACE_NAMES.has(entry.name)) continue;\n if (isOfficeKey(entry.name)) continue;\n if (entry.isSymbolicLink()) {\n throw new Error(`Workspace entry must not be a symlink: ${join(workspaceRoot, entry.name)}`);\n }\n if (!entry.isDirectory()) continue;\n if (!looksLikeConversationOffice(join(workspaceRoot, entry.name))) {\n log.logInfo(\n `[office] Skipping non-office workspace directory (no log.jsonl or sessions/): ${entry.name}`,\n );\n continue;\n }\n candidates.push(entry.name);\n }\n return candidates.toSorted();\n}\n\nfunction looksLikeConversationOffice(dir: string): boolean {\n return existsSync(join(dir, \"log.jsonl\")) || existsSync(join(dir, \"sessions\"));\n}\n\nfunction pathExists(path: string): boolean {\n try {\n lstatSync(path);\n return true;\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return false;\n throw err;\n }\n}\n\n/** Operator-facing boot failure for offices the engine may not move itself. */\nexport function formatUnmigratedOfficesError(summary: OfficeMigrationRunSummary): string {\n const lines = [\"Conversation office migration cannot complete:\"];\n if (summary.unowned.length > 0) {\n lines.push(\n \"\",\n \"These legacy conversation directories have no owning platform (several\",\n \"platforms are enabled, so ownership cannot be inferred):\",\n ...summary.unowned.map((id) => ` - ${id}`),\n \"\",\n \"Assign each one with:\",\n \" mikan office claim <conversationId> <platform>\",\n );\n }\n if (summary.failed.length > 0) {\n lines.push(\n \"\",\n \"These migrations previously failed and need manual repair (see\",\n \"office-registry.json in the state dir for each error):\",\n ...summary.failed.map((id) => ` - ${id}`),\n );\n }\n if (summary.vaultConflicts.length > 0) {\n lines.push(\n \"\",\n \"These conversations have credentials under both the legacy and the\",\n \"office-key vault directory; merge them manually under <state-dir>/vaults:\",\n ...summary.vaultConflicts.map((id) => ` - ${id}`),\n );\n }\n if (summary.stateDirConflicts.length > 0) {\n lines.push(\n \"\",\n \"These conversations have host state under both the legacy and the\",\n \"office-key directory; merge them manually under <state-dir>/conversations:\",\n ...summary.stateDirConflicts.map((id) => ` - ${id}`),\n );\n }\n return lines.join(\"\\n\");\n}\n\n/**\n * Bind-spec translator for the container layout migration: rewrites every\n * host path the office migration renamed — workspace dirs, per-conversation\n * state trees, conversation vaults — and the guest workspace segment, using\n * the registry's office inventory as the raw-id ↔ office mapping. Specs that\n * reference none of the renamed paths come back unchanged, which is also how\n * an already-migrated container is recognized.\n */\nfunction replacePrefix(path: string, pairs: Array<[string, string]>): string {\n for (const [oldPrefix, newPrefix] of pairs) {\n if (path === oldPrefix) return newPrefix;\n if (path.startsWith(`${oldPrefix}/`)) return newPrefix + path.slice(oldPrefix.length);\n }\n return path;\n}\n\nexport function buildContainerBindTranslator(options: {\n offices: readonly OfficeRecord[];\n workspaceRoot: string;\n stateDir: string;\n}): (bindSpec: string) => string {\n const hostPairs: Array<[string, string]> = [];\n const guestPairs: Array<[string, string]> = [];\n for (const office of options.offices) {\n const key = officeKey(office);\n const rawId = office.conversationId;\n hostPairs.push([join(options.workspaceRoot, rawId), join(options.workspaceRoot, key)]);\n hostPairs.push([\n join(options.stateDir, \"conversations\", rawId),\n officeStateDir(options.stateDir, office),\n ]);\n hostPairs.push([\n join(options.stateDir, \"vaults\", legacyConversationCredentialKey(rawId)),\n join(options.stateDir, \"vaults\", key),\n ]);\n guestPairs.push([`/workspace/${rawId}`, `/workspace/${key}`]);\n }\n\n return (bindSpec: string): string => {\n const readOnly = bindSpec.endsWith(\":ro\");\n const spec = readOnly ? bindSpec.slice(0, -3) : bindSpec;\n const separator = spec.indexOf(\":\");\n if (separator === -1) return bindSpec;\n const source = replacePrefix(spec.slice(0, separator), hostPairs);\n const target = replacePrefix(spec.slice(separator + 1), guestPairs);\n return `${source}:${target}${readOnly ? \":ro\" : \"\"}`;\n };\n}\n"]}
@@ -1,13 +1,13 @@
1
- import type { OfficeAddress, OfficeMigrationPreparation, OfficeMigrationRecord, OfficeRecord, OfficeRegistryState, PlatformName } from "./types.js";
1
+ import type { OfficeAddress, OfficeMigrationPreparation, OfficeMigrationRecord, OfficeRecord, OfficeRegistryState, PlatformName } from "../types.js";
2
2
  /**
3
3
  * Host-only office directory and migration journal.
4
4
  *
5
- * Office records are the durable raw-id ↔ (platform, office) mapping: once
6
- * the ADR 0005 layout migration renames workspace dirs to office keys, dir
7
- * names stop carrying raw platform ids, and enumeration/legacy-scope lookups
5
+ * Office records are the durable raw-id ↔ (platform, office) mapping: the
6
+ * ADR 0005 layout migration renamed workspace dirs to office keys, so dir
7
+ * names carry no raw platform ids and enumeration/legacy-scope lookups
8
8
  * resolve through these records. Migration records track claiming legacy
9
- * raw-id directories; existing runtime consumers keep their current layout
10
- * until that migration commit lands.
9
+ * raw-id directories. Office materialization lives in `layout.ts`; this
10
+ * module owns only the durable record and its crash-safe transitions.
11
11
  */
12
12
  interface OfficeRegistryOptions {
13
13
  writeState?: (path: string, content: string) => void;
@@ -57,25 +57,19 @@ export declare class OfficeRegistry {
57
57
  private readState;
58
58
  }
59
59
  /**
60
- * Materialize an office working directory: record the office in the registry,
61
- * then create the directory. Record-first ordering means a crash can leave a
62
- * record without a directory (harmless; recreated on the next message) but
63
- * never an anonymous office directory the registry cannot enumerate.
64
- *
65
- * This is the single creation seam for office dirs; read paths keep using
66
- * `conversationOfficeDir` and simply see missing files for unknown offices.
67
- */
68
- export declare function ensureOfficeDir(workspaceRoot: string, address: OfficeAddress): string;
69
- /**
70
- * Resolve the office behind a raw conversation id for surfaces that predate
71
- * OfficeAddress (Admin scope, settings mutation). The registry is the only
72
- * authority: office records first, then a committed migration's owner, then
73
- * the sole enabled platform. Two platforms sharing the raw id make the scope
60
+ * Resolve the office behind a raw conversation id for surfaces that name
61
+ * offices by raw id (CLI operators). The registry is the only authority:
62
+ * office records first, then a committed migration's owner, then the sole
63
+ * enabled platform. Two platforms sharing the raw id make the scope
74
64
  * genuinely ambiguous, and an unknown id has no office to resolve — both
75
65
  * fail loudly rather than guessing a directory.
66
+ *
67
+ * Constructs a registry per call, which re-reads the journal from disk; this
68
+ * is a one-shot CLI/Admin surface, never a per-message path (those go
69
+ * through the Workspace value's cached registry in `layout.ts`).
76
70
  */
77
- export declare function resolveOwnedOfficeAddress(rawConversationId: string, stateDir?: string): OfficeAddress;
78
- /** Current office inventory, re-read from disk for cross-process freshness. */
79
- export declare function listRegisteredOffices(): readonly OfficeRecord[];
71
+ export declare function resolveOwnedOfficeAddress(rawConversationId: string, stateDir: string): OfficeAddress;
72
+ /** Current office inventory, read fresh from disk for cross-process freshness. */
73
+ export declare function listRegisteredOffices(stateDir: string): readonly OfficeRecord[];
80
74
  export {};
81
- //# sourceMappingURL=office-registry.d.ts.map
75
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/office/registry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EACb,0BAA0B,EAC1B,qBAAqB,EAErB,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACb,MAAM,aAAa,CAAC;AA0BrB;;;;;;;;;GASG;AACH,UAAU,qBAAqB;IAC7B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0C;IACrE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,KAAK,CAAsB;IAEnC,YAAY,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,EAShE;IAED,6EAA6E;IAC7E,MAAM,IAAI,mBAAmB,CAG5B;IAED,QAAQ,IAAI,mBAAmB,CAE9B;IAED,YAAY,CAAC,iBAAiB,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAGzE;IAED,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,mBAAmB,CAS1D;IAED;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CAmBjD;IAED,UAAU,IAAI,SAAS,YAAY,EAAE,CAEpC;IAED,OAAO,CAAC,UAAU;IAOlB;;;;OAIG;IACH,sBAAsB,CAAC,OAAO,EAAE,0BAA0B,GAAG,qBAAqB,CAsDjF;IAED,UAAU,CAAC,iBAAiB,EAAE,MAAM,GAAG,qBAAqB,CAyB3D;IAED,aAAa,CAAC,iBAAiB,EAAE,MAAM,GAAG,qBAAqB,CAgB9D;IAED,UAAU,CAAC,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,qBAAqB,CAS1E;IAED,OAAO,CAAC,YAAY;IAkBpB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,gBAAgB;IAaxB,OAAO,CAAC,YAAY;IAUpB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,SAAS;CAelB;AA8VD;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CACvC,iBAAiB,EAAE,MAAM,EACzB,QAAQ,EAAE,MAAM,GACf,aAAa,CA4Bf;AAED,kFAAkF;AAClF,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,YAAY,EAAE,CAE/E"}
@@ -1,11 +1,10 @@
1
1
  import { randomBytes } from "node:crypto";
2
2
  import { lstatSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
3
3
  import { isAbsolute, join, resolve } from "node:path";
4
- import { officeDir, officeKey, assertConversationId, assertPlatformName, conversationOfficeDir, validateOfficeAddress, } from "./office-address.js";
5
- import { parseGithubConversationId } from "./adapters/github/ids.js";
6
- import { effectiveStateDir } from "./cli/arg-grammar.js";
7
- import { isRecord, readTextFileIfExists } from "./utils/file-guards.js";
8
- import { atomicWritePrivateFile } from "./utils/fs-atomic.js";
4
+ import { officeDir, officeKey, assertConversationId, assertPlatformName, validateOfficeAddress, } from "./address.js";
5
+ import { parseGithubConversationId } from "../adapters/github/ids.js";
6
+ import { isRecord, readTextFileIfExists } from "../utils/file-guards.js";
7
+ import { atomicWritePrivateFile } from "../utils/fs-atomic.js";
9
8
  const REGISTRY_VERSION = 1;
10
9
  const REGISTRY_FILENAME = "office-registry.json";
11
10
  const MIGRATION_STATUSES = new Set([
@@ -566,67 +565,25 @@ function registryLockIsStale(lockPath) {
566
565
  function sleepSync(milliseconds) {
567
566
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, milliseconds);
568
567
  }
569
- // ── office materialization ────────────────────────────────────────────────────
568
+ // ── raw-id lookups (cold paths: CLI, Admin enumeration) ──────────────────────
570
569
  /**
571
- * Process-wide registries keyed by state dir. Office materialization happens
572
- * on hot per-message paths (log appends, attachment writes), so each state
573
- * dir keeps one registry instance plus the set of office keys already
574
- * recorded; after the first sighting an office costs one Set lookup.
575
- */
576
- const registriesByStateDir = new Map();
577
- const recordedOfficesByStateDir = new Map();
578
- function registryFor(stateDir) {
579
- const key = resolve(stateDir);
580
- const existing = registriesByStateDir.get(key);
581
- if (existing)
582
- return existing;
583
- const registry = new OfficeRegistry(key);
584
- registriesByStateDir.set(key, registry);
585
- return registry;
586
- }
587
- /**
588
- * Materialize an office working directory: record the office in the registry,
589
- * then create the directory. Record-first ordering means a crash can leave a
590
- * record without a directory (harmless; recreated on the next message) but
591
- * never an anonymous office directory the registry cannot enumerate.
592
- *
593
- * This is the single creation seam for office dirs; read paths keep using
594
- * `conversationOfficeDir` and simply see missing files for unknown offices.
595
- */
596
- export function ensureOfficeDir(workspaceRoot, address) {
597
- const normalized = validateOfficeAddress(address);
598
- const stateKey = resolve(effectiveStateDir());
599
- const cached = recordedOfficesByStateDir.get(stateKey) ?? new Set();
600
- if (!recordedOfficesByStateDir.has(stateKey))
601
- recordedOfficesByStateDir.set(stateKey, cached);
602
- const key = officeKey(normalized);
603
- if (!cached.has(key)) {
604
- registryFor(stateKey).recordOffice(normalized);
605
- cached.add(key);
606
- }
607
- const dir = conversationOfficeDir(workspaceRoot, normalized);
608
- ensureRegularOfficeDirectory(dir);
609
- return dir;
610
- }
611
- /**
612
- * Resolve the office behind a raw conversation id for surfaces that predate
613
- * OfficeAddress (Admin scope, settings mutation). The registry is the only
614
- * authority: office records first, then a committed migration's owner, then
615
- * the sole enabled platform. Two platforms sharing the raw id make the scope
570
+ * Resolve the office behind a raw conversation id for surfaces that name
571
+ * offices by raw id (CLI operators). The registry is the only authority:
572
+ * office records first, then a committed migration's owner, then the sole
573
+ * enabled platform. Two platforms sharing the raw id make the scope
616
574
  * genuinely ambiguous, and an unknown id has no office to resolve — both
617
575
  * fail loudly rather than guessing a directory.
576
+ *
577
+ * Constructs a registry per call, which re-reads the journal from disk; this
578
+ * is a one-shot CLI/Admin surface, never a per-message path (those go
579
+ * through the Workspace value's cached registry in `layout.ts`).
618
580
  */
619
- export function resolveOwnedOfficeAddress(rawConversationId, stateDir = effectiveStateDir()) {
581
+ export function resolveOwnedOfficeAddress(rawConversationId, stateDir) {
620
582
  assertConversationId(rawConversationId);
621
- const registry = registryFor(stateDir);
622
- const owners = () => registry.getState().offices.filter((record) => record.conversationId === rawConversationId);
623
- let matches = owners();
624
- if (matches.length === 0) {
625
- // Another process (the daemon, `mikan office claim`) may have written
626
- // since this instance loaded; check the file before giving up.
627
- registry.reload();
628
- matches = owners();
629
- }
583
+ const registry = new OfficeRegistry(stateDir);
584
+ const matches = registry
585
+ .getState()
586
+ .offices.filter((record) => record.conversationId === rawConversationId);
630
587
  if (matches.length === 1) {
631
588
  return { platform: matches[0].platform, conversationId: rawConversationId };
632
589
  }
@@ -644,27 +601,9 @@ export function resolveOwnedOfficeAddress(rawConversationId, stateDir = effectiv
644
601
  }
645
602
  throw new Error(`No office is registered for conversation id ${JSON.stringify(rawConversationId)}`);
646
603
  }
647
- /** Current office inventory, re-read from disk for cross-process freshness. */
648
- export function listRegisteredOffices() {
649
- const registry = registryFor(effectiveStateDir());
650
- registry.reload();
651
- return registry.getOffices();
652
- }
653
- /** mkdir-if-missing with the same fail-closed type guard as projection roots. */
654
- function ensureRegularOfficeDirectory(dir) {
655
- let stats;
656
- try {
657
- stats = lstatSync(dir);
658
- }
659
- catch (err) {
660
- if (!isErrno(err, "ENOENT"))
661
- throw err;
662
- mkdirSync(dir, { recursive: true, mode: 0o700 });
663
- return;
664
- }
665
- if (stats.isSymbolicLink() || !stats.isDirectory()) {
666
- throw new Error(`Office directory must be a regular non-symlink directory: ${dir}`);
667
- }
604
+ /** Current office inventory, read fresh from disk for cross-process freshness. */
605
+ export function listRegisteredOffices(stateDir) {
606
+ return new OfficeRegistry(stateDir).getOffices();
668
607
  }
669
608
  /**
670
609
  * Enabled platforms whose id format could have produced this raw
@@ -702,4 +641,4 @@ function isGithubConversationId(rawConversationId) {
702
641
  function isErrno(error, code) {
703
642
  return error instanceof Error && "code" in error && error.code === code;
704
643
  }
705
- //# sourceMappingURL=office-registry.js.map
644
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/office/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUtD,OAAO,EACL,SAAS,EACT,SAAS,EACT,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AACjD,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAwB;IACxD,aAAa;IACb,UAAU;IACV,QAAQ;IACR,WAAW;IACX,QAAQ;CACT,CAAC,CAAC;AACH,MAAM,sBAAsB,GAAG,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KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AAC1E,CAAC","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { lstatSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from \"node:fs\";\nimport { isAbsolute, join, resolve } from \"node:path\";\nimport type {\n OfficeAddress,\n OfficeMigrationPreparation,\n OfficeMigrationRecord,\n OfficeMigrationStatus,\n OfficeRecord,\n OfficeRegistryState,\n PlatformName,\n} from \"../types.js\";\nimport {\n officeDir,\n officeKey,\n assertConversationId,\n assertPlatformName,\n validateOfficeAddress,\n} from \"./address.js\";\nimport { parseGithubConversationId } from \"../adapters/github/ids.js\";\nimport { isRecord, readTextFileIfExists } from \"../utils/file-guards.js\";\nimport { atomicWritePrivateFile } from \"../utils/fs-atomic.js\";\n\nconst REGISTRY_VERSION = 1;\nconst REGISTRY_FILENAME = \"office-registry.json\";\nconst MIGRATION_STATUSES = new Set<OfficeMigrationStatus>([\n \"needs-owner\",\n \"prepared\",\n \"moving\",\n \"committed\",\n \"failed\",\n]);\nconst REGISTRY_LOCK_FILENAME = \".office-registry.lock\";\nconst REGISTRY_LOCK_RETRY_MS = 25;\nconst REGISTRY_LOCK_TIMEOUT_MS = 5_000;\nconst REGISTRY_LOCK_STALE_MS = 60_000;\n\n/**\n * Host-only office directory and migration journal.\n *\n * Office records are the durable raw-id ↔ (platform, office) mapping: the\n * ADR 0005 layout migration renamed workspace dirs to office keys, so dir\n * names carry no raw platform ids and enumeration/legacy-scope lookups\n * resolve through these records. Migration records track claiming legacy\n * raw-id directories. Office materialization lives in `layout.ts`; this\n * module owns only the durable record and its crash-safe transitions.\n */\ninterface OfficeRegistryOptions {\n writeState?: (path: string, content: string) => void;\n lockTimeoutMs?: number;\n}\n\nexport class OfficeRegistry {\n private readonly stateDir: string;\n private readonly registryPath: string;\n private readonly lockPath: string;\n private readonly writeState: (path: string, content: string) => void;\n private readonly lockTimeoutMs: number;\n private state: OfficeRegistryState;\n\n constructor(stateDir: string, options: OfficeRegistryOptions = {}) {\n this.stateDir = resolve(stateDir);\n mkdirSync(this.stateDir, { recursive: true, mode: 0o700 });\n assertRegularDirectory(this.stateDir, \"State directory\");\n this.registryPath = resolve(this.stateDir, REGISTRY_FILENAME);\n this.lockPath = join(this.stateDir, REGISTRY_LOCK_FILENAME);\n this.writeState = options.writeState ?? atomicWritePrivateFile;\n this.lockTimeoutMs = options.lockTimeoutMs ?? REGISTRY_LOCK_TIMEOUT_MS;\n this.state = this.readState();\n }\n\n /** Reload the atomic registry file after another host process changed it. */\n reload(): OfficeRegistryState {\n this.state = this.readState();\n return this.state;\n }\n\n getState(): OfficeRegistryState {\n return this.state;\n }\n\n getMigration(rawConversationId: string): OfficeMigrationRecord | undefined {\n assertConversationId(rawConversationId);\n return this.state.migrations.find((record) => record.rawConversationId === rawConversationId);\n }\n\n enablePlatform(platform: PlatformName): OfficeRegistryState {\n const validPlatform = assertPlatformName(platform);\n return this.withExclusiveLease(() => {\n if (this.state.enabledPlatforms.includes(validPlatform)) return this.state;\n\n const enabledPlatforms = [...this.state.enabledPlatforms, validPlatform].toSorted();\n this.replaceState(enabledPlatforms, this.state.offices, this.state.migrations);\n return this.state;\n });\n }\n\n /**\n * Record that an office exists. Idempotent: re-recording a known office is\n * a lock-free cache hit for callers that materialize directories per\n * message, so this sits safely on hot write paths.\n */\n recordOffice(address: OfficeAddress): OfficeRecord {\n const normalized = validateOfficeAddress(address);\n const existing = this.findOffice(normalized);\n if (existing) return existing;\n return this.withExclusiveLease(() => {\n const found = this.findOffice(normalized);\n if (found) return found;\n const record: OfficeRecord = Object.freeze({\n platform: normalized.platform,\n conversationId: normalized.conversationId,\n recordedAt: new Date().toISOString(),\n });\n this.replaceState(\n this.state.enabledPlatforms,\n [...this.state.offices, record],\n this.state.migrations,\n );\n return record;\n });\n }\n\n getOffices(): readonly OfficeRecord[] {\n return this.state.offices;\n }\n\n private findOffice(address: OfficeAddress): OfficeRecord | undefined {\n return this.state.offices.find(\n (record) =>\n record.platform === address.platform && record.conversationId === address.conversationId,\n );\n }\n\n /**\n * Validate and record a legacy directory. With exactly one enabled platform,\n * ownership is safe to infer. With zero or multiple platforms, the record\n * remains explicit `needs-owner` unless the caller supplies an owner.\n */\n prepareLegacyMigration(options: OfficeMigrationPreparation): OfficeMigrationRecord {\n const rawConversationId = assertConversationId(options.rawConversationId);\n const sourceDir = resolve(options.sourceDir);\n const workspaceRoot = resolve(options.workspaceRoot);\n return this.withExclusiveLease(() => {\n const existing = this.getMigration(rawConversationId);\n assertCanonicalSource(sourceDir, workspaceRoot, rawConversationId);\n if (existing) {\n assertSameMigrationInputs(existing, sourceDir, workspaceRoot);\n if (existing.status !== \"needs-owner\") return existing;\n }\n\n assertRegularDirectory(sourceDir, \"Legacy office source\");\n const ownerPlatform = this.resolveOwner(options.ownerPlatform, rawConversationId);\n if (!ownerPlatform) {\n const record = makeRecord({\n rawConversationId,\n sourceDir,\n workspaceRoot,\n status: \"needs-owner\",\n });\n this.replaceMigration(existing, record);\n return record;\n }\n\n const targetDir = officeDir(workspaceRoot, {\n platform: ownerPlatform,\n conversationId: rawConversationId,\n });\n if (pathExists(targetDir)) {\n const failed = makeRecord({\n rawConversationId,\n sourceDir,\n workspaceRoot,\n ownerPlatform,\n targetDir,\n status: \"failed\",\n error: \"Target office directory already exists\",\n });\n this.replaceMigration(existing, failed);\n throw new Error(`${failed.error}: ${targetDir}`);\n }\n\n const prepared = makeRecord({\n rawConversationId,\n sourceDir,\n workspaceRoot,\n ownerPlatform,\n targetDir,\n status: \"prepared\",\n });\n this.replaceMigration(existing, prepared);\n return prepared;\n });\n }\n\n markMoving(rawConversationId: string): OfficeMigrationRecord {\n return this.withExclusiveLease(() => {\n const record = this.requireMigration(rawConversationId);\n if (\n record.status === \"moving\" ||\n record.status === \"committed\" ||\n record.status === \"failed\"\n ) {\n return record;\n }\n if (record.status === \"needs-owner\") {\n throw new Error(`Legacy office ${JSON.stringify(rawConversationId)} still needs an owner`);\n }\n assertRegularDirectory(record.sourceDir, \"Legacy office source\");\n const targetDir = migrationTarget(record);\n if (!targetDir) throw new Error(\"Prepared office migration has no target directory\");\n if (pathExists(targetDir)) {\n const failed = this.failRecord(record, \"Target office directory appeared before moving\");\n throw new Error(`${failed.error}: ${targetDir}`);\n }\n\n const moving = transitionRecord(record, \"moving\");\n this.replaceMigration(record, moving);\n return moving;\n });\n }\n\n markCommitted(rawConversationId: string): OfficeMigrationRecord {\n return this.withExclusiveLease(() => {\n const record = this.requireMigration(rawConversationId);\n if (record.status === \"committed\" || record.status === \"failed\") return record;\n if (record.status !== \"moving\") {\n throw new Error(`Cannot commit office migration from ${record.status}`);\n }\n const targetDir = migrationTarget(record);\n if (!targetDir) throw new Error(\"Moving office migration has no target directory\");\n assertRegularDirectory(targetDir, \"Migrated office target\");\n assertPathAbsent(record.sourceDir, \"Legacy office source\");\n\n const committed = transitionRecord(record, \"committed\");\n this.replaceMigration(record, committed);\n return committed;\n });\n }\n\n markFailed(rawConversationId: string, error: string): OfficeMigrationRecord {\n return this.withExclusiveLease(() => {\n const record = this.requireMigration(rawConversationId);\n if (record.status === \"committed\") {\n throw new Error(\"A committed office migration cannot be marked failed\");\n }\n if (record.status === \"failed\") return record;\n return this.failRecord(record, error);\n });\n }\n\n private resolveOwner(\n ownerPlatform: PlatformName | undefined,\n rawConversationId: string,\n ): PlatformName | undefined {\n if (ownerPlatform !== undefined) {\n const validPlatform = assertPlatformName(ownerPlatform);\n if (!this.state.enabledPlatforms.includes(validPlatform)) {\n throw new Error(`Owner platform ${validPlatform} is not enabled`);\n }\n return validPlatform;\n }\n const candidates = platformsMatchingConversationIdFormat(\n rawConversationId,\n this.state.enabledPlatforms,\n );\n return candidates.length === 1 ? candidates[0] : undefined;\n }\n\n private requireMigration(rawConversationId: string): OfficeMigrationRecord {\n assertConversationId(rawConversationId);\n const record = this.getMigration(rawConversationId);\n if (!record) throw new Error(`No office migration registered for ${rawConversationId}`);\n return record;\n }\n\n private failRecord(record: OfficeMigrationRecord, error: string): OfficeMigrationRecord {\n const message = error.trim();\n if (!message) throw new Error(\"Office migration failure reason must not be empty\");\n const failed = transitionRecord(record, \"failed\", message);\n this.replaceMigration(record, failed);\n return failed;\n }\n\n private replaceMigration(\n previous: OfficeMigrationRecord | undefined,\n next: OfficeMigrationRecord,\n ): void {\n const migrations = [...this.state.migrations];\n const index = previous\n ? migrations.findIndex((record) => record.rawConversationId === previous.rawConversationId)\n : -1;\n if (index === -1) migrations.push(next);\n else migrations[index] = next;\n this.replaceState(this.state.enabledPlatforms, this.state.offices, migrations);\n }\n\n private replaceState(\n enabledPlatforms: readonly PlatformName[],\n offices: readonly OfficeRecord[],\n migrations: readonly OfficeMigrationRecord[],\n ): void {\n const candidate = freezeState({ enabledPlatforms, offices, migrations });\n this.writeState(this.registryPath, `${JSON.stringify(candidate, null, 2)}\\n`);\n this.state = candidate;\n }\n\n /**\n * Acquire the domain lease, reload while holding it, then perform one\n * read-modify-write. A future move transaction can retain the same lease\n * across its filesystem operation instead of splitting the transition.\n */\n private withExclusiveLease<T>(operation: () => T): T {\n const release = acquireRegistryLease(this.lockPath, this.lockTimeoutMs);\n try {\n this.state = this.readState();\n return operation();\n } finally {\n release();\n }\n }\n\n private readState(): OfficeRegistryState {\n assertRegistryFileSafe(this.registryPath);\n const raw = readTextFileIfExists(this.registryPath);\n if (raw === undefined) {\n return freezeState({ enabledPlatforms: [], offices: [], migrations: [] });\n }\n\n let value: unknown;\n try {\n value = JSON.parse(raw);\n } catch (error) {\n throw new Error(`Invalid office registry JSON at ${this.registryPath}`, { cause: error });\n }\n return parseState(value, this.registryPath);\n }\n}\n\ninterface RecordFields {\n rawConversationId: string;\n sourceDir: string;\n workspaceRoot: string;\n ownerPlatform?: PlatformName;\n targetDir?: string;\n status: OfficeMigrationStatus;\n error?: string;\n updatedAt?: string;\n}\n\nfunction makeRecord(fields: RecordFields): OfficeMigrationRecord {\n const record: OfficeMigrationRecord = {\n rawConversationId: fields.rawConversationId,\n sourceDir: fields.sourceDir,\n workspaceRoot: fields.workspaceRoot,\n ...(fields.ownerPlatform ? { ownerPlatform: fields.ownerPlatform } : {}),\n ...(fields.targetDir ? { targetDir: fields.targetDir } : {}),\n status: fields.status,\n ...(fields.error ? { error: fields.error } : {}),\n updatedAt: fields.updatedAt ?? new Date().toISOString(),\n };\n return Object.freeze(record);\n}\n\nfunction transitionRecord(\n record: OfficeMigrationRecord,\n status: OfficeMigrationStatus,\n error?: string,\n): OfficeMigrationRecord {\n const targetDir = migrationTarget(record);\n return makeRecord({\n rawConversationId: record.rawConversationId,\n sourceDir: record.sourceDir,\n workspaceRoot: record.workspaceRoot,\n ...(record.ownerPlatform ? { ownerPlatform: record.ownerPlatform } : {}),\n ...(targetDir ? { targetDir } : {}),\n status,\n ...(error ? { error } : {}),\n });\n}\n\nfunction migrationTarget(record: OfficeMigrationRecord): string | undefined {\n return record.ownerPlatform\n ? officeDir(record.workspaceRoot, {\n platform: record.ownerPlatform,\n conversationId: record.rawConversationId,\n })\n : undefined;\n}\n\nfunction freezeState(input: {\n enabledPlatforms: readonly PlatformName[];\n offices: readonly OfficeRecord[];\n migrations: readonly OfficeMigrationRecord[];\n}): OfficeRegistryState {\n return Object.freeze({\n version: REGISTRY_VERSION as 1,\n enabledPlatforms: Object.freeze([...input.enabledPlatforms]),\n offices: Object.freeze(input.offices.map((record) => Object.freeze({ ...record }))),\n migrations: Object.freeze(input.migrations.map((record) => Object.freeze({ ...record }))),\n });\n}\n\nfunction parseState(value: unknown, path: string): OfficeRegistryState {\n if (!isRecord(value) || value.version !== REGISTRY_VERSION) {\n throw new Error(`Invalid office registry version at ${path}`);\n }\n if (!Array.isArray(value.enabledPlatforms) || !Array.isArray(value.migrations)) {\n throw new Error(`Invalid office registry shape at ${path}`);\n }\n\n const enabledPlatforms = value.enabledPlatforms.map((platform) => {\n if (typeof platform !== \"string\") throw new Error(`Invalid enabled platform in ${path}`);\n return assertPlatformName(platform);\n });\n if (new Set(enabledPlatforms).size !== enabledPlatforms.length) {\n throw new Error(`Duplicate enabled platform in ${path}`);\n }\n\n // Files written before office records existed simply have no offices yet.\n const offices = (Array.isArray(value.offices) ? value.offices : []).map((entry) =>\n parseOfficeRecord(entry, path),\n );\n if (new Set(offices.map((record) => officeKey(record))).size !== offices.length) {\n throw new Error(`Duplicate office record in ${path}`);\n }\n\n const migrations = value.migrations.map((entry) => parseRecord(entry, path, enabledPlatforms));\n if (new Set(migrations.map((record) => record.rawConversationId)).size !== migrations.length) {\n throw new Error(`Duplicate office migration in ${path}`);\n }\n return freezeState({ enabledPlatforms, offices, migrations });\n}\n\nfunction parseOfficeRecord(value: unknown, path: string): OfficeRecord {\n if (!isRecord(value)) throw new Error(`Invalid office record in ${path}`);\n if (\n typeof value.platform !== \"string\" ||\n typeof value.conversationId !== \"string\" ||\n typeof value.recordedAt !== \"string\"\n ) {\n throw new Error(`Invalid office record fields in ${path}`);\n }\n return Object.freeze({\n platform: assertPlatformName(value.platform),\n conversationId: assertConversationId(value.conversationId),\n recordedAt: value.recordedAt,\n });\n}\n\nfunction parseRecord(\n value: unknown,\n path: string,\n enabledPlatforms: readonly PlatformName[],\n): OfficeMigrationRecord {\n if (!isRecord(value)) throw new Error(`Invalid office migration record in ${path}`);\n if (\n typeof value.rawConversationId !== \"string\" ||\n typeof value.sourceDir !== \"string\" ||\n typeof value.workspaceRoot !== \"string\" ||\n typeof value.status !== \"string\" ||\n typeof value.updatedAt !== \"string\"\n ) {\n throw new Error(`Invalid office migration fields in ${path}`);\n }\n assertConversationId(value.rawConversationId);\n if (!isAbsolute(value.sourceDir) || !isAbsolute(value.workspaceRoot)) {\n throw new Error(`Office migration paths must be absolute in ${path}`);\n }\n assertCanonicalSource(value.sourceDir, value.workspaceRoot, value.rawConversationId);\n if (!MIGRATION_STATUSES.has(value.status as OfficeMigrationStatus)) {\n throw new Error(`Invalid office migration status in ${path}`);\n }\n\n const ownerPlatform = optionalPlatform(value.ownerPlatform);\n const targetDir = optionalString(value.targetDir);\n const error = optionalString(value.error);\n if (ownerPlatform !== undefined && !enabledPlatforms.includes(ownerPlatform)) {\n throw new Error(`Office migration owner is not enabled in ${path}`);\n }\n if (value.status === \"needs-owner\" && (ownerPlatform !== undefined || targetDir !== undefined)) {\n throw new Error(`Needs-owner migration cannot have an owner or target in ${path}`);\n }\n if (\n value.status !== \"needs-owner\" &&\n value.status !== \"failed\" &&\n (ownerPlatform === undefined || targetDir === undefined)\n ) {\n throw new Error(`Prepared office migration is missing ownership in ${path}`);\n }\n if (ownerPlatform === undefined && targetDir !== undefined) {\n throw new Error(`Office migration target has no owner in ${path}`);\n }\n const expectedTargetDir = ownerPlatform\n ? officeDir(value.workspaceRoot, {\n platform: ownerPlatform,\n conversationId: value.rawConversationId,\n })\n : undefined;\n if (targetDir !== expectedTargetDir) {\n throw new Error(`Office migration target does not match its office address in ${path}`);\n }\n if (value.status === \"failed\" && !error) {\n throw new Error(`Failed office migration is missing an error in ${path}`);\n }\n\n return makeRecord({\n rawConversationId: value.rawConversationId,\n sourceDir: value.sourceDir,\n workspaceRoot: value.workspaceRoot,\n ...(ownerPlatform ? { ownerPlatform } : {}),\n ...(expectedTargetDir ? { targetDir: expectedTargetDir } : {}),\n status: value.status as OfficeMigrationStatus,\n ...(error ? { error } : {}),\n updatedAt: value.updatedAt,\n });\n}\n\nfunction optionalPlatform(value: unknown): PlatformName | undefined {\n return value === undefined\n ? undefined\n : typeof value === \"string\"\n ? assertPlatformName(value)\n : failOptional(\"platform\");\n}\n\nfunction optionalString(value: unknown): string | undefined {\n return value === undefined\n ? undefined\n : typeof value === \"string\"\n ? value\n : failOptional(\"string\");\n}\n\nfunction failOptional(label: string): never {\n throw new Error(`Invalid optional ${label} in office registry`);\n}\n\nfunction assertSameMigrationInputs(\n existing: OfficeMigrationRecord,\n sourceDir: string,\n workspaceRoot: string,\n): void {\n if (existing.sourceDir !== sourceDir || existing.workspaceRoot !== workspaceRoot) {\n throw new Error(`Legacy office migration inputs changed for ${existing.rawConversationId}`);\n }\n}\n\nfunction assertCanonicalSource(\n sourceDir: string,\n workspaceRoot: string,\n rawConversationId: string,\n): void {\n const expectedSourceDir = resolve(workspaceRoot, rawConversationId);\n if (sourceDir !== expectedSourceDir) {\n throw new Error(`Legacy office source must be ${expectedSourceDir}`);\n }\n assertRegularDirectory(workspaceRoot, \"Workspace root\");\n assertPathIfPresent(sourceDir, \"Legacy office source\");\n}\n\nfunction assertRegularDirectory(path: string, label: string): void {\n let stat;\n try {\n stat = lstatSync(path);\n } catch (error) {\n throw new Error(`${label} does not exist: ${path}`, { cause: error });\n }\n if (stat.isSymbolicLink() || !stat.isDirectory()) {\n throw new Error(`${label} must be a regular directory: ${path}`);\n }\n}\n\nfunction assertRegistryFileSafe(path: string): void {\n try {\n const stat = lstatSync(path);\n if (stat.isSymbolicLink() || !stat.isFile()) {\n throw new Error(`Office registry must be a regular file: ${path}`);\n }\n } catch (error) {\n if (isErrno(error, \"ENOENT\")) return;\n throw error;\n }\n}\n\nfunction assertPathIfPresent(path: string, label: string): void {\n try {\n const stat = lstatSync(path);\n if (stat.isSymbolicLink() || !stat.isDirectory()) {\n throw new Error(`${label} must be a regular directory: ${path}`);\n }\n } catch (error) {\n if (isErrno(error, \"ENOENT\")) return;\n throw error;\n }\n}\n\nfunction assertPathAbsent(path: string, label: string): void {\n try {\n lstatSync(path);\n } catch (error) {\n if (isErrno(error, \"ENOENT\")) return;\n throw error;\n }\n throw new Error(`${label} must be absent: ${path}`);\n}\n\nfunction pathExists(path: string): boolean {\n try {\n lstatSync(path);\n return true;\n } catch (error) {\n if (isErrno(error, \"ENOENT\")) return false;\n throw error;\n }\n}\n\nfunction acquireRegistryLease(lockPath: string, timeoutMs: number): () => void {\n const deadline = Date.now() + timeoutMs;\n const token = `${process.pid}:${randomBytes(8).toString(\"hex\")}`;\n\n for (;;) {\n try {\n mkdirSync(lockPath, { mode: 0o700 });\n try {\n writeFileSync(join(lockPath, \"owner\"), `${token}\\n`, { mode: 0o600 });\n } catch (error) {\n rmSync(lockPath, { recursive: true, force: true });\n throw error;\n }\n return () => releaseRegistryLease(lockPath, token);\n } catch (error) {\n if (!isErrno(error, \"EEXIST\")) throw error;\n if (registryLockIsStale(lockPath)) {\n rmSync(lockPath, { recursive: true, force: true });\n continue;\n }\n if (Date.now() >= deadline) {\n throw new Error(`Timed out acquiring office registry lock: ${lockPath}`, { cause: error });\n }\n sleepSync(REGISTRY_LOCK_RETRY_MS);\n }\n }\n}\n\nfunction releaseRegistryLease(lockPath: string, token: string): void {\n try {\n if (readFileSync(join(lockPath, \"owner\"), \"utf8\").trim() === token) {\n rmSync(lockPath, { recursive: true, force: true });\n }\n } catch (error) {\n if (!isErrno(error, \"ENOENT\")) throw error;\n }\n}\n\nfunction registryLockIsStale(lockPath: string): boolean {\n let ownerKnown = false;\n let ownerAlive = false;\n try {\n const owner = readFileSync(join(lockPath, \"owner\"), \"utf8\").trim();\n const pid = Number(owner.split(\":\", 1)[0]);\n if (Number.isInteger(pid) && pid > 0) {\n ownerKnown = true;\n try {\n process.kill(pid, 0);\n ownerAlive = true;\n } catch (error) {\n if (isErrno(error, \"EPERM\")) ownerAlive = true;\n }\n }\n } catch {\n // The owner file may not have been written before its process died.\n }\n try {\n const oldEnough = Date.now() - statSync(lockPath).mtimeMs >= REGISTRY_LOCK_STALE_MS;\n return ownerKnown ? !ownerAlive : oldEnough;\n } catch {\n return false;\n }\n}\n\nfunction sleepSync(milliseconds: number): void {\n Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, milliseconds);\n}\n\n// ── raw-id lookups (cold paths: CLI, Admin enumeration) ──────────────────────\n\n/**\n * Resolve the office behind a raw conversation id for surfaces that name\n * offices by raw id (CLI operators). The registry is the only authority:\n * office records first, then a committed migration's owner, then the sole\n * enabled platform. Two platforms sharing the raw id make the scope\n * genuinely ambiguous, and an unknown id has no office to resolve — both\n * fail loudly rather than guessing a directory.\n *\n * Constructs a registry per call, which re-reads the journal from disk; this\n * is a one-shot CLI/Admin surface, never a per-message path (those go\n * through the Workspace value's cached registry in `layout.ts`).\n */\nexport function resolveOwnedOfficeAddress(\n rawConversationId: string,\n stateDir: string,\n): OfficeAddress {\n assertConversationId(rawConversationId);\n const registry = new OfficeRegistry(stateDir);\n\n const matches = registry\n .getState()\n .offices.filter((record) => record.conversationId === rawConversationId);\n if (matches.length === 1) {\n return { platform: matches[0].platform, conversationId: rawConversationId };\n }\n if (matches.length > 1) {\n throw new Error(\n `Conversation id ${JSON.stringify(rawConversationId)} names offices on several platforms; ` +\n \"use a platform-scoped surface instead\",\n );\n }\n\n const migration = registry.getMigration(rawConversationId);\n if (migration?.ownerPlatform) {\n return { platform: migration.ownerPlatform, conversationId: rawConversationId };\n }\n const { enabledPlatforms } = registry.getState();\n if (enabledPlatforms.length === 1) {\n return { platform: enabledPlatforms[0], conversationId: rawConversationId };\n }\n throw new Error(\n `No office is registered for conversation id ${JSON.stringify(rawConversationId)}`,\n );\n}\n\n/** Current office inventory, read fresh from disk for cross-process freshness. */\nexport function listRegisteredOffices(stateDir: string): readonly OfficeRecord[] {\n return new OfficeRegistry(stateDir).getOffices();\n}\n\n/**\n * Enabled platforms whose id format could have produced this raw\n * conversation id. Auto-claiming uses this as verification, not guessing:\n * every format below is one mikan itself writes (GitHub ids are mikan-derived\n * slugs; Slack/Telegram/Discord ids are the platforms' own grammars), and a\n * directory is only claimed when exactly one enabled platform's format\n * matches. Bare digits stay ambiguous while both Telegram and Discord are\n * enabled (negative ids are Telegram-only); anything matching no enabled\n * format fails closed to needs-owner.\n */\nfunction platformsMatchingConversationIdFormat(\n rawConversationId: string,\n enabledPlatforms: readonly PlatformName[],\n): PlatformName[] {\n return enabledPlatforms.filter((platform) => {\n switch (platform) {\n case \"github\":\n return isGithubConversationId(rawConversationId);\n case \"telegram\":\n return /^-?\\d+$/.test(rawConversationId);\n case \"discord\":\n return /^\\d+$/.test(rawConversationId);\n case \"slack\":\n return /^[A-Z][A-Z0-9]*$/.test(rawConversationId);\n }\n });\n}\n\nfunction isGithubConversationId(rawConversationId: string): boolean {\n try {\n parseGithubConversationId(rawConversationId);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction isErrno(error: unknown, code: string): error is NodeJS.ErrnoException {\n return error instanceof Error && \"code\" in error && error.code === code;\n}\n"]}
@@ -0,0 +1,71 @@
1
+ import type { OfficeAddress, OfficeKey } from "../types.js";
2
+ /**
3
+ * One mikan deployment's agent world on the host: the workspace root, the
4
+ * workspace-global surfaces, and the factory for per-conversation offices.
5
+ * Constructed once per process (`createWorkspace`); everything downstream
6
+ * receives the value instead of re-deriving paths from root strings.
7
+ */
8
+ export interface Workspace {
9
+ /** Host workspace root directory. */
10
+ readonly root: string;
11
+ /**
12
+ * Host-only state root (settings, credentials, extension code/data).
13
+ * Not part of the Workspace projection; carried here so offices can
14
+ * derive their state dirs and the registry knows where its journal lives.
15
+ */
16
+ readonly stateDir: string;
17
+ /** Workspace-global memory file: `<root>/MEMORY.md`. */
18
+ readonly memoryPath: string;
19
+ /** Workspace-global skills directory: `<root>/skills`. */
20
+ readonly skillsDir: string;
21
+ /** The workspace scheduling bus: `<root>/events` (global by design). */
22
+ readonly eventsDir: string;
23
+ /** Subagent profile patches: `<root>/agents`. */
24
+ readonly agentsDir: string;
25
+ /** Workspace-root entries that are shared infrastructure, never office dirs. */
26
+ readonly reservedNames: ReadonlySet<string>;
27
+ /**
28
+ * The Conversation office for an address. Values are memoized per address,
29
+ * so repeated calls on hot paths cost one map lookup, not a hash.
30
+ */
31
+ office(address: OfficeAddress): Office;
32
+ }
33
+ /**
34
+ * One Conversation office: canonical identity plus the office's host-side
35
+ * directory layout. A frozen value — every field is precomputed at
36
+ * construction. Fields exist only for paths that more than one module needs;
37
+ * single-consumer subpaths stay `join(office.dir, …)` at their call site.
38
+ */
39
+ export interface Office {
40
+ /** Canonical identity: platform plus raw platform conversation id. */
41
+ readonly address: OfficeAddress;
42
+ /**
43
+ * The office key — the collision-resistant directory segment, identical on
44
+ * the host and inside sandbox runtimes, and the conversation vault key.
45
+ */
46
+ readonly key: OfficeKey;
47
+ /** The office working directory: `<workspace root>/<key>`. */
48
+ readonly dir: string;
49
+ /** Conversation memory file: `<dir>/MEMORY.md`. */
50
+ readonly memoryPath: string;
51
+ /** Conversation skills directory: `<dir>/skills`. */
52
+ readonly skillsDir: string;
53
+ /** Persisted chat-session files: `<dir>/sessions`. */
54
+ readonly sessionsDir: string;
55
+ /** Downloaded message attachments: `<dir>/attachments`. */
56
+ readonly attachmentsDir: string;
57
+ /** Human-readable message history: `<dir>/log.jsonl`. */
58
+ readonly logPath: string;
59
+ /** Host-only per-office state: `<state dir>/conversations/<key>`. */
60
+ readonly stateDir: string;
61
+ /** The workspace this office belongs to. */
62
+ readonly workspace: Workspace;
63
+ /**
64
+ * Materialize the office working directory: record the office in the
65
+ * registry, then create the directory. Idempotent and safe on hot
66
+ * per-message paths — recording is cached, the mkdir is a guarded check.
67
+ * Returns `dir`.
68
+ */
69
+ ensure(): string;
70
+ }
71
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/office/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,qCAAqC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,wDAAwD;IACxD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,0DAA0D;IAC1D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,iDAAiD;IACjD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,gFAAgF;IAChF,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,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