@tienne/gestalt 0.128.1 → 0.130.0

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 (178) hide show
  1. package/CLAUDE.md +1 -0
  2. package/README.md +3 -0
  3. package/dist/package.json +2 -1
  4. package/dist/plugin/.codex-plugin/plugin.json +1 -1
  5. package/dist/plugin/skills/_shared/proactive-routing.md +1 -0
  6. package/dist/plugin/skills/architecture/SKILL.md +168 -140
  7. package/dist/plugin/skills/conductor/SKILL.md +180 -0
  8. package/dist/plugin/skills/handoff/SKILL.md +1 -1
  9. package/dist/schemas/architecture-ir.schema.json +40 -4
  10. package/dist/schemas/gestalt.schema.json +64 -0
  11. package/dist/src/agent-sync/config.d.ts +8 -8
  12. package/dist/src/architecture/delta.d.ts.map +1 -1
  13. package/dist/src/architecture/delta.js +6 -0
  14. package/dist/src/architecture/delta.js.map +1 -1
  15. package/dist/src/architecture/drilldown.d.ts +6 -2
  16. package/dist/src/architecture/drilldown.d.ts.map +1 -1
  17. package/dist/src/architecture/drilldown.js +114 -3
  18. package/dist/src/architecture/drilldown.js.map +1 -1
  19. package/dist/src/architecture/html-client.d.ts +2 -0
  20. package/dist/src/architecture/html-client.d.ts.map +1 -1
  21. package/dist/src/architecture/html-client.js +10 -4
  22. package/dist/src/architecture/html-client.js.map +1 -1
  23. package/dist/src/architecture/html-renderer.d.ts +9 -0
  24. package/dist/src/architecture/html-renderer.d.ts.map +1 -1
  25. package/dist/src/architecture/html-renderer.js +213 -64
  26. package/dist/src/architecture/html-renderer.js.map +1 -1
  27. package/dist/src/architecture/html-theme.d.ts +10 -1
  28. package/dist/src/architecture/html-theme.d.ts.map +1 -1
  29. package/dist/src/architecture/html-theme.js +102 -16
  30. package/dist/src/architecture/html-theme.js.map +1 -1
  31. package/dist/src/architecture/infra-layout.d.ts +87 -0
  32. package/dist/src/architecture/infra-layout.d.ts.map +1 -0
  33. package/dist/src/architecture/infra-layout.js +424 -0
  34. package/dist/src/architecture/infra-layout.js.map +1 -0
  35. package/dist/src/architecture/infra-placement.d.ts +16 -0
  36. package/dist/src/architecture/infra-placement.d.ts.map +1 -0
  37. package/dist/src/architecture/infra-placement.js +49 -0
  38. package/dist/src/architecture/infra-placement.js.map +1 -0
  39. package/dist/src/architecture/infra-router.d.ts +41 -0
  40. package/dist/src/architecture/infra-router.d.ts.map +1 -0
  41. package/dist/src/architecture/infra-router.js +309 -0
  42. package/dist/src/architecture/infra-router.js.map +1 -0
  43. package/dist/src/architecture/ir-schema.d.ts +28 -0
  44. package/dist/src/architecture/ir-schema.d.ts.map +1 -1
  45. package/dist/src/architecture/ir-schema.js +23 -3
  46. package/dist/src/architecture/ir-schema.js.map +1 -1
  47. package/dist/src/architecture/merge.d.ts.map +1 -1
  48. package/dist/src/architecture/merge.js +6 -2
  49. package/dist/src/architecture/merge.js.map +1 -1
  50. package/dist/src/architecture/store.d.ts.map +1 -1
  51. package/dist/src/architecture/store.js +1 -0
  52. package/dist/src/architecture/store.js.map +1 -1
  53. package/dist/src/architecture/types.d.ts +24 -2
  54. package/dist/src/architecture/types.d.ts.map +1 -1
  55. package/dist/src/architecture/types.js +19 -2
  56. package/dist/src/architecture/types.js.map +1 -1
  57. package/dist/src/architecture/validator.d.ts +9 -2
  58. package/dist/src/architecture/validator.d.ts.map +1 -1
  59. package/dist/src/architecture/validator.js +44 -1
  60. package/dist/src/architecture/validator.js.map +1 -1
  61. package/dist/src/architecture/vendor-icon-cache.d.ts +31 -0
  62. package/dist/src/architecture/vendor-icon-cache.d.ts.map +1 -0
  63. package/dist/src/architecture/vendor-icon-cache.js +358 -0
  64. package/dist/src/architecture/vendor-icon-cache.js.map +1 -0
  65. package/dist/src/architecture/vendor-icon-keys.d.ts +26 -0
  66. package/dist/src/architecture/vendor-icon-keys.d.ts.map +1 -0
  67. package/dist/src/architecture/vendor-icon-keys.js +154 -0
  68. package/dist/src/architecture/vendor-icon-keys.js.map +1 -0
  69. package/dist/src/architecture/vendor-icons.d.ts +43 -0
  70. package/dist/src/architecture/vendor-icons.d.ts.map +1 -0
  71. package/dist/src/architecture/vendor-icons.js +81 -0
  72. package/dist/src/architecture/vendor-icons.js.map +1 -0
  73. package/dist/src/cli/commands/conductor.d.ts +109 -0
  74. package/dist/src/cli/commands/conductor.d.ts.map +1 -0
  75. package/dist/src/cli/commands/conductor.js +466 -0
  76. package/dist/src/cli/commands/conductor.js.map +1 -0
  77. package/dist/src/cli/index.d.ts.map +1 -1
  78. package/dist/src/cli/index.js +151 -0
  79. package/dist/src/cli/index.js.map +1 -1
  80. package/dist/src/conductor/account-name.d.ts +6 -0
  81. package/dist/src/conductor/account-name.d.ts.map +1 -0
  82. package/dist/src/conductor/account-name.js +10 -0
  83. package/dist/src/conductor/account-name.js.map +1 -0
  84. package/dist/src/conductor/adapters.d.ts +101 -0
  85. package/dist/src/conductor/adapters.d.ts.map +1 -0
  86. package/dist/src/conductor/adapters.js +355 -0
  87. package/dist/src/conductor/adapters.js.map +1 -0
  88. package/dist/src/conductor/context.d.ts +12 -0
  89. package/dist/src/conductor/context.d.ts.map +1 -0
  90. package/dist/src/conductor/context.js +25 -0
  91. package/dist/src/conductor/context.js.map +1 -0
  92. package/dist/src/conductor/engine.d.ts +86 -0
  93. package/dist/src/conductor/engine.d.ts.map +1 -0
  94. package/dist/src/conductor/engine.js +730 -0
  95. package/dist/src/conductor/engine.js.map +1 -0
  96. package/dist/src/conductor/gates.d.ts +70 -0
  97. package/dist/src/conductor/gates.d.ts.map +1 -0
  98. package/dist/src/conductor/gates.js +153 -0
  99. package/dist/src/conductor/gates.js.map +1 -0
  100. package/dist/src/conductor/intake.d.ts +104 -0
  101. package/dist/src/conductor/intake.d.ts.map +1 -0
  102. package/dist/src/conductor/intake.js +263 -0
  103. package/dist/src/conductor/intake.js.map +1 -0
  104. package/dist/src/conductor/jira.d.ts +36 -0
  105. package/dist/src/conductor/jira.d.ts.map +1 -0
  106. package/dist/src/conductor/jira.js +72 -0
  107. package/dist/src/conductor/jira.js.map +1 -0
  108. package/dist/src/conductor/launcher.d.ts +196 -0
  109. package/dist/src/conductor/launcher.d.ts.map +1 -0
  110. package/dist/src/conductor/launcher.js +532 -0
  111. package/dist/src/conductor/launcher.js.map +1 -0
  112. package/dist/src/conductor/metrics.d.ts +81 -0
  113. package/dist/src/conductor/metrics.d.ts.map +1 -0
  114. package/dist/src/conductor/metrics.js +303 -0
  115. package/dist/src/conductor/metrics.js.map +1 -0
  116. package/dist/src/conductor/parent-worktree.d.ts +22 -0
  117. package/dist/src/conductor/parent-worktree.d.ts.map +1 -0
  118. package/dist/src/conductor/parent-worktree.js +113 -0
  119. package/dist/src/conductor/parent-worktree.js.map +1 -0
  120. package/dist/src/conductor/pr-ref.d.ts +5 -0
  121. package/dist/src/conductor/pr-ref.d.ts.map +1 -0
  122. package/dist/src/conductor/pr-ref.js +17 -0
  123. package/dist/src/conductor/pr-ref.js.map +1 -0
  124. package/dist/src/conductor/pr-watch.d.ts +46 -0
  125. package/dist/src/conductor/pr-watch.d.ts.map +1 -0
  126. package/dist/src/conductor/pr-watch.js +73 -0
  127. package/dist/src/conductor/pr-watch.js.map +1 -0
  128. package/dist/src/conductor/result.d.ts +24 -0
  129. package/dist/src/conductor/result.d.ts.map +1 -0
  130. package/dist/src/conductor/result.js +136 -0
  131. package/dist/src/conductor/result.js.map +1 -0
  132. package/dist/src/conductor/resume.d.ts +69 -0
  133. package/dist/src/conductor/resume.d.ts.map +1 -0
  134. package/dist/src/conductor/resume.js +187 -0
  135. package/dist/src/conductor/resume.js.map +1 -0
  136. package/dist/src/conductor/scheduler.d.ts +22 -0
  137. package/dist/src/conductor/scheduler.d.ts.map +1 -0
  138. package/dist/src/conductor/scheduler.js +13 -0
  139. package/dist/src/conductor/scheduler.js.map +1 -0
  140. package/dist/src/conductor/slack.d.ts +54 -0
  141. package/dist/src/conductor/slack.d.ts.map +1 -0
  142. package/dist/src/conductor/slack.js +105 -0
  143. package/dist/src/conductor/slack.js.map +1 -0
  144. package/dist/src/conductor/store.d.ts +68 -0
  145. package/dist/src/conductor/store.d.ts.map +1 -0
  146. package/dist/src/conductor/store.js +319 -0
  147. package/dist/src/conductor/store.js.map +1 -0
  148. package/dist/src/conductor/types.d.ts +254 -0
  149. package/dist/src/conductor/types.d.ts.map +1 -0
  150. package/dist/src/conductor/types.js +94 -0
  151. package/dist/src/conductor/types.js.map +1 -0
  152. package/dist/src/core/config.d.ts +66 -0
  153. package/dist/src/core/config.d.ts.map +1 -1
  154. package/dist/src/core/config.js +95 -3
  155. package/dist/src/core/config.js.map +1 -1
  156. package/dist/src/core/constants.d.ts +5 -0
  157. package/dist/src/core/constants.d.ts.map +1 -1
  158. package/dist/src/core/constants.js +5 -0
  159. package/dist/src/core/constants.js.map +1 -1
  160. package/dist/src/digest/lens-schema.d.ts +6 -6
  161. package/dist/src/digest/schema.d.ts +23 -23
  162. package/dist/src/lens/attach.d.ts +16 -16
  163. package/dist/src/mcp/tools/architecture-passthrough.d.ts.map +1 -1
  164. package/dist/src/mcp/tools/architecture-passthrough.js +19 -3
  165. package/dist/src/mcp/tools/architecture-passthrough.js.map +1 -1
  166. package/dist/src/research/schema.d.ts +30 -30
  167. package/dist/src/research/source-create.d.ts +2 -2
  168. package/dist/src/research/source-schema.d.ts +4 -4
  169. package/package.json +2 -1
  170. package/plugin/.codex-plugin/plugin.json +1 -1
  171. package/plugin/.mcp.json +1 -1
  172. package/plugin/mcp.json +1 -1
  173. package/plugin/skills/_shared/proactive-routing.md +1 -0
  174. package/plugin/skills/architecture/SKILL.md +168 -140
  175. package/plugin/skills/conductor/SKILL.md +180 -0
  176. package/plugin/skills/handoff/SKILL.md +1 -1
  177. package/schemas/architecture-ir.schema.json +40 -4
  178. package/schemas/gestalt.schema.json +64 -0
