@di-code/coding-agent 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +489 -143
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +74 -0
- package/dist/cli.js.map +1 -1
- package/dist/core/clipboard-image.d.ts +13 -0
- package/dist/core/clipboard-image.d.ts.map +1 -0
- package/dist/core/clipboard-image.js +99 -0
- package/dist/core/clipboard-image.js.map +1 -0
- package/dist/core/image-input.d.ts +13 -0
- package/dist/core/image-input.d.ts.map +1 -0
- package/dist/core/image-input.js +102 -0
- package/dist/core/image-input.js.map +1 -0
- package/dist/core/resources/index.d.ts +3 -0
- package/dist/core/resources/index.d.ts.map +1 -0
- package/dist/core/resources/index.js +2 -0
- package/dist/core/resources/index.js.map +1 -0
- package/dist/core/resources/loader.d.ts +8 -0
- package/dist/core/resources/loader.d.ts.map +1 -0
- package/dist/core/resources/loader.js +174 -0
- package/dist/core/resources/loader.js.map +1 -0
- package/dist/core/resources/skills.d.ts +10 -0
- package/dist/core/resources/skills.d.ts.map +1 -0
- package/dist/core/resources/skills.js +167 -0
- package/dist/core/resources/skills.js.map +1 -0
- package/dist/core/resources/types.d.ts +41 -0
- package/dist/core/resources/types.d.ts.map +1 -0
- package/dist/core/resources/types.js +2 -0
- package/dist/core/resources/types.js.map +1 -0
- package/dist/core/session.d.ts +10 -1
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +33 -5
- package/dist/core/session.js.map +1 -1
- package/dist/core/skill-command.d.ts +3 -0
- package/dist/core/skill-command.d.ts.map +1 -0
- package/dist/core/skill-command.js +34 -0
- package/dist/core/skill-command.js.map +1 -0
- package/dist/core/system-prompt.d.ts +6 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +57 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/extensions/runtime.d.ts +7 -4
- package/dist/extensions/runtime.d.ts.map +1 -1
- package/dist/extensions/runtime.js +45 -10
- package/dist/extensions/runtime.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +1 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +91 -2
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive-components.d.ts +1 -0
- package/dist/modes/interactive-components.d.ts.map +1 -1
- package/dist/modes/interactive-components.js +48 -20
- package/dist/modes/interactive-components.js.map +1 -1
- package/dist/modes/interactive-layout.d.ts +2 -1
- package/dist/modes/interactive-layout.d.ts.map +1 -1
- package/dist/modes/interactive-layout.js +17 -1
- package/dist/modes/interactive-layout.js.map +1 -1
- package/dist/modes/interactive-state.d.ts +12 -2
- package/dist/modes/interactive-state.d.ts.map +1 -1
- package/dist/modes/interactive-state.js +50 -3
- package/dist/modes/interactive-state.js.map +1 -1
- package/dist/modes/interactive.d.ts +12 -0
- package/dist/modes/interactive.d.ts.map +1 -1
- package/dist/modes/interactive.js +125 -9
- package/dist/modes/interactive.js.map +1 -1
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +5 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/loader.d.ts +18 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +92 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manager.d.ts +23 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +152 -0
- package/dist/plugins/manager.js.map +1 -0
- package/dist/plugins/manifest.d.ts +7 -0
- package/dist/plugins/manifest.d.ts.map +1 -0
- package/dist/plugins/manifest.js +116 -0
- package/dist/plugins/manifest.js.map +1 -0
- package/dist/plugins/types.d.ts +41 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +2 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/provider-onboarding.d.ts.map +1 -1
- package/dist/provider-onboarding.js +20 -1
- package/dist/provider-onboarding.js.map +1 -1
- package/dist/startup.d.ts.map +1 -1
- package/dist/startup.js +65 -16
- package/dist/startup.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +2 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -0
- package/dist/utils/syntax-highlight.js +55 -0
- package/dist/utils/syntax-highlight.js.map +1 -0
- package/package.json +19 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive.js","sourceRoot":"","sources":["../../src/modes/interactive.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,4BAA4B,EAC5B,MAAM,EAEN,UAAU,EACV,YAAY,GAEZ,MAAM,cAAc,CAAC;AAEtB,OAAO,EACN,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,GAEjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAI/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAgB/D,MAAM,OAAO,eAAe;IACV,UAAU,GAAG,IAAI,qBAAqB,EAAE,CAAC;IACzC,IAAI,CAAoB;IACxB,MAAM,CAAS;IACxB,OAAO,CAAe;IACb,GAAG,CAAM;IACT,cAAc,CAAsC;IAC7D,kBAAkB,CAAc;IAChC,gBAAgB,GAAG,KAAK,CAAC;IACzB,cAAc,GAAG,KAAK,CAAC;IACvB,kBAAkB,GAAG,KAAK,CAAC;IAC3B,WAAW,CAAmB;IAC9B,OAAO,GAAG,KAAK,CAAC;IAChB,gBAAgB,CAAU;IAC1B,aAAa,GAAa,EAAE,CAAC;IACpB,MAAM,CAAc;IAC7B,KAAK,GAAqB,MAAM,CAAC;IACjC,OAAO,CAAiB;IACxB,mBAAmB,CAA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AAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAClF,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;YAChC,IAAI,CAAC,OAAO,EAAE,CAAC;QAChB,CAAC;IACF,CAAC;CACD","sourcesContent":["import {\n\ttype AutocompleteProvider,\n\tCombinedAutocompleteProvider,\n\tEditor,\n\ttype OverlayHandle,\n\tSelectList,\n\tSettingsList,\n\ttype TUI,\n} from \"@di-code/tui\";\nimport type { AgentSession, AgentSessionEvent } from \"../core/session.ts\";\nimport {\n\tAutocompleteMenu,\n\tInteractiveChat,\n\tInteractiveComposer,\n\tInteractiveFooter,\n\tInteractiveHeader,\n\ttype InteractiveViewState,\n} from \"./interactive-components.ts\";\nimport { InteractiveLayout } from \"./interactive-layout.ts\";\nimport { InteractiveProjection } from \"./interactive-state.ts\";\n\nexport type { AgentSessionEvent };\nexport type { InteractiveMessage, InteractiveProcessItem, InteractiveState } from \"./interactive-state.ts\";\nexport { InteractiveProjection } from \"./interactive-state.ts\";\n\nexport interface InteractiveModeOptions {\n\treadonly session: AgentSession;\n\treadonly tui: TUI;\n\treadonly onExit?: () => void;\n\treadonly sessions?: readonly InteractiveSessionChoice[];\n}\n\nexport interface InteractiveSessionChoice {\n\treadonly id: string;\n\treadonly label: string;\n\treadonly description?: string;\n\topen(): AgentSession | Promise<AgentSession>;\n}\n\nexport class InteractiveMode {\n\tprivate readonly projection = new InteractiveProjection();\n\tprivate readonly root: InteractiveLayout;\n\tprivate readonly editor: Editor;\n\tprivate session: AgentSession;\n\tprivate readonly tui: TUI;\n\tprivate readonly sessionChoices: readonly InteractiveSessionChoice[];\n\tprivate unsubscribeSession?: () => void;\n\tprivate sessionSwitching = false;\n\tprivate promptInFlight = false;\n\tprivate compactionInFlight = false;\n\tprivate activeAbort?: AbortController;\n\tprivate started = false;\n\tprivate lastFailedPrompt?: string;\n\tprivate queuedPrompts: string[] = [];\n\tprivate readonly onExit?: () => void;\n\tprivate theme: \"dark\" | \"light\" = \"dark\";\n\tprivate overlay?: OverlayHandle;\n\tprivate autocompleteOverlay?: OverlayHandle;\n\tprivate spinnerTimer?: ReturnType<typeof setInterval>;\n\n\tconstructor(options: InteractiveModeOptions) {\n\t\tthis.session = options.session;\n\t\tthis.tui = options.tui;\n\t\tthis.onExit = options.onExit;\n\t\tthis.sessionChoices = [...(options.sessions ?? [])];\n\t\tconst commands = [\n\t\t\t{ name: \"help\", description: \"Show interactive commands\" },\n\t\t\t{ name: \"clear\", description: \"Clear visible messages\" },\n\t\t\t{ name: \"model\", description: \"Open the model selector\" },\n\t\t\t{ name: \"session\", description: \"Open the session selector\" },\n\t\t\t{ name: \"theme\", description: \"Open the theme selector\" },\n\t\t\t{ name: \"settings\", description: \"Open the settings selector\" },\n\t\t\t{ name: \"compact\", description: \"Compact the persisted context now\" },\n\t\t\t{ name: \"usage\", description: \"Show token and cost usage\" },\n\t\t\t{ name: \"retry\", description: \"Retry the last failed prompt\" },\n\t\t] as const;\n\t\tconst autocomplete: AutocompleteProvider = {\n\t\t\tgetSuggestions: (context, autocompleteOptions) =>\n\t\t\t\tnew CombinedAutocompleteProvider(commands, this.session.allowedRoot).getSuggestions(\n\t\t\t\t\tcontext,\n\t\t\t\t\tautocompleteOptions,\n\t\t\t\t),\n\t\t\tapplyCompletion: (context, item, prefix) =>\n\t\t\t\tnew CombinedAutocompleteProvider(commands, this.session.allowedRoot).applyCompletion(context, item, prefix),\n\t\t};\n\t\tthis.editor = new Editor({\n\t\t\tmaxHeight: 3,\n\t\t\tautocomplete,\n\t\t});\n\t\tthis.editor.onSubmit = (text) => void this.submit(text);\n\t\tthis.editor.onEscape = () => this.activeAbort?.abort();\n\t\tthis.editor.onCommand = (data) => this.handleCommand(data);\n\t\tthis.editor.onInterrupt = () => this.exit();\n\t\tthis.editor.onAutocompleteChange = () => this.updateAutocompleteOverlay();\n\t\tconst readViewState = (): InteractiveViewState => ({\n\t\t\t...this.projection.state,\n\t\t\tmodel: this.session.modelId,\n\t\t\ttheme: this.theme,\n\t\t});\n\t\tthis.root = new InteractiveLayout({\n\t\t\theader: new InteractiveHeader(readViewState),\n\t\t\tchat: new InteractiveChat(readViewState),\n\t\t\tcomposer: new InteractiveComposer(readViewState),\n\t\t\teditor: this.editor,\n\t\t\tfooter: new InteractiveFooter(readViewState),\n\t\t});\n\t\tthis.tui.addChild(this.root);\n\t\tthis.tui.setFocus(this.editor);\n\t}\n\n\tstart(initialPrompt?: string): void {\n\t\tif (this.started) throw new Error(\"Interactive mode is already started\");\n\t\tthis.started = true;\n\t\tthis.projection.replaceTranscript(this.session.transcript);\n\t\tthis.projection.setUsage(this.session.usage);\n\t\tthis.subscribeToSession();\n\t\ttry {\n\t\t\tthis.tui.start();\n\t\t} catch (cause) {\n\t\t\tthis.started = false;\n\t\t\tthis.unsubscribeSession?.();\n\t\t\tthis.unsubscribeSession = undefined;\n\t\t\tthrow cause;\n\t\t}\n\t\tthis.startSpinnerTimer();\n\t\tif (initialPrompt?.trim()) void this.submit(initialPrompt);\n\t}\n\n\tstop(): void {\n\t\tif (!this.started && !this.unsubscribeSession) return;\n\t\tthis.started = false;\n\t\tthis.activeAbort?.abort();\n\t\tthis.activeAbort = undefined;\n\t\tthis.stopSpinnerTimer();\n\t\tthis.projection.clearTransientProcess();\n\t\tthis.closeOverlay();\n\t\tthis.closeAutocompleteOverlay();\n\t\tthis.unsubscribeSession?.();\n\t\tthis.unsubscribeSession = undefined;\n\t\tthis.tui.stop({ finalLines: this.root.renderTranscript(this.tui.columns) });\n\t}\n\n\tprivate exit(): void {\n\t\tthis.stop();\n\t\tthis.onExit?.();\n\t}\n\n\tprivate handleCommand(data: string): boolean {\n\t\tif (data === \"\\x14\") {\n\t\t\tthis.openThemeSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x13\") {\n\t\t\tthis.openSettingsSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x0f\") {\n\t\t\tthis.openModelSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x0c\") {\n\t\t\tthis.openSessionSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x12\" && this.lastFailedPrompt && !this.promptInFlight) {\n\t\t\tvoid this.submit(this.lastFailedPrompt, true);\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate openThemeSelector(): void {\n\t\tconst list = new SelectList([\n\t\t\t{ value: \"dark\", label: \"Dark\", description: \"Dark terminal theme\" },\n\t\t\t{ value: \"light\", label: \"Light\", description: \"Light terminal theme\" },\n\t\t]);\n\t\tlist.onSelect = (item) => {\n\t\t\tthis.theme = item.value === \"light\" ? \"light\" : \"dark\";\n\t\t\tthis.projection.setStatus(`theme=${this.theme}`);\n\t\t\tthis.closeOverlay();\n\t\t\tthis.refresh();\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate openModelSelector(): void {\n\t\tconst list = new SelectList(\n\t\t\tthis.session.availableModels.map((model) => ({\n\t\t\t\tvalue: model.id,\n\t\t\t\tlabel: model.name,\n\t\t\t\tdescription: `${model.provider} / ${model.id} / context ${model.contextWindow}`,\n\t\t\t})),\n\t\t);\n\t\tlist.onSelect = (item) => {\n\t\t\ttry {\n\t\t\t\tthis.session.setModel(item.value);\n\t\t\t\tthis.projection.setStatus(`model=${item.value}`);\n\t\t\t\tthis.closeOverlay();\n\t\t\t\tthis.refresh();\n\t\t\t} catch (cause) {\n\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t}\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate openSessionSelector(): void {\n\t\tconst list = new SelectList([\n\t\t\t{\n\t\t\t\tvalue: \"__current__\",\n\t\t\t\tlabel: \"Current session\",\n\t\t\t\tdescription: this.session.sessionFile ?? \"In-memory session\",\n\t\t\t},\n\t\t\t...this.sessionChoices.map((choice) => ({\n\t\t\t\tvalue: choice.id,\n\t\t\t\tlabel: choice.label,\n\t\t\t\t...(choice.description ? { description: choice.description } : {}),\n\t\t\t})),\n\t\t]);\n\t\tlist.onSelect = (item) => {\n\t\t\tif (item.value === \"__current__\") {\n\t\t\t\tthis.projection.setStatus(\"session=current\");\n\t\t\t\tthis.closeOverlay();\n\t\t\t\tthis.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst choice = this.sessionChoices.find((candidate) => candidate.id === item.value);\n\t\t\tif (!choice) return;\n\t\t\tthis.closeOverlay();\n\t\t\tvoid this.switchSession(choice);\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate openSettingsSelector(): void {\n\t\tconst list = new SettingsList([\n\t\t\t{\n\t\t\t\tid: \"compaction\",\n\t\t\t\tlabel: \"Context compaction\",\n\t\t\t\tcurrentValue: this.session.compactionEnabled ? \"on\" : \"off\",\n\t\t\t\tvalues: [\"on\", \"off\"],\n\t\t\t\tdescription: \"Summarize older persisted context before the model limit is reached.\",\n\t\t\t},\n\t\t]);\n\t\tlist.onChange = (id, value) => {\n\t\t\tif (id !== \"compaction\") return;\n\t\t\ttry {\n\t\t\t\tconst enabled = this.session.setCompactionEnabled(value === \"on\");\n\t\t\t\tlist.updateValue(id, enabled ? \"on\" : \"off\");\n\t\t\t\tthis.projection.setStatus(\n\t\t\t\t\tenabled === (value === \"on\")\n\t\t\t\t\t\t? `compaction=${enabled ? \"on\" : \"off\"}`\n\t\t\t\t\t\t: \"compaction unavailable without a persisted session\",\n\t\t\t\t);\n\t\t\t} catch (cause) {\n\t\t\t\tlist.updateValue(id, this.session.compactionEnabled ? \"on\" : \"off\");\n\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t\tthis.closeOverlay();\n\t\t\t}\n\t\t\tthis.refresh();\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate showOverlay(component: SelectList | SettingsList): void {\n\t\tthis.editor.cancelAutocomplete();\n\t\tthis.closeAutocompleteOverlay();\n\t\tthis.closeOverlay();\n\t\tthis.overlay = this.tui.showOverlay(component, {\n\t\t\twidth: \"70%\",\n\t\t\tmaxHeight: \"60%\",\n\t\t\tanchor: \"center\",\n\t\t\tmargin: 1,\n\t\t});\n\t}\n\n\tprivate closeOverlay(): void {\n\t\tthis.overlay?.hide();\n\t\tthis.overlay = undefined;\n\t}\n\n\tprivate updateAutocompleteOverlay(): void {\n\t\tthis.closeAutocompleteOverlay();\n\t\tif (!this.editor.isShowingAutocomplete()) {\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tconst menu = new AutocompleteMenu(() => ({\n\t\t\titems: this.editor.getAutocompleteItems(),\n\t\t\tindex: this.editor.getAutocompleteIndex(),\n\t\t}));\n\t\tthis.autocompleteOverlay = this.tui.showOverlay(menu, {\n\t\t\twidth: \"55%\",\n\t\t\tmaxHeight: 8,\n\t\t\tanchor: \"bottom-left\",\n\t\t\tmargin: 1,\n\t\t\tnonCapturing: true,\n\t\t});\n\t\tthis.refresh();\n\t}\n\n\tprivate closeAutocompleteOverlay(): void {\n\t\tthis.autocompleteOverlay?.hide();\n\t\tthis.autocompleteOverlay = undefined;\n\t}\n\n\tprivate refresh(): void {\n\t\tthis.root.invalidate();\n\t\tthis.tui.requestRender();\n\t}\n\n\tprivate startSpinnerTimer(): void {\n\t\tthis.stopSpinnerTimer();\n\t\tthis.spinnerTimer = setInterval(() => {\n\t\t\tif (this.projection.advanceSpinner()) this.refresh();\n\t\t}, 120);\n\t\tthis.spinnerTimer.unref?.();\n\t}\n\n\tprivate stopSpinnerTimer(): void {\n\t\tif (this.spinnerTimer) clearInterval(this.spinnerTimer);\n\t\tthis.spinnerTimer = undefined;\n\t}\n\n\tprivate subscribeToSession(): void {\n\t\tthis.unsubscribeSession?.();\n\t\tthis.unsubscribeSession = this.session.subscribeSession((event) => {\n\t\t\tif (!this.started) return;\n\t\t\tthis.projection.apply(event);\n\t\t\tthis.refresh();\n\t\t});\n\t}\n\n\tprivate async switchSession(choice: InteractiveSessionChoice): Promise<void> {\n\t\tif (this.promptInFlight || this.sessionSwitching) {\n\t\t\tthis.projection.setError(\"Cannot switch sessions while a prompt is running.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tthis.sessionSwitching = true;\n\t\tthis.projection.setStatus(`opening session=${choice.id}`);\n\t\tthis.refresh();\n\t\ttry {\n\t\t\tconst next = await choice.open();\n\t\t\tif (!this.started) return;\n\t\t\tthis.unsubscribeSession?.();\n\t\t\tthis.session = next;\n\t\t\tthis.queuedPrompts = [];\n\t\t\tthis.projection.setQueue([]);\n\t\t\tthis.projection.replaceTranscript(next.transcript);\n\t\t\tthis.projection.setUsage(next.usage);\n\t\t\tthis.projection.setStatus(`session=${choice.id}`);\n\t\t\tthis.subscribeToSession();\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.sessionSwitching = false;\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate async submit(text: string, retry = false): Promise<void> {\n\t\tconst prompt = text.trim();\n\t\tif (prompt.length === 0 || !this.started) return;\n\t\tif (prompt.startsWith(\"/\")) {\n\t\t\tthis.editor.setValue(\"\");\n\t\t\tthis.handleSlashCommand(prompt);\n\t\t\treturn;\n\t\t}\n\t\tif (this.sessionSwitching) {\n\t\t\tthis.projection.setError(\"A session is opening; wait before submitting a prompt.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.compactionInFlight) {\n\t\t\tthis.projection.setError(\"A compaction is running; wait before submitting a prompt.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.promptInFlight) {\n\t\t\tthis.queuedPrompts.push(prompt);\n\t\t\tthis.projection.setQueue(this.queuedPrompts);\n\t\t\tthis.root.invalidate();\n\t\t\tthis.tui.requestRender();\n\t\t\treturn;\n\t\t}\n\t\tthis.promptInFlight = true;\n\t\tthis.activeAbort = new AbortController();\n\t\tthis.projection.setRetrying(retry);\n\t\tthis.editor.setValue(\"\");\n\t\ttry {\n\t\t\tconst result = await this.session.prompt(prompt, this.activeAbort.signal);\n\t\t\tif (result.stopReason === \"error\" || result.stopReason === \"aborted\") this.lastFailedPrompt = prompt;\n\t\t\telse this.lastFailedPrompt = undefined;\n\t\t} catch (cause) {\n\t\t\tthis.lastFailedPrompt = prompt;\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.promptInFlight = false;\n\t\t\tthis.activeAbort = undefined;\n\t\t\tthis.projection.setRetrying(false);\n\t\t\tconst next = this.queuedPrompts.shift();\n\t\t\tthis.projection.setQueue(this.queuedPrompts);\n\t\t\tthis.root.invalidate();\n\t\t\tthis.tui.requestRender();\n\t\t\tif (next && this.started) void this.submit(next);\n\t\t}\n\t}\n\n\tprivate handleSlashCommand(input: string): void {\n\t\tconst command = input.slice(1).trim().split(/\\s+/, 1)[0]?.toLowerCase();\n\t\tswitch (command) {\n\t\t\tcase \"help\":\n\t\t\t\tthis.projection.setStatus(\"commands: /clear /model /session /theme /settings /compact /usage /retry\");\n\t\t\t\tbreak;\n\t\t\tcase \"clear\":\n\t\t\t\tthis.projection.clearVisibleMessages();\n\t\t\t\tthis.projection.setStatus(\"visible messages cleared\");\n\t\t\t\tbreak;\n\t\t\tcase \"model\":\n\t\t\t\tthis.openModelSelector();\n\t\t\t\treturn;\n\t\t\tcase \"session\":\n\t\t\t\tthis.openSessionSelector();\n\t\t\t\treturn;\n\t\t\tcase \"theme\":\n\t\t\t\tthis.openThemeSelector();\n\t\t\t\treturn;\n\t\t\tcase \"settings\":\n\t\t\t\tthis.openSettingsSelector();\n\t\t\t\treturn;\n\t\t\tcase \"compact\":\n\t\t\t\tvoid this.runManualCompaction();\n\t\t\t\treturn;\n\t\t\tcase \"usage\":\n\t\t\t\tthis.projection.setStatus(this.formatUsage());\n\t\t\t\tbreak;\n\t\t\tcase \"retry\":\n\t\t\t\tif (this.lastFailedPrompt && !this.promptInFlight) void this.submit(this.lastFailedPrompt, true);\n\t\t\t\telse this.projection.setStatus(\"nothing to retry\");\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthis.projection.setError(`Unknown command: /${command ?? \"\"}`);\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate formatUsage(): string {\n\t\tconst usage = this.session.usage;\n\t\treturn `usage: requests=${usage.requestCount} input=${usage.inputTokens} output=${usage.outputTokens} total=${usage.totalTokens} cost=$${usage.cost.total.toFixed(4)} context=${usage.estimatedContextTokens}/${usage.contextWindow}`;\n\t}\n\n\tprivate async runManualCompaction(): Promise<void> {\n\t\tif (this.promptInFlight || this.compactionInFlight) {\n\t\t\tthis.projection.setError(\"Cannot compact while a prompt is running.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tthis.compactionInFlight = true;\n\t\tthis.projection.setStatus(\"starting manual compaction\");\n\t\tthis.refresh();\n\t\ttry {\n\t\t\tawait this.session.compact();\n\t\t\tthis.projection.setStatus(\"manual compaction complete\");\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.compactionInFlight = false;\n\t\t\tthis.refresh();\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"interactive.js","sourceRoot":"","sources":["../../src/modes/interactive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAEN,4BAA4B,EAC5B,MAAM,EACN,GAAG,EACH,UAAU,EAEV,UAAU,EACV,YAAY,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,CAAC,OAAO,EAAE,CAAC;QAChB,CAAC;IACF,CAAC;CACD","sourcesContent":["import { statSync } from \"node:fs\";\nimport { extname, resolve } from \"node:path\";\nimport {\n\ttype AutocompleteProvider,\n\tCombinedAutocompleteProvider,\n\tEditor,\n\tKey,\n\tmatchesKey,\n\ttype OverlayHandle,\n\tSelectList,\n\tSettingsList,\n\ttype TUI,\n} from \"@di-code/tui\";\nimport {\n\tcleanupStaleClipboardImages,\n\tclipboardImageDirectory,\n\tisClipboardImagePath,\n\treadClipboardImagePath,\n\tremoveClipboardImage,\n} from \"../core/clipboard-image.ts\";\nimport { extractImageAttachments } from \"../core/image-input.ts\";\nimport type { AgentSession, AgentSessionEvent } from \"../core/session.ts\";\nimport type { ExtensionHost } from \"../extensions/runtime.ts\";\nimport {\n\tAutocompleteMenu,\n\tInteractiveChat,\n\tInteractiveComposer,\n\tInteractiveFooter,\n\tInteractiveHeader,\n\ttype InteractiveViewState,\n} from \"./interactive-components.ts\";\nimport { InteractiveLayout } from \"./interactive-layout.ts\";\nimport { InteractiveProjection } from \"./interactive-state.ts\";\n\nexport type { AgentSessionEvent };\nexport type { InteractiveMessage, InteractiveProcessItem, InteractiveState } from \"./interactive-state.ts\";\nexport { InteractiveProjection } from \"./interactive-state.ts\";\n\nconst IMAGE_EXTENSIONS = new Set([\".gif\", \".jpeg\", \".jpg\", \".png\", \".webp\"]);\nconst PASTE_IMAGE_KEY = process.platform === \"win32\" ? Key.alt(\"v\") : Key.ctrl(\"v\");\nconst PASTE_IMAGE_SHORTCUT = process.platform === \"win32\" ? \"Alt+V\" : \"Ctrl+V\";\n\nfunction asImageAttachmentReference(pasted: string, cwd: string): string {\n\tif (pasted.includes(\"\\n\")) return pasted;\n\tconst candidate = pasted.trim().replace(/^(?:\"([\\s\\S]*)\"|'([\\s\\S]*)')$/, \"$1$2\");\n\tif (!candidate || !IMAGE_EXTENSIONS.has(extname(candidate).toLowerCase())) return pasted;\n\ttry {\n\t\tif (!statSync(resolve(cwd, candidate)).isFile()) return pasted;\n\t} catch {\n\t\treturn pasted;\n\t}\n\treturn `@\"${candidate.replaceAll('\"', '\\\\\"')}\" `;\n}\n\nfunction normalizeDroppedImagePrompt(prompt: string, cwd: string): string {\n\tconst normalized = asImageAttachmentReference(prompt, cwd);\n\tif (normalized !== prompt) return normalized;\n\tconst prefix = /^((?:(?:[A-Za-z]:[\\\\/])|(?:\\.\\.?[\\\\/])|\\/)[\\s\\S]*?\\.(?:gif|jpe?g|png|webp))([\\s\\S]*)$/i.exec(prompt);\n\tif (!prefix) return prompt;\n\tconst imageReference = asImageAttachmentReference(prefix[1] ?? \"\", cwd);\n\treturn imageReference === prefix[1]\n\t\t? prompt\n\t\t: `${imageReference}${normalizeDroppedImagePrompt(prefix[2] ?? \"\", cwd)}`;\n}\n\nexport interface InteractiveModeOptions {\n\treadonly session: AgentSession;\n\treadonly tui: TUI;\n\treadonly onExit?: () => void;\n\treadonly sessions?: readonly InteractiveSessionChoice[];\n\treadonly extensionHost?: ExtensionHost;\n\treadonly readClipboardImagePath?: (directory?: string) => Promise<string | null>;\n}\n\nexport interface InteractiveSessionChoice {\n\treadonly id: string;\n\treadonly label: string;\n\treadonly description?: string;\n\topen(): AgentSession | Promise<AgentSession>;\n}\n\nexport class InteractiveMode {\n\tprivate readonly projection = new InteractiveProjection();\n\tprivate readonly root: InteractiveLayout;\n\tprivate readonly editor: Editor;\n\tprivate session: AgentSession;\n\tprivate readonly tui: TUI;\n\tprivate readonly sessionChoices: readonly InteractiveSessionChoice[];\n\tprivate readonly extensionHost?: ExtensionHost;\n\tprivate readonly readClipboardImagePath: (directory?: string) => Promise<string | null>;\n\tprivate clipboardDirectory: string;\n\tprivate readonly clipboardFiles = new Set<string>();\n\tprivate unsubscribeSession?: () => void;\n\tprivate sessionSwitching = false;\n\tprivate promptInFlight = false;\n\tprivate compactionInFlight = false;\n\tprivate activeAbort?: AbortController;\n\tprivate started = false;\n\tprivate lastFailedPrompt?: string;\n\tprivate queuedPrompts: string[] = [];\n\tprivate readonly onExit?: () => void;\n\tprivate theme: \"dark\" | \"light\" = \"dark\";\n\tprivate overlay?: OverlayHandle;\n\tprivate autocompleteOverlay?: OverlayHandle;\n\tprivate spinnerTimer?: ReturnType<typeof setInterval>;\n\tprivate shutdownEmitted = false;\n\tprivate preserveClipboardFiles = false;\n\n\tconstructor(options: InteractiveModeOptions) {\n\t\tthis.session = options.session;\n\t\tthis.tui = options.tui;\n\t\tthis.onExit = options.onExit;\n\t\tthis.sessionChoices = [...(options.sessions ?? [])];\n\t\tthis.extensionHost = options.extensionHost;\n\t\tthis.readClipboardImagePath = options.readClipboardImagePath ?? readClipboardImagePath;\n\t\tthis.clipboardDirectory = clipboardImageDirectory(this.session.allowedRoot);\n\t\tconst commands = [\n\t\t\t{ name: \"help\", description: \"Show interactive commands\" },\n\t\t\t{ name: \"clear\", description: \"Clear visible messages\" },\n\t\t\t{ name: \"model\", description: \"Open the model selector\" },\n\t\t\t{ name: \"session\", description: \"Open the session selector\" },\n\t\t\t{ name: \"theme\", description: \"Open the theme selector\" },\n\t\t\t{ name: \"settings\", description: \"Open the settings selector\" },\n\t\t\t{ name: \"compact\", description: \"Compact the persisted context now\" },\n\t\t\t{ name: \"usage\", description: \"Show token and cost usage\" },\n\t\t\t{ name: \"retry\", description: \"Retry the last failed prompt\" },\n\t\t] as const;\n\t\tconst allCommands = [...commands, ...(this.extensionHost?.listCommands() ?? [])];\n\t\tconst autocomplete: AutocompleteProvider = {\n\t\t\tgetSuggestions: (context, autocompleteOptions) =>\n\t\t\t\tnew CombinedAutocompleteProvider(allCommands, this.session.allowedRoot).getSuggestions(\n\t\t\t\t\tcontext,\n\t\t\t\t\tautocompleteOptions,\n\t\t\t\t),\n\t\t\tapplyCompletion: (context, item, prefix) =>\n\t\t\t\tnew CombinedAutocompleteProvider(allCommands, this.session.allowedRoot).applyCompletion(context, item, prefix),\n\t\t};\n\t\tthis.editor = new Editor({\n\t\t\tmaxHeight: 3,\n\t\t\tautocomplete,\n\t\t});\n\t\tthis.editor.onSubmit = (text) => void this.submit(text);\n\t\tthis.editor.onEscape = () => this.activeAbort?.abort();\n\t\tthis.editor.onCommand = (data) => this.handleCommand(data);\n\t\tthis.editor.onInterrupt = () => this.exit();\n\t\tthis.editor.onChange = () => {\n\t\t\tif (!this.preserveClipboardFiles) {\n\t\t\t\tvoid this.cleanupUnreferencedClipboardFiles().catch((cause) => {\n\t\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t\t\tthis.refresh();\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\t\tthis.editor.onAutocompleteChange = () => this.updateAutocompleteOverlay();\n\t\tconst readViewState = (): InteractiveViewState => ({\n\t\t\t...this.projection.state,\n\t\t\tmodel: this.session.modelId,\n\t\t\ttheme: this.theme,\n\t\t\tpasteImageShortcut: PASTE_IMAGE_SHORTCUT,\n\t\t});\n\t\tthis.root = new InteractiveLayout({\n\t\t\theader: new InteractiveHeader(readViewState),\n\t\t\tchat: new InteractiveChat(readViewState),\n\t\t\tcomposer: new InteractiveComposer(readViewState),\n\t\t\teditor: this.editor,\n\t\t\tfooter: new InteractiveFooter(readViewState),\n\t\t});\n\t\tthis.tui.addChild(this.root);\n\t\tthis.tui.setFocus(this.editor);\n\t}\n\n\tstart(initialPrompt?: string): void {\n\t\tif (this.started) throw new Error(\"Interactive mode is already started\");\n\t\tthis.started = true;\n\t\tthis.shutdownEmitted = false;\n\t\tvoid this.extensionHost?.emit({ type: \"session_start\", cwd: this.session.allowedRoot });\n\t\tthis.projection.replaceTranscript(this.session.transcript);\n\t\tthis.projection.setUsage(this.session.usage);\n\t\tthis.subscribeToSession();\n\t\tvoid cleanupStaleClipboardImages(this.session.allowedRoot).catch((cause) => {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\tthis.refresh();\n\t\t});\n\t\ttry {\n\t\t\tthis.tui.start();\n\t\t} catch (cause) {\n\t\t\tthis.started = false;\n\t\t\tthis.unsubscribeSession?.();\n\t\t\tthis.unsubscribeSession = undefined;\n\t\t\tthrow cause;\n\t\t}\n\t\tthis.startSpinnerTimer();\n\t\tif (initialPrompt?.trim()) void this.submit(initialPrompt);\n\t}\n\n\tstop(): void {\n\t\tif (!this.started && !this.unsubscribeSession) return;\n\t\tthis.started = false;\n\t\tthis.activeAbort?.abort();\n\t\tthis.activeAbort = undefined;\n\t\tthis.stopSpinnerTimer();\n\t\tthis.projection.clearTransientProcess();\n\t\tthis.closeOverlay();\n\t\tthis.closeAutocompleteOverlay();\n\t\tthis.unsubscribeSession?.();\n\t\tthis.unsubscribeSession = undefined;\n\t\tvoid this.cleanupClipboardFiles();\n\t\tthis.tui.stop({ finalLines: this.root.renderTranscript(this.tui.columns) });\n\t\tif (!this.shutdownEmitted) {\n\t\t\tthis.shutdownEmitted = true;\n\t\t\tvoid this.extensionHost?.emit({ type: \"session_shutdown\", reason: \"user\" });\n\t\t}\n\t}\n\n\tprivate exit(): void {\n\t\tthis.stop();\n\t\tthis.onExit?.();\n\t}\n\n\tprivate handleCommand(data: string): boolean {\n\t\tif (data === \"\\x14\") {\n\t\t\tthis.openThemeSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x13\") {\n\t\t\tthis.openSettingsSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x0f\") {\n\t\t\tthis.openModelSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x0c\") {\n\t\t\tthis.openSessionSelector();\n\t\t\treturn true;\n\t\t}\n\t\tif (data === \"\\x12\" && this.lastFailedPrompt && !this.promptInFlight) {\n\t\t\tvoid this.submit(this.lastFailedPrompt, true);\n\t\t\treturn true;\n\t\t}\n\t\tif (matchesKey(data, PASTE_IMAGE_KEY)) {\n\t\t\tvoid this.attachClipboardImage();\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate async attachClipboardImage(): Promise<void> {\n\t\ttry {\n\t\t\tconst path = await this.readClipboardImagePath(this.clipboardDirectory);\n\t\t\tif (!path) {\n\t\t\t\tthis.projection.setStatus(\"Clipboard has no supported image.\");\n\t\t\t} else {\n\t\t\t\tthis.editor.insertTextAtCursor(path);\n\t\t\t\tif (isClipboardImagePath(path, this.clipboardDirectory)) this.clipboardFiles.add(path);\n\t\t\t}\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate openThemeSelector(): void {\n\t\tconst list = new SelectList([\n\t\t\t{ value: \"dark\", label: \"Dark\", description: \"Dark terminal theme\" },\n\t\t\t{ value: \"light\", label: \"Light\", description: \"Light terminal theme\" },\n\t\t]);\n\t\tlist.onSelect = (item) => {\n\t\t\tthis.theme = item.value === \"light\" ? \"light\" : \"dark\";\n\t\t\tthis.projection.setStatus(`theme=${this.theme}`);\n\t\t\tthis.closeOverlay();\n\t\t\tthis.refresh();\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate openModelSelector(): void {\n\t\tconst list = new SelectList(\n\t\t\tthis.session.availableModels.map((model) => ({\n\t\t\t\tvalue: model.id,\n\t\t\t\tlabel: model.name,\n\t\t\t\tdescription: `${model.provider} / ${model.id} / context ${model.contextWindow}`,\n\t\t\t})),\n\t\t);\n\t\tlist.onSelect = (item) => {\n\t\t\ttry {\n\t\t\t\tthis.session.setModel(item.value);\n\t\t\t\tthis.projection.setStatus(`model=${item.value}`);\n\t\t\t\tthis.closeOverlay();\n\t\t\t\tthis.refresh();\n\t\t\t} catch (cause) {\n\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t}\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate openSessionSelector(): void {\n\t\tconst list = new SelectList([\n\t\t\t{\n\t\t\t\tvalue: \"__current__\",\n\t\t\t\tlabel: \"Current session\",\n\t\t\t\tdescription: this.session.sessionFile ?? \"In-memory session\",\n\t\t\t},\n\t\t\t...this.sessionChoices.map((choice) => ({\n\t\t\t\tvalue: choice.id,\n\t\t\t\tlabel: choice.label,\n\t\t\t\t...(choice.description ? { description: choice.description } : {}),\n\t\t\t})),\n\t\t]);\n\t\tlist.onSelect = (item) => {\n\t\t\tif (item.value === \"__current__\") {\n\t\t\t\tthis.projection.setStatus(\"session=current\");\n\t\t\t\tthis.closeOverlay();\n\t\t\t\tthis.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst choice = this.sessionChoices.find((candidate) => candidate.id === item.value);\n\t\t\tif (!choice) return;\n\t\t\tthis.closeOverlay();\n\t\t\tvoid this.switchSession(choice);\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate openSettingsSelector(): void {\n\t\tconst list = new SettingsList([\n\t\t\t{\n\t\t\t\tid: \"compaction\",\n\t\t\t\tlabel: \"Context compaction\",\n\t\t\t\tcurrentValue: this.session.compactionEnabled ? \"on\" : \"off\",\n\t\t\t\tvalues: [\"on\", \"off\"],\n\t\t\t\tdescription: \"Summarize older persisted context before the model limit is reached.\",\n\t\t\t},\n\t\t]);\n\t\tlist.onChange = (id, value) => {\n\t\t\tif (id !== \"compaction\") return;\n\t\t\ttry {\n\t\t\t\tconst enabled = this.session.setCompactionEnabled(value === \"on\");\n\t\t\t\tlist.updateValue(id, enabled ? \"on\" : \"off\");\n\t\t\t\tthis.projection.setStatus(\n\t\t\t\t\tenabled === (value === \"on\")\n\t\t\t\t\t\t? `compaction=${enabled ? \"on\" : \"off\"}`\n\t\t\t\t\t\t: \"compaction unavailable without a persisted session\",\n\t\t\t\t);\n\t\t\t} catch (cause) {\n\t\t\t\tlist.updateValue(id, this.session.compactionEnabled ? \"on\" : \"off\");\n\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t\tthis.closeOverlay();\n\t\t\t}\n\t\t\tthis.refresh();\n\t\t};\n\t\tlist.onCancel = () => this.closeOverlay();\n\t\tthis.showOverlay(list);\n\t}\n\n\tprivate showOverlay(component: SelectList | SettingsList): void {\n\t\tthis.editor.cancelAutocomplete();\n\t\tthis.closeAutocompleteOverlay();\n\t\tthis.closeOverlay();\n\t\tthis.overlay = this.tui.showOverlay(component, {\n\t\t\twidth: \"70%\",\n\t\t\tmaxHeight: \"60%\",\n\t\t\tanchor: \"center\",\n\t\t\tmargin: 1,\n\t\t});\n\t}\n\n\tprivate closeOverlay(): void {\n\t\tthis.overlay?.hide();\n\t\tthis.overlay = undefined;\n\t}\n\n\tprivate updateAutocompleteOverlay(): void {\n\t\tthis.closeAutocompleteOverlay();\n\t\tif (!this.editor.isShowingAutocomplete()) {\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tconst menu = new AutocompleteMenu(() => ({\n\t\t\titems: this.editor.getAutocompleteItems(),\n\t\t\tindex: this.editor.getAutocompleteIndex(),\n\t\t}));\n\t\tthis.autocompleteOverlay = this.tui.showOverlay(menu, {\n\t\t\twidth: \"55%\",\n\t\t\tmaxHeight: 8,\n\t\t\tanchor: \"bottom-left\",\n\t\t\tmargin: 1,\n\t\t\tnonCapturing: true,\n\t\t});\n\t\tthis.refresh();\n\t}\n\n\tprivate closeAutocompleteOverlay(): void {\n\t\tthis.autocompleteOverlay?.hide();\n\t\tthis.autocompleteOverlay = undefined;\n\t}\n\n\tprivate refresh(): void {\n\t\tthis.root.invalidate();\n\t\tthis.tui.requestRender();\n\t}\n\n\tprivate startSpinnerTimer(): void {\n\t\tthis.stopSpinnerTimer();\n\t\tthis.spinnerTimer = setInterval(() => {\n\t\t\tif (this.projection.advanceSpinner()) this.refresh();\n\t\t}, 120);\n\t\tthis.spinnerTimer.unref?.();\n\t}\n\n\tprivate stopSpinnerTimer(): void {\n\t\tif (this.spinnerTimer) clearInterval(this.spinnerTimer);\n\t\tthis.spinnerTimer = undefined;\n\t}\n\n\tprivate subscribeToSession(): void {\n\t\tthis.unsubscribeSession?.();\n\t\tthis.unsubscribeSession = this.session.subscribeSession((event) => {\n\t\t\tif (!this.started) return;\n\t\t\tthis.projection.apply(event);\n\t\t\tthis.refresh();\n\t\t});\n\t}\n\n\tprivate async switchSession(choice: InteractiveSessionChoice): Promise<void> {\n\t\tif (this.promptInFlight || this.sessionSwitching) {\n\t\t\tthis.projection.setError(\"Cannot switch sessions while a prompt is running.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tthis.sessionSwitching = true;\n\t\tthis.projection.setStatus(`opening session=${choice.id}`);\n\t\tthis.refresh();\n\t\ttry {\n\t\t\tconst next = await choice.open();\n\t\t\tif (!this.started) return;\n\t\t\tthis.unsubscribeSession?.();\n\t\t\tthis.session = next;\n\t\t\tthis.clipboardDirectory = clipboardImageDirectory(next.allowedRoot);\n\t\t\tvoid cleanupStaleClipboardImages(next.allowedRoot);\n\t\t\tthis.queuedPrompts = [];\n\t\t\tthis.projection.setQueue([]);\n\t\t\tthis.projection.replaceTranscript(next.transcript);\n\t\t\tthis.projection.setUsage(next.usage);\n\t\t\tthis.projection.setStatus(`session=${choice.id}`);\n\t\t\tthis.subscribeToSession();\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.sessionSwitching = false;\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate async submit(text: string, retry = false): Promise<void> {\n\t\tconst prompt = text.trim();\n\t\tif (prompt.length === 0 || !this.started) return;\n\t\tif (prompt.startsWith(\"/\")) {\n\t\t\tthis.editor.setValue(\"\");\n\t\t\tthis.handleSlashCommand(prompt);\n\t\t\treturn;\n\t\t}\n\t\tif (this.sessionSwitching) {\n\t\t\tthis.projection.setError(\"A session is opening; wait before submitting a prompt.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.compactionInFlight) {\n\t\t\tthis.projection.setError(\"A compaction is running; wait before submitting a prompt.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tif (this.promptInFlight) {\n\t\t\tthis.queuedPrompts.push(prompt);\n\t\t\tthis.projection.setQueue(this.queuedPrompts);\n\t\t\tthis.root.invalidate();\n\t\t\tthis.tui.requestRender();\n\t\t\treturn;\n\t\t}\n\t\tthis.promptInFlight = true;\n\t\tthis.activeAbort = new AbortController();\n\t\tthis.projection.setRetrying(retry);\n\t\ttry {\n\t\t\tconst input = await extractImageAttachments(\n\t\t\t\tnormalizeDroppedImagePrompt(prompt, this.session.allowedRoot),\n\t\t\t\tthis.session.allowedRoot,\n\t\t\t);\n\t\t\tthis.preserveClipboardFiles = true;\n\t\t\tthis.editor.setValue(\"\");\n\t\t\tconst result = await this.session.promptWithImages(input.text, input.images, this.activeAbort.signal);\n\t\t\tif (result.stopReason === \"error\" || result.stopReason === \"aborted\") this.lastFailedPrompt = prompt;\n\t\t\telse {\n\t\t\t\tthis.lastFailedPrompt = undefined;\n\t\t\t\tawait this.cleanupClipboardFiles();\n\t\t\t}\n\t\t} catch (cause) {\n\t\t\tthis.lastFailedPrompt = prompt;\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.preserveClipboardFiles = false;\n\t\t\tthis.promptInFlight = false;\n\t\t\tthis.activeAbort = undefined;\n\t\t\tthis.projection.setRetrying(false);\n\t\t\tconst next = this.queuedPrompts.shift();\n\t\t\tthis.projection.setQueue(this.queuedPrompts);\n\t\t\tthis.root.invalidate();\n\t\t\tthis.tui.requestRender();\n\t\t\tif (next && this.started) void this.submit(next);\n\t\t}\n\t}\n\n\tprivate async cleanupUnreferencedClipboardFiles(): Promise<void> {\n\t\tconst text = this.editor.getValue();\n\t\tconst files = [...this.clipboardFiles].filter((path) => !text.includes(path));\n\t\tawait Promise.all(files.map((path) => removeClipboardImage(path, this.clipboardDirectory)));\n\t\tfor (const path of files) this.clipboardFiles.delete(path);\n\t}\n\n\tprivate async cleanupClipboardFiles(): Promise<void> {\n\t\tconst files = [...this.clipboardFiles];\n\t\tawait Promise.all(files.map((path) => removeClipboardImage(path, this.clipboardDirectory)));\n\t\tfor (const path of files) this.clipboardFiles.delete(path);\n\t}\n\n\tprivate handleSlashCommand(input: string): void {\n\t\tconst trimmed = input.slice(1).trim();\n\t\tconst [rawCommand = \"\", ...argParts] = trimmed.split(/\\s+/);\n\t\tconst command = rawCommand.toLowerCase();\n\t\tconst args = argParts.join(\" \");\n\t\tswitch (command) {\n\t\t\tcase \"help\":\n\t\t\t\tthis.projection.setStatus(\"commands: /clear /model /session /theme /settings /compact /usage /retry\");\n\t\t\t\tbreak;\n\t\t\tcase \"clear\":\n\t\t\t\tthis.projection.clearVisibleMessages();\n\t\t\t\tthis.projection.setStatus(\"visible messages cleared\");\n\t\t\t\tbreak;\n\t\t\tcase \"model\":\n\t\t\t\tthis.openModelSelector();\n\t\t\t\treturn;\n\t\t\tcase \"session\":\n\t\t\t\tthis.openSessionSelector();\n\t\t\t\treturn;\n\t\t\tcase \"theme\":\n\t\t\t\tthis.openThemeSelector();\n\t\t\t\treturn;\n\t\t\tcase \"settings\":\n\t\t\t\tthis.openSettingsSelector();\n\t\t\t\treturn;\n\t\t\tcase \"compact\":\n\t\t\t\tvoid this.runManualCompaction();\n\t\t\t\treturn;\n\t\t\tcase \"usage\":\n\t\t\t\tthis.projection.setStatus(this.formatUsage());\n\t\t\t\tbreak;\n\t\t\tcase \"retry\":\n\t\t\t\tif (this.lastFailedPrompt && !this.promptInFlight) void this.submit(this.lastFailedPrompt, true);\n\t\t\t\telse this.projection.setStatus(\"nothing to retry\");\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tif (this.extensionHost?.listCommands().some((entry) => entry.name === command)) {\n\t\t\t\t\tvoid this.extensionHost.runCommand(command, args).catch((cause) => {\n\t\t\t\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t\t\t\t\tthis.refresh();\n\t\t\t\t\t});\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tthis.projection.setError(`Unknown command: /${command}`);\n\t\t\t}\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tprivate formatUsage(): string {\n\t\tconst usage = this.session.usage;\n\t\treturn `usage: requests=${usage.requestCount} input=${usage.inputTokens} output=${usage.outputTokens} total=${usage.totalTokens} cost=$${usage.cost.total.toFixed(4)} context=${usage.estimatedContextTokens}/${usage.contextWindow}`;\n\t}\n\n\tprivate async runManualCompaction(): Promise<void> {\n\t\tif (this.promptInFlight || this.compactionInFlight) {\n\t\t\tthis.projection.setError(\"Cannot compact while a prompt is running.\");\n\t\t\tthis.refresh();\n\t\t\treturn;\n\t\t}\n\t\tthis.compactionInFlight = true;\n\t\tthis.projection.setStatus(\"starting manual compaction\");\n\t\tthis.refresh();\n\t\ttry {\n\t\t\tawait this.session.compact();\n\t\t\tthis.projection.setStatus(\"manual compaction complete\");\n\t\t} catch (cause) {\n\t\t\tthis.projection.setError(cause instanceof Error ? cause.message : String(cause));\n\t\t} finally {\n\t\t\tthis.compactionInFlight = false;\n\t\t\tthis.refresh();\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC","sourcesContent":["export * from \"./loader.ts\";\nexport * from \"./manager.ts\";\nexport * from \"./manifest.ts\";\nexport * from \"./types.ts\";\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ExtensionHost } from "../extensions/runtime.ts";
|
|
2
|
+
import type { ProjectTrustManager } from "../extensions/trust.ts";
|
|
3
|
+
import type { DiscoveredPlugin, PluginDiagnostic } from "./types.ts";
|
|
4
|
+
export interface PluginLoadOptions {
|
|
5
|
+
readonly cwd: string;
|
|
6
|
+
readonly agentDir?: string;
|
|
7
|
+
readonly projectTrusted?: boolean;
|
|
8
|
+
readonly trustManager?: ProjectTrustManager;
|
|
9
|
+
readonly mode?: "interactive" | "print" | "json";
|
|
10
|
+
readonly explicitPaths?: readonly string[];
|
|
11
|
+
}
|
|
12
|
+
export interface PluginLoadResult {
|
|
13
|
+
readonly host: ExtensionHost;
|
|
14
|
+
readonly loaded: readonly DiscoveredPlugin[];
|
|
15
|
+
readonly diagnostics: readonly PluginDiagnostic[];
|
|
16
|
+
}
|
|
17
|
+
export declare function loadPlugins(options: PluginLoadOptions): Promise<PluginLoadResult>;
|
|
18
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/plugins/loader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAIlE,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAErE,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,YAAY,CAAC,EAAE,mBAAmB,CAAC;IAC5C,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,GAAG,MAAM,CAAC;IACjD,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C;AAED,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC7C,QAAQ,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,CAAC;CAClD;AA0BD,wBAAsB,WAAW,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAyDvF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { createJiti } from "jiti";
|
|
5
|
+
import { loadExtensions } from "../extensions/runtime.js";
|
|
6
|
+
import { PluginManager } from "./manager.js";
|
|
7
|
+
import { readPackagePluginManifest, readPluginManifest, resolvePluginEntry } from "./manifest.js";
|
|
8
|
+
async function isPluginPackage(root) {
|
|
9
|
+
try {
|
|
10
|
+
const parsed = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
|
|
11
|
+
return typeof parsed === "object" && parsed !== null && "diCode" in parsed;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function discoverPluginRoots(cwd, agentDir, trusted) {
|
|
18
|
+
const roots = [...(trusted ? [join(cwd, ".di-code", "plugins")] : []), join(agentDir, "plugins", "installed")];
|
|
19
|
+
const result = [];
|
|
20
|
+
for (const root of roots) {
|
|
21
|
+
if (!existsSync(root))
|
|
22
|
+
continue;
|
|
23
|
+
for (const entry of await readdir(root, { withFileTypes: true })) {
|
|
24
|
+
if (!entry.isDirectory())
|
|
25
|
+
continue;
|
|
26
|
+
const pluginRoot = join(root, entry.name);
|
|
27
|
+
if (existsSync(join(pluginRoot, "plugin.json")) || (await isPluginPackage(pluginRoot)))
|
|
28
|
+
result.push(resolve(pluginRoot));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result.sort((a, b) => a.localeCompare(b));
|
|
32
|
+
}
|
|
33
|
+
export async function loadPlugins(options) {
|
|
34
|
+
const cwd = resolve(options.cwd);
|
|
35
|
+
const agentDir = resolve(options.agentDir ?? join(cwd, ".di-code"));
|
|
36
|
+
const trusted = options.projectTrusted ?? (options.trustManager ? (await options.trustManager.get(cwd)) === true : false);
|
|
37
|
+
const extensionResult = await loadExtensions({
|
|
38
|
+
cwd,
|
|
39
|
+
projectTrusted: trusted,
|
|
40
|
+
trustManager: options.trustManager,
|
|
41
|
+
mode: options.mode,
|
|
42
|
+
paths: options.explicitPaths,
|
|
43
|
+
});
|
|
44
|
+
const diagnostics = extensionResult.diagnostics.map((diagnostic) => ({
|
|
45
|
+
sourcePath: diagnostic.path,
|
|
46
|
+
stage: diagnostic.stage,
|
|
47
|
+
severity: "error",
|
|
48
|
+
message: diagnostic.message,
|
|
49
|
+
}));
|
|
50
|
+
const enabledGlobal = new Set((await new PluginManager({ agentDir }).list()).filter((plugin) => plugin.enabled).map((plugin) => plugin.id));
|
|
51
|
+
const pluginRoots = await discoverPluginRoots(cwd, agentDir, trusted);
|
|
52
|
+
const loaded = [];
|
|
53
|
+
const jiti = createJiti(import.meta.url, { moduleCache: false });
|
|
54
|
+
for (const root of pluginRoots) {
|
|
55
|
+
const manifestPath = join(root, "plugin.json");
|
|
56
|
+
let manifest;
|
|
57
|
+
try {
|
|
58
|
+
manifest = await readPluginManifest(manifestPath).catch(async () => readPackagePluginManifest(root));
|
|
59
|
+
}
|
|
60
|
+
catch (cause) {
|
|
61
|
+
diagnostics.push({
|
|
62
|
+
sourcePath: manifestPath,
|
|
63
|
+
stage: "manifest",
|
|
64
|
+
severity: "error",
|
|
65
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
66
|
+
});
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const projectLocal = root.startsWith(resolve(cwd, ".di-code", "plugins"));
|
|
70
|
+
if (!projectLocal && !enabledGlobal.has(manifest.id))
|
|
71
|
+
continue;
|
|
72
|
+
try {
|
|
73
|
+
const entry = await resolvePluginEntry(root, manifest.entry);
|
|
74
|
+
const module = await jiti.import(entry);
|
|
75
|
+
if (typeof module.default !== "function")
|
|
76
|
+
throw new Error("plugin entry must export a default factory function");
|
|
77
|
+
await extensionResult.host.registerExtension(entry, module.default, manifest.id);
|
|
78
|
+
loaded.push({ manifest, root, sourcePath: manifestPath, projectLocal });
|
|
79
|
+
}
|
|
80
|
+
catch (cause) {
|
|
81
|
+
diagnostics.push({
|
|
82
|
+
pluginId: manifest.id,
|
|
83
|
+
sourcePath: manifestPath,
|
|
84
|
+
stage: "import",
|
|
85
|
+
severity: "error",
|
|
86
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { host: extensionResult.host, loaded, diagnostics };
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/plugins/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAsB,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG9E,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAkBlG,KAAK,UAAU,eAAe,CAAC,IAAY;IAC1C,IAAI,CAAC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,KAAK,CAAC,CAAC;YAC/D,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,UAAU;gBAAE,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;YACjH,MAAM,eAAe,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,OAA2B,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;YACrG,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC,CAAC;QACzE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,WAAW,CAAC,IAAI,CAAC;gBAChB,QAAQ,EAAE,QAAQ,CAAC,EAAE;gBACrB,UAAU,EAAE,YAAY;gBACxB,KAAK,EAAE,QAAQ;gBACf,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC/D,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AAC5D,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { readdir, readFile } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { createJiti } from \"jiti\";\nimport { type ExtensionHost, loadExtensions } from \"../extensions/runtime.ts\";\nimport type { ProjectTrustManager } from \"../extensions/trust.ts\";\nimport type { ExtensionFactory } from \"../extensions/types.ts\";\nimport { PluginManager } from \"./manager.ts\";\nimport { readPackagePluginManifest, readPluginManifest, resolvePluginEntry } from \"./manifest.ts\";\nimport type { DiscoveredPlugin, PluginDiagnostic } from \"./types.ts\";\n\nexport interface PluginLoadOptions {\n\treadonly cwd: string;\n\treadonly agentDir?: string;\n\treadonly projectTrusted?: boolean;\n\treadonly trustManager?: ProjectTrustManager;\n\treadonly mode?: \"interactive\" | \"print\" | \"json\";\n\treadonly explicitPaths?: readonly string[];\n}\n\nexport interface PluginLoadResult {\n\treadonly host: ExtensionHost;\n\treadonly loaded: readonly DiscoveredPlugin[];\n\treadonly diagnostics: readonly PluginDiagnostic[];\n}\n\nasync function isPluginPackage(root: string): Promise<boolean> {\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(await readFile(join(root, \"package.json\"), \"utf8\"));\n\t\treturn typeof parsed === \"object\" && parsed !== null && \"diCode\" in parsed;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function discoverPluginRoots(cwd: string, agentDir: string, trusted: boolean): Promise<string[]> {\n\tconst roots = [...(trusted ? [join(cwd, \".di-code\", \"plugins\")] : []), join(agentDir, \"plugins\", \"installed\")];\n\tconst result: string[] = [];\n\tfor (const root of roots) {\n\t\tif (!existsSync(root)) continue;\n\t\tfor (const entry of await readdir(root, { withFileTypes: true })) {\n\t\t\tif (!entry.isDirectory()) continue;\n\t\t\tconst pluginRoot = join(root, entry.name);\n\t\t\tif (existsSync(join(pluginRoot, \"plugin.json\")) || (await isPluginPackage(pluginRoot)))\n\t\t\t\tresult.push(resolve(pluginRoot));\n\t\t}\n\t}\n\treturn result.sort((a, b) => a.localeCompare(b));\n}\n\nexport async function loadPlugins(options: PluginLoadOptions): Promise<PluginLoadResult> {\n\tconst cwd = resolve(options.cwd);\n\tconst agentDir = resolve(options.agentDir ?? join(cwd, \".di-code\"));\n\tconst trusted =\n\t\toptions.projectTrusted ?? (options.trustManager ? (await options.trustManager.get(cwd)) === true : false);\n\tconst extensionResult = await loadExtensions({\n\t\tcwd,\n\t\tprojectTrusted: trusted,\n\t\ttrustManager: options.trustManager,\n\t\tmode: options.mode,\n\t\tpaths: options.explicitPaths,\n\t});\n\tconst diagnostics: PluginDiagnostic[] = extensionResult.diagnostics.map((diagnostic) => ({\n\t\tsourcePath: diagnostic.path,\n\t\tstage: diagnostic.stage,\n\t\tseverity: \"error\",\n\t\tmessage: diagnostic.message,\n\t}));\n\tconst enabledGlobal = new Set(\n\t\t(await new PluginManager({ agentDir }).list()).filter((plugin) => plugin.enabled).map((plugin) => plugin.id),\n\t);\n\tconst pluginRoots = await discoverPluginRoots(cwd, agentDir, trusted);\n\tconst loaded: DiscoveredPlugin[] = [];\n\tconst jiti = createJiti(import.meta.url, { moduleCache: false });\n\tfor (const root of pluginRoots) {\n\t\tconst manifestPath = join(root, \"plugin.json\");\n\t\tlet manifest: Awaited<ReturnType<typeof readPluginManifest>>;\n\t\ttry {\n\t\t\tmanifest = await readPluginManifest(manifestPath).catch(async () => readPackagePluginManifest(root));\n\t\t} catch (cause) {\n\t\t\tdiagnostics.push({\n\t\t\t\tsourcePath: manifestPath,\n\t\t\t\tstage: \"manifest\",\n\t\t\t\tseverity: \"error\",\n\t\t\t\tmessage: cause instanceof Error ? cause.message : String(cause),\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tconst projectLocal = root.startsWith(resolve(cwd, \".di-code\", \"plugins\"));\n\t\tif (!projectLocal && !enabledGlobal.has(manifest.id)) continue;\n\t\ttry {\n\t\t\tconst entry = await resolvePluginEntry(root, manifest.entry);\n\t\t\tconst module = await jiti.import<{ default?: unknown }>(entry);\n\t\t\tif (typeof module.default !== \"function\") throw new Error(\"plugin entry must export a default factory function\");\n\t\t\tawait extensionResult.host.registerExtension(entry, module.default as ExtensionFactory, manifest.id);\n\t\t\tloaded.push({ manifest, root, sourcePath: manifestPath, projectLocal });\n\t\t} catch (cause) {\n\t\t\tdiagnostics.push({\n\t\t\t\tpluginId: manifest.id,\n\t\t\t\tsourcePath: manifestPath,\n\t\t\t\tstage: \"import\",\n\t\t\t\tseverity: \"error\",\n\t\t\t\tmessage: cause instanceof Error ? cause.message : String(cause),\n\t\t\t});\n\t\t}\n\t}\n\treturn { host: extensionResult.host, loaded, diagnostics };\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ManagedPlugin } from "./types.ts";
|
|
2
|
+
export interface PluginManagerOptions {
|
|
3
|
+
readonly agentDir: string;
|
|
4
|
+
readonly now?: () => Date;
|
|
5
|
+
}
|
|
6
|
+
export declare class PluginManager {
|
|
7
|
+
private readonly registryPath;
|
|
8
|
+
private readonly installRoot;
|
|
9
|
+
private readonly now;
|
|
10
|
+
constructor(options: PluginManagerOptions);
|
|
11
|
+
list(): Promise<readonly ManagedPlugin[]>;
|
|
12
|
+
enable(id: string): Promise<ManagedPlugin>;
|
|
13
|
+
disable(id: string): Promise<ManagedPlugin>;
|
|
14
|
+
remove(id: string): Promise<void>;
|
|
15
|
+
installLocal(sourcePath: string): Promise<ManagedPlugin>;
|
|
16
|
+
install(source: string): Promise<ManagedPlugin>;
|
|
17
|
+
update(id: string): Promise<ManagedPlugin>;
|
|
18
|
+
private installCopied;
|
|
19
|
+
private setEnabled;
|
|
20
|
+
private readRegistry;
|
|
21
|
+
private writeRegistry;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/plugins/manager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,YAAY,CAAC;AAEhE,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAC1B;AAgBD,qBAAa,aAAa;IACzB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAa;gBACrB,OAAO,EAAE,oBAAoB;IAKnC,IAAI,IAAI,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC;IAGzC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAG1C,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAG3C,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASjC,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAuBxD,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAwB/C,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;YAMlC,aAAa;YAuBb,UAAU;YASV,YAAY;YAQZ,aAAa;CAM3B"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { cp, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
4
|
+
import { readPackagePluginManifest, readPluginManifest } from "./manifest.js";
|
|
5
|
+
function emptyRegistry() {
|
|
6
|
+
return { version: 1, plugins: {} };
|
|
7
|
+
}
|
|
8
|
+
function isRegistry(value) {
|
|
9
|
+
if (typeof value !== "object" || value === null)
|
|
10
|
+
return false;
|
|
11
|
+
const candidate = value;
|
|
12
|
+
return candidate.version === 1 && typeof candidate.plugins === "object" && candidate.plugins !== null;
|
|
13
|
+
}
|
|
14
|
+
function assertManagedPath(target, root) {
|
|
15
|
+
const child = relative(resolve(root), resolve(target));
|
|
16
|
+
if (!child || child.startsWith("..") || isAbsolute(child))
|
|
17
|
+
throw new Error("plugin path is outside the managed install directory");
|
|
18
|
+
}
|
|
19
|
+
export class PluginManager {
|
|
20
|
+
registryPath;
|
|
21
|
+
installRoot;
|
|
22
|
+
now;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
this.registryPath = resolve(options.agentDir, "plugins", "registry.json");
|
|
25
|
+
this.installRoot = resolve(options.agentDir, "plugins", "installed");
|
|
26
|
+
this.now = options.now ?? (() => new Date());
|
|
27
|
+
}
|
|
28
|
+
async list() {
|
|
29
|
+
return Object.values((await this.readRegistry()).plugins).sort((a, b) => a.id.localeCompare(b.id));
|
|
30
|
+
}
|
|
31
|
+
async enable(id) {
|
|
32
|
+
return this.setEnabled(id, true);
|
|
33
|
+
}
|
|
34
|
+
async disable(id) {
|
|
35
|
+
return this.setEnabled(id, false);
|
|
36
|
+
}
|
|
37
|
+
async remove(id) {
|
|
38
|
+
const registry = await this.readRegistry();
|
|
39
|
+
const plugin = registry.plugins[id];
|
|
40
|
+
if (!plugin)
|
|
41
|
+
throw new Error(`Unknown plugin: ${id}`);
|
|
42
|
+
assertManagedPath(plugin.installedPath, this.installRoot);
|
|
43
|
+
await rm(plugin.installedPath, { recursive: true, force: true });
|
|
44
|
+
delete registry.plugins[id];
|
|
45
|
+
await this.writeRegistry(registry);
|
|
46
|
+
}
|
|
47
|
+
async installLocal(sourcePath) {
|
|
48
|
+
const source = resolve(sourcePath);
|
|
49
|
+
const manifest = await readPluginManifest(join(source, "plugin.json")).catch(() => readPackagePluginManifest(source));
|
|
50
|
+
const destination = resolve(this.installRoot, manifest.id);
|
|
51
|
+
assertManagedPath(destination, this.installRoot);
|
|
52
|
+
await mkdir(this.installRoot, { recursive: true });
|
|
53
|
+
await rm(destination, { recursive: true, force: true });
|
|
54
|
+
await cp(source, destination, { recursive: true, force: false, errorOnExist: false });
|
|
55
|
+
const plugin = {
|
|
56
|
+
id: manifest.id,
|
|
57
|
+
source,
|
|
58
|
+
installedPath: destination,
|
|
59
|
+
enabled: true,
|
|
60
|
+
installedAt: this.now().toISOString(),
|
|
61
|
+
manifest,
|
|
62
|
+
};
|
|
63
|
+
const registry = await this.readRegistry();
|
|
64
|
+
registry.plugins[plugin.id] = plugin;
|
|
65
|
+
await this.writeRegistry(registry);
|
|
66
|
+
return plugin;
|
|
67
|
+
}
|
|
68
|
+
async install(source) {
|
|
69
|
+
if (!source.startsWith("npm:") && !source.startsWith("git:"))
|
|
70
|
+
return this.installLocal(source);
|
|
71
|
+
const staging = resolve(this.installRoot, `.staging-${process.pid}-${Date.now()}`);
|
|
72
|
+
await mkdir(staging, { recursive: true });
|
|
73
|
+
try {
|
|
74
|
+
if (source.startsWith("npm:")) {
|
|
75
|
+
await runCommand("npm", ["install", "--ignore-scripts", "--prefix", staging, source.slice(4)], this.installRoot);
|
|
76
|
+
const modules = join(staging, "node_modules");
|
|
77
|
+
const packageName = source.slice(4).replace(/@[^@]+$/, "");
|
|
78
|
+
const sourceRoot = join(modules, packageName);
|
|
79
|
+
return await this.installCopied(sourceRoot, source, staging);
|
|
80
|
+
}
|
|
81
|
+
await rm(staging, { recursive: true, force: true });
|
|
82
|
+
await runCommand("git", ["clone", "--depth", "1", source.slice(4), staging], this.installRoot);
|
|
83
|
+
return await this.installCopied(staging, source, staging);
|
|
84
|
+
}
|
|
85
|
+
catch (cause) {
|
|
86
|
+
await rm(staging, { recursive: true, force: true });
|
|
87
|
+
throw cause;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async update(id) {
|
|
91
|
+
const plugin = (await this.readRegistry()).plugins[id];
|
|
92
|
+
if (!plugin)
|
|
93
|
+
throw new Error(`Unknown plugin: ${id}`);
|
|
94
|
+
const updated = await this.install(plugin.source);
|
|
95
|
+
return plugin.enabled ? updated : this.disable(updated.id);
|
|
96
|
+
}
|
|
97
|
+
async installCopied(sourceRoot, source, temporaryRoot) {
|
|
98
|
+
const manifest = await readPluginManifest(join(sourceRoot, "plugin.json")).catch(() => readPackagePluginManifest(sourceRoot));
|
|
99
|
+
const destination = resolve(this.installRoot, manifest.id);
|
|
100
|
+
assertManagedPath(destination, this.installRoot);
|
|
101
|
+
await mkdir(this.installRoot, { recursive: true });
|
|
102
|
+
await rm(destination, { recursive: true, force: true });
|
|
103
|
+
await cp(sourceRoot, destination, { recursive: true, force: false, errorOnExist: false });
|
|
104
|
+
if (resolve(temporaryRoot) !== resolve(sourceRoot))
|
|
105
|
+
await rm(temporaryRoot, { recursive: true, force: true });
|
|
106
|
+
const plugin = {
|
|
107
|
+
id: manifest.id,
|
|
108
|
+
source,
|
|
109
|
+
installedPath: destination,
|
|
110
|
+
enabled: true,
|
|
111
|
+
installedAt: this.now().toISOString(),
|
|
112
|
+
manifest,
|
|
113
|
+
};
|
|
114
|
+
const registry = await this.readRegistry();
|
|
115
|
+
registry.plugins[plugin.id] = plugin;
|
|
116
|
+
await this.writeRegistry(registry);
|
|
117
|
+
return plugin;
|
|
118
|
+
}
|
|
119
|
+
async setEnabled(id, enabled) {
|
|
120
|
+
const registry = await this.readRegistry();
|
|
121
|
+
const plugin = registry.plugins[id];
|
|
122
|
+
if (!plugin)
|
|
123
|
+
throw new Error(`Unknown plugin: ${id}`);
|
|
124
|
+
const next = { ...plugin, enabled };
|
|
125
|
+
registry.plugins[id] = next;
|
|
126
|
+
await this.writeRegistry(registry);
|
|
127
|
+
return next;
|
|
128
|
+
}
|
|
129
|
+
async readRegistry() {
|
|
130
|
+
try {
|
|
131
|
+
const value = JSON.parse(await readFile(this.registryPath, "utf8"));
|
|
132
|
+
return isRegistry(value) ? { version: 1, plugins: { ...value.plugins } } : emptyRegistry();
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return emptyRegistry();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async writeRegistry(registry) {
|
|
139
|
+
await mkdir(dirname(this.registryPath), { recursive: true });
|
|
140
|
+
const temporary = `${this.registryPath}.tmp-${process.pid}`;
|
|
141
|
+
await writeFile(temporary, `${JSON.stringify(registry, null, 2)}\n`, "utf8");
|
|
142
|
+
await rename(temporary, this.registryPath);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function runCommand(command, args, cwd) {
|
|
146
|
+
await new Promise((resolveResult, reject) => {
|
|
147
|
+
const child = spawn(command, [...args], { cwd, stdio: "ignore" });
|
|
148
|
+
child.once("error", reject);
|
|
149
|
+
child.once("close", (code) => code === 0 ? resolveResult() : reject(new Error(`${command} plugin install failed`)));
|
|
150
|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G,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAClE,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAC5B,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,GAAG,OAAO,wBAAwB,CAAC,CAAC,CACpF,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { cp, mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, isAbsolute, join, relative, resolve } from \"node:path\";\nimport { readPackagePluginManifest, readPluginManifest } from \"./manifest.ts\";\nimport type { ManagedPlugin, PluginRegistry } from \"./types.ts\";\n\nexport interface PluginManagerOptions {\n\treadonly agentDir: string;\n\treadonly now?: () => Date;\n}\n\nfunction emptyRegistry(): PluginRegistry {\n\treturn { version: 1, plugins: {} };\n}\nfunction isRegistry(value: unknown): value is PluginRegistry {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst candidate = value as { version?: unknown; plugins?: unknown };\n\treturn candidate.version === 1 && typeof candidate.plugins === \"object\" && candidate.plugins !== null;\n}\nfunction assertManagedPath(target: string, root: string): void {\n\tconst child = relative(resolve(root), resolve(target));\n\tif (!child || child.startsWith(\"..\") || isAbsolute(child))\n\t\tthrow new Error(\"plugin path is outside the managed install directory\");\n}\n\nexport class PluginManager {\n\tprivate readonly registryPath: string;\n\tprivate readonly installRoot: string;\n\tprivate readonly now: () => Date;\n\tconstructor(options: PluginManagerOptions) {\n\t\tthis.registryPath = resolve(options.agentDir, \"plugins\", \"registry.json\");\n\t\tthis.installRoot = resolve(options.agentDir, \"plugins\", \"installed\");\n\t\tthis.now = options.now ?? (() => new Date());\n\t}\n\tasync list(): Promise<readonly ManagedPlugin[]> {\n\t\treturn Object.values((await this.readRegistry()).plugins).sort((a, b) => a.id.localeCompare(b.id));\n\t}\n\tasync enable(id: string): Promise<ManagedPlugin> {\n\t\treturn this.setEnabled(id, true);\n\t}\n\tasync disable(id: string): Promise<ManagedPlugin> {\n\t\treturn this.setEnabled(id, false);\n\t}\n\tasync remove(id: string): Promise<void> {\n\t\tconst registry = await this.readRegistry();\n\t\tconst plugin = registry.plugins[id];\n\t\tif (!plugin) throw new Error(`Unknown plugin: ${id}`);\n\t\tassertManagedPath(plugin.installedPath, this.installRoot);\n\t\tawait rm(plugin.installedPath, { recursive: true, force: true });\n\t\tdelete registry.plugins[id];\n\t\tawait this.writeRegistry(registry);\n\t}\n\tasync installLocal(sourcePath: string): Promise<ManagedPlugin> {\n\t\tconst source = resolve(sourcePath);\n\t\tconst manifest = await readPluginManifest(join(source, \"plugin.json\")).catch(() =>\n\t\t\treadPackagePluginManifest(source),\n\t\t);\n\t\tconst destination = resolve(this.installRoot, manifest.id);\n\t\tassertManagedPath(destination, this.installRoot);\n\t\tawait mkdir(this.installRoot, { recursive: true });\n\t\tawait rm(destination, { recursive: true, force: true });\n\t\tawait cp(source, destination, { recursive: true, force: false, errorOnExist: false });\n\t\tconst plugin: ManagedPlugin = {\n\t\t\tid: manifest.id,\n\t\t\tsource,\n\t\t\tinstalledPath: destination,\n\t\t\tenabled: true,\n\t\t\tinstalledAt: this.now().toISOString(),\n\t\t\tmanifest,\n\t\t};\n\t\tconst registry = await this.readRegistry();\n\t\tregistry.plugins[plugin.id] = plugin;\n\t\tawait this.writeRegistry(registry);\n\t\treturn plugin;\n\t}\n\tasync install(source: string): Promise<ManagedPlugin> {\n\t\tif (!source.startsWith(\"npm:\") && !source.startsWith(\"git:\")) return this.installLocal(source);\n\t\tconst staging = resolve(this.installRoot, `.staging-${process.pid}-${Date.now()}`);\n\t\tawait mkdir(staging, { recursive: true });\n\t\ttry {\n\t\t\tif (source.startsWith(\"npm:\")) {\n\t\t\t\tawait runCommand(\n\t\t\t\t\t\"npm\",\n\t\t\t\t\t[\"install\", \"--ignore-scripts\", \"--prefix\", staging, source.slice(4)],\n\t\t\t\t\tthis.installRoot,\n\t\t\t\t);\n\t\t\t\tconst modules = join(staging, \"node_modules\");\n\t\t\t\tconst packageName = source.slice(4).replace(/@[^@]+$/, \"\");\n\t\t\t\tconst sourceRoot = join(modules, packageName);\n\t\t\t\treturn await this.installCopied(sourceRoot, source, staging);\n\t\t\t}\n\t\t\tawait rm(staging, { recursive: true, force: true });\n\t\t\tawait runCommand(\"git\", [\"clone\", \"--depth\", \"1\", source.slice(4), staging], this.installRoot);\n\t\t\treturn await this.installCopied(staging, source, staging);\n\t\t} catch (cause) {\n\t\t\tawait rm(staging, { recursive: true, force: true });\n\t\t\tthrow cause;\n\t\t}\n\t}\n\tasync update(id: string): Promise<ManagedPlugin> {\n\t\tconst plugin = (await this.readRegistry()).plugins[id];\n\t\tif (!plugin) throw new Error(`Unknown plugin: ${id}`);\n\t\tconst updated = await this.install(plugin.source);\n\t\treturn plugin.enabled ? updated : this.disable(updated.id);\n\t}\n\tprivate async installCopied(sourceRoot: string, source: string, temporaryRoot: string): Promise<ManagedPlugin> {\n\t\tconst manifest = await readPluginManifest(join(sourceRoot, \"plugin.json\")).catch(() =>\n\t\t\treadPackagePluginManifest(sourceRoot),\n\t\t);\n\t\tconst destination = resolve(this.installRoot, manifest.id);\n\t\tassertManagedPath(destination, this.installRoot);\n\t\tawait mkdir(this.installRoot, { recursive: true });\n\t\tawait rm(destination, { recursive: true, force: true });\n\t\tawait cp(sourceRoot, destination, { recursive: true, force: false, errorOnExist: false });\n\t\tif (resolve(temporaryRoot) !== resolve(sourceRoot)) await rm(temporaryRoot, { recursive: true, force: true });\n\t\tconst plugin: ManagedPlugin = {\n\t\t\tid: manifest.id,\n\t\t\tsource,\n\t\t\tinstalledPath: destination,\n\t\t\tenabled: true,\n\t\t\tinstalledAt: this.now().toISOString(),\n\t\t\tmanifest,\n\t\t};\n\t\tconst registry = await this.readRegistry();\n\t\tregistry.plugins[plugin.id] = plugin;\n\t\tawait this.writeRegistry(registry);\n\t\treturn plugin;\n\t}\n\tprivate async setEnabled(id: string, enabled: boolean): Promise<ManagedPlugin> {\n\t\tconst registry = await this.readRegistry();\n\t\tconst plugin = registry.plugins[id];\n\t\tif (!plugin) throw new Error(`Unknown plugin: ${id}`);\n\t\tconst next = { ...plugin, enabled };\n\t\tregistry.plugins[id] = next;\n\t\tawait this.writeRegistry(registry);\n\t\treturn next;\n\t}\n\tprivate async readRegistry(): Promise<PluginRegistry> {\n\t\ttry {\n\t\t\tconst value: unknown = JSON.parse(await readFile(this.registryPath, \"utf8\"));\n\t\t\treturn isRegistry(value) ? { version: 1, plugins: { ...value.plugins } } : emptyRegistry();\n\t\t} catch {\n\t\t\treturn emptyRegistry();\n\t\t}\n\t}\n\tprivate async writeRegistry(registry: PluginRegistry): Promise<void> {\n\t\tawait mkdir(dirname(this.registryPath), { recursive: true });\n\t\tconst temporary = `${this.registryPath}.tmp-${process.pid}`;\n\t\tawait writeFile(temporary, `${JSON.stringify(registry, null, 2)}\\n`, \"utf8\");\n\t\tawait rename(temporary, this.registryPath);\n\t}\n}\n\nasync function runCommand(command: string, args: readonly string[], cwd: string): Promise<void> {\n\tawait new Promise<void>((resolveResult, reject) => {\n\t\tconst child = spawn(command, [...args], { cwd, stdio: \"ignore\" });\n\t\tchild.once(\"error\", reject);\n\t\tchild.once(\"close\", (code) =>\n\t\t\tcode === 0 ? resolveResult() : reject(new Error(`${command} plugin install failed`)),\n\t\t);\n\t});\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type PluginManifest } from "./types.ts";
|
|
2
|
+
export declare function parsePluginManifest(value: unknown): PluginManifest;
|
|
3
|
+
export declare function readPluginManifest(manifestPath: string): Promise<PluginManifest>;
|
|
4
|
+
export declare function readPackagePluginManifest(root: string): Promise<PluginManifest>;
|
|
5
|
+
export declare function resolvePluginEntry(root: string, entry: string): Promise<string>;
|
|
6
|
+
export declare function pluginRootFromManifest(manifestPath: string): string;
|
|
7
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/plugins/manifest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,KAAK,cAAc,EAA0B,MAAM,YAAY,CAAC;AA4C7F,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAgBlE;AAED,wBAAsB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAQtF;AAED,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAqBrF;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBrF;AAED,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAEnE"}
|