@@ -0,0 +1,81 @@
1
+ import { mkdirSync } from 'node:fs';
2
+ import { log } from '../core/log.js';
3
+ import { fetchVendor, needsFetch, readCached, readManifest, writeManifest, } from './vendor-icon-cache.js';
4
+ import { splitKey } from './vendor-icon-keys.js';
5
+ export const ICON_MODE_ENV = 'GESTALT_ARCH_ICONS';
6
+ export function iconModeFromEnv() {
7
+ const raw = process.env[ICON_MODE_ENV];
8
+ return raw === 'offline' || raw === 'off' ? raw : 'auto';
9
+ }
10
+ /** 아이콘 출처 표기. 상표는 각 소유자의 것이다 */
11
+ export const ICON_CREDITS = {
12
+ aws: 'AWS Architecture Icons',
13
+ gcp: 'Google Cloud product icons',
14
+ azure: 'Azure Public Service Icons',
15
+ };
16
+ /**
17
+ * iconKey 목록을 아이콘으로 바꾼다. 캐시에 있는 건 그대로 쓴다. auto 모드면 캐시에 없는 벤더 패키지를
18
+ * 한 번 받아 필요한 SVG만 캐시에 푼다. 어떤 실패도 던지지 않고 그 아이콘만 내장 아이콘으로 돌린다
19
+ */
20
+ export async function resolveVendorIcons(keys, opts) {
21
+ const mode = opts.mode ?? iconModeFromEnv();
22
+ const now = opts.now ?? (() => new Date());
23
+ const sorted = [...new Set(keys)].sort();
24
+ const icons = {};
25
+ const finish = () => {
26
+ const values = Object.values(icons);
27
+ return {
28
+ icons,
29
+ stats: {
30
+ official: values.filter((v) => v.source === 'official').length,
31
+ fallback: values.filter((v) => v.source === 'fallback').length,
32
+ },
33
+ };
34
+ };
35
+ if (mode === 'off') {
36
+ for (const k of sorted)
37
+ icons[k] = { source: 'fallback' };
38
+ return finish();
39
+ }
40
+ const dir = opts.cacheDir;
41
+ let manifest = readManifest(dir);
42
+ const at = now();
43
+ const missing = sorted.filter((k) => needsFetch(manifest.icons[k], at));
44
+ if (mode === 'auto' && missing.length > 0) {
45
+ const byVendor = new Map();
46
+ for (const k of missing) {
47
+ const [vendor, name] = splitKey(k);
48
+ if (vendor === undefined)
49
+ continue;
50
+ byVendor.set(vendor, [...(byVendor.get(vendor) ?? []), name]);
51
+ }
52
+ try {
53
+ mkdirSync(dir, { recursive: true });
54
+ // 벤더끼리는 서로 기다릴 이유가 없다. 한 벤더가 실패해도 나머지는 캐시에 쓴다
55
+ const vendors = [...byVendor.keys()].sort();
56
+ const results = await Promise.allSettled(vendors.map((v) => fetchVendor(v, byVendor.get(v), dir, manifest, {
57
+ fetchImpl: opts.fetchImpl ?? fetch,
58
+ now,
59
+ pageTimeoutMs: opts.pageTimeoutMs ?? 15_000,
60
+ packageTimeoutMs: opts.packageTimeoutMs ?? 120_000,
61
+ })));
62
+ results.forEach((r, i) => {
63
+ if (r.status === 'rejected') {
64
+ const message = r.reason instanceof Error ? r.reason.message : String(r.reason);
65
+ log(`architecture: ${vendors[i]} 아이콘을 받지 못해 내장 아이콘을 쓴다. ${message}`);
66
+ }
67
+ });
68
+ writeManifest(dir, manifest);
69
+ }
70
+ catch (e) {
71
+ log(`architecture: 아이콘 캐시를 쓰지 못했다. ${e instanceof Error ? e.message : String(e)}`);
72
+ }
73
+ manifest = readManifest(dir);
74
+ }
75
+ for (const k of sorted) {
76
+ const dataUri = readCached(dir, manifest.icons[k]);
77
+ icons[k] = dataUri !== undefined ? { source: 'official', dataUri } : { source: 'fallback' };
78
+ }
79
+ return finish();
80
+ }
81
+ //# sourceMappingURL=vendor-icons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vendor-icons.js","sourceRoot":"","sources":["../../../src/architecture/vendor-icons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EACL,WAAW,EACX,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,GACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAoCjD,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAElD,MAAM,UAAU,eAAe;IAC7B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACvC,OAAO,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,KAAK,CAAC,CA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과 워커가 실행 상태 저장소를 읽고 쓰는 명령.
3
+ *
4
+ * 컨덕터 세션은 이 명령의 짧은 출력만 대화에 싣는다. 저장소를 대화 밖에 두니까
5
+ * 세션이 압축되거나 다시 떠도 `status`로 진행 상황을 되찾는다.
6
+ * 실패하면 stderr에 이유를 쓰고 1로 끝난다.
7
+ */
8
+ export interface ConductorCommonOptions {
9
+ stateDir?: string;
10
+ json?: boolean;
11
+ }
12
+ export interface ConductorOrderAddOptions extends ConductorCommonOptions {
13
+ repo: string;
14
+ title: string;
15
+ description?: string;
16
+ /** 긴 설명은 셸 인용이 깨지기 쉬워 파일로 받는다. `-`면 stdin */
17
+ descriptionFile?: string;
18
+ scope?: string;
19
+ skills?: string;
20
+ workerKind?: string;
21
+ parentWorktree?: string;
22
+ baseBranch?: string;
23
+ source?: string;
24
+ sourceRef?: string;
25
+ issueKey?: string;
26
+ issueType?: string;
27
+ jiraStatus?: string;
28
+ pr?: string;
29
+ }
30
+ export declare function conductorOrderAddCommand(opts: ConductorOrderAddOptions): void;
31
+ export interface ConductorContextPathOptions extends ConductorCommonOptions {
32
+ repo: string;
33
+ }
34
+ /**
35
+ * 레포 공통 맥락 파일 경로를 알려 준다. 디렉토리는 만들어 두고 파일은 만들지 않는다.
36
+ * 컨덕터가 경로를 받아 직접 쓰고 워커는 지시서에 실린 경로로 읽는다.
37
+ */
38
+ export declare function conductorContextPathCommand(opts: ConductorContextPathOptions): void;
39
+ export interface ConductorStatusOptions extends ConductorCommonOptions {
40
+ /** 끝난 주문도 보여준다. bypass로 넘긴 일을 사후 보고할 때 쓴다 */
41
+ all?: boolean;
42
+ }
43
+ export declare function conductorStatusCommand(opts: ConductorStatusOptions): void;
44
+ export interface ConductorTickOptions extends ConductorCommonOptions {
45
+ force?: boolean;
46
+ prWatch?: boolean;
47
+ queue?: boolean;
48
+ }
49
+ export declare function conductorTickCommand(opts: ConductorTickOptions): Promise<void>;
50
+ export interface ConductorWorkerReportOptions extends ConductorCommonOptions {
51
+ worker: string;
52
+ status?: string;
53
+ summary?: string;
54
+ ref?: string[];
55
+ skill?: string;
56
+ pr?: string;
57
+ merged?: boolean;
58
+ stopReason?: string;
59
+ need?: string;
60
+ needDetail?: string;
61
+ spawnTitle?: string;
62
+ spawnDetail?: string;
63
+ file?: string;
64
+ }
65
+ export declare function conductorWorkerReportCommand(opts: ConductorWorkerReportOptions): void;
66
+ export declare function conductorGateListCommand(opts: ConductorCommonOptions): void;
67
+ export interface ConductorGateResolveOptions extends ConductorCommonOptions {
68
+ approve?: boolean;
69
+ reject?: boolean;
70
+ answer?: string;
71
+ }
72
+ export declare function conductorGateResolveCommand(gateId: string, opts: ConductorGateResolveOptions): Promise<void>;
73
+ export interface ConductorCheckpointSaveOptions extends ConductorCommonOptions {
74
+ worker: string;
75
+ skill: string;
76
+ next: string;
77
+ phase?: string;
78
+ round?: string;
79
+ done?: string;
80
+ shipDir?: string;
81
+ ref?: string[];
82
+ }
83
+ export declare function conductorCheckpointSaveCommand(opts: ConductorCheckpointSaveOptions): void;
84
+ export interface ConductorDeployReportOptions extends ConductorCommonOptions {
85
+ order: string;
86
+ status: string;
87
+ ref?: string;
88
+ }
89
+ export declare function conductorDeployReportCommand(opts: ConductorDeployReportOptions): void;
90
+ export interface ConductorQueueAddOptions extends ConductorCommonOptions {
91
+ bodyFile: string;
92
+ id?: string;
93
+ }
94
+ /** 외부 큐에 메시지를 넣는다. 웹훅 수신기 같은 바깥 프로세스가 부른다. `-`면 stdin에서 읽는다 */
95
+ export declare function conductorQueueAddCommand(opts: ConductorQueueAddOptions): void;
96
+ export interface ConductorSlackDraftOptions extends ConductorCommonOptions {
97
+ channel: string;
98
+ textFile: string;
99
+ order?: string;
100
+ thread?: string;
101
+ }
102
+ export declare function conductorSlackDraftCommand(opts: ConductorSlackDraftOptions): void;
103
+ export interface ConductorMetricsOptions {
104
+ since: string;
105
+ root?: string;
106
+ json?: boolean;
107
+ }
108
+ export declare function conductorMetricsCommand(opts: ConductorMetricsOptions): void;
109
+ //# sourceMappingURL=conductor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conductor.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/conductor.ts"],"names":[],"mappings":"AAyDA;;;;;;GAMG;AAEH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAwED,MAAM,WAAW,wBAAyB,SAAQ,sBAAsB;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAYD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,wBAAwB,GAAG,IAAI,CAkD7E;AAqBD,MAAM,WAAW,2BAA4B,SAAQ,sBAAsB;IACzE,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,2BAA2B,GAAG,IAAI,CAanF;AAED,MAAM,WAAW,sBAAuB,SAAQ,sBAAsB;IACpE,6CAA6C;IAC7C,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,sBAAsB,GAAG,IAAI,CA4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import { homedir } from 'node:os';
3
+ import { dirname, join, resolve } from 'node:path';
4
+ import { loadConfig } from '../../core/config.js';
5
+ import { gestaltPath } from '../../core/home.js';
6
+ import { fileDeploySource, fileQueue, GhAccounts, GhAccountSwitcher, GhPrWatchSource, hostJiraClient, hostSlackClient, writeDeploySignal, writeQueueMessage, } from '../../conductor/adapters.js';
7
+ import { deliverGateDecision, inboxDirOf, tick, writeReport, } from '../../conductor/engine.js';
8
+ import { existingRepoContext, repoContextPath } from '../../conductor/context.js';
9
+ import { resolveGate } from '../../conductor/gates.js';
10
+ import { intakeOrder, ISSUE_KEY_RE, KNOWN_SKILLS } from '../../conductor/intake.js';
11
+ import { assertCanSpawn, detectOrca, GitWorktreeLauncher, OrcaLauncher, SubagentLauncher, workerAt, } from '../../conductor/launcher.js';
12
+ import { measure } from '../../conductor/metrics.js';
13
+ import { resolveParentWorktree } from '../../conductor/parent-worktree.js';
14
+ import { normalizePrRef } from '../../conductor/pr-ref.js';
15
+ import { saveSkillCheckpoint } from '../../conductor/resume.js';
16
+ import { draftSlack } from '../../conductor/slack.js';
17
+ import { ConductorStore } from '../../conductor/store.js';
18
+ import { INTAKE_KINDS, ISSUE_TYPES, JIRA_STATUSES, ORDER_SCOPES, WORKER_KINDS, } from '../../conductor/types.js';
19
+ /** 상태 저장소 위치는 플래그, 환경 변수, 설정, 기본값 순서로 정한다 */
20
+ function open(opts) {
21
+ const config = loadConfig().conductor;
22
+ const dir = opts.stateDir ??
23
+ process.env['GESTALT_CONDUCTOR_STATE_DIR'] ??
24
+ config.stateDir ??
25
+ gestaltPath('conductor');
26
+ return { store: ConductorStore.open(resolve(dir)), config };
27
+ }
28
+ function launchersFor(ctx, env) {
29
+ const promptDir = join(ctx.store.dir, 'prompts');
30
+ const orca = detectOrca(env);
31
+ const launchers = {
32
+ subagent: new SubagentLauncher({ promptDir }),
33
+ 'git-worktree': new GitWorktreeLauncher({
34
+ worktreeRoot: join(ctx.store.dir, 'worktrees'),
35
+ promptDir,
36
+ repoPaths: ctx.config.repoPaths,
37
+ }),
38
+ };
39
+ if (orca) {
40
+ launchers['orca-worktree'] = new OrcaLauncher({
41
+ orcaCommand: orca,
42
+ promptDir,
43
+ repoPaths: ctx.config.repoPaths,
44
+ });
45
+ }
46
+ return { launchers, orcaAvailable: orca !== undefined };
47
+ }
48
+ /**
49
+ * 컨덕터 전용 명령(tick, gate resolve, order add, deploy report, queue add)을 워커 안에서 부르면 거절한다.
50
+ *
51
+ * 환경 변수는 호스트가 git 워크트리 세션을 열 때 넣어 준 경우에만 있다. 오르카 워커는 환경이
52
+ * 컨덕터와 같아서 작업 디렉토리가 살아 있는 워커의 워크트리 안인지로 가른다. 서브에이전트는
53
+ * 컨덕터와 같은 자리, 같은 환경이라 여기서 못 막고 지시서 규칙에만 기댄다. 사고를 막는 장치이지
54
+ * 적대적인 워커를 막는 경계는 아니다.
55
+ */
56
+ function assertConductorSession(ctx, command, cwd = process.cwd()) {
57
+ assertCanSpawn(process.env);
58
+ const w = workerAt(cwd, ctx.store.workers());
59
+ if (w)
60
+ throw new Error(`여기는 워커 ${w.id}(${w.orderId})의 워크트리라 \`gestalt conductor ${command}\`를 못 불러요. 컨덕터 세션에서 불러 주세요`);
61
+ }
62
+ /**
63
+ * 워커 세션에서 다른 워커 이름으로 보고나 체크포인트를 남기면 거절한다.
64
+ *
65
+ * `GESTALT_CONDUCTOR_WORKER_ID`는 git 워크트리 런처가 세션을 열 때만 넣는다. 오르카와 서브에이전트
66
+ * 워커는 이 값이 없어서 여기서 못 막는다. 실수로 남의 id를 적는 걸 막는 장치다.
67
+ */
68
+ function assertOwnWorkerId(worker, env = process.env) {
69
+ const self = env['GESTALT_CONDUCTOR_WORKER_ID'];
70
+ if (self && self !== worker) {
71
+ throw new Error(`이 세션은 워커 ${self}라 ${worker} 이름으로 못 남겨요`);
72
+ }
73
+ }
74
+ function resolveParent(input, repo, repoPaths) {
75
+ if (input === undefined)
76
+ return undefined;
77
+ const orca = detectOrca(process.env);
78
+ return resolveParentWorktree(input, repo, { repoPaths, ...(orca ? { orcaCommand: orca } : {}) });
79
+ }
80
+ export function conductorOrderAddCommand(opts) {
81
+ run(() => {
82
+ const ctx = open(opts);
83
+ assertConductorSession(ctx, 'order add');
84
+ const source = oneOf(opts.source ?? 'spoken', INTAKE_KINDS, '--source');
85
+ if (opts.description !== undefined && opts.descriptionFile !== undefined)
86
+ throw new Error('--description과 --description-file은 하나만 써 주세요');
87
+ const description = opts.descriptionFile !== undefined
88
+ ? readDescriptionFile(opts.descriptionFile)
89
+ : opts.description;
90
+ const parentWorktree = resolveParent(opts.parentWorktree, opts.repo, ctx.config.repoPaths);
91
+ const out = intakeOrder(ctx.store, {
92
+ source,
93
+ repo: opts.repo,
94
+ title: opts.title,
95
+ ...(opts.sourceRef ? { sourceRef: opts.sourceRef } : {}),
96
+ ...(description ? { description } : {}),
97
+ ...(opts.scope ? { scope: oneOf(opts.scope, ORDER_SCOPES, '--scope') } : {}),
98
+ ...(opts.skills ? { skillChain: skillList(opts.skills, '--skills') } : {}),
99
+ ...(opts.workerKind
100
+ ? { workerKind: oneOf(opts.workerKind, WORKER_KINDS, '--worker-kind') }
101
+ : {}),
102
+ ...(parentWorktree ? { parentWorktree } : {}),
103
+ ...(opts.baseBranch !== undefined ? { baseBranch: opts.baseBranch } : {}),
104
+ ...(opts.issueKey ? { issueKey: issueKey(opts.issueKey) } : {}),
105
+ ...(opts.issueType
106
+ ? { issueType: oneOf(opts.issueType, ISSUE_TYPES, '--issue-type') }
107
+ : {}),
108
+ ...(opts.jiraStatus
109
+ ? {
110
+ explicitJiraStatus: oneOf(opts.jiraStatus, JIRA_STATUSES, '--jira-status'),
111
+ }
112
+ : {}),
113
+ ...(opts.pr ? { prRef: prRef(opts.pr) } : {}),
114
+ }, { defaultScope: ctx.config.defaultScope }, { trusted: true });
115
+ if (opts.json)
116
+ return print({ created: out.created, order: out.order });
117
+ console.log(`${out.created ? '주문을 받았어요' : '이미 받은 주문이에요'}: ${out.order.id} (${out.order.scope})`);
118
+ });
119
+ }
120
+ /** 신뢰 경로라 길이로 자르지 않으니 엉뚱한 파일을 통째로 싣지 않게 크기에서 막는다 */
121
+ const DESCRIPTION_FILE_MAX = 64 * 1024;
122
+ function readDescriptionFile(file) {
123
+ if (file !== '-') {
124
+ const st = statSync(file, { throwIfNoEntry: false });
125
+ if (!st)
126
+ throw new Error(`설명 파일을 찾을 수 없어요: ${file}`);
127
+ if (!st.isFile())
128
+ throw new Error(`설명 파일이 일반 파일이 아니에요: ${file}`);
129
+ if (st.size > DESCRIPTION_FILE_MAX)
130
+ throw new Error(`설명 파일이 ${DESCRIPTION_FILE_MAX / 1024}KB를 넘어요: ${file}`);
131
+ }
132
+ const raw = readFileSync(file === '-' ? 0 : file, 'utf-8');
133
+ if (Buffer.byteLength(raw) > DESCRIPTION_FILE_MAX)
134
+ throw new Error(`설명이 ${DESCRIPTION_FILE_MAX / 1024}KB를 넘어요`);
135
+ const text = raw.trim();
136
+ if (!text)
137
+ throw new Error(`설명 파일이 비어 있어요: ${file}`);
138
+ return text;
139
+ }
140
+ /**
141
+ * 레포 공통 맥락 파일 경로를 알려 준다. 디렉토리는 만들어 두고 파일은 만들지 않는다.
142
+ * 컨덕터가 경로를 받아 직접 쓰고 워커는 지시서에 실린 경로로 읽는다.
143
+ */
144
+ export function conductorContextPathCommand(opts) {
145
+ run(() => {
146
+ const ctx = open(opts);
147
+ const path = repoContextPath(resolve(ctx.store.dir), opts.repo);
148
+ mkdirSync(dirname(path), { recursive: true });
149
+ if (opts.json)
150
+ return print({
151
+ repo: opts.repo,
152
+ path,
153
+ exists: existingRepoContext(ctx.store.dir, opts.repo) !== undefined,
154
+ });
155
+ console.log(path);
156
+ });
157
+ }
158
+ export function conductorStatusCommand(opts) {
159
+ run(() => {
160
+ const { store } = open(opts);
161
+ const orders = store.orders().filter((o) => opts.all || o.status !== 'done');
162
+ const gates = store.openGates();
163
+ const bypassesOf = new Map();
164
+ for (const b of store.snapshot.bypasses) {
165
+ const key = b.orderId ?? '';
166
+ const list = bypassesOf.get(key) ?? [];
167
+ list.push({ need: b.need, action: b.action, at: b.at });
168
+ bypassesOf.set(key, list);
169
+ }
170
+ if (opts.json) {
171
+ return print({
172
+ lastTickAt: store.snapshot.lastTickAt ?? null,
173
+ orders: orders.map((o) => ({
174
+ id: o.id,
175
+ status: o.status,
176
+ scope: o.scope,
177
+ repo: o.repo,
178
+ title: o.title,
179
+ ...(o.workerId ? { worker: o.workerId } : {}),
180
+ ...(o.prRef ? { pr: o.prRef } : {}),
181
+ ...(o.issueKey ? { issue: o.issueKey } : {}),
182
+ bypasses: bypassesOf.get(o.id) ?? [],
183
+ })),
184
+ unassignedBypasses: bypassesOf.get('') ?? [],
185
+ gates: gates.map((g) => ({
186
+ id: g.id,
187
+ type: g.type,
188
+ orderId: g.orderId ?? null,
189
+ reason: g.reason,
190
+ })),
191
+ });
192
+ }
193
+ console.log(`마지막 tick: ${store.snapshot.lastTickAt ?? '없음'}`);
194
+ for (const o of orders) {
195
+ console.log(`${o.id} ${o.status} ${o.scope} ${o.repo} ${o.title}`);
196
+ for (const b of bypassesOf.get(o.id) ?? [])
197
+ console.log(` bypass ${b.at} ${b.need} ${b.action}`);
198
+ }
199
+ for (const b of bypassesOf.get('') ?? [])
200
+ console.log(`bypass ${b.at} ${b.need} ${b.action}`);
201
+ for (const g of gates)
202
+ console.log(`게이트 ${g.id} ${g.type} ${g.reason}`);
203
+ });
204
+ }
205
+ export async function conductorTickCommand(opts) {
206
+ try {
207
+ const ctx = open(opts);
208
+ assertConductorSession(ctx, 'tick');
209
+ const deferred = [];
210
+ const prWatch = opts.prWatch !== false && Object.keys(ctx.config.repoPaths).length > 0;
211
+ // 토큰과 로그인 계정 캐시를 PR 감시와 계정 맞추기가 tick 하나 동안 함께 쓴다
212
+ const gh = new GhAccounts(ctx.config.accounts);
213
+ const prSource = prWatch
214
+ ? new GhPrWatchSource({ repoPaths: ctx.config.repoPaths, accounts: gh })
215
+ : undefined;
216
+ const queue = opts.queue !== false ? fileQueue(queueDirOf(ctx)) : undefined;
217
+ const deps = {
218
+ config: ctx.config,
219
+ ...launchersFor(ctx, process.env),
220
+ jira: hostJiraClient(deferred),
221
+ slack: hostSlackClient(deferred),
222
+ deploy: fileDeploySource(join(ctx.store.dir, 'deploy')),
223
+ ...(prSource ? { prSource } : {}),
224
+ ...(queue ? { queue } : {}),
225
+ ...(Object.keys(ctx.config.accounts).length > 0
226
+ ? { accounts: new GhAccountSwitcher({ accounts: gh }) }
227
+ : {}),
228
+ };
229
+ const report = await tick(ctx.store, deps, { force: opts.force === true });
230
+ report.hostActions.push(...deferred);
231
+ report.errors.push(...(queue?.errors ?? []));
232
+ for (const repo of prSource?.truncatedRepos ?? [])
233
+ report.errors.push(`${repo}: 열린 PR이 상한에 닿아 뒤쪽 PR은 이번 감시에서 빠졌어요`);
234
+ if (opts.json)
235
+ return print(report);
236
+ if (report.skipped) {
237
+ console.log(`건너뛰었어요${report.errors[0] ? `: ${report.errors[0]}` : ' (감시 간격 안)'}`);
238
+ return;
239
+ }
240
+ const c = report.counts;
241
+ console.log(`대기 ${c.queued}, 진행 ${c.running}, 게이트 ${c.openGates}, 새 주문 ${report.created.length}, 띄움 ${report.launched.length}`);
242
+ for (const a of report.hostActions)
243
+ console.log(`할 일: ${JSON.stringify(a)}`);
244
+ for (const w of report.warnings)
245
+ console.log(`경고: ${w}`);
246
+ for (const e of report.errors)
247
+ console.log(`오류: ${e}`);
248
+ }
249
+ catch (e) {
250
+ exitWithError(e);
251
+ }
252
+ }
253
+ export function conductorWorkerReportCommand(opts) {
254
+ run(() => {
255
+ assertOwnWorkerId(opts.worker);
256
+ const ctx = open(opts);
257
+ const fromFile = opts.file
258
+ ? JSON.parse(readFileSync(opts.file, 'utf-8'))
259
+ : {};
260
+ const raw = {
261
+ ...fromFile,
262
+ workerId: opts.worker,
263
+ ...(opts.status ? { status: opts.status } : {}),
264
+ ...(opts.summary ? { summary: opts.summary } : {}),
265
+ ...(opts.ref?.length ? { refs: opts.ref } : { refs: fromFile['refs'] ?? [] }),
266
+ ...(opts.skill ? { skill: opts.skill } : {}),
267
+ ...(opts.pr ? { prRef: prRef(opts.pr) } : {}),
268
+ ...(opts.merged ? { merged: true } : {}),
269
+ ...(opts.stopReason ? { stopReason: opts.stopReason } : {}),
270
+ ...(opts.need ? { need: { kind: opts.need, detail: opts.needDetail ?? '' } } : {}),
271
+ ...(opts.spawnTitle
272
+ ? { spawnRequest: { title: opts.spawnTitle, detail: opts.spawnDetail ?? '' } }
273
+ : {}),
274
+ };
275
+ const name = writeReport(inboxDirOf(ctx.store, {}), raw, ctx.config.resultMaxChars);
276
+ if (opts.json)
277
+ return print({ queued: name });
278
+ console.log('결과를 넘겼어요. 다음 tick에 반영돼요');
279
+ });
280
+ }
281
+ export function conductorGateListCommand(opts) {
282
+ run(() => {
283
+ const { store } = open(opts);
284
+ const gates = store.openGates();
285
+ if (opts.json)
286
+ return print(gates);
287
+ if (gates.length === 0)
288
+ console.log('열린 게이트가 없어요');
289
+ for (const g of gates) {
290
+ console.log(`${g.id} ${g.type} ${g.orderId ?? '-'} ${g.reason}`);
291
+ for (const r of g.refs)
292
+ console.log(` ${r}`);
293
+ }
294
+ });
295
+ }
296
+ export async function conductorGateResolveCommand(gateId, opts) {
297
+ try {
298
+ if (opts.approve === opts.reject)
299
+ throw new Error('--approve와 --reject 중 하나만 주세요');
300
+ const ctx = open(opts);
301
+ assertConductorSession(ctx, 'gate resolve');
302
+ const gate = ctx.store.snapshot.gates[gateId];
303
+ if (!gate)
304
+ throw new Error(`모르는 게이트예요: ${gateId}`);
305
+ if (gate.status !== 'open')
306
+ throw new Error(`이미 종료된 게이트예요: ${gateId}`);
307
+ const closed = resolveGate(ctx.store, gateId, opts.approve ? 'approved' : 'rejected', opts.answer);
308
+ const delivered = await deliverGateDecision(ctx.store, closed, launchersFor(ctx, process.env));
309
+ if (opts.json)
310
+ return print({ gate: closed, ...delivered });
311
+ console.log(`${gateId}를 ${closed.decision === 'approved' ? '승인' : '거절'}했어요`);
312
+ for (const a of delivered.hostActions)
313
+ console.log(`할 일: ${JSON.stringify(a)}`);
314
+ for (const e of delivered.errors)
315
+ console.log(`오류: ${e}`);
316
+ }
317
+ catch (e) {
318
+ exitWithError(e);
319
+ }
320
+ }
321
+ export function conductorCheckpointSaveCommand(opts) {
322
+ run(() => {
323
+ assertOwnWorkerId(opts.worker);
324
+ const ctx = open(opts);
325
+ const cp = saveSkillCheckpoint(ctx.store, {
326
+ workerId: opts.worker,
327
+ skill: opts.skill,
328
+ next: opts.next,
329
+ ...(opts.phase ? { phase: opts.phase } : {}),
330
+ ...(opts.round !== undefined ? { round: nonNegativeInt(opts.round, '--round') } : {}),
331
+ ...(opts.done ? { completedSkills: list(opts.done) } : {}),
332
+ ...(opts.shipDir ? { shipDir: opts.shipDir } : {}),
333
+ ...(opts.ref?.length ? { refs: opts.ref } : {}),
334
+ });
335
+ if (opts.json)
336
+ return print(cp);
337
+ console.log(`체크포인트를 남겼어요: ${cp.skill}${cp.phase ? ` ${cp.phase}` : ''}`);
338
+ });
339
+ }
340
+ export function conductorDeployReportCommand(opts) {
341
+ run(() => {
342
+ const ctx = open(opts);
343
+ assertConductorSession(ctx, 'deploy report');
344
+ const { store } = ctx;
345
+ if (!store.order(opts.order))
346
+ throw new Error(`모르는 주문이에요: ${opts.order}`);
347
+ const signal = {
348
+ status: oneOf(opts.status, DEPLOY_STATUSES, '--status'),
349
+ ...(opts.ref ? { ref: opts.ref } : {}),
350
+ };
351
+ writeDeploySignal(join(store.dir, 'deploy'), opts.order, signal);
352
+ if (opts.json)
353
+ return print({ orderId: opts.order, ...signal });
354
+ console.log('배포 결과를 남겼어요. 다음 tick에 반영돼요');
355
+ });
356
+ }
357
+ /** 외부 큐에 메시지를 넣는다. 웹훅 수신기 같은 바깥 프로세스가 부른다. `-`면 stdin에서 읽는다 */
358
+ export function conductorQueueAddCommand(opts) {
359
+ run(() => {
360
+ const ctx = open(opts);
361
+ // 워커가 큐로 주문을 만들면 하위 워커를 컨덕터 몰래 띄우는 길이 된다
362
+ assertConductorSession(ctx, 'queue add');
363
+ const raw = readFileSync(opts.bodyFile === '-' ? 0 : opts.bodyFile, 'utf-8');
364
+ let body;
365
+ try {
366
+ body = JSON.parse(raw);
367
+ }
368
+ catch (err) {
369
+ throw new Error(`JSON이 아니에요: ${String(err)}`, { cause: err });
370
+ }
371
+ const id = writeQueueMessage(queueDirOf(ctx), body, opts.id);
372
+ if (opts.json)
373
+ return print({ id, sourceRef: `queue:${id}` });
374
+ console.log(`큐에 넣었어요: ${id}. 다음 tick에 주문으로 받아요`);
375
+ });
376
+ }
377
+ function queueDirOf(ctx) {
378
+ return join(ctx.store.dir, 'queue');
379
+ }
380
+ export function conductorSlackDraftCommand(opts) {
381
+ run(() => {
382
+ const { store } = open(opts);
383
+ const text = readFileSync(opts.textFile, 'utf-8').trim();
384
+ if (!text)
385
+ throw new Error('초안이 비었어요');
386
+ const { gate, reused } = draftSlack(store, {
387
+ channel: opts.channel,
388
+ text,
389
+ ...(opts.order ? { orderId: opts.order } : {}),
390
+ ...(opts.thread ? { threadTs: opts.thread } : {}),
391
+ }, join(store.dir, 'slack'));
392
+ if (opts.json)
393
+ return print({ gateId: gate.id, reused });
394
+ console.log(`승인을 기다려요: ${gate.id}${reused ? ' (같은 초안이 이미 올라가 있어요)' : ''}`);
395
+ });
396
+ }
397
+ export function conductorMetricsCommand(opts) {
398
+ run(() => {
399
+ const since = Date.parse(opts.since);
400
+ if (Number.isNaN(since))
401
+ throw new Error(`--since 날짜를 못 읽었어요: ${opts.since}`);
402
+ const root = opts.root ?? join(homedir(), '.claude', 'projects');
403
+ const r = measure({ root, since });
404
+ if (opts.json)
405
+ return print(r);
406
+ const c = r.comparison;
407
+ const pct = (v) => (v === null ? '-' : `${Math.round(v * 100)}%`);
408
+ console.log(`기준 세션 ${c.baseline.sessions}개, 컨덕터 세션 ${c.current.sessions}개`);
409
+ console.log(`끼어든 발화 감소 ${pct(c.interventionReduction)} (목표 40%), 토큰 변화 ${pct(c.tokenDelta)} (목표 +10% 이내)`);
410
+ console.log(`판정: ${c.passed ? '통과' : '미달'}`);
411
+ for (const n of c.notes)
412
+ console.log(`- ${n}`);
413
+ });
414
+ }
415
+ function list(v) {
416
+ return v
417
+ .split(',')
418
+ .map((s) => s.trim())
419
+ .filter(Boolean);
420
+ }
421
+ const DEPLOY_STATUSES = ['success', 'failed', 'pending', 'unknown'];
422
+ function skillList(v, flag) {
423
+ const skills = list(v);
424
+ const unknown = skills.filter((s) => !KNOWN_SKILLS.has(s));
425
+ if (unknown.length > 0)
426
+ throw new Error(`${flag}에 모르는 스킬이 있어요: ${unknown.join(', ')}. ${[...KNOWN_SKILLS].join(', ')} 중에서 골라 주세요`);
427
+ return skills;
428
+ }
429
+ function issueKey(v) {
430
+ if (!ISSUE_KEY_RE.test(v))
431
+ throw new Error(`--issue-key는 PROJ-123 꼴이어야 해요: ${v}`);
432
+ return v;
433
+ }
434
+ function prRef(v) {
435
+ const ref = normalizePrRef(v);
436
+ if (!ref)
437
+ throw new Error(`--pr은 owner/name#번호나 GitHub PR 주소여야 해요: ${v}`);
438
+ return ref;
439
+ }
440
+ function oneOf(v, allowed, flag) {
441
+ if (!allowed.includes(v))
442
+ throw new Error(`${flag}는 ${allowed.join(', ')} 중 하나예요: ${v}`);
443
+ return v;
444
+ }
445
+ function nonNegativeInt(v, flag) {
446
+ const n = Number(v);
447
+ if (!Number.isInteger(n) || n < 0)
448
+ throw new Error(`${flag}는 0 이상의 정수여야 해요: ${v}`);
449
+ return n;
450
+ }
451
+ function print(v) {
452
+ console.log(JSON.stringify(v, null, 2));
453
+ }
454
+ function run(body) {
455
+ try {
456
+ body();
457
+ }
458
+ catch (e) {
459
+ exitWithError(e);
460
+ }
461
+ }
462
+ function exitWithError(e) {
463
+ console.error(e instanceof Error ? e.message : String(e));
464
+ process.exit(1);
465
+ }
466
+ //# sourceMappingURL=conductor.js.map