@ashx-j/lunr 0.2.24 → 0.2.26
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/CHANGELOG.md +24 -1
- package/dist/builtin-extensions/index.d.ts.map +1 -1
- package/dist/builtin-extensions/index.js +1 -0
- package/dist/builtin-extensions/index.js.map +1 -1
- package/dist/builtin-extensions/lunr-computer-use.d.ts +3 -0
- package/dist/builtin-extensions/lunr-computer-use.d.ts.map +1 -0
- package/dist/builtin-extensions/lunr-computer-use.js +179 -0
- package/dist/builtin-extensions/lunr-computer-use.js.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts +4 -4
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js +8 -5
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js +11 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js +3 -3
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js +15 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/chain-outputs.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/chain-outputs.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/chain-outputs.js +5 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/chain-outputs.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.js +2 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js +5 -3
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js.map +1 -1
- package/dist/core/computer-use/adapter.d.ts +28 -0
- package/dist/core/computer-use/adapter.d.ts.map +1 -0
- package/dist/core/computer-use/adapter.js +133 -0
- package/dist/core/computer-use/adapter.js.map +1 -0
- package/dist/core/computer-use/image.d.ts +27 -0
- package/dist/core/computer-use/image.d.ts.map +1 -0
- package/dist/core/computer-use/image.js +72 -0
- package/dist/core/computer-use/image.js.map +1 -0
- package/dist/core/computer-use/lease.d.ts +18 -0
- package/dist/core/computer-use/lease.d.ts.map +1 -0
- package/dist/core/computer-use/lease.js +129 -0
- package/dist/core/computer-use/lease.js.map +1 -0
- package/dist/core/computer-use/macos-runtime.d.ts +14 -0
- package/dist/core/computer-use/macos-runtime.d.ts.map +1 -0
- package/dist/core/computer-use/macos-runtime.js +148 -0
- package/dist/core/computer-use/macos-runtime.js.map +1 -0
- package/dist/core/computer-use/policy.d.ts +19 -0
- package/dist/core/computer-use/policy.d.ts.map +1 -0
- package/dist/core/computer-use/policy.js +67 -0
- package/dist/core/computer-use/policy.js.map +1 -0
- package/dist/core/computer-use/release.generated.d.ts +31 -0
- package/dist/core/computer-use/release.generated.d.ts.map +1 -0
- package/dist/core/computer-use/release.generated.js +36 -0
- package/dist/core/computer-use/release.generated.js.map +1 -0
- package/dist/core/computer-use/runtime.d.ts +13 -0
- package/dist/core/computer-use/runtime.d.ts.map +1 -0
- package/dist/core/computer-use/runtime.js +158 -0
- package/dist/core/computer-use/runtime.js.map +1 -0
- package/dist/core/computer-use/schemas.d.ts +100 -0
- package/dist/core/computer-use/schemas.d.ts.map +1 -0
- package/dist/core/computer-use/schemas.js +79 -0
- package/dist/core/computer-use/schemas.js.map +1 -0
- package/dist/core/computer-use/windows-desktop.d.ts +3 -0
- package/dist/core/computer-use/windows-desktop.d.ts.map +1 -0
- package/dist/core/computer-use/windows-desktop.js +48 -0
- package/dist/core/computer-use/windows-desktop.js.map +1 -0
- package/dist/core/computer-use/workflow.d.ts +38 -0
- package/dist/core/computer-use/workflow.d.ts.map +1 -0
- package/dist/core/computer-use/workflow.js +560 -0
- package/dist/core/computer-use/workflow.js.map +1 -0
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +4 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/permissions.d.ts +1 -1
- package/dist/core/permissions.d.ts.map +1 -1
- package/dist/core/permissions.js +14 -3
- package/dist/core/permissions.js.map +1 -1
- package/dist/core/plan-mode.d.ts.map +1 -1
- package/dist/core/plan-mode.js +9 -0
- package/dist/core/plan-mode.js.map +1 -1
- package/dist/core/settings-manager.d.ts +6 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +19 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/subagent-event-transport.d.ts +3 -0
- package/dist/core/subagent-event-transport.d.ts.map +1 -0
- package/dist/core/subagent-event-transport.js +61 -0
- package/dist/core/subagent-event-transport.js.map +1 -0
- package/dist/gateway/adapters/discord.d.ts.map +1 -1
- package/dist/gateway/adapters/discord.js +4 -9
- package/dist/gateway/adapters/discord.js.map +1 -1
- package/dist/gateway/adapters/telegram.d.ts.map +1 -1
- package/dist/gateway/adapters/telegram.js +7 -0
- package/dist/gateway/adapters/telegram.js.map +1 -1
- package/dist/gateway/agent-bridge.d.ts +4 -1
- package/dist/gateway/agent-bridge.d.ts.map +1 -1
- package/dist/gateway/agent-bridge.js +57 -17
- package/dist/gateway/agent-bridge.js.map +1 -1
- package/dist/gateway/approval.d.ts.map +1 -1
- package/dist/gateway/approval.js +3 -3
- package/dist/gateway/approval.js.map +1 -1
- package/dist/gateway/authz.d.ts +4 -4
- package/dist/gateway/authz.d.ts.map +1 -1
- package/dist/gateway/authz.js +8 -12
- package/dist/gateway/authz.js.map +1 -1
- package/dist/gateway/buttons.d.ts.map +1 -1
- package/dist/gateway/buttons.js +29 -19
- package/dist/gateway/buttons.js.map +1 -1
- package/dist/gateway/commands.d.ts +2 -0
- package/dist/gateway/commands.d.ts.map +1 -1
- package/dist/gateway/commands.js +35 -18
- package/dist/gateway/commands.js.map +1 -1
- package/dist/gateway/config.d.ts +1 -0
- package/dist/gateway/config.d.ts.map +1 -1
- package/dist/gateway/config.js +2 -0
- package/dist/gateway/config.js.map +1 -1
- package/dist/gateway/cron.d.ts +1 -1
- package/dist/gateway/cron.d.ts.map +1 -1
- package/dist/gateway/cron.js +22 -8
- package/dist/gateway/cron.js.map +1 -1
- package/dist/gateway/index.d.ts.map +1 -1
- package/dist/gateway/index.js +26 -26
- package/dist/gateway/index.js.map +1 -1
- package/dist/gateway/mobile-commands.d.ts.map +1 -1
- package/dist/gateway/mobile-commands.js +11 -11
- package/dist/gateway/mobile-commands.js.map +1 -1
- package/dist/gateway/presenter.d.ts +12 -1
- package/dist/gateway/presenter.d.ts.map +1 -1
- package/dist/gateway/presenter.js +148 -50
- package/dist/gateway/presenter.js.map +1 -1
- package/dist/gateway/router.d.ts +5 -5
- package/dist/gateway/router.d.ts.map +1 -1
- package/dist/gateway/router.js +95 -43
- package/dist/gateway/router.js.map +1 -1
- package/dist/gateway/service.d.ts.map +1 -1
- package/dist/gateway/service.js +13 -4
- package/dist/gateway/service.js.map +1 -1
- package/dist/gateway/setup.d.ts +5 -0
- package/dist/gateway/setup.d.ts.map +1 -1
- package/dist/gateway/setup.js +101 -43
- package/dist/gateway/setup.js.map +1 -1
- package/dist/gateway/stream.d.ts +6 -5
- package/dist/gateway/stream.d.ts.map +1 -1
- package/dist/gateway/stream.js +24 -11
- package/dist/gateway/stream.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +4 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +20 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +8 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +9 -1
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/node-runtime/adapter-VFG7WNPX.js +17 -0
- package/dist/node-runtime/{agent-session-services-IEF7LQWD.js → agent-session-services-5YXS2PLF.js} +13 -10
- package/dist/node-runtime/{builtin-extensions-EBAWTH4M.js → builtin-extensions-I2HIFEMY.js} +3 -2
- package/dist/node-runtime/{chunk-K5AGHH57.js → chunk-2CFDTH5B.js} +7 -3
- package/dist/node-runtime/{chunk-VWCE2HSZ.js → chunk-2HMIRK7W.js} +4 -4
- package/dist/node-runtime/chunk-2IDTZAG5.js +1415 -0
- package/dist/node-runtime/{chunk-IGV54Q5V.js → chunk-3MISGG4S.js} +137 -76
- package/dist/node-runtime/chunk-4SBQAI4T.js +2185 -0
- package/dist/node-runtime/{chunk-WHLRAGUQ.js → chunk-5B5QN3ZQ.js} +16 -16
- package/dist/node-runtime/chunk-5B6VKFEV.js +180 -0
- package/dist/node-runtime/{chunk-AD6VXAO7.js → chunk-5Q4A37RB.js} +15 -104
- package/dist/node-runtime/{chunk-4TLO4PO2.js → chunk-7IQGBKBJ.js} +7 -1401
- package/dist/node-runtime/{chunk-R3K2F5GI.js → chunk-B4HP6ZWM.js} +2 -0
- package/dist/node-runtime/{chunk-OCVIXVTZ.js → chunk-D5UCKPBQ.js} +12 -1
- package/dist/node-runtime/chunk-DVQSHCVP.js +97 -0
- package/dist/node-runtime/{chunk-HFVZUPFJ.js → chunk-E75WFZ33.js} +2 -2
- package/dist/node-runtime/chunk-FY4A63RK.js +73 -0
- package/dist/node-runtime/{chunk-RORY2HMJ.js → chunk-I74LN5JG.js} +16 -1
- package/dist/node-runtime/chunk-IKU6Y7DL.js +287 -0
- package/dist/node-runtime/{chunk-QM43FEAE.js → chunk-L24TPBS4.js} +6 -5
- package/dist/node-runtime/{chunk-DE2JB6J5.js → chunk-LJTIVM7I.js} +7 -7
- package/dist/node-runtime/{chunk-DSIKTUPW.js → chunk-LWJXTA6Z.js} +274 -2433
- package/dist/node-runtime/{chunk-YVI6L6LU.js → chunk-P7XBVXGT.js} +36 -21
- package/dist/node-runtime/{chunk-OVX6X377.js → chunk-PTFBPO3C.js} +1 -1
- package/dist/node-runtime/{chunk-F4FLTQKV.js → chunk-RAK2QA2B.js} +186 -1529
- package/dist/node-runtime/{chunk-L3LX4SNR.js → chunk-RCR3XAQY.js} +36 -8
- package/dist/node-runtime/chunk-RGQAEOM5.js +81 -0
- package/dist/node-runtime/{chunk-UWPJL22I.js → chunk-SLVOAQOY.js} +15 -4
- package/dist/node-runtime/chunk-SN2KSMPQ.js +1364 -0
- package/dist/node-runtime/{chunk-FU6OODRZ.js → chunk-SPVDBUOS.js} +1 -1
- package/dist/node-runtime/{chunk-5Q3EHOHI.js → chunk-T4DA4XE7.js} +19 -17
- package/dist/node-runtime/chunk-U5F4IC7R.js +53 -0
- package/dist/node-runtime/{chunk-UP2XBVH5.js → chunk-UOEDI7RP.js} +1 -1
- package/dist/node-runtime/{chunk-Y73WPE6S.js → chunk-UVWCDQYF.js} +79 -44
- package/dist/node-runtime/{chunk-ZXSGTGJ6.js → chunk-WIF24I7G.js} +21 -5
- package/dist/node-runtime/{chunk-OF7PWMG4.js → chunk-X3PGBLQ7.js} +3 -87
- package/dist/node-runtime/chunk-XHIRAZ26.js +108 -0
- package/dist/node-runtime/{chunk-YDO2F2IA.js → chunk-YWOJIGFY.js} +1 -1
- package/dist/node-runtime/{command-7BG7VVTS.js → command-FSBU2EVZ.js} +5 -5
- package/dist/node-runtime/{commands-NZLSOHPE.js → commands-EMBQQVVT.js} +4 -2
- package/dist/node-runtime/{commands-QFDKNQTL.js → commands-NAAL7KNT.js} +7 -6
- package/dist/node-runtime/{config-RORQUQFG.js → config-D4QUPAHX.js} +1 -1
- package/dist/node-runtime/{direct-tool-executor-77GW4F5P.js → direct-tool-executor-4D7UXYU4.js} +7 -4
- package/dist/node-runtime/{gateway-TWR3N65G.js → gateway-DQM333YV.js} +140 -85
- package/dist/node-runtime/index.js +28 -21
- package/dist/node-runtime/{init-HS6NQXSK.js → init-P5AUV77I.js} +4 -2
- package/dist/node-runtime/{install-cli-VAP6KBFN.js → install-cli-NN4YAU44.js} +3 -3
- package/dist/node-runtime/{interactive-mode-6J5VZ2TT.js → interactive-mode-YOHZVMKX.js} +14 -11
- package/dist/node-runtime/{lunr-browser-J5ZZYVGM.js → lunr-browser-IR7TL3J7.js} +3 -3
- package/dist/node-runtime/lunr-computer-use-Y23CCDIJ.js +158 -0
- package/dist/node-runtime/{lunr-cron-CXOL37AL.js → lunr-cron-USHC4LXH.js} +9 -7
- package/dist/node-runtime/main.js +19 -15
- package/dist/node-runtime/{mcp-auth-flow-QIXHW6QN.js → mcp-auth-flow-QVLFVLEO.js} +2 -1
- package/dist/node-runtime/{mobile-commands-VTBM5DSZ.js → mobile-commands-O5LCHL32.js} +6 -5
- package/dist/node-runtime/{package-manager-cli-ZLW5DZXF.js → package-manager-cli-Q7BL6KZO.js} +12 -8
- package/dist/node-runtime/{pi-mcp-adapter-5UKBZP44.js → pi-mcp-adapter-3PHF4KZ4.js} +5 -5
- package/dist/node-runtime/{pi-subagents-XPCLLKIM.js → pi-subagents-7IBSSGEW.js} +27 -21
- package/dist/node-runtime/{print-mode-XSFM26EL.js → print-mode-XQ76CYMT.js} +2 -1
- package/dist/node-runtime/{proxy-modes-LGEUYD7R.js → proxy-modes-5FAPSZEZ.js} +7 -4
- package/dist/node-runtime/rpc-entry.js +19 -15
- package/dist/node-runtime/runtime-EFPPD2UW.js +21 -0
- package/dist/node-runtime/{runtime-bridges-QYXUX2TG.js → runtime-bridges-7WVCLI76.js} +6 -5
- package/dist/node-runtime/{service-ISSP6VHE.js → service-MDQIPQ26.js} +1 -1
- package/dist/node-runtime/{settings-manager-WCQDUVQB.js → settings-manager-DJDM5AHM.js} +5 -4
- package/dist/node-runtime/setup-PFBWRNUI.js +215 -0
- package/dist/node-runtime/{subagent-executor-OTNISDQU.js → subagent-executor-LPZ4BHWE.js} +32 -14
- package/dist/node-runtime/{update-cli-VBR2777K.js → update-cli-HNMOTNGX.js} +5 -4
- package/dist/node-runtime/workflow-OHPBEFO4.js +637 -0
- package/dist/utils/image-resize-core.d.ts +2 -0
- package/dist/utils/image-resize-core.d.ts.map +1 -1
- package/dist/utils/image-resize-core.js +10 -0
- package/dist/utils/image-resize-core.js.map +1 -1
- package/docs/computer-use.md +362 -0
- package/docs/features.md +9 -7
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/install-lock/package-lock.json +3841 -0
- package/install-lock/package.json +18 -0
- package/native/computer-use/LICENSE.md +21 -0
- package/npm-shrinkwrap.json +3822 -0
- package/package.json +15 -9
- package/dist/node-runtime/setup-YRBKH2LD.js +0 -155
|
@@ -1,42 +1,21 @@
|
|
|
1
1
|
import { createRequire as __lunrRequire } from "node:module"; const require = __lunrRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
isStdoutTakenOver
|
|
4
|
-
} from "./chunk-OBMWP3I5.js";
|
|
5
2
|
import {
|
|
6
3
|
require_semver
|
|
7
4
|
} from "./chunk-DVGWF6A2.js";
|
|
8
5
|
import {
|
|
9
|
-
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import {
|
|
12
|
-
SettingsManager
|
|
13
|
-
} from "./chunk-RORY2HMJ.js";
|
|
6
|
+
isStdoutTakenOver
|
|
7
|
+
} from "./chunk-OBMWP3I5.js";
|
|
14
8
|
import {
|
|
15
9
|
minimatch
|
|
16
10
|
} from "./chunk-CGBXPL3E.js";
|
|
17
|
-
import {
|
|
18
|
-
getGlobalInstructionsPath,
|
|
19
|
-
loadSelectedUserInstructions
|
|
20
|
-
} from "./chunk-M3LZLQW2.js";
|
|
21
|
-
import {
|
|
22
|
-
measureStartup,
|
|
23
|
-
resetTimings
|
|
24
|
-
} from "./chunk-PVCDKGR6.js";
|
|
25
|
-
import {
|
|
26
|
-
loadThemeFromPath
|
|
27
|
-
} from "./chunk-RDDAZOMU.js";
|
|
28
11
|
import {
|
|
29
12
|
CONFIG_DIR_NAME,
|
|
30
13
|
canonicalizePath,
|
|
31
|
-
getAgentDir,
|
|
32
|
-
isBunBinary,
|
|
33
14
|
isLocalPath,
|
|
34
|
-
isNodeBundle,
|
|
35
15
|
markPathIgnoredByCloudSync,
|
|
36
16
|
resolvePath,
|
|
37
17
|
spawnProcess,
|
|
38
|
-
spawnProcessSync
|
|
39
|
-
waitForChildProcess
|
|
18
|
+
spawnProcessSync
|
|
40
19
|
} from "./chunk-FQMM2EZ2.js";
|
|
41
20
|
import {
|
|
42
21
|
__commonJS,
|
|
@@ -634,13 +613,13 @@ var require_hosts = __commonJS({
|
|
|
634
613
|
var maybeJoin = (...args) => args.every((arg) => arg) ? args.join("") : "", maybeEncode = (arg) => arg ? encodeURIComponent(arg) : "", formatHashFragment = (f) => f.toLowerCase().replace(/^\W+/g, "").replace(/(?<!\W)\W+$/, "").replace(/\//g, "").replace(/\W+/g, "-"), defaults = {
|
|
635
614
|
sshtemplate: ({ domain, user, project, committish }) => `git@${domain}:${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
636
615
|
sshurltemplate: ({ domain, user, project, committish }) => `git+ssh://git@${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
637
|
-
edittemplate: ({ domain, user, project, committish, editpath, path
|
|
616
|
+
edittemplate: ({ domain, user, project, committish, editpath, path }) => `https://${domain}/${user}/${project}${maybeJoin("/", editpath, "/", maybeEncode(committish || "HEAD"), "/", path)}`,
|
|
638
617
|
browsetemplate: ({ domain, user, project, committish, treepath }) => `https://${domain}/${user}/${project}${maybeJoin("/", treepath, "/", maybeEncode(committish))}`,
|
|
639
|
-
browsetreetemplate: ({ domain, user, project, committish, treepath, path
|
|
640
|
-
browseblobtemplate: ({ domain, user, project, committish, blobpath, path
|
|
618
|
+
browsetreetemplate: ({ domain, user, project, committish, treepath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${treepath}/${maybeEncode(committish || "HEAD")}/${path}${maybeJoin("#", hashformat(fragment || ""))}`,
|
|
619
|
+
browseblobtemplate: ({ domain, user, project, committish, blobpath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${blobpath}/${maybeEncode(committish || "HEAD")}/${path}${maybeJoin("#", hashformat(fragment || ""))}`,
|
|
641
620
|
docstemplate: ({ domain, user, project, treepath, committish }) => `https://${domain}/${user}/${project}${maybeJoin("/", treepath, "/", maybeEncode(committish))}#readme`,
|
|
642
621
|
httpstemplate: ({ auth, domain, user, project, committish }) => `git+https://${maybeJoin(auth, "@")}${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
643
|
-
filetemplate: ({ domain, user, project, committish, path
|
|
622
|
+
filetemplate: ({ domain, user, project, committish, path }) => `https://${domain}/${user}/${project}/raw/${maybeEncode(committish || "HEAD")}/${path}`,
|
|
644
623
|
shortcuttemplate: ({ type, user, project, committish }) => `${type}:${user}/${project}${maybeJoin("#", committish)}`,
|
|
645
624
|
pathtemplate: ({ user, project, committish }) => `${user}/${project}${maybeJoin("#", committish)}`,
|
|
646
625
|
bugstemplate: ({ domain, user, project }) => `https://${domain}/${user}/${project}/issues`,
|
|
@@ -654,7 +633,7 @@ var require_hosts = __commonJS({
|
|
|
654
633
|
treepath: "tree",
|
|
655
634
|
blobpath: "blob",
|
|
656
635
|
editpath: "edit",
|
|
657
|
-
filetemplate: ({ auth, user, project, committish, path
|
|
636
|
+
filetemplate: ({ auth, user, project, committish, path }) => `https://${maybeJoin(auth, "@")}raw.githubusercontent.com/${user}/${project}/${maybeEncode(committish || "HEAD")}/${path}`,
|
|
658
637
|
gittemplate: ({ auth, domain, user, project, committish }) => `git://${maybeJoin(auth, "@")}${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
659
638
|
tarballtemplate: ({ domain, user, project, committish }) => `https://codeload.${domain}/${user}/${project}/tar.gz/${maybeEncode(committish || "HEAD")}`,
|
|
660
639
|
extract: (url) => {
|
|
@@ -669,7 +648,7 @@ var require_hosts = __commonJS({
|
|
|
669
648
|
treepath: "src",
|
|
670
649
|
blobpath: "src",
|
|
671
650
|
editpath: "?mode=edit",
|
|
672
|
-
edittemplate: ({ domain, user, project, committish, treepath, path
|
|
651
|
+
edittemplate: ({ domain, user, project, committish, treepath, path, editpath }) => `https://${domain}/${user}/${project}${maybeJoin("/", treepath, "/", maybeEncode(committish || "HEAD"), "/", path, editpath)}`,
|
|
673
652
|
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/get/${maybeEncode(committish || "HEAD")}.tar.gz`,
|
|
674
653
|
extract: (url) => {
|
|
675
654
|
let [, user, project, aux] = url.pathname.split("/", 4);
|
|
@@ -685,10 +664,10 @@ var require_hosts = __commonJS({
|
|
|
685
664
|
editpath: "-/edit",
|
|
686
665
|
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/api/v4/projects/${maybeEncode(user + "/" + project)}/repository/archive.tar.gz?sha=${maybeEncode(committish || "HEAD")}`,
|
|
687
666
|
extract: (url) => {
|
|
688
|
-
let
|
|
689
|
-
if (
|
|
667
|
+
let path = url.pathname.slice(1);
|
|
668
|
+
if (path.includes("/-/") || path.includes("/archive.tar.gz"))
|
|
690
669
|
return;
|
|
691
|
-
let segments =
|
|
670
|
+
let segments = path.split("/"), project = segments.pop();
|
|
692
671
|
project.endsWith(".git") && (project = project.slice(0, -4));
|
|
693
672
|
let user = segments.join("/");
|
|
694
673
|
if (!(!user || !project))
|
|
@@ -703,11 +682,11 @@ var require_hosts = __commonJS({
|
|
|
703
682
|
sshurltemplate: ({ domain, project, committish }) => `git+ssh://git@${domain}/${project}.git${maybeJoin("#", committish)}`,
|
|
704
683
|
edittemplate: ({ domain, user, project, committish, editpath }) => `https://${domain}/${user}/${project}${maybeJoin("/", maybeEncode(committish))}/${editpath}`,
|
|
705
684
|
browsetemplate: ({ domain, project, committish }) => `https://${domain}/${project}${maybeJoin("/", maybeEncode(committish))}`,
|
|
706
|
-
browsetreetemplate: ({ domain, project, committish, path
|
|
707
|
-
browseblobtemplate: ({ domain, project, committish, path
|
|
685
|
+
browsetreetemplate: ({ domain, project, committish, path, hashformat }) => `https://${domain}/${project}${maybeJoin("/", maybeEncode(committish))}${maybeJoin("#", hashformat(path))}`,
|
|
686
|
+
browseblobtemplate: ({ domain, project, committish, path, hashformat }) => `https://${domain}/${project}${maybeJoin("/", maybeEncode(committish))}${maybeJoin("#", hashformat(path))}`,
|
|
708
687
|
docstemplate: ({ domain, project, committish }) => `https://${domain}/${project}${maybeJoin("/", maybeEncode(committish))}`,
|
|
709
688
|
httpstemplate: ({ domain, project, committish }) => `git+https://${domain}/${project}.git${maybeJoin("#", committish)}`,
|
|
710
|
-
filetemplate: ({ user, project, committish, path
|
|
689
|
+
filetemplate: ({ user, project, committish, path }) => `https://gist.githubusercontent.com/${user}/${project}/raw${maybeJoin("/", maybeEncode(committish))}/${path}`,
|
|
711
690
|
shortcuttemplate: ({ type, project, committish }) => `${type}:${project}${maybeJoin("#", committish)}`,
|
|
712
691
|
pathtemplate: ({ project, committish }) => `${project}${maybeJoin("#", committish)}`,
|
|
713
692
|
bugstemplate: ({ domain, project }) => `https://${domain}/${project}`,
|
|
@@ -733,7 +712,7 @@ var require_hosts = __commonJS({
|
|
|
733
712
|
domain: "git.sr.ht",
|
|
734
713
|
treepath: "tree",
|
|
735
714
|
blobpath: "tree",
|
|
736
|
-
filetemplate: ({ domain, user, project, committish, path
|
|
715
|
+
filetemplate: ({ domain, user, project, committish, path }) => `https://${domain}/${user}/${project}/blob/${maybeEncode(committish) || "HEAD"}/${path}`,
|
|
737
716
|
httpstemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}${maybeJoin("#", committish)}`,
|
|
738
717
|
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/archive/${maybeEncode(committish) || "HEAD"}.tar.gz`,
|
|
739
718
|
bugstemplate: () => null,
|
|
@@ -835,8 +814,8 @@ var require_lib = __commonJS({
|
|
|
835
814
|
} = new URL(url);
|
|
836
815
|
if (!hostname)
|
|
837
816
|
return null;
|
|
838
|
-
let proto = /(?:git\+)http:$/.test(protocol) ? "http:" : "https:",
|
|
839
|
-
return `${proto}//${hostname}${
|
|
817
|
+
let proto = /(?:git\+)http:$/.test(protocol) ? "http:" : "https:", path = pathname.replace(/\.git$/, "");
|
|
818
|
+
return `${proto}//${hostname}${path}`;
|
|
840
819
|
} catch {
|
|
841
820
|
return null;
|
|
842
821
|
}
|
|
@@ -911,16 +890,16 @@ var require_lib = __commonJS({
|
|
|
911
890
|
sshurl(opts) {
|
|
912
891
|
return this.#fill(this.sshurltemplate, opts);
|
|
913
892
|
}
|
|
914
|
-
browse(
|
|
915
|
-
return typeof
|
|
893
|
+
browse(path, ...args) {
|
|
894
|
+
return typeof path != "string" ? this.#fill(this.browsetemplate, path) : typeof args[0] != "string" ? this.#fill(this.browsetreetemplate, { ...args[0], path }) : this.#fill(this.browsetreetemplate, { ...args[1], fragment: args[0], path });
|
|
916
895
|
}
|
|
917
896
|
// If the path is known to be a file, then browseFile should be used. For some hosts
|
|
918
897
|
// the url is the same as browse, but for others like GitHub a file can use both `/tree/`
|
|
919
898
|
// and `/blob/` in the path. When using a default committish of `HEAD` then the `/tree/`
|
|
920
899
|
// path will redirect to a specific commit. Using the `/blob/` path avoids this and
|
|
921
900
|
// does not redirect to a different commit.
|
|
922
|
-
browseFile(
|
|
923
|
-
return typeof args[0] != "string" ? this.#fill(this.browseblobtemplate, { ...args[0], path
|
|
901
|
+
browseFile(path, ...args) {
|
|
902
|
+
return typeof args[0] != "string" ? this.#fill(this.browseblobtemplate, { ...args[0], path }) : this.#fill(this.browseblobtemplate, { ...args[1], fragment: args[0], path });
|
|
924
903
|
}
|
|
925
904
|
docs(opts) {
|
|
926
905
|
return this.#fill(this.docstemplate, opts);
|
|
@@ -943,11 +922,11 @@ var require_lib = __commonJS({
|
|
|
943
922
|
tarball(opts) {
|
|
944
923
|
return this.#fill(this.tarballtemplate, { ...opts, noCommittish: !1 });
|
|
945
924
|
}
|
|
946
|
-
file(
|
|
947
|
-
return this.#fill(this.filetemplate, { ...opts, path
|
|
925
|
+
file(path, opts) {
|
|
926
|
+
return this.#fill(this.filetemplate, { ...opts, path });
|
|
948
927
|
}
|
|
949
|
-
edit(
|
|
950
|
-
return this.#fill(this.edittemplate, { ...opts, path
|
|
928
|
+
edit(path, opts) {
|
|
929
|
+
return this.#fill(this.edittemplate, { ...opts, path });
|
|
951
930
|
}
|
|
952
931
|
getDefaultRepresentation() {
|
|
953
932
|
return this.default;
|
|
@@ -1197,11 +1176,11 @@ var require_ignore = __commonJS({
|
|
|
1197
1176
|
// path matching.
|
|
1198
1177
|
// - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
|
|
1199
1178
|
// @returns {TestResult} true if a file is ignored
|
|
1200
|
-
test(
|
|
1179
|
+
test(path, checkUnignored, mode) {
|
|
1201
1180
|
let ignored = !1, unignored = !1, matchedRule;
|
|
1202
1181
|
this._rules.forEach((rule) => {
|
|
1203
1182
|
let { negative } = rule;
|
|
1204
|
-
unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored || !rule[mode].test(
|
|
1183
|
+
unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored || !rule[mode].test(path) || (ignored = !negative, unignored = negative, matchedRule = negative ? UNDEFINED : rule);
|
|
1205
1184
|
});
|
|
1206
1185
|
let ret = {
|
|
1207
1186
|
ignored,
|
|
@@ -1211,13 +1190,13 @@ var require_ignore = __commonJS({
|
|
|
1211
1190
|
}
|
|
1212
1191
|
}, throwError = (message, Ctor) => {
|
|
1213
1192
|
throw new Ctor(message);
|
|
1214
|
-
}, checkPath = (
|
|
1193
|
+
}, checkPath = (path, originalPath, doThrow) => isString(path) ? path ? checkPath.isNotRelative(path) ? doThrow(
|
|
1215
1194
|
`path should be a \`path.relative()\`d string, but got "${originalPath}"`,
|
|
1216
1195
|
RangeError
|
|
1217
1196
|
) : !0 : doThrow("path must not be empty", TypeError) : doThrow(
|
|
1218
1197
|
`path must be a string, but got \`${originalPath}\``,
|
|
1219
1198
|
TypeError
|
|
1220
|
-
), isNotRelative = (
|
|
1199
|
+
), isNotRelative = (path) => REGEX_TEST_INVALID_PATH.test(path);
|
|
1221
1200
|
checkPath.isNotRelative = isNotRelative;
|
|
1222
1201
|
checkPath.convert = (p) => p;
|
|
1223
1202
|
var Ignore = class {
|
|
@@ -1240,17 +1219,17 @@ var require_ignore = __commonJS({
|
|
|
1240
1219
|
}
|
|
1241
1220
|
// @returns {TestResult}
|
|
1242
1221
|
_test(originalPath, cache, checkUnignored, slices) {
|
|
1243
|
-
let
|
|
1222
|
+
let path = originalPath && checkPath.convert(originalPath);
|
|
1244
1223
|
return checkPath(
|
|
1245
|
-
|
|
1224
|
+
path,
|
|
1246
1225
|
originalPath,
|
|
1247
1226
|
this._strictPathCheck ? throwError : RETURN_FALSE
|
|
1248
|
-
), this._t(
|
|
1227
|
+
), this._t(path, cache, checkUnignored, slices);
|
|
1249
1228
|
}
|
|
1250
|
-
checkIgnore(
|
|
1251
|
-
if (!REGEX_TEST_TRAILING_SLASH.test(
|
|
1252
|
-
return this.test(
|
|
1253
|
-
let slices =
|
|
1229
|
+
checkIgnore(path) {
|
|
1230
|
+
if (!REGEX_TEST_TRAILING_SLASH.test(path))
|
|
1231
|
+
return this.test(path);
|
|
1232
|
+
let slices = path.split(SLASH).filter(Boolean);
|
|
1254
1233
|
if (slices.pop(), slices.length) {
|
|
1255
1234
|
let parent = this._t(
|
|
1256
1235
|
slices.join(SLASH) + SLASH,
|
|
@@ -1261,39 +1240,39 @@ var require_ignore = __commonJS({
|
|
|
1261
1240
|
if (parent.ignored)
|
|
1262
1241
|
return parent;
|
|
1263
1242
|
}
|
|
1264
|
-
return this._rules.test(
|
|
1243
|
+
return this._rules.test(path, !1, MODE_CHECK_IGNORE);
|
|
1265
1244
|
}
|
|
1266
|
-
_t(
|
|
1267
|
-
if (
|
|
1268
|
-
return cache[
|
|
1269
|
-
if (slices || (slices =
|
|
1270
|
-
return cache[
|
|
1245
|
+
_t(path, cache, checkUnignored, slices) {
|
|
1246
|
+
if (path in cache)
|
|
1247
|
+
return cache[path];
|
|
1248
|
+
if (slices || (slices = path.split(SLASH).filter(Boolean)), slices.pop(), !slices.length)
|
|
1249
|
+
return cache[path] = this._rules.test(path, checkUnignored, MODE_IGNORE);
|
|
1271
1250
|
let parent = this._t(
|
|
1272
1251
|
slices.join(SLASH) + SLASH,
|
|
1273
1252
|
cache,
|
|
1274
1253
|
checkUnignored,
|
|
1275
1254
|
slices
|
|
1276
1255
|
);
|
|
1277
|
-
return cache[
|
|
1256
|
+
return cache[path] = parent.ignored ? parent : this._rules.test(path, checkUnignored, MODE_IGNORE);
|
|
1278
1257
|
}
|
|
1279
|
-
ignores(
|
|
1280
|
-
return this._test(
|
|
1258
|
+
ignores(path) {
|
|
1259
|
+
return this._test(path, this._ignoreCache, !1).ignored;
|
|
1281
1260
|
}
|
|
1282
1261
|
createFilter() {
|
|
1283
|
-
return (
|
|
1262
|
+
return (path) => !this.ignores(path);
|
|
1284
1263
|
}
|
|
1285
1264
|
filter(paths) {
|
|
1286
1265
|
return makeArray(paths).filter(this.createFilter());
|
|
1287
1266
|
}
|
|
1288
1267
|
// @returns {TestResult}
|
|
1289
|
-
test(
|
|
1290
|
-
return this._test(
|
|
1268
|
+
test(path) {
|
|
1269
|
+
return this._test(path, this._testCache, !0);
|
|
1291
1270
|
}
|
|
1292
|
-
}, factory = (options) => new Ignore(options), isPathValid = (
|
|
1271
|
+
}, factory = (options) => new Ignore(options), isPathValid = (path) => checkPath(path && checkPath.convert(path), path, RETURN_FALSE), setupWindows = () => {
|
|
1293
1272
|
let makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
|
|
1294
1273
|
checkPath.convert = makePosix;
|
|
1295
1274
|
let REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
1296
|
-
checkPath.isNotRelative = (
|
|
1275
|
+
checkPath.isNotRelative = (path) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
|
|
1297
1276
|
};
|
|
1298
1277
|
// Detect `process` so that it can run in browsers.
|
|
1299
1278
|
typeof process < "u" && process.platform === "win32" && setupWindows();
|
|
@@ -1304,417 +1283,6 @@ var require_ignore = __commonJS({
|
|
|
1304
1283
|
}
|
|
1305
1284
|
});
|
|
1306
1285
|
|
|
1307
|
-
// packages/coding-agent/dist/core/event-bus.js
|
|
1308
|
-
import { EventEmitter } from "node:events";
|
|
1309
|
-
function createEventBus() {
|
|
1310
|
-
let emitter = new EventEmitter();
|
|
1311
|
-
return {
|
|
1312
|
-
emit: (channel, data) => {
|
|
1313
|
-
emitter.emit(channel, data);
|
|
1314
|
-
},
|
|
1315
|
-
on: (channel, handler) => {
|
|
1316
|
-
let safeHandler = async (data) => {
|
|
1317
|
-
try {
|
|
1318
|
-
await handler(data);
|
|
1319
|
-
} catch (err) {
|
|
1320
|
-
console.error(`Event handler error (${channel}):`, err);
|
|
1321
|
-
}
|
|
1322
|
-
};
|
|
1323
|
-
return emitter.on(channel, safeHandler), () => emitter.off(channel, safeHandler);
|
|
1324
|
-
},
|
|
1325
|
-
clear: () => {
|
|
1326
|
-
emitter.removeAllListeners();
|
|
1327
|
-
}
|
|
1328
|
-
};
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
// packages/coding-agent/dist/core/source-info.js
|
|
1332
|
-
function createSourceInfo(path2, metadata) {
|
|
1333
|
-
return {
|
|
1334
|
-
path: path2,
|
|
1335
|
-
source: metadata.source,
|
|
1336
|
-
scope: metadata.scope,
|
|
1337
|
-
origin: metadata.origin,
|
|
1338
|
-
baseDir: metadata.baseDir
|
|
1339
|
-
};
|
|
1340
|
-
}
|
|
1341
|
-
function createSyntheticSourceInfo(path2, options) {
|
|
1342
|
-
return {
|
|
1343
|
-
path: path2,
|
|
1344
|
-
source: options.source,
|
|
1345
|
-
scope: options.scope ?? "temporary",
|
|
1346
|
-
origin: options.origin ?? "top-level",
|
|
1347
|
-
baseDir: options.baseDir
|
|
1348
|
-
};
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
// packages/coding-agent/dist/core/extensions/loader.js
|
|
1352
|
-
import * as fs from "node:fs";
|
|
1353
|
-
import { createRequire } from "node:module";
|
|
1354
|
-
import * as path from "node:path";
|
|
1355
|
-
import { fileURLToPath } from "node:url";
|
|
1356
|
-
|
|
1357
|
-
// packages/coding-agent/dist/core/exec.js
|
|
1358
|
-
import { spawn } from "node:child_process";
|
|
1359
|
-
async function execCommand(command, args, cwd, options) {
|
|
1360
|
-
return new Promise((resolve6) => {
|
|
1361
|
-
let proc = spawn(command, args, {
|
|
1362
|
-
cwd,
|
|
1363
|
-
shell: !1,
|
|
1364
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
1365
|
-
}), stdout = "", stderr = "", killed = !1, timeoutId, killProcess = () => {
|
|
1366
|
-
killed || (killed = !0, proc.kill("SIGTERM"), setTimeout(() => {
|
|
1367
|
-
proc.killed || proc.kill("SIGKILL");
|
|
1368
|
-
}, 5e3));
|
|
1369
|
-
};
|
|
1370
|
-
options?.signal && (options.signal.aborted ? killProcess() : options.signal.addEventListener("abort", killProcess, { once: !0 })), options?.timeout && options.timeout > 0 && (timeoutId = setTimeout(() => {
|
|
1371
|
-
killProcess();
|
|
1372
|
-
}, options.timeout)), proc.stdout?.on("data", (data) => {
|
|
1373
|
-
stdout += data.toString();
|
|
1374
|
-
}), proc.stderr?.on("data", (data) => {
|
|
1375
|
-
stderr += data.toString();
|
|
1376
|
-
}), waitForChildProcess(proc).then((code) => {
|
|
1377
|
-
timeoutId && clearTimeout(timeoutId), options?.signal && options.signal.removeEventListener("abort", killProcess), resolve6({ stdout, stderr, code: code ?? 0, killed });
|
|
1378
|
-
}).catch((_err) => {
|
|
1379
|
-
timeoutId && clearTimeout(timeoutId), options?.signal && options.signal.removeEventListener("abort", killProcess), resolve6({ stdout, stderr, code: 1, killed });
|
|
1380
|
-
});
|
|
1381
|
-
});
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
|
-
// packages/coding-agent/dist/core/extensions/loader.js
|
|
1385
|
-
var bunExtensionHost, createJitiFn;
|
|
1386
|
-
var require2 = createRequire(new URL("../core/extensions/loader.js", import.meta.url).href), _aliases = null;
|
|
1387
|
-
function getAliases() {
|
|
1388
|
-
if (_aliases)
|
|
1389
|
-
return _aliases;
|
|
1390
|
-
let __dirname = path.dirname(fileURLToPath(new URL("../core/extensions/loader.js", import.meta.url).href)), packageIndex = path.resolve(__dirname, "../..", isNodeBundle ? "node-runtime/index.js" : "index.js"), typeboxEntry = require2.resolve("typebox"), typeboxCompileEntry = require2.resolve("typebox/compile"), typeboxValueEntry = require2.resolve("typebox/value"), packagesRoot = path.resolve(__dirname, "../../../../"), resolveWorkspaceOrImport = (workspaceRelativePath, specifier) => {
|
|
1391
|
-
let workspacePath = path.join(packagesRoot, workspaceRelativePath);
|
|
1392
|
-
return fs.existsSync(workspacePath) ? workspacePath : fileURLToPath(import.meta.resolve(specifier));
|
|
1393
|
-
}, piCodingAgentEntry = packageIndex, piAgentCoreEntry = resolveWorkspaceOrImport("agent/dist/index.js", "@ashx-j/lunr-agent"), piTuiEntry = resolveWorkspaceOrImport("tui/dist/index.js", "@ashx-j/lunr-tui"), piAiCompatEntry = resolveWorkspaceOrImport("ai/dist/compat.js", "@ashx-j/lunr-ai/compat"), piAiOauthEntry = resolveWorkspaceOrImport("ai/dist/oauth.js", "@ashx-j/lunr-ai/oauth"), piAiProvidersEntry = resolveWorkspaceOrImport("ai/dist/providers/all.js", "@ashx-j/lunr-ai/providers/all");
|
|
1394
|
-
return _aliases = {
|
|
1395
|
-
"@ashx-j/lunr": piCodingAgentEntry,
|
|
1396
|
-
"@ashx-j/lunr-agent": piAgentCoreEntry,
|
|
1397
|
-
"@ashx-j/lunr-tui": piTuiEntry,
|
|
1398
|
-
"@ashx-j/lunr-ai/providers/all": piAiProvidersEntry,
|
|
1399
|
-
"@ashx-j/lunr-ai/compat": piAiCompatEntry,
|
|
1400
|
-
"@ashx-j/lunr-ai/oauth": piAiOauthEntry,
|
|
1401
|
-
"@ashx-j/lunr-ai": piAiCompatEntry,
|
|
1402
|
-
"@ashx-j/lunr": piCodingAgentEntry,
|
|
1403
|
-
"@ashx-j/lunr-agent": piAgentCoreEntry,
|
|
1404
|
-
"@ashx-j/lunr-tui": piTuiEntry,
|
|
1405
|
-
"@ashx-j/lunr-ai/providers/all": piAiProvidersEntry,
|
|
1406
|
-
"@ashx-j/lunr-ai/compat": piAiCompatEntry,
|
|
1407
|
-
"@ashx-j/lunr-ai/oauth": piAiOauthEntry,
|
|
1408
|
-
"@ashx-j/lunr-ai": piAiCompatEntry,
|
|
1409
|
-
"@mariozechner/pi-coding-agent": piCodingAgentEntry,
|
|
1410
|
-
"@mariozechner/pi-agent-core": piAgentCoreEntry,
|
|
1411
|
-
"@mariozechner/pi-tui": piTuiEntry,
|
|
1412
|
-
"@mariozechner/pi-ai/providers/all": piAiProvidersEntry,
|
|
1413
|
-
"@mariozechner/pi-ai/compat": piAiCompatEntry,
|
|
1414
|
-
"@mariozechner/pi-ai/oauth": piAiOauthEntry,
|
|
1415
|
-
"@mariozechner/pi-ai": piAiCompatEntry,
|
|
1416
|
-
typebox: typeboxEntry,
|
|
1417
|
-
"typebox/compile": typeboxCompileEntry,
|
|
1418
|
-
"typebox/value": typeboxValueEntry,
|
|
1419
|
-
"@sinclair/typebox": typeboxEntry,
|
|
1420
|
-
"@sinclair/typebox/compile": typeboxCompileEntry,
|
|
1421
|
-
"@sinclair/typebox/value": typeboxValueEntry
|
|
1422
|
-
}, _aliases;
|
|
1423
|
-
}
|
|
1424
|
-
var extensionCacheCwd, extensionCacheGeneration = 0, extensionCache = /* @__PURE__ */ new Map();
|
|
1425
|
-
function clearExtensionCache() {
|
|
1426
|
-
extensionCache.clear(), extensionCacheCwd = void 0, extensionCacheGeneration++;
|
|
1427
|
-
}
|
|
1428
|
-
function useExtensionCacheCwd(cwd) {
|
|
1429
|
-
let resolvedCwd = resolvePath(cwd);
|
|
1430
|
-
return extensionCacheCwd !== void 0 && extensionCacheCwd !== resolvedCwd && clearExtensionCache(), extensionCacheCwd = resolvedCwd, { cwd: resolvedCwd, generation: extensionCacheGeneration };
|
|
1431
|
-
}
|
|
1432
|
-
function createExtensionRuntime() {
|
|
1433
|
-
let notInitialized = () => {
|
|
1434
|
-
throw new Error("Extension runtime not initialized. Action methods cannot be called during extension loading.");
|
|
1435
|
-
}, state = {}, runtime = {
|
|
1436
|
-
sendMessage: notInitialized,
|
|
1437
|
-
sendUserMessage: notInitialized,
|
|
1438
|
-
appendEntry: notInitialized,
|
|
1439
|
-
setSessionName: notInitialized,
|
|
1440
|
-
getSessionName: notInitialized,
|
|
1441
|
-
setLabel: notInitialized,
|
|
1442
|
-
getActiveTools: notInitialized,
|
|
1443
|
-
getAllTools: notInitialized,
|
|
1444
|
-
setActiveTools: notInitialized,
|
|
1445
|
-
// registerTool() is valid during extension load; refresh is only needed post-bind.
|
|
1446
|
-
refreshTools: () => {
|
|
1447
|
-
},
|
|
1448
|
-
getCommands: notInitialized,
|
|
1449
|
-
setModel: () => Promise.reject(new Error("Extension runtime not initialized")),
|
|
1450
|
-
getThinkingLevel: notInitialized,
|
|
1451
|
-
setThinkingLevel: notInitialized,
|
|
1452
|
-
flagValues: /* @__PURE__ */ new Map(),
|
|
1453
|
-
pendingProviderRegistrations: [],
|
|
1454
|
-
assertActive: () => {
|
|
1455
|
-
if (state.staleMessage)
|
|
1456
|
-
throw new Error(state.staleMessage);
|
|
1457
|
-
},
|
|
1458
|
-
invalidate: (message) => {
|
|
1459
|
-
state.staleMessage ??= message ?? "This extension ctx is stale after session replacement or reload. Do not use a captured pi or command ctx after ctx.newSession(), ctx.fork(), ctx.switchSession(), or ctx.reload(). For newSession, fork, and switchSession, move post-replacement work into withSession and use the ctx passed to withSession. For reload, do not use the old ctx after await ctx.reload().";
|
|
1460
|
-
},
|
|
1461
|
-
// Pre-bind: queue registrations so bindCore() can flush them once the
|
|
1462
|
-
// model registry is available. bindCore() replaces both with direct calls.
|
|
1463
|
-
registerProvider: (name, config, extensionPath = "<unknown>") => {
|
|
1464
|
-
runtime.pendingProviderRegistrations.push({ name, config, extensionPath });
|
|
1465
|
-
},
|
|
1466
|
-
unregisterProvider: (name) => {
|
|
1467
|
-
runtime.pendingProviderRegistrations = runtime.pendingProviderRegistrations.filter((r) => r.name !== name);
|
|
1468
|
-
}
|
|
1469
|
-
};
|
|
1470
|
-
return runtime;
|
|
1471
|
-
}
|
|
1472
|
-
function createExtensionAPI(extension, runtime, cwd, eventBus) {
|
|
1473
|
-
return {
|
|
1474
|
-
// Registration methods - write to extension
|
|
1475
|
-
on(event, handler) {
|
|
1476
|
-
runtime.assertActive();
|
|
1477
|
-
let list = extension.handlers.get(event) ?? [];
|
|
1478
|
-
list.push(handler), extension.handlers.set(event, list);
|
|
1479
|
-
},
|
|
1480
|
-
registerTool(tool) {
|
|
1481
|
-
runtime.assertActive(), extension.tools.set(tool.name, {
|
|
1482
|
-
definition: tool,
|
|
1483
|
-
sourceInfo: extension.sourceInfo
|
|
1484
|
-
}), runtime.refreshTools();
|
|
1485
|
-
},
|
|
1486
|
-
registerCommand(name, options) {
|
|
1487
|
-
runtime.assertActive(), extension.commands.set(name, {
|
|
1488
|
-
name,
|
|
1489
|
-
sourceInfo: extension.sourceInfo,
|
|
1490
|
-
...options
|
|
1491
|
-
});
|
|
1492
|
-
},
|
|
1493
|
-
registerShortcut(shortcut, options) {
|
|
1494
|
-
runtime.assertActive(), extension.shortcuts.set(shortcut, { shortcut, extensionPath: extension.path, ...options });
|
|
1495
|
-
},
|
|
1496
|
-
registerFlag(name, options) {
|
|
1497
|
-
runtime.assertActive(), extension.flags.set(name, { name, extensionPath: extension.path, ...options }), options.default !== void 0 && !runtime.flagValues.has(name) && runtime.flagValues.set(name, options.default);
|
|
1498
|
-
},
|
|
1499
|
-
registerMessageRenderer(customType, renderer) {
|
|
1500
|
-
runtime.assertActive(), extension.messageRenderers.set(customType, renderer);
|
|
1501
|
-
},
|
|
1502
|
-
registerEntryRenderer(customType, renderer) {
|
|
1503
|
-
runtime.assertActive(), extension.entryRenderers ??= /* @__PURE__ */ new Map(), extension.entryRenderers.set(customType, renderer);
|
|
1504
|
-
},
|
|
1505
|
-
// Flag access - checks extension registered it, reads from runtime
|
|
1506
|
-
getFlag(name) {
|
|
1507
|
-
if (runtime.assertActive(), !!extension.flags.has(name))
|
|
1508
|
-
return runtime.flagValues.get(name);
|
|
1509
|
-
},
|
|
1510
|
-
// Action methods - delegate to shared runtime
|
|
1511
|
-
sendMessage(message, options) {
|
|
1512
|
-
runtime.assertActive(), runtime.sendMessage(message, options);
|
|
1513
|
-
},
|
|
1514
|
-
sendUserMessage(content, options) {
|
|
1515
|
-
runtime.assertActive(), runtime.sendUserMessage(content, options);
|
|
1516
|
-
},
|
|
1517
|
-
appendEntry(customType, data) {
|
|
1518
|
-
runtime.assertActive(), runtime.appendEntry(customType, data);
|
|
1519
|
-
},
|
|
1520
|
-
setSessionName(name) {
|
|
1521
|
-
runtime.assertActive(), runtime.setSessionName(name);
|
|
1522
|
-
},
|
|
1523
|
-
getSessionName() {
|
|
1524
|
-
return runtime.assertActive(), runtime.getSessionName();
|
|
1525
|
-
},
|
|
1526
|
-
setLabel(entryId, label) {
|
|
1527
|
-
runtime.assertActive(), runtime.setLabel(entryId, label);
|
|
1528
|
-
},
|
|
1529
|
-
exec(command, args, options) {
|
|
1530
|
-
return runtime.assertActive(), execCommand(command, args, options?.cwd ?? cwd, options);
|
|
1531
|
-
},
|
|
1532
|
-
getActiveTools() {
|
|
1533
|
-
return runtime.assertActive(), runtime.getActiveTools();
|
|
1534
|
-
},
|
|
1535
|
-
getAllTools() {
|
|
1536
|
-
return runtime.assertActive(), runtime.getAllTools();
|
|
1537
|
-
},
|
|
1538
|
-
setActiveTools(toolNames) {
|
|
1539
|
-
runtime.assertActive(), runtime.setActiveTools(toolNames);
|
|
1540
|
-
},
|
|
1541
|
-
getCommands() {
|
|
1542
|
-
return runtime.assertActive(), runtime.getCommands();
|
|
1543
|
-
},
|
|
1544
|
-
setModel(model) {
|
|
1545
|
-
return runtime.assertActive(), runtime.setModel(model);
|
|
1546
|
-
},
|
|
1547
|
-
getThinkingLevel() {
|
|
1548
|
-
return runtime.assertActive(), runtime.getThinkingLevel();
|
|
1549
|
-
},
|
|
1550
|
-
setThinkingLevel(level) {
|
|
1551
|
-
runtime.assertActive(), runtime.setThinkingLevel(level);
|
|
1552
|
-
},
|
|
1553
|
-
registerProvider(name, config) {
|
|
1554
|
-
runtime.assertActive(), runtime.registerProvider(name, config, extension.path);
|
|
1555
|
-
},
|
|
1556
|
-
unregisterProvider(name) {
|
|
1557
|
-
runtime.assertActive(), runtime.unregisterProvider(name, extension.path);
|
|
1558
|
-
},
|
|
1559
|
-
events: eventBus
|
|
1560
|
-
};
|
|
1561
|
-
}
|
|
1562
|
-
function isCurrentCacheToken(cacheToken) {
|
|
1563
|
-
return cacheToken !== void 0 && extensionCacheCwd === cacheToken.cwd && extensionCacheGeneration === cacheToken.generation;
|
|
1564
|
-
}
|
|
1565
|
-
async function ensureExtensionHost() {
|
|
1566
|
-
if (createJitiFn)
|
|
1567
|
-
return createJitiFn;
|
|
1568
|
-
if (isBunBinary && bunExtensionHost)
|
|
1569
|
-
return bunExtensionHost.createJiti;
|
|
1570
|
-
let { createJiti } = await import("jiti/static");
|
|
1571
|
-
return createJitiFn = createJiti, createJiti;
|
|
1572
|
-
}
|
|
1573
|
-
async function loadExtensionModule(extensionPath, cacheToken) {
|
|
1574
|
-
if (isCurrentCacheToken(cacheToken)) {
|
|
1575
|
-
let cachedFactory = extensionCache.get(extensionPath);
|
|
1576
|
-
if (cachedFactory)
|
|
1577
|
-
return cachedFactory;
|
|
1578
|
-
}
|
|
1579
|
-
let factory = await (await ensureExtensionHost())(new URL("../core/extensions/loader.js", import.meta.url).href, {
|
|
1580
|
-
moduleCache: !1,
|
|
1581
|
-
// In Bun binary: use virtualModules for bundled packages (no filesystem resolution)
|
|
1582
|
-
// Also disable tryNative so jiti handles ALL imports (not just the entry point)
|
|
1583
|
-
// In Node.js/dev: use aliases to resolve to node_modules paths
|
|
1584
|
-
...isBunBinary ? { virtualModules: bunExtensionHost?.virtualModules, tryNative: !1 } : { alias: getAliases() }
|
|
1585
|
-
}).import(extensionPath, { default: !0 });
|
|
1586
|
-
if (typeof factory == "function")
|
|
1587
|
-
return isCurrentCacheToken(cacheToken) && extensionCache.set(extensionPath, factory), factory;
|
|
1588
|
-
}
|
|
1589
|
-
function createExtension(extensionPath, resolvedPath) {
|
|
1590
|
-
let source = extensionPath.startsWith("<") && extensionPath.endsWith(">") ? extensionPath.slice(1, -1).split(":")[0] || "temporary" : "local", baseDir = extensionPath.startsWith("<") ? void 0 : path.dirname(resolvedPath);
|
|
1591
|
-
return {
|
|
1592
|
-
path: extensionPath,
|
|
1593
|
-
resolvedPath,
|
|
1594
|
-
sourceInfo: createSyntheticSourceInfo(extensionPath, { source, baseDir }),
|
|
1595
|
-
handlers: /* @__PURE__ */ new Map(),
|
|
1596
|
-
tools: /* @__PURE__ */ new Map(),
|
|
1597
|
-
messageRenderers: /* @__PURE__ */ new Map(),
|
|
1598
|
-
entryRenderers: /* @__PURE__ */ new Map(),
|
|
1599
|
-
commands: /* @__PURE__ */ new Map(),
|
|
1600
|
-
flags: /* @__PURE__ */ new Map(),
|
|
1601
|
-
shortcuts: /* @__PURE__ */ new Map()
|
|
1602
|
-
};
|
|
1603
|
-
}
|
|
1604
|
-
async function loadExtension(extensionPath, cwd, eventBus, runtime, cacheToken) {
|
|
1605
|
-
let resolvedPath = resolvePath(extensionPath, cwd, { normalizeUnicodeSpaces: !0 });
|
|
1606
|
-
try {
|
|
1607
|
-
let factory = await measureStartup(`${extensionPath} module import`, () => loadExtensionModule(resolvedPath, cacheToken));
|
|
1608
|
-
if (!factory)
|
|
1609
|
-
return { extension: null, error: `Extension does not export a valid factory function: ${extensionPath}` };
|
|
1610
|
-
let extension = createExtension(extensionPath, resolvedPath), api = createExtensionAPI(extension, runtime, cwd, eventBus);
|
|
1611
|
-
return await measureStartup(`${extensionPath} factory`, () => factory(api)), { extension, error: null };
|
|
1612
|
-
} catch (err) {
|
|
1613
|
-
return { extension: null, error: `Failed to load extension: ${err instanceof Error ? err.message : String(err)}` };
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
async function loadExtensionFromFactory(factory, cwd, eventBus, runtime, extensionPath = "<inline>") {
|
|
1617
|
-
let extension = createExtension(extensionPath, extensionPath), resolvedCwd = resolvePath(cwd), api = createExtensionAPI(extension, runtime, resolvedCwd, eventBus);
|
|
1618
|
-
return await measureStartup(`${extensionPath} factory`, () => factory(api)), extension;
|
|
1619
|
-
}
|
|
1620
|
-
async function loadExtensionsInternal(paths, cwd, eventBus, runtime, useCache = !1) {
|
|
1621
|
-
let extensions = [], errors = [], cacheToken = useCache ? useExtensionCacheCwd(cwd) : void 0, resolvedCwd = cacheToken?.cwd ?? resolvePath(cwd), resolvedEventBus = eventBus ?? createEventBus(), resolvedRuntime = runtime ?? createExtensionRuntime();
|
|
1622
|
-
for (let extPath of paths) {
|
|
1623
|
-
let { extension, error } = await loadExtension(extPath, resolvedCwd, resolvedEventBus, resolvedRuntime, cacheToken);
|
|
1624
|
-
if (error) {
|
|
1625
|
-
errors.push({ path: extPath, error });
|
|
1626
|
-
continue;
|
|
1627
|
-
}
|
|
1628
|
-
extension && extensions.push(extension);
|
|
1629
|
-
}
|
|
1630
|
-
return {
|
|
1631
|
-
extensions,
|
|
1632
|
-
errors,
|
|
1633
|
-
runtime: resolvedRuntime
|
|
1634
|
-
};
|
|
1635
|
-
}
|
|
1636
|
-
async function loadExtensions(paths, cwd, eventBus, runtime) {
|
|
1637
|
-
return loadExtensionsInternal(paths, cwd, eventBus, runtime);
|
|
1638
|
-
}
|
|
1639
|
-
async function loadExtensionsCached(paths, cwd, eventBus, runtime) {
|
|
1640
|
-
return loadExtensionsInternal(paths, cwd, eventBus, runtime, !0);
|
|
1641
|
-
}
|
|
1642
|
-
function readPiManifest(packageJsonPath) {
|
|
1643
|
-
try {
|
|
1644
|
-
let content = fs.readFileSync(packageJsonPath, "utf-8"), pkg = JSON.parse(content);
|
|
1645
|
-
return pkg.pi && typeof pkg.pi == "object" ? pkg.pi : null;
|
|
1646
|
-
} catch {
|
|
1647
|
-
return null;
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
function isExtensionFile(name) {
|
|
1651
|
-
return name.endsWith(".ts") || name.endsWith(".js");
|
|
1652
|
-
}
|
|
1653
|
-
function resolveExtensionEntries(dir) {
|
|
1654
|
-
let packageJsonPath = path.join(dir, "package.json");
|
|
1655
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
1656
|
-
let manifest = readPiManifest(packageJsonPath);
|
|
1657
|
-
if (manifest?.extensions?.length) {
|
|
1658
|
-
let entries = [];
|
|
1659
|
-
for (let extPath of manifest.extensions) {
|
|
1660
|
-
let resolvedExtPath = path.resolve(dir, extPath);
|
|
1661
|
-
fs.existsSync(resolvedExtPath) && entries.push(resolvedExtPath);
|
|
1662
|
-
}
|
|
1663
|
-
if (entries.length > 0)
|
|
1664
|
-
return entries;
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
let indexTs = path.join(dir, "index.ts"), indexJs = path.join(dir, "index.js");
|
|
1668
|
-
return fs.existsSync(indexTs) ? [indexTs] : fs.existsSync(indexJs) ? [indexJs] : null;
|
|
1669
|
-
}
|
|
1670
|
-
function discoverExtensionsInDir(dir) {
|
|
1671
|
-
if (!fs.existsSync(dir))
|
|
1672
|
-
return [];
|
|
1673
|
-
let discovered = [];
|
|
1674
|
-
try {
|
|
1675
|
-
let entries = fs.readdirSync(dir, { withFileTypes: !0 });
|
|
1676
|
-
for (let entry of entries) {
|
|
1677
|
-
let entryPath = path.join(dir, entry.name);
|
|
1678
|
-
if ((entry.isFile() || entry.isSymbolicLink()) && isExtensionFile(entry.name)) {
|
|
1679
|
-
discovered.push(entryPath);
|
|
1680
|
-
continue;
|
|
1681
|
-
}
|
|
1682
|
-
if (entry.isDirectory() || entry.isSymbolicLink()) {
|
|
1683
|
-
let entries2 = resolveExtensionEntries(entryPath);
|
|
1684
|
-
entries2 && discovered.push(...entries2);
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
} catch {
|
|
1688
|
-
return [];
|
|
1689
|
-
}
|
|
1690
|
-
return discovered;
|
|
1691
|
-
}
|
|
1692
|
-
async function discoverAndLoadExtensions(configuredPaths, cwd, agentDir = getAgentDir(), eventBus) {
|
|
1693
|
-
let resolvedCwd = resolvePath(cwd), resolvedAgentDir = resolvePath(agentDir), allPaths = [], seen = /* @__PURE__ */ new Set(), addPaths = (paths) => {
|
|
1694
|
-
for (let p of paths) {
|
|
1695
|
-
let resolved = path.resolve(p);
|
|
1696
|
-
seen.has(resolved) || (seen.add(resolved), allPaths.push(p));
|
|
1697
|
-
}
|
|
1698
|
-
}, localExtDir = path.join(resolvedCwd, CONFIG_DIR_NAME, "extensions");
|
|
1699
|
-
addPaths(discoverExtensionsInDir(localExtDir));
|
|
1700
|
-
let globalExtDir = path.join(resolvedAgentDir, "extensions");
|
|
1701
|
-
addPaths(discoverExtensionsInDir(globalExtDir));
|
|
1702
|
-
for (let p of configuredPaths) {
|
|
1703
|
-
let resolved = resolvePath(p, resolvedCwd, { normalizeUnicodeSpaces: !0 });
|
|
1704
|
-
if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) {
|
|
1705
|
-
let entries = resolveExtensionEntries(resolved);
|
|
1706
|
-
if (entries) {
|
|
1707
|
-
addPaths(entries);
|
|
1708
|
-
continue;
|
|
1709
|
-
}
|
|
1710
|
-
addPaths(discoverExtensionsInDir(resolved));
|
|
1711
|
-
continue;
|
|
1712
|
-
}
|
|
1713
|
-
addPaths([resolved]);
|
|
1714
|
-
}
|
|
1715
|
-
return loadExtensions(allPaths, resolvedCwd, eventBus);
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
1286
|
// packages/coding-agent/dist/utils/git.js
|
|
1719
1287
|
var import_hosted_git_info = __toESM(require_lib(), 1);
|
|
1720
1288
|
function splitRef(url) {
|
|
@@ -1785,23 +1353,23 @@ function buildGitSource(args) {
|
|
|
1785
1353
|
};
|
|
1786
1354
|
}
|
|
1787
1355
|
function parseGenericGitUrl(url) {
|
|
1788
|
-
let { repo: repoWithoutRef, ref } = splitRef(url), repo = repoWithoutRef, host = "",
|
|
1356
|
+
let { repo: repoWithoutRef, ref } = splitRef(url), repo = repoWithoutRef, host = "", path = "", scpLikeMatch = repoWithoutRef.match(/^git@([^:]+):(.+)$/);
|
|
1789
1357
|
if (scpLikeMatch)
|
|
1790
|
-
host = scpLikeMatch[1] ?? "",
|
|
1358
|
+
host = scpLikeMatch[1] ?? "", path = scpLikeMatch[2] ?? "";
|
|
1791
1359
|
else if (repoWithoutRef.startsWith("https://") || repoWithoutRef.startsWith("http://") || repoWithoutRef.startsWith("ssh://") || repoWithoutRef.startsWith("git://"))
|
|
1792
1360
|
try {
|
|
1793
1361
|
let parsed = new URL(repoWithoutRef);
|
|
1794
|
-
host = parsed.hostname,
|
|
1362
|
+
host = parsed.hostname, path = parsed.pathname.replace(/^\/+/, "");
|
|
1795
1363
|
} catch {
|
|
1796
1364
|
return null;
|
|
1797
1365
|
}
|
|
1798
1366
|
else {
|
|
1799
1367
|
let slashIndex = repoWithoutRef.indexOf("/");
|
|
1800
|
-
if (slashIndex < 0 || (host = repoWithoutRef.slice(0, slashIndex),
|
|
1368
|
+
if (slashIndex < 0 || (host = repoWithoutRef.slice(0, slashIndex), path = repoWithoutRef.slice(slashIndex + 1), !host.includes(".") && host !== "localhost"))
|
|
1801
1369
|
return null;
|
|
1802
1370
|
repo = `https://${repoWithoutRef}`;
|
|
1803
1371
|
}
|
|
1804
|
-
return buildGitSource({ repo, host, path
|
|
1372
|
+
return buildGitSource({ repo, host, path, ref });
|
|
1805
1373
|
}
|
|
1806
1374
|
function parseGitUrl(source) {
|
|
1807
1375
|
let trimmed = source.trim(), hasGitPrefix = trimmed.startsWith("git:"), url = hasGitPrefix ? trimmed.slice(4).trim() : trimmed;
|
|
@@ -1841,9 +1409,9 @@ function parseGitUrl(source) {
|
|
|
1841
1409
|
|
|
1842
1410
|
// packages/coding-agent/dist/core/package-manager.js
|
|
1843
1411
|
import { createHash } from "node:crypto";
|
|
1844
|
-
import { chmodSync, existsSync
|
|
1412
|
+
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
1845
1413
|
import { homedir } from "node:os";
|
|
1846
|
-
import { basename, dirname
|
|
1414
|
+
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
1847
1415
|
|
|
1848
1416
|
// node_modules/glob/dist/esm/index.min.js
|
|
1849
1417
|
import { fileURLToPath as Wi } from "node:url";
|
|
@@ -1876,12 +1444,12 @@ var Gt = (n7, t, e) => {
|
|
|
1876
1444
|
s.length && o !== void 0 && (h = [r, o]);
|
|
1877
1445
|
}
|
|
1878
1446
|
return h;
|
|
1879
|
-
}, fe = "\0SLASH" + Math.random() + "\0", ue = "\0OPEN" + Math.random() + "\0", qt = "\0CLOSE" + Math.random() + "\0", de = "\0COMMA" + Math.random() + "\0", pe = "\0PERIOD" + Math.random() + "\0", is = new RegExp(fe, "g"), rs = new RegExp(ue, "g"), ns = new RegExp(qt, "g"), os = new RegExp(de, "g"), hs = new RegExp(pe, "g"), as = /\\\\/g, ls = /\\{/g, cs = /\\}/g,
|
|
1447
|
+
}, fe = "\0SLASH" + Math.random() + "\0", ue = "\0OPEN" + Math.random() + "\0", qt = "\0CLOSE" + Math.random() + "\0", de = "\0COMMA" + Math.random() + "\0", pe = "\0PERIOD" + Math.random() + "\0", is = new RegExp(fe, "g"), rs = new RegExp(ue, "g"), ns = new RegExp(qt, "g"), os = new RegExp(de, "g"), hs = new RegExp(pe, "g"), as = /\\\\/g, ls = /\\{/g, cs = /\\}/g, fs = /\\,/g, us = /\\./g, ds = 1e5;
|
|
1880
1448
|
function Ht(n7) {
|
|
1881
1449
|
return isNaN(n7) ? n7.charCodeAt(0) : parseInt(n7, 10);
|
|
1882
1450
|
}
|
|
1883
1451
|
function ps(n7) {
|
|
1884
|
-
return n7.replace(as, fe).replace(ls, ue).replace(cs, qt).replace(
|
|
1452
|
+
return n7.replace(as, fe).replace(ls, ue).replace(cs, qt).replace(fs, de).replace(us, pe);
|
|
1885
1453
|
}
|
|
1886
1454
|
function ms(n7) {
|
|
1887
1455
|
return n7.replace(is, "\\").replace(rs, "{").replace(ns, "}").replace(os, ",").replace(hs, ".");
|
|
@@ -4650,7 +4218,7 @@ function getEnv() {
|
|
|
4650
4218
|
if (process.platform !== "linux" || Object.keys(process.env).length > 0)
|
|
4651
4219
|
return process.env;
|
|
4652
4220
|
try {
|
|
4653
|
-
let data =
|
|
4221
|
+
let data = readFileSync("/proc/self/environ", "utf-8"), env = {};
|
|
4654
4222
|
for (let entry of data.split("\0")) {
|
|
4655
4223
|
let idx = entry.indexOf("=");
|
|
4656
4224
|
idx > 0 && (env[entry.slice(0, idx)] = entry.slice(idx + 1));
|
|
@@ -4687,7 +4255,7 @@ function getHomeDir() {
|
|
|
4687
4255
|
return process.env.HOME || homedir();
|
|
4688
4256
|
}
|
|
4689
4257
|
function getExtensionTempFolder(agentDir) {
|
|
4690
|
-
let tempFolder =
|
|
4258
|
+
let tempFolder = join(agentDir, "tmp", "extensions");
|
|
4691
4259
|
return mkdirSync(tempFolder, { recursive: !0, mode: 448 }), chmodSync(tempFolder, 448), tempFolder;
|
|
4692
4260
|
}
|
|
4693
4261
|
function prefixIgnorePattern(line, prefix) {
|
|
@@ -4702,10 +4270,10 @@ function prefixIgnorePattern(line, prefix) {
|
|
|
4702
4270
|
function addIgnoreRules(ig, dir, rootDir) {
|
|
4703
4271
|
let relativeDir = relative(rootDir, dir), prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : "";
|
|
4704
4272
|
for (let filename of IGNORE_FILE_NAMES) {
|
|
4705
|
-
let ignorePath =
|
|
4706
|
-
if (
|
|
4273
|
+
let ignorePath = join(dir, filename);
|
|
4274
|
+
if (existsSync(ignorePath))
|
|
4707
4275
|
try {
|
|
4708
|
-
let patterns =
|
|
4276
|
+
let patterns = readFileSync(ignorePath, "utf-8").split(/\r?\n/).map((line) => prefixIgnorePattern(line, prefix)).filter((line) => !!line);
|
|
4709
4277
|
patterns.length > 0 && ig.add(patterns);
|
|
4710
4278
|
} catch {
|
|
4711
4279
|
}
|
|
@@ -4728,19 +4296,19 @@ function splitPatterns(entries) {
|
|
|
4728
4296
|
}
|
|
4729
4297
|
function collectFiles(dir, filePattern, skipNodeModules = !0, ignoreMatcher, rootDir) {
|
|
4730
4298
|
let files = [];
|
|
4731
|
-
if (!
|
|
4299
|
+
if (!existsSync(dir))
|
|
4732
4300
|
return files;
|
|
4733
4301
|
let root = rootDir ?? dir, ig = ignoreMatcher ?? (0, import_ignore.default)();
|
|
4734
4302
|
addIgnoreRules(ig, dir, root);
|
|
4735
4303
|
try {
|
|
4736
|
-
let entries =
|
|
4304
|
+
let entries = readdirSync(dir, { withFileTypes: !0 });
|
|
4737
4305
|
for (let entry of entries) {
|
|
4738
4306
|
if (entry.name.startsWith(".") || skipNodeModules && entry.name === "node_modules")
|
|
4739
4307
|
continue;
|
|
4740
|
-
let fullPath =
|
|
4308
|
+
let fullPath = join(dir, entry.name), isDir = entry.isDirectory(), isFile = entry.isFile();
|
|
4741
4309
|
if (entry.isSymbolicLink())
|
|
4742
4310
|
try {
|
|
4743
|
-
let stats =
|
|
4311
|
+
let stats = statSync(fullPath);
|
|
4744
4312
|
isDir = stats.isDirectory(), isFile = stats.isFile();
|
|
4745
4313
|
} catch {
|
|
4746
4314
|
continue;
|
|
@@ -4754,19 +4322,19 @@ function collectFiles(dir, filePattern, skipNodeModules = !0, ignoreMatcher, roo
|
|
|
4754
4322
|
}
|
|
4755
4323
|
function collectSkillEntries(dir, mode, ignoreMatcher, rootDir) {
|
|
4756
4324
|
let entries = [];
|
|
4757
|
-
if (!
|
|
4325
|
+
if (!existsSync(dir))
|
|
4758
4326
|
return entries;
|
|
4759
4327
|
let root = rootDir ?? dir, ig = ignoreMatcher ?? (0, import_ignore.default)();
|
|
4760
4328
|
addIgnoreRules(ig, dir, root);
|
|
4761
4329
|
try {
|
|
4762
|
-
let dirEntries =
|
|
4330
|
+
let dirEntries = readdirSync(dir, { withFileTypes: !0 });
|
|
4763
4331
|
for (let entry of dirEntries) {
|
|
4764
4332
|
if (entry.name !== "SKILL.md")
|
|
4765
4333
|
continue;
|
|
4766
|
-
let fullPath =
|
|
4334
|
+
let fullPath = join(dir, entry.name), isFile = entry.isFile();
|
|
4767
4335
|
if (entry.isSymbolicLink())
|
|
4768
4336
|
try {
|
|
4769
|
-
isFile =
|
|
4337
|
+
isFile = statSync(fullPath).isFile();
|
|
4770
4338
|
} catch {
|
|
4771
4339
|
continue;
|
|
4772
4340
|
}
|
|
@@ -4777,10 +4345,10 @@ function collectSkillEntries(dir, mode, ignoreMatcher, rootDir) {
|
|
|
4777
4345
|
for (let entry of dirEntries) {
|
|
4778
4346
|
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
4779
4347
|
continue;
|
|
4780
|
-
let fullPath =
|
|
4348
|
+
let fullPath = join(dir, entry.name), isDir = entry.isDirectory(), isFile = entry.isFile();
|
|
4781
4349
|
if (entry.isSymbolicLink())
|
|
4782
4350
|
try {
|
|
4783
|
-
let stats =
|
|
4351
|
+
let stats = statSync(fullPath);
|
|
4784
4352
|
isDir = stats.isDirectory(), isFile = stats.isFile();
|
|
4785
4353
|
} catch {
|
|
4786
4354
|
continue;
|
|
@@ -4800,20 +4368,20 @@ function collectAutoSkillEntries(dir, mode) {
|
|
|
4800
4368
|
return collectSkillEntries(dir, mode);
|
|
4801
4369
|
}
|
|
4802
4370
|
function findGitRepoRoot(startDir) {
|
|
4803
|
-
let dir =
|
|
4371
|
+
let dir = resolve(startDir);
|
|
4804
4372
|
for (; ; ) {
|
|
4805
|
-
if (
|
|
4373
|
+
if (existsSync(join(dir, ".git")))
|
|
4806
4374
|
return dir;
|
|
4807
|
-
let parent =
|
|
4375
|
+
let parent = dirname(dir);
|
|
4808
4376
|
if (parent === dir)
|
|
4809
4377
|
return null;
|
|
4810
4378
|
dir = parent;
|
|
4811
4379
|
}
|
|
4812
4380
|
}
|
|
4813
4381
|
function collectAncestorAgentsSkillDirs(startDir) {
|
|
4814
|
-
let skillDirs = [], resolvedStartDir =
|
|
4815
|
-
for (; skillDirs.push(
|
|
4816
|
-
let parent =
|
|
4382
|
+
let skillDirs = [], resolvedStartDir = resolve(startDir), gitRepoRoot = findGitRepoRoot(resolvedStartDir), dir = resolvedStartDir;
|
|
4383
|
+
for (; skillDirs.push(join(dir, ".agents", "skills")), !(gitRepoRoot && dir === gitRepoRoot); ) {
|
|
4384
|
+
let parent = dirname(dir);
|
|
4817
4385
|
if (parent === dir)
|
|
4818
4386
|
break;
|
|
4819
4387
|
dir = parent;
|
|
@@ -4822,19 +4390,19 @@ function collectAncestorAgentsSkillDirs(startDir) {
|
|
|
4822
4390
|
}
|
|
4823
4391
|
function collectAutoPromptEntries(dir) {
|
|
4824
4392
|
let entries = [];
|
|
4825
|
-
if (!
|
|
4393
|
+
if (!existsSync(dir))
|
|
4826
4394
|
return entries;
|
|
4827
4395
|
let ig = (0, import_ignore.default)();
|
|
4828
4396
|
addIgnoreRules(ig, dir, dir);
|
|
4829
4397
|
try {
|
|
4830
|
-
let dirEntries =
|
|
4398
|
+
let dirEntries = readdirSync(dir, { withFileTypes: !0 });
|
|
4831
4399
|
for (let entry of dirEntries) {
|
|
4832
4400
|
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
4833
4401
|
continue;
|
|
4834
|
-
let fullPath =
|
|
4402
|
+
let fullPath = join(dir, entry.name), isFile = entry.isFile();
|
|
4835
4403
|
if (entry.isSymbolicLink())
|
|
4836
4404
|
try {
|
|
4837
|
-
isFile =
|
|
4405
|
+
isFile = statSync(fullPath).isFile();
|
|
4838
4406
|
} catch {
|
|
4839
4407
|
continue;
|
|
4840
4408
|
}
|
|
@@ -4847,19 +4415,19 @@ function collectAutoPromptEntries(dir) {
|
|
|
4847
4415
|
}
|
|
4848
4416
|
function collectAutoThemeEntries(dir) {
|
|
4849
4417
|
let entries = [];
|
|
4850
|
-
if (!
|
|
4418
|
+
if (!existsSync(dir))
|
|
4851
4419
|
return entries;
|
|
4852
4420
|
let ig = (0, import_ignore.default)();
|
|
4853
4421
|
addIgnoreRules(ig, dir, dir);
|
|
4854
4422
|
try {
|
|
4855
|
-
let dirEntries =
|
|
4423
|
+
let dirEntries = readdirSync(dir, { withFileTypes: !0 });
|
|
4856
4424
|
for (let entry of dirEntries) {
|
|
4857
4425
|
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
4858
4426
|
continue;
|
|
4859
|
-
let fullPath =
|
|
4427
|
+
let fullPath = join(dir, entry.name), isFile = entry.isFile();
|
|
4860
4428
|
if (entry.isSymbolicLink())
|
|
4861
4429
|
try {
|
|
4862
|
-
isFile =
|
|
4430
|
+
isFile = statSync(fullPath).isFile();
|
|
4863
4431
|
} catch {
|
|
4864
4432
|
continue;
|
|
4865
4433
|
}
|
|
@@ -4872,47 +4440,47 @@ function collectAutoThemeEntries(dir) {
|
|
|
4872
4440
|
}
|
|
4873
4441
|
function readPiManifestFile(packageJsonPath) {
|
|
4874
4442
|
try {
|
|
4875
|
-
let content =
|
|
4443
|
+
let content = readFileSync(packageJsonPath, "utf-8");
|
|
4876
4444
|
return JSON.parse(content).pi ?? null;
|
|
4877
4445
|
} catch {
|
|
4878
4446
|
return null;
|
|
4879
4447
|
}
|
|
4880
4448
|
}
|
|
4881
|
-
function
|
|
4882
|
-
let packageJsonPath =
|
|
4883
|
-
if (
|
|
4449
|
+
function resolveExtensionEntries(dir) {
|
|
4450
|
+
let packageJsonPath = join(dir, "package.json");
|
|
4451
|
+
if (existsSync(packageJsonPath)) {
|
|
4884
4452
|
let manifest = readPiManifestFile(packageJsonPath);
|
|
4885
4453
|
if (manifest?.extensions?.length) {
|
|
4886
4454
|
let entries = [];
|
|
4887
4455
|
for (let extPath of manifest.extensions) {
|
|
4888
|
-
let resolvedExtPath =
|
|
4889
|
-
|
|
4456
|
+
let resolvedExtPath = resolve(dir, extPath);
|
|
4457
|
+
existsSync(resolvedExtPath) && entries.push(resolvedExtPath);
|
|
4890
4458
|
}
|
|
4891
4459
|
if (entries.length > 0)
|
|
4892
4460
|
return entries;
|
|
4893
4461
|
}
|
|
4894
4462
|
}
|
|
4895
|
-
let indexTs =
|
|
4896
|
-
return
|
|
4463
|
+
let indexTs = join(dir, "index.ts"), indexJs = join(dir, "index.js");
|
|
4464
|
+
return existsSync(indexTs) ? [indexTs] : existsSync(indexJs) ? [indexJs] : null;
|
|
4897
4465
|
}
|
|
4898
4466
|
function collectAutoExtensionEntries(dir) {
|
|
4899
4467
|
let entries = [];
|
|
4900
|
-
if (!
|
|
4468
|
+
if (!existsSync(dir))
|
|
4901
4469
|
return entries;
|
|
4902
|
-
let rootEntries =
|
|
4470
|
+
let rootEntries = resolveExtensionEntries(dir);
|
|
4903
4471
|
if (rootEntries)
|
|
4904
4472
|
return rootEntries;
|
|
4905
4473
|
let ig = (0, import_ignore.default)();
|
|
4906
4474
|
addIgnoreRules(ig, dir, dir);
|
|
4907
4475
|
try {
|
|
4908
|
-
let dirEntries =
|
|
4476
|
+
let dirEntries = readdirSync(dir, { withFileTypes: !0 });
|
|
4909
4477
|
for (let entry of dirEntries) {
|
|
4910
4478
|
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
4911
4479
|
continue;
|
|
4912
|
-
let fullPath =
|
|
4480
|
+
let fullPath = join(dir, entry.name), isDir = entry.isDirectory(), isFile = entry.isFile();
|
|
4913
4481
|
if (entry.isSymbolicLink())
|
|
4914
4482
|
try {
|
|
4915
|
-
let stats =
|
|
4483
|
+
let stats = statSync(fullPath);
|
|
4916
4484
|
isDir = stats.isDirectory(), isFile = stats.isFile();
|
|
4917
4485
|
} catch {
|
|
4918
4486
|
continue;
|
|
@@ -4922,7 +4490,7 @@ function collectAutoExtensionEntries(dir) {
|
|
|
4922
4490
|
if (isFile && (entry.name.endsWith(".ts") || entry.name.endsWith(".js")))
|
|
4923
4491
|
entries.push(fullPath);
|
|
4924
4492
|
else if (isDir) {
|
|
4925
|
-
let resolvedEntries =
|
|
4493
|
+
let resolvedEntries = resolveExtensionEntries(fullPath);
|
|
4926
4494
|
resolvedEntries && entries.push(...resolvedEntries);
|
|
4927
4495
|
}
|
|
4928
4496
|
}
|
|
@@ -4935,7 +4503,7 @@ function collectResourceFiles(dir, resourceType) {
|
|
|
4935
4503
|
return resourceType === "skills" ? collectSkillEntries(dir, "pi") : resourceType === "extensions" ? collectAutoExtensionEntries(dir) : collectFiles(dir, FILE_PATTERNS[resourceType]);
|
|
4936
4504
|
}
|
|
4937
4505
|
function matchesAnyPattern(filePath, patterns, baseDir) {
|
|
4938
|
-
let rel = toPosixPath(relative(baseDir, filePath)), name = basename(filePath), filePathPosix = toPosixPath(filePath), isSkillFile = name === "SKILL.md", parentDir = isSkillFile ?
|
|
4506
|
+
let rel = toPosixPath(relative(baseDir, filePath)), name = basename(filePath), filePathPosix = toPosixPath(filePath), isSkillFile = name === "SKILL.md", parentDir = isSkillFile ? dirname(filePath) : void 0, parentRel = isSkillFile ? toPosixPath(relative(baseDir, parentDir)) : void 0, parentName = isSkillFile ? basename(parentDir) : void 0, parentDirPosix = isSkillFile ? toPosixPath(parentDir) : void 0;
|
|
4939
4507
|
return patterns.some((pattern) => {
|
|
4940
4508
|
let normalizedPattern = toPosixPath(pattern);
|
|
4941
4509
|
return minimatch(rel, normalizedPattern) || minimatch(name, normalizedPattern) || minimatch(filePathPosix, normalizedPattern) ? !0 : isSkillFile ? minimatch(parentRel, normalizedPattern) || minimatch(parentName, normalizedPattern) || minimatch(parentDirPosix, normalizedPattern) : !1;
|
|
@@ -4948,7 +4516,7 @@ function normalizeExactPattern(pattern) {
|
|
|
4948
4516
|
function matchesAnyExactPattern(filePath, patterns, baseDir) {
|
|
4949
4517
|
if (patterns.length === 0)
|
|
4950
4518
|
return !1;
|
|
4951
|
-
let rel = toPosixPath(relative(baseDir, filePath)), name = basename(filePath), filePathPosix = toPosixPath(filePath), isSkillFile = name === "SKILL.md", parentDir = isSkillFile ?
|
|
4519
|
+
let rel = toPosixPath(relative(baseDir, filePath)), name = basename(filePath), filePathPosix = toPosixPath(filePath), isSkillFile = name === "SKILL.md", parentDir = isSkillFile ? dirname(filePath) : void 0, parentRel = isSkillFile ? toPosixPath(relative(baseDir, parentDir)) : void 0, parentDirPosix = isSkillFile ? toPosixPath(parentDir) : void 0;
|
|
4952
4520
|
return patterns.some((pattern) => {
|
|
4953
4521
|
let normalized = normalizeExactPattern(pattern);
|
|
4954
4522
|
return normalized === rel || normalized === filePathPosix ? !0 : isSkillFile ? normalized === parentRel || normalized === parentDirPosix : !1;
|
|
@@ -5012,16 +4580,16 @@ var DefaultPackageManager = class {
|
|
|
5012
4580
|
getInstalledPath(source, scope) {
|
|
5013
4581
|
let parsed = this.parseSource(source);
|
|
5014
4582
|
if (parsed.type === "npm") {
|
|
5015
|
-
let
|
|
5016
|
-
return
|
|
4583
|
+
let path = this.getNpmInstallPath(parsed, scope);
|
|
4584
|
+
return existsSync(path) ? path : void 0;
|
|
5017
4585
|
}
|
|
5018
4586
|
if (parsed.type === "git") {
|
|
5019
|
-
let
|
|
5020
|
-
return
|
|
4587
|
+
let path = this.getGitInstallPath(parsed, scope);
|
|
4588
|
+
return existsSync(path) ? path : void 0;
|
|
5021
4589
|
}
|
|
5022
4590
|
if (parsed.type === "local") {
|
|
5023
|
-
let baseDir = this.getBaseDirForScope(scope),
|
|
5024
|
-
return
|
|
4591
|
+
let baseDir = this.getBaseDirForScope(scope), path = this.resolvePathFromBase(parsed.path, baseDir);
|
|
4592
|
+
return existsSync(path) ? path : void 0;
|
|
5025
4593
|
}
|
|
5026
4594
|
}
|
|
5027
4595
|
emitProgress(event) {
|
|
@@ -5044,7 +4612,7 @@ var DefaultPackageManager = class {
|
|
|
5044
4612
|
allPackages.push({ pkg, scope: "user" });
|
|
5045
4613
|
let packageSources = this.dedupePackages(allPackages);
|
|
5046
4614
|
await this.resolvePackageSources(packageSources, accumulator, onMissing);
|
|
5047
|
-
let globalBaseDir = this.agentDir, projectBaseDir =
|
|
4615
|
+
let globalBaseDir = this.agentDir, projectBaseDir = join(this.cwd, CONFIG_DIR_NAME);
|
|
5048
4616
|
for (let resourceType of RESOURCE_TYPES) {
|
|
5049
4617
|
let target = this.getTargetMap(accumulator, resourceType), globalEntries = globalSettings[resourceType] ?? [], projectEntries = projectSettings[resourceType] ?? [];
|
|
5050
4618
|
this.resolveLocalEntries(projectEntries, resourceType, target, {
|
|
@@ -5098,7 +4666,7 @@ var DefaultPackageManager = class {
|
|
|
5098
4666
|
}
|
|
5099
4667
|
if (parsed.type === "local") {
|
|
5100
4668
|
let resolved = this.resolvePath(parsed.path);
|
|
5101
|
-
if (!
|
|
4669
|
+
if (!existsSync(resolved))
|
|
5102
4670
|
throw new Error(`Path does not exist: ${resolved}`);
|
|
5103
4671
|
return;
|
|
5104
4672
|
}
|
|
@@ -5168,7 +4736,7 @@ var DefaultPackageManager = class {
|
|
|
5168
4736
|
await Promise.all(tasks);
|
|
5169
4737
|
}
|
|
5170
4738
|
async shouldUpdateNpmSource(source, scope) {
|
|
5171
|
-
let installedPath = this.getManagedNpmInstallPath(source, scope), installedVersion =
|
|
4739
|
+
let installedPath = this.getManagedNpmInstallPath(source, scope), installedVersion = existsSync(installedPath) ? this.getInstalledNpmVersion(installedPath) : void 0;
|
|
5172
4740
|
if (!installedVersion)
|
|
5173
4741
|
return !0;
|
|
5174
4742
|
try {
|
|
@@ -5211,7 +4779,7 @@ var DefaultPackageManager = class {
|
|
|
5211
4779
|
};
|
|
5212
4780
|
if (parsed.type === "npm") {
|
|
5213
4781
|
let installedPath = this.getNpmInstallPath(parsed, resolvedScope);
|
|
5214
|
-
if (!
|
|
4782
|
+
if (!existsSync(installedPath) || !await this.installedNpmMatchesConfiguredVersion(parsed, installedPath)) {
|
|
5215
4783
|
if (!await installMissing())
|
|
5216
4784
|
continue;
|
|
5217
4785
|
installedPath = this.getNpmInstallPath(parsed, resolvedScope);
|
|
@@ -5221,7 +4789,7 @@ var DefaultPackageManager = class {
|
|
|
5221
4789
|
}
|
|
5222
4790
|
if (parsed.type === "git") {
|
|
5223
4791
|
let installedPath = this.getGitInstallPath(parsed, resolvedScope);
|
|
5224
|
-
if (
|
|
4792
|
+
if (existsSync(installedPath))
|
|
5225
4793
|
resolvedScope === "temporary" && !parsed.pinned && !isOfflineModeEnabled() && await this.refreshTemporaryGitSource(parsed, resolvedSource);
|
|
5226
4794
|
else if (!await installMissing())
|
|
5227
4795
|
continue;
|
|
@@ -5237,11 +4805,11 @@ var DefaultPackageManager = class {
|
|
|
5237
4805
|
}
|
|
5238
4806
|
resolveLocalExtensionSource(source, accumulator, filter, metadata, baseDir) {
|
|
5239
4807
|
let resolved = this.resolvePathFromBase(source.path, baseDir);
|
|
5240
|
-
if (
|
|
4808
|
+
if (existsSync(resolved))
|
|
5241
4809
|
try {
|
|
5242
|
-
let stats =
|
|
4810
|
+
let stats = statSync(resolved);
|
|
5243
4811
|
if (stats.isFile()) {
|
|
5244
|
-
metadata.baseDir =
|
|
4812
|
+
metadata.baseDir = dirname(resolved), this.addResource(accumulator.extensions, resolved, metadata, !0);
|
|
5245
4813
|
return;
|
|
5246
4814
|
}
|
|
5247
4815
|
stats.isDirectory() && (metadata.baseDir = resolved, this.collectPackageResources(resolved, accumulator, filter, metadata) || this.addResource(accumulator.extensions, resolved, metadata, !0));
|
|
@@ -5327,10 +4895,10 @@ var DefaultPackageManager = class {
|
|
|
5327
4895
|
return installedVersion ? source.range ? (0, import_semver.satisfies)(installedVersion, source.range) : !0 : !1;
|
|
5328
4896
|
}
|
|
5329
4897
|
getInstalledNpmVersion(installedPath) {
|
|
5330
|
-
let packageJsonPath =
|
|
5331
|
-
if (
|
|
4898
|
+
let packageJsonPath = join(installedPath, "package.json");
|
|
4899
|
+
if (existsSync(packageJsonPath))
|
|
5332
4900
|
try {
|
|
5333
|
-
let content =
|
|
4901
|
+
let content = readFileSync(packageJsonPath, "utf-8");
|
|
5334
4902
|
return JSON.parse(content).version;
|
|
5335
4903
|
} catch {
|
|
5336
4904
|
return;
|
|
@@ -5508,7 +5076,7 @@ var DefaultPackageManager = class {
|
|
|
5508
5076
|
}
|
|
5509
5077
|
async uninstallNpm(source, scope) {
|
|
5510
5078
|
let installRoot = this.getNpmInstallRoot(scope, !1);
|
|
5511
|
-
if (!
|
|
5079
|
+
if (!existsSync(installRoot))
|
|
5512
5080
|
return;
|
|
5513
5081
|
let packageManagerName = this.getPackageManagerName();
|
|
5514
5082
|
if (packageManagerName === "bun") {
|
|
@@ -5520,7 +5088,7 @@ var DefaultPackageManager = class {
|
|
|
5520
5088
|
}
|
|
5521
5089
|
async installGit(source, scope) {
|
|
5522
5090
|
let targetDir = this.getGitInstallPath(source, scope);
|
|
5523
|
-
if (
|
|
5091
|
+
if (existsSync(targetDir)) {
|
|
5524
5092
|
if (source.ref) {
|
|
5525
5093
|
await this.ensureGitRef(targetDir, ["fetch", "origin", source.ref], "FETCH_HEAD");
|
|
5526
5094
|
return;
|
|
@@ -5530,16 +5098,16 @@ var DefaultPackageManager = class {
|
|
|
5530
5098
|
return;
|
|
5531
5099
|
}
|
|
5532
5100
|
let gitRoot = this.getGitInstallRoot(scope);
|
|
5533
|
-
gitRoot && this.ensureGitIgnore(gitRoot), mkdirSync(
|
|
5101
|
+
gitRoot && this.ensureGitIgnore(gitRoot), mkdirSync(dirname(targetDir), { recursive: !0 }), await this.runCommand("git", ["clone", source.repo, targetDir], { timeoutMs: PACKAGE_INSTALL_TIMEOUT_MS }), source.ref && await this.runCommand("git", ["checkout", source.ref], {
|
|
5534
5102
|
cwd: targetDir,
|
|
5535
5103
|
timeoutMs: PACKAGE_INSTALL_TIMEOUT_MS
|
|
5536
5104
|
});
|
|
5537
|
-
let packageJsonPath =
|
|
5538
|
-
|
|
5105
|
+
let packageJsonPath = join(targetDir, "package.json");
|
|
5106
|
+
existsSync(packageJsonPath) && await this.runNpmCommand(this.getGitDependencyInstallArgs(), { cwd: targetDir });
|
|
5539
5107
|
}
|
|
5540
5108
|
async updateGit(source, scope) {
|
|
5541
5109
|
let targetDir = this.getGitInstallPath(source, scope);
|
|
5542
|
-
if (!
|
|
5110
|
+
if (!existsSync(targetDir)) {
|
|
5543
5111
|
await this.installGit(source, scope);
|
|
5544
5112
|
return;
|
|
5545
5113
|
}
|
|
@@ -5562,8 +5130,8 @@ var DefaultPackageManager = class {
|
|
|
5562
5130
|
if (localHead.trim() === targetHead.trim())
|
|
5563
5131
|
return;
|
|
5564
5132
|
await this.runCommand("git", ["reset", "--hard", commitRef], { cwd: targetDir }), await this.runCommand("git", ["clean", "-fdx"], { cwd: targetDir });
|
|
5565
|
-
let packageJsonPath =
|
|
5566
|
-
|
|
5133
|
+
let packageJsonPath = join(targetDir, "package.json");
|
|
5134
|
+
existsSync(packageJsonPath) && await this.runNpmCommand(this.getGitDependencyInstallArgs(), { cwd: targetDir });
|
|
5567
5135
|
}
|
|
5568
5136
|
async refreshTemporaryGitSource(source, sourceStr) {
|
|
5569
5137
|
if (!isOfflineModeEnabled())
|
|
@@ -5576,41 +5144,41 @@ var DefaultPackageManager = class {
|
|
|
5576
5144
|
}
|
|
5577
5145
|
async removeGit(source, scope) {
|
|
5578
5146
|
let targetDir = this.getGitInstallPath(source, scope);
|
|
5579
|
-
|
|
5147
|
+
existsSync(targetDir) && (rmSync(targetDir, { recursive: !0, force: !0 }), this.pruneEmptyGitParents(targetDir, this.getGitInstallRoot(scope)));
|
|
5580
5148
|
}
|
|
5581
5149
|
pruneEmptyGitParents(targetDir, installRoot) {
|
|
5582
5150
|
if (!installRoot)
|
|
5583
5151
|
return;
|
|
5584
|
-
let resolvedRoot =
|
|
5152
|
+
let resolvedRoot = resolve(installRoot), current = dirname(targetDir);
|
|
5585
5153
|
for (; current.startsWith(resolvedRoot) && current !== resolvedRoot; ) {
|
|
5586
|
-
if (!
|
|
5587
|
-
current =
|
|
5154
|
+
if (!existsSync(current)) {
|
|
5155
|
+
current = dirname(current);
|
|
5588
5156
|
continue;
|
|
5589
5157
|
}
|
|
5590
|
-
if (
|
|
5158
|
+
if (readdirSync(current).length > 0)
|
|
5591
5159
|
break;
|
|
5592
5160
|
try {
|
|
5593
5161
|
rmSync(current, { recursive: !0, force: !0 });
|
|
5594
5162
|
} catch {
|
|
5595
5163
|
break;
|
|
5596
5164
|
}
|
|
5597
|
-
current =
|
|
5165
|
+
current = dirname(current);
|
|
5598
5166
|
}
|
|
5599
5167
|
}
|
|
5600
5168
|
ensureNpmProject(installRoot) {
|
|
5601
|
-
|
|
5602
|
-
let packageJsonPath =
|
|
5603
|
-
|
|
5169
|
+
existsSync(installRoot) || mkdirSync(installRoot, { recursive: !0 }), markPathIgnoredByCloudSync(installRoot), this.ensureGitIgnore(installRoot);
|
|
5170
|
+
let packageJsonPath = join(installRoot, "package.json");
|
|
5171
|
+
existsSync(packageJsonPath) || writeFileSync(packageJsonPath, JSON.stringify({ name: "pi-extensions", private: !0 }, null, 2), "utf-8");
|
|
5604
5172
|
}
|
|
5605
5173
|
ensureGitIgnore(dir) {
|
|
5606
|
-
|
|
5607
|
-
let ignorePath =
|
|
5608
|
-
|
|
5174
|
+
existsSync(dir) || mkdirSync(dir, { recursive: !0 });
|
|
5175
|
+
let ignorePath = join(dir, ".gitignore");
|
|
5176
|
+
existsSync(ignorePath) || writeFileSync(ignorePath, `*
|
|
5609
5177
|
!.gitignore
|
|
5610
5178
|
`, "utf-8");
|
|
5611
5179
|
}
|
|
5612
5180
|
getNpmInstallRoot(scope, temporary) {
|
|
5613
|
-
return temporary ? this.getTemporaryDir("npm") : scope === "project" ? (this.assertProjectTrustedForScope(scope),
|
|
5181
|
+
return temporary ? this.getTemporaryDir("npm") : scope === "project" ? (this.assertProjectTrustedForScope(scope), join(this.cwd, CONFIG_DIR_NAME, "npm")) : join(this.agentDir, "npm");
|
|
5614
5182
|
}
|
|
5615
5183
|
getGlobalNpmRoot() {
|
|
5616
5184
|
let npmCommand = this.getNpmCommand(), commandKey = [npmCommand.command, ...npmCommand.args].join("\0");
|
|
@@ -5618,7 +5186,7 @@ var DefaultPackageManager = class {
|
|
|
5618
5186
|
return this.globalNpmRoot;
|
|
5619
5187
|
if (this.getPackageManagerName() === "bun") {
|
|
5620
5188
|
let binDir = this.runNpmCommandSync(["pm", "bin", "-g"]).trim();
|
|
5621
|
-
this.globalNpmRoot =
|
|
5189
|
+
this.globalNpmRoot = join(dirname(binDir), "install", "global", "node_modules");
|
|
5622
5190
|
} else
|
|
5623
5191
|
this.globalNpmRoot = this.runNpmCommandSync(["root", "-g"]).trim();
|
|
5624
5192
|
return this.globalNpmRootCommandKey = commandKey, this.globalNpmRoot;
|
|
@@ -5628,27 +5196,27 @@ var DefaultPackageManager = class {
|
|
|
5628
5196
|
return;
|
|
5629
5197
|
let output = this.runNpmCommandSync(["list", "-g", "--depth", "0", "--json"]), entries = JSON.parse(output);
|
|
5630
5198
|
for (let entry of entries) {
|
|
5631
|
-
let
|
|
5632
|
-
if (
|
|
5633
|
-
return
|
|
5199
|
+
let path = entry.dependencies?.[packageName]?.path;
|
|
5200
|
+
if (path)
|
|
5201
|
+
return path;
|
|
5634
5202
|
}
|
|
5635
5203
|
}
|
|
5636
5204
|
getManagedNpmInstallPath(source, scope) {
|
|
5637
|
-
return scope === "temporary" ?
|
|
5205
|
+
return scope === "temporary" ? join(this.getTemporaryDir("npm"), "node_modules", source.name) : scope === "project" ? (this.assertProjectTrustedForScope(scope), join(this.cwd, CONFIG_DIR_NAME, "npm", "node_modules", source.name)) : join(this.agentDir, "npm", "node_modules", source.name);
|
|
5638
5206
|
}
|
|
5639
5207
|
getLegacyGlobalNpmInstallPath(source) {
|
|
5640
5208
|
try {
|
|
5641
|
-
return this.getPnpmGlobalPackagePath(source.name) ??
|
|
5209
|
+
return this.getPnpmGlobalPackagePath(source.name) ?? join(this.getGlobalNpmRoot(), source.name);
|
|
5642
5210
|
} catch {
|
|
5643
5211
|
return;
|
|
5644
5212
|
}
|
|
5645
5213
|
}
|
|
5646
5214
|
getNpmInstallPath(source, scope) {
|
|
5647
5215
|
let managedPath = this.getManagedNpmInstallPath(source, scope);
|
|
5648
|
-
if (scope !== "user" ||
|
|
5216
|
+
if (scope !== "user" || existsSync(managedPath))
|
|
5649
5217
|
return managedPath;
|
|
5650
5218
|
let legacyPath = this.getLegacyGlobalNpmInstallPath(source);
|
|
5651
|
-
return legacyPath &&
|
|
5219
|
+
return legacyPath && existsSync(legacyPath) ? legacyPath : managedPath;
|
|
5652
5220
|
}
|
|
5653
5221
|
getGitInstallPath(source, scope) {
|
|
5654
5222
|
if (scope === "temporary")
|
|
@@ -5660,20 +5228,20 @@ var DefaultPackageManager = class {
|
|
|
5660
5228
|
}
|
|
5661
5229
|
getGitInstallRoot(scope) {
|
|
5662
5230
|
if (scope !== "temporary")
|
|
5663
|
-
return scope === "project" ? (this.assertProjectTrustedForScope(scope),
|
|
5231
|
+
return scope === "project" ? (this.assertProjectTrustedForScope(scope), join(this.cwd, CONFIG_DIR_NAME, "git")) : join(this.agentDir, "git");
|
|
5664
5232
|
}
|
|
5665
5233
|
getTemporaryDir(prefix, suffix) {
|
|
5666
5234
|
let root = this.resolveManagedPath(getExtensionTempFolder(this.agentDir), prefix), hash = createHash("sha256").update(`${prefix}-${suffix ?? ""}`).digest("hex").slice(0, 8);
|
|
5667
5235
|
return this.resolveManagedPath(root, hash, suffix ?? "");
|
|
5668
5236
|
}
|
|
5669
5237
|
resolveManagedPath(root, ...parts) {
|
|
5670
|
-
let resolvedRoot =
|
|
5238
|
+
let resolvedRoot = resolve(root), resolvedPath = resolve(resolvedRoot, ...parts);
|
|
5671
5239
|
if (resolvedPath !== resolvedRoot && !resolvedPath.startsWith(`${resolvedRoot}${sep}`))
|
|
5672
5240
|
throw new Error(`Refusing to use path outside package install root: ${resolvedPath}`);
|
|
5673
5241
|
return resolvedPath;
|
|
5674
5242
|
}
|
|
5675
5243
|
getBaseDirForScope(scope) {
|
|
5676
|
-
return scope === "project" ? (this.assertProjectTrustedForScope(scope),
|
|
5244
|
+
return scope === "project" ? (this.assertProjectTrustedForScope(scope), join(this.cwd, CONFIG_DIR_NAME)) : scope === "user" ? this.agentDir : this.cwd;
|
|
5677
5245
|
}
|
|
5678
5246
|
resolvePath(input) {
|
|
5679
5247
|
return resolvePath(input, this.cwd, { homeDir: getHomeDir(), trim: !0 });
|
|
@@ -5699,8 +5267,8 @@ var DefaultPackageManager = class {
|
|
|
5699
5267
|
}
|
|
5700
5268
|
let hasAnyDir = !1;
|
|
5701
5269
|
for (let resourceType of RESOURCE_TYPES) {
|
|
5702
|
-
let dir =
|
|
5703
|
-
if (
|
|
5270
|
+
let dir = join(packageRoot, resourceType);
|
|
5271
|
+
if (existsSync(dir)) {
|
|
5704
5272
|
let files = collectResourceFiles(dir, resourceType);
|
|
5705
5273
|
for (let f of files)
|
|
5706
5274
|
this.addResource(this.getTargetMap(accumulator, resourceType), f, metadata, !0);
|
|
@@ -5715,8 +5283,8 @@ var DefaultPackageManager = class {
|
|
|
5715
5283
|
this.addManifestEntries(entries, packageRoot, resourceType, target, metadata);
|
|
5716
5284
|
return;
|
|
5717
5285
|
}
|
|
5718
|
-
let dir =
|
|
5719
|
-
if (
|
|
5286
|
+
let dir = join(packageRoot, resourceType);
|
|
5287
|
+
if (existsSync(dir)) {
|
|
5720
5288
|
let files = collectResourceFiles(dir, resourceType);
|
|
5721
5289
|
for (let f of files)
|
|
5722
5290
|
this.addResource(target, f, metadata, !0);
|
|
@@ -5753,18 +5321,18 @@ var DefaultPackageManager = class {
|
|
|
5753
5321
|
let allFiles2 = this.collectFilesFromManifestEntries(entries, packageRoot, resourceType), manifestPatterns = entries.filter(isOverridePattern), enabledByManifest = manifestPatterns.length > 0 ? applyPatterns(allFiles2, manifestPatterns, packageRoot) : new Set(allFiles2);
|
|
5754
5322
|
return { allFiles: Array.from(enabledByManifest), enabledByManifest };
|
|
5755
5323
|
}
|
|
5756
|
-
let conventionDir =
|
|
5757
|
-
if (!
|
|
5324
|
+
let conventionDir = join(packageRoot, resourceType);
|
|
5325
|
+
if (!existsSync(conventionDir))
|
|
5758
5326
|
return { allFiles: [], enabledByManifest: /* @__PURE__ */ new Set() };
|
|
5759
5327
|
let allFiles = collectResourceFiles(conventionDir, resourceType);
|
|
5760
5328
|
return { allFiles, enabledByManifest: new Set(allFiles) };
|
|
5761
5329
|
}
|
|
5762
5330
|
readPiManifest(packageRoot) {
|
|
5763
|
-
let packageJsonPath =
|
|
5764
|
-
if (!
|
|
5331
|
+
let packageJsonPath = join(packageRoot, "package.json");
|
|
5332
|
+
if (!existsSync(packageJsonPath))
|
|
5765
5333
|
return null;
|
|
5766
5334
|
try {
|
|
5767
|
-
let content =
|
|
5335
|
+
let content = readFileSync(packageJsonPath, "utf-8");
|
|
5768
5336
|
return JSON.parse(content).pi ?? null;
|
|
5769
5337
|
} catch {
|
|
5770
5338
|
return null;
|
|
@@ -5783,7 +5351,7 @@ var DefaultPackageManager = class {
|
|
|
5783
5351
|
absolute: !0,
|
|
5784
5352
|
dot: !1,
|
|
5785
5353
|
nodir: !1
|
|
5786
|
-
}).map((match) =>
|
|
5354
|
+
}).map((match) => resolve(match)) : [resolve(root, entry)]);
|
|
5787
5355
|
return this.collectFilesFromPaths(resolved, resourceType);
|
|
5788
5356
|
}
|
|
5789
5357
|
resolveLocalEntries(entries, resourceType, target, metadata, baseDir) {
|
|
@@ -5815,32 +5383,32 @@ var DefaultPackageManager = class {
|
|
|
5815
5383
|
prompts: projectSettings.prompts ?? [],
|
|
5816
5384
|
themes: projectSettings.themes ?? []
|
|
5817
5385
|
}, userDirs = {
|
|
5818
|
-
extensions:
|
|
5819
|
-
skills:
|
|
5820
|
-
prompts:
|
|
5821
|
-
themes:
|
|
5386
|
+
extensions: join(globalBaseDir, "extensions"),
|
|
5387
|
+
skills: join(globalBaseDir, "skills"),
|
|
5388
|
+
prompts: join(globalBaseDir, "prompts"),
|
|
5389
|
+
themes: join(globalBaseDir, "themes")
|
|
5822
5390
|
}, projectDirs = {
|
|
5823
|
-
extensions:
|
|
5824
|
-
skills:
|
|
5825
|
-
prompts:
|
|
5826
|
-
themes:
|
|
5827
|
-
}, userAgentsSkillsDir =
|
|
5391
|
+
extensions: join(projectBaseDir, "extensions"),
|
|
5392
|
+
skills: join(projectBaseDir, "skills"),
|
|
5393
|
+
prompts: join(projectBaseDir, "prompts"),
|
|
5394
|
+
themes: join(projectBaseDir, "themes")
|
|
5395
|
+
}, userAgentsSkillsDir = join(getHomeDir(), ".agents", "skills"), projectTrusted = this.settingsManager.isProjectTrusted(), projectAgentsSkillDirs = projectTrusted ? collectAncestorAgentsSkillDirs(this.cwd).filter((dir) => resolve(dir) !== resolve(userAgentsSkillsDir)) : [], addResources = (resourceType, paths, metadata, overrides, baseDir) => {
|
|
5828
5396
|
let target = this.getTargetMap(accumulator, resourceType);
|
|
5829
|
-
for (let
|
|
5830
|
-
let enabled = isEnabledByOverrides(
|
|
5831
|
-
this.addResource(target,
|
|
5397
|
+
for (let path of paths) {
|
|
5398
|
+
let enabled = isEnabledByOverrides(path, overrides, baseDir);
|
|
5399
|
+
this.addResource(target, path, metadata, enabled);
|
|
5832
5400
|
}
|
|
5833
5401
|
};
|
|
5834
5402
|
projectTrusted && (addResources("extensions", collectAutoExtensionEntries(projectDirs.extensions), projectMetadata, projectOverrides.extensions, projectBaseDir), addResources("skills", collectAutoSkillEntries(projectDirs.skills, "pi"), projectMetadata, projectOverrides.skills, projectBaseDir));
|
|
5835
5403
|
for (let agentsSkillsDir of projectAgentsSkillDirs) {
|
|
5836
|
-
let agentsBaseDir =
|
|
5404
|
+
let agentsBaseDir = dirname(agentsSkillsDir), agentsMetadata = {
|
|
5837
5405
|
...projectMetadata,
|
|
5838
5406
|
baseDir: agentsBaseDir
|
|
5839
5407
|
};
|
|
5840
5408
|
addResources("skills", collectAutoSkillEntries(agentsSkillsDir, "agents"), agentsMetadata, projectOverrides.skills, agentsBaseDir);
|
|
5841
5409
|
}
|
|
5842
5410
|
projectTrusted && (addResources("prompts", collectAutoPromptEntries(projectDirs.prompts), projectMetadata, projectOverrides.prompts, projectBaseDir), addResources("themes", collectAutoThemeEntries(projectDirs.themes), projectMetadata, projectOverrides.themes, projectBaseDir)), addResources("extensions", collectAutoExtensionEntries(userDirs.extensions), userMetadata, userOverrides.extensions, globalBaseDir), addResources("skills", collectAutoSkillEntries(userDirs.skills, "pi"), userMetadata, userOverrides.skills, globalBaseDir);
|
|
5843
|
-
let userAgentsBaseDir =
|
|
5411
|
+
let userAgentsBaseDir = dirname(userAgentsSkillsDir), userAgentsMetadata = {
|
|
5844
5412
|
...userMetadata,
|
|
5845
5413
|
baseDir: userAgentsBaseDir
|
|
5846
5414
|
};
|
|
@@ -5849,9 +5417,9 @@ var DefaultPackageManager = class {
|
|
|
5849
5417
|
collectFilesFromPaths(paths, resourceType) {
|
|
5850
5418
|
let files = [];
|
|
5851
5419
|
for (let p of paths)
|
|
5852
|
-
if (
|
|
5420
|
+
if (existsSync(p))
|
|
5853
5421
|
try {
|
|
5854
|
-
let stats =
|
|
5422
|
+
let stats = statSync(p);
|
|
5855
5423
|
stats.isFile() ? files.push(p) : stats.isDirectory() && files.push(...collectResourceFiles(p, resourceType));
|
|
5856
5424
|
} catch {
|
|
5857
5425
|
}
|
|
@@ -5871,8 +5439,8 @@ var DefaultPackageManager = class {
|
|
|
5871
5439
|
throw new Error(`Unknown resource type: ${resourceType}`);
|
|
5872
5440
|
}
|
|
5873
5441
|
}
|
|
5874
|
-
addResource(map,
|
|
5875
|
-
|
|
5442
|
+
addResource(map, path, metadata, enabled) {
|
|
5443
|
+
path && (map.has(path) || map.set(path, { metadata, enabled }));
|
|
5876
5444
|
}
|
|
5877
5445
|
createAccumulator() {
|
|
5878
5446
|
return {
|
|
@@ -5884,8 +5452,8 @@ var DefaultPackageManager = class {
|
|
|
5884
5452
|
}
|
|
5885
5453
|
toResolvedPaths(accumulator) {
|
|
5886
5454
|
let mapToResolved = (entries) => {
|
|
5887
|
-
let resolved = Array.from(entries.entries()).map(([
|
|
5888
|
-
path
|
|
5455
|
+
let resolved = Array.from(entries.entries()).map(([path, { metadata, enabled }]) => ({
|
|
5456
|
+
path,
|
|
5889
5457
|
enabled,
|
|
5890
5458
|
metadata
|
|
5891
5459
|
}));
|
|
@@ -5975,919 +5543,8 @@ var DefaultPackageManager = class {
|
|
|
5975
5543
|
}
|
|
5976
5544
|
};
|
|
5977
5545
|
|
|
5978
|
-
// packages/coding-agent/dist/core/skills.js
|
|
5979
|
-
var import_ignore2 = __toESM(require_ignore(), 1);
|
|
5980
|
-
import { existsSync as existsSync3, readdirSync as readdirSync3, readFileSync as readFileSync3, statSync as statSync3 } from "fs";
|
|
5981
|
-
import { basename as basename2, dirname as dirname3, join as join3, relative as relative2, resolve as resolve3, sep as sep2 } from "path";
|
|
5982
|
-
var MAX_NAME_LENGTH = 64, MAX_DESCRIPTION_LENGTH = 1024, IGNORE_FILE_NAMES2 = [".gitignore", ".ignore", ".fdignore"];
|
|
5983
|
-
function toPosixPath2(p) {
|
|
5984
|
-
return p.split(sep2).join("/");
|
|
5985
|
-
}
|
|
5986
|
-
function prefixIgnorePattern2(line, prefix) {
|
|
5987
|
-
let trimmed = line.trim();
|
|
5988
|
-
if (!trimmed || trimmed.startsWith("#") && !trimmed.startsWith("\\#"))
|
|
5989
|
-
return null;
|
|
5990
|
-
let pattern = line, negated = !1;
|
|
5991
|
-
pattern.startsWith("!") ? (negated = !0, pattern = pattern.slice(1)) : pattern.startsWith("\\!") && (pattern = pattern.slice(1)), pattern.startsWith("/") && (pattern = pattern.slice(1));
|
|
5992
|
-
let prefixed = prefix ? `${prefix}${pattern}` : pattern;
|
|
5993
|
-
return negated ? `!${prefixed}` : prefixed;
|
|
5994
|
-
}
|
|
5995
|
-
function addIgnoreRules2(ig, dir, rootDir) {
|
|
5996
|
-
let relativeDir = relative2(rootDir, dir), prefix = relativeDir ? `${toPosixPath2(relativeDir)}/` : "";
|
|
5997
|
-
for (let filename of IGNORE_FILE_NAMES2) {
|
|
5998
|
-
let ignorePath = join3(dir, filename);
|
|
5999
|
-
if (existsSync3(ignorePath))
|
|
6000
|
-
try {
|
|
6001
|
-
let patterns = readFileSync3(ignorePath, "utf-8").split(/\r?\n/).map((line) => prefixIgnorePattern2(line, prefix)).filter((line) => !!line);
|
|
6002
|
-
patterns.length > 0 && ig.add(patterns);
|
|
6003
|
-
} catch {
|
|
6004
|
-
}
|
|
6005
|
-
}
|
|
6006
|
-
}
|
|
6007
|
-
function validateName(name) {
|
|
6008
|
-
let errors = [];
|
|
6009
|
-
return name.length > MAX_NAME_LENGTH && errors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`), /^[a-z0-9-]+$/.test(name) || errors.push("name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)"), (name.startsWith("-") || name.endsWith("-")) && errors.push("name must not start or end with a hyphen"), name.includes("--") && errors.push("name must not contain consecutive hyphens"), errors;
|
|
6010
|
-
}
|
|
6011
|
-
function validateDescription(description) {
|
|
6012
|
-
let errors = [];
|
|
6013
|
-
return !description || description.trim() === "" ? errors.push("description is required") : description.length > MAX_DESCRIPTION_LENGTH && errors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`), errors;
|
|
6014
|
-
}
|
|
6015
|
-
function createSkillSourceInfo(filePath, baseDir, source) {
|
|
6016
|
-
switch (source) {
|
|
6017
|
-
case "user":
|
|
6018
|
-
return createSyntheticSourceInfo(filePath, {
|
|
6019
|
-
source: "local",
|
|
6020
|
-
scope: "user",
|
|
6021
|
-
baseDir
|
|
6022
|
-
});
|
|
6023
|
-
case "project":
|
|
6024
|
-
return createSyntheticSourceInfo(filePath, {
|
|
6025
|
-
source: "local",
|
|
6026
|
-
scope: "project",
|
|
6027
|
-
baseDir
|
|
6028
|
-
});
|
|
6029
|
-
case "path":
|
|
6030
|
-
return createSyntheticSourceInfo(filePath, {
|
|
6031
|
-
source: "local",
|
|
6032
|
-
baseDir
|
|
6033
|
-
});
|
|
6034
|
-
default:
|
|
6035
|
-
return createSyntheticSourceInfo(filePath, { source, baseDir });
|
|
6036
|
-
}
|
|
6037
|
-
}
|
|
6038
|
-
function loadSkillsFromDir(options) {
|
|
6039
|
-
let { dir, source } = options;
|
|
6040
|
-
return loadSkillsFromDirInternal(dir, source, !0);
|
|
6041
|
-
}
|
|
6042
|
-
function loadSkillsFromDirInternal(dir, source, includeRootFiles, ignoreMatcher, rootDir) {
|
|
6043
|
-
let skills = [], diagnostics = [];
|
|
6044
|
-
if (!existsSync3(dir))
|
|
6045
|
-
return { skills, diagnostics };
|
|
6046
|
-
let root = rootDir ?? dir, ig = ignoreMatcher ?? (0, import_ignore2.default)();
|
|
6047
|
-
addIgnoreRules2(ig, dir, root);
|
|
6048
|
-
try {
|
|
6049
|
-
let entries = readdirSync3(dir, { withFileTypes: !0 });
|
|
6050
|
-
for (let entry of entries) {
|
|
6051
|
-
if (entry.name !== "SKILL.md")
|
|
6052
|
-
continue;
|
|
6053
|
-
let fullPath = join3(dir, entry.name), isFile = entry.isFile();
|
|
6054
|
-
if (entry.isSymbolicLink())
|
|
6055
|
-
try {
|
|
6056
|
-
isFile = statSync3(fullPath).isFile();
|
|
6057
|
-
} catch {
|
|
6058
|
-
continue;
|
|
6059
|
-
}
|
|
6060
|
-
let relPath = toPosixPath2(relative2(root, fullPath));
|
|
6061
|
-
if (!isFile || ig.ignores(relPath))
|
|
6062
|
-
continue;
|
|
6063
|
-
let result = loadSkillFromFile(fullPath, source);
|
|
6064
|
-
return result.skill && skills.push(result.skill), diagnostics.push(...result.diagnostics), { skills, diagnostics };
|
|
6065
|
-
}
|
|
6066
|
-
for (let entry of entries) {
|
|
6067
|
-
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
6068
|
-
continue;
|
|
6069
|
-
let fullPath = join3(dir, entry.name), isDirectory = entry.isDirectory(), isFile = entry.isFile();
|
|
6070
|
-
if (entry.isSymbolicLink())
|
|
6071
|
-
try {
|
|
6072
|
-
let stats = statSync3(fullPath);
|
|
6073
|
-
isDirectory = stats.isDirectory(), isFile = stats.isFile();
|
|
6074
|
-
} catch {
|
|
6075
|
-
continue;
|
|
6076
|
-
}
|
|
6077
|
-
let relPath = toPosixPath2(relative2(root, fullPath)), ignorePath = isDirectory ? `${relPath}/` : relPath;
|
|
6078
|
-
if (ig.ignores(ignorePath))
|
|
6079
|
-
continue;
|
|
6080
|
-
if (isDirectory) {
|
|
6081
|
-
let subResult = loadSkillsFromDirInternal(fullPath, source, !1, ig, root);
|
|
6082
|
-
skills.push(...subResult.skills), diagnostics.push(...subResult.diagnostics);
|
|
6083
|
-
continue;
|
|
6084
|
-
}
|
|
6085
|
-
if (!isFile || !includeRootFiles || !entry.name.endsWith(".md"))
|
|
6086
|
-
continue;
|
|
6087
|
-
let result = loadSkillFromFile(fullPath, source);
|
|
6088
|
-
result.skill && skills.push(result.skill), diagnostics.push(...result.diagnostics);
|
|
6089
|
-
}
|
|
6090
|
-
} catch {
|
|
6091
|
-
}
|
|
6092
|
-
return { skills, diagnostics };
|
|
6093
|
-
}
|
|
6094
|
-
function loadSkillFromFile(filePath, source) {
|
|
6095
|
-
let diagnostics = [];
|
|
6096
|
-
try {
|
|
6097
|
-
let rawContent = readFileSync3(filePath, "utf-8"), { frontmatter } = parseFrontmatter(rawContent), skillDir = dirname3(filePath), parentDirName = basename2(skillDir), descErrors = validateDescription(frontmatter.description);
|
|
6098
|
-
for (let error of descErrors)
|
|
6099
|
-
diagnostics.push({ type: "warning", message: error, path: filePath });
|
|
6100
|
-
let name = frontmatter.name || parentDirName, nameErrors = validateName(name);
|
|
6101
|
-
for (let error of nameErrors)
|
|
6102
|
-
diagnostics.push({ type: "warning", message: error, path: filePath });
|
|
6103
|
-
return !frontmatter.description || frontmatter.description.trim() === "" ? { skill: null, diagnostics } : {
|
|
6104
|
-
skill: {
|
|
6105
|
-
name,
|
|
6106
|
-
description: frontmatter.description,
|
|
6107
|
-
filePath,
|
|
6108
|
-
baseDir: skillDir,
|
|
6109
|
-
sourceInfo: createSkillSourceInfo(filePath, skillDir, source),
|
|
6110
|
-
disableModelInvocation: frontmatter["disable-model-invocation"] === !0
|
|
6111
|
-
},
|
|
6112
|
-
diagnostics
|
|
6113
|
-
};
|
|
6114
|
-
} catch (error) {
|
|
6115
|
-
let message = error instanceof Error ? error.message : "failed to parse skill file";
|
|
6116
|
-
return diagnostics.push({ type: "warning", message, path: filePath }), { skill: null, diagnostics };
|
|
6117
|
-
}
|
|
6118
|
-
}
|
|
6119
|
-
function formatSkillsForPrompt(skills) {
|
|
6120
|
-
let visibleSkills = skills.filter((s) => !s.disableModelInvocation);
|
|
6121
|
-
if (visibleSkills.length === 0)
|
|
6122
|
-
return "";
|
|
6123
|
-
let lines = [
|
|
6124
|
-
`
|
|
6125
|
-
|
|
6126
|
-
The following skills provide specialized instructions for specific tasks.`,
|
|
6127
|
-
"Use the read tool to load a skill's file when the task matches its description.",
|
|
6128
|
-
"When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.",
|
|
6129
|
-
"",
|
|
6130
|
-
"<available_skills>"
|
|
6131
|
-
];
|
|
6132
|
-
for (let skill of visibleSkills)
|
|
6133
|
-
lines.push(" <skill>"), lines.push(` <name>${escapeXml(skill.name)}</name>`), lines.push(` <description>${escapeXml(skill.description)}</description>`), lines.push(` <location>${escapeXml(skill.filePath)}</location>`), lines.push(" </skill>");
|
|
6134
|
-
return lines.push("</available_skills>"), lines.join(`
|
|
6135
|
-
`);
|
|
6136
|
-
}
|
|
6137
|
-
function escapeXml(str) {
|
|
6138
|
-
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
6139
|
-
}
|
|
6140
|
-
function loadSkills(options) {
|
|
6141
|
-
let { agentDir, skillPaths, includeDefaults } = options, resolvedCwd = resolvePath(options.cwd), resolvedAgentDir = resolvePath(agentDir ?? getAgentDir()), skillMap = /* @__PURE__ */ new Map(), realPathSet = /* @__PURE__ */ new Set(), allDiagnostics = [], collisionDiagnostics = [];
|
|
6142
|
-
function addSkills(result) {
|
|
6143
|
-
allDiagnostics.push(...result.diagnostics);
|
|
6144
|
-
for (let skill of result.skills) {
|
|
6145
|
-
let realPath = canonicalizePath(skill.filePath);
|
|
6146
|
-
if (realPathSet.has(realPath))
|
|
6147
|
-
continue;
|
|
6148
|
-
let existing = skillMap.get(skill.name);
|
|
6149
|
-
existing ? collisionDiagnostics.push({
|
|
6150
|
-
type: "collision",
|
|
6151
|
-
message: `name "${skill.name}" collision`,
|
|
6152
|
-
path: skill.filePath,
|
|
6153
|
-
collision: {
|
|
6154
|
-
resourceType: "skill",
|
|
6155
|
-
name: skill.name,
|
|
6156
|
-
winnerPath: existing.filePath,
|
|
6157
|
-
loserPath: skill.filePath
|
|
6158
|
-
}
|
|
6159
|
-
}) : (skillMap.set(skill.name, skill), realPathSet.add(realPath));
|
|
6160
|
-
}
|
|
6161
|
-
}
|
|
6162
|
-
includeDefaults && (addSkills(loadSkillsFromDirInternal(join3(resolvedAgentDir, "skills"), "user", !0)), addSkills(loadSkillsFromDirInternal(resolve3(resolvedCwd, CONFIG_DIR_NAME, "skills"), "project", !0)));
|
|
6163
|
-
let userSkillsDir = join3(resolvedAgentDir, "skills"), projectSkillsDir = resolve3(resolvedCwd, CONFIG_DIR_NAME, "skills"), isUnderPath = (target, root) => {
|
|
6164
|
-
let normalizedRoot = resolve3(root);
|
|
6165
|
-
if (target === normalizedRoot)
|
|
6166
|
-
return !0;
|
|
6167
|
-
let prefix = normalizedRoot.endsWith(sep2) ? normalizedRoot : `${normalizedRoot}${sep2}`;
|
|
6168
|
-
return target.startsWith(prefix);
|
|
6169
|
-
}, getSource = (resolvedPath) => {
|
|
6170
|
-
if (!includeDefaults) {
|
|
6171
|
-
if (isUnderPath(resolvedPath, userSkillsDir))
|
|
6172
|
-
return "user";
|
|
6173
|
-
if (isUnderPath(resolvedPath, projectSkillsDir))
|
|
6174
|
-
return "project";
|
|
6175
|
-
}
|
|
6176
|
-
return "path";
|
|
6177
|
-
};
|
|
6178
|
-
for (let rawPath of skillPaths) {
|
|
6179
|
-
let resolvedPath = resolvePath(rawPath, resolvedCwd, { trim: !0 });
|
|
6180
|
-
if (!existsSync3(resolvedPath)) {
|
|
6181
|
-
allDiagnostics.push({ type: "warning", message: "skill path does not exist", path: resolvedPath });
|
|
6182
|
-
continue;
|
|
6183
|
-
}
|
|
6184
|
-
try {
|
|
6185
|
-
let stats = statSync3(resolvedPath), source = getSource(resolvedPath);
|
|
6186
|
-
if (stats.isDirectory())
|
|
6187
|
-
addSkills(loadSkillsFromDirInternal(resolvedPath, source, !0));
|
|
6188
|
-
else if (stats.isFile() && resolvedPath.endsWith(".md")) {
|
|
6189
|
-
let result = loadSkillFromFile(resolvedPath, source);
|
|
6190
|
-
result.skill ? addSkills({ skills: [result.skill], diagnostics: result.diagnostics }) : allDiagnostics.push(...result.diagnostics);
|
|
6191
|
-
} else
|
|
6192
|
-
allDiagnostics.push({ type: "warning", message: "skill path is not a markdown file", path: resolvedPath });
|
|
6193
|
-
} catch (error) {
|
|
6194
|
-
let message = error instanceof Error ? error.message : "failed to read skill path";
|
|
6195
|
-
allDiagnostics.push({ type: "warning", message, path: resolvedPath });
|
|
6196
|
-
}
|
|
6197
|
-
}
|
|
6198
|
-
return {
|
|
6199
|
-
skills: Array.from(skillMap.values()),
|
|
6200
|
-
diagnostics: [...allDiagnostics, ...collisionDiagnostics]
|
|
6201
|
-
};
|
|
6202
|
-
}
|
|
6203
|
-
|
|
6204
|
-
// packages/coding-agent/dist/core/resource-loader.js
|
|
6205
|
-
import { existsSync as existsSync5, readdirSync as readdirSync5, readFileSync as readFileSync5, statSync as statSync5 } from "node:fs";
|
|
6206
|
-
import { dirname as dirname5, join as join5, resolve as resolve5, sep as sep4 } from "node:path";
|
|
6207
|
-
import chalk from "chalk";
|
|
6208
|
-
|
|
6209
|
-
// packages/coding-agent/dist/core/prompt-templates.js
|
|
6210
|
-
import { existsSync as existsSync4, readdirSync as readdirSync4, readFileSync as readFileSync4, statSync as statSync4 } from "fs";
|
|
6211
|
-
import { basename as basename3, dirname as dirname4, join as join4, resolve as resolve4, sep as sep3 } from "path";
|
|
6212
|
-
function parseCommandArgs(argsString) {
|
|
6213
|
-
let args = [], current = "", inQuote = null;
|
|
6214
|
-
for (let i = 0; i < argsString.length; i++) {
|
|
6215
|
-
let char = argsString[i];
|
|
6216
|
-
inQuote ? char === inQuote ? inQuote = null : current += char : char === '"' || char === "'" ? inQuote = char : /\s/.test(char) ? current && (args.push(current), current = "") : current += char;
|
|
6217
|
-
}
|
|
6218
|
-
return current && args.push(current), args;
|
|
6219
|
-
}
|
|
6220
|
-
function substituteArgs(content, args) {
|
|
6221
|
-
let allArgs = args.join(" ");
|
|
6222
|
-
return content.replace(/\$\{(\d+):-([^}]*)\}|\$\{@:(\d+)(?::(\d+))?\}|\$(ARGUMENTS|@|\d+)/g, (_match, defaultNum, defaultValue, sliceStart, sliceLength, simple) => {
|
|
6223
|
-
if (defaultNum) {
|
|
6224
|
-
let index2 = parseInt(defaultNum, 10) - 1, value = args[index2];
|
|
6225
|
-
return value || defaultValue;
|
|
6226
|
-
}
|
|
6227
|
-
if (sliceStart) {
|
|
6228
|
-
let start = parseInt(sliceStart, 10) - 1;
|
|
6229
|
-
if (start < 0 && (start = 0), sliceLength) {
|
|
6230
|
-
let length = parseInt(sliceLength, 10);
|
|
6231
|
-
return args.slice(start, start + length).join(" ");
|
|
6232
|
-
}
|
|
6233
|
-
return args.slice(start).join(" ");
|
|
6234
|
-
}
|
|
6235
|
-
if (simple === "ARGUMENTS" || simple === "@")
|
|
6236
|
-
return allArgs;
|
|
6237
|
-
let index = parseInt(simple, 10) - 1;
|
|
6238
|
-
return args[index] ?? "";
|
|
6239
|
-
});
|
|
6240
|
-
}
|
|
6241
|
-
function loadTemplateFromFile(filePath, sourceInfo) {
|
|
6242
|
-
try {
|
|
6243
|
-
let rawContent = readFileSync4(filePath, "utf-8"), { frontmatter, body } = parseFrontmatter(rawContent), name = basename3(filePath).replace(/\.md$/, ""), description = frontmatter.description || "";
|
|
6244
|
-
if (!description) {
|
|
6245
|
-
let firstLine = body.split(`
|
|
6246
|
-
`).find((line) => line.trim());
|
|
6247
|
-
firstLine && (description = firstLine.slice(0, 60), firstLine.length > 60 && (description += "..."));
|
|
6248
|
-
}
|
|
6249
|
-
return {
|
|
6250
|
-
name,
|
|
6251
|
-
description,
|
|
6252
|
-
...frontmatter["argument-hint"] && { argumentHint: frontmatter["argument-hint"] },
|
|
6253
|
-
content: body,
|
|
6254
|
-
sourceInfo,
|
|
6255
|
-
filePath
|
|
6256
|
-
};
|
|
6257
|
-
} catch {
|
|
6258
|
-
return null;
|
|
6259
|
-
}
|
|
6260
|
-
}
|
|
6261
|
-
function loadTemplatesFromDir(dir, getSourceInfo) {
|
|
6262
|
-
let templates = [];
|
|
6263
|
-
if (!existsSync4(dir))
|
|
6264
|
-
return templates;
|
|
6265
|
-
try {
|
|
6266
|
-
let entries = readdirSync4(dir, { withFileTypes: !0 });
|
|
6267
|
-
for (let entry of entries) {
|
|
6268
|
-
let fullPath = join4(dir, entry.name), isFile = entry.isFile();
|
|
6269
|
-
if (entry.isSymbolicLink())
|
|
6270
|
-
try {
|
|
6271
|
-
isFile = statSync4(fullPath).isFile();
|
|
6272
|
-
} catch {
|
|
6273
|
-
continue;
|
|
6274
|
-
}
|
|
6275
|
-
if (isFile && entry.name.endsWith(".md")) {
|
|
6276
|
-
let template = loadTemplateFromFile(fullPath, getSourceInfo(fullPath));
|
|
6277
|
-
template && templates.push(template);
|
|
6278
|
-
}
|
|
6279
|
-
}
|
|
6280
|
-
} catch {
|
|
6281
|
-
return templates;
|
|
6282
|
-
}
|
|
6283
|
-
return templates;
|
|
6284
|
-
}
|
|
6285
|
-
function loadPromptTemplates(options) {
|
|
6286
|
-
let resolvedCwd = resolvePath(options.cwd), resolvedAgentDir = resolvePath(options.agentDir), promptPaths = options.promptPaths, includeDefaults = options.includeDefaults, templates = [], globalPromptsDir = join4(resolvedAgentDir, "prompts"), projectPromptsDir = resolve4(resolvedCwd, CONFIG_DIR_NAME, "prompts"), isUnderPath = (target, root) => {
|
|
6287
|
-
let normalizedRoot = resolve4(root);
|
|
6288
|
-
if (target === normalizedRoot)
|
|
6289
|
-
return !0;
|
|
6290
|
-
let prefix = normalizedRoot.endsWith(sep3) ? normalizedRoot : `${normalizedRoot}${sep3}`;
|
|
6291
|
-
return target.startsWith(prefix);
|
|
6292
|
-
}, getSourceInfo = (resolvedPath) => isUnderPath(resolvedPath, globalPromptsDir) ? createSyntheticSourceInfo(resolvedPath, {
|
|
6293
|
-
source: "local",
|
|
6294
|
-
scope: "user",
|
|
6295
|
-
baseDir: globalPromptsDir
|
|
6296
|
-
}) : isUnderPath(resolvedPath, projectPromptsDir) ? createSyntheticSourceInfo(resolvedPath, {
|
|
6297
|
-
source: "local",
|
|
6298
|
-
scope: "project",
|
|
6299
|
-
baseDir: projectPromptsDir
|
|
6300
|
-
}) : createSyntheticSourceInfo(resolvedPath, {
|
|
6301
|
-
source: "local",
|
|
6302
|
-
baseDir: statSync4(resolvedPath).isDirectory() ? resolvedPath : dirname4(resolvedPath)
|
|
6303
|
-
});
|
|
6304
|
-
includeDefaults && (templates.push(...loadTemplatesFromDir(globalPromptsDir, getSourceInfo)), templates.push(...loadTemplatesFromDir(projectPromptsDir, getSourceInfo)));
|
|
6305
|
-
for (let rawPath of promptPaths) {
|
|
6306
|
-
let resolvedPath = resolvePath(rawPath, resolvedCwd, { trim: !0 });
|
|
6307
|
-
if (existsSync4(resolvedPath))
|
|
6308
|
-
try {
|
|
6309
|
-
let stats = statSync4(resolvedPath);
|
|
6310
|
-
if (stats.isDirectory())
|
|
6311
|
-
templates.push(...loadTemplatesFromDir(resolvedPath, getSourceInfo));
|
|
6312
|
-
else if (stats.isFile() && resolvedPath.endsWith(".md")) {
|
|
6313
|
-
let template = loadTemplateFromFile(resolvedPath, getSourceInfo(resolvedPath));
|
|
6314
|
-
template && templates.push(template);
|
|
6315
|
-
}
|
|
6316
|
-
} catch {
|
|
6317
|
-
}
|
|
6318
|
-
}
|
|
6319
|
-
return templates;
|
|
6320
|
-
}
|
|
6321
|
-
function expandPromptTemplate(text, templates) {
|
|
6322
|
-
if (!text.startsWith("/"))
|
|
6323
|
-
return text;
|
|
6324
|
-
let match = text.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);
|
|
6325
|
-
if (!match)
|
|
6326
|
-
return text;
|
|
6327
|
-
let templateName = match[1], argsString = match[2] ?? "", template = templates.find((t) => t.name === templateName);
|
|
6328
|
-
if (template) {
|
|
6329
|
-
let args = parseCommandArgs(argsString);
|
|
6330
|
-
return substituteArgs(template.content, args);
|
|
6331
|
-
}
|
|
6332
|
-
return text;
|
|
6333
|
-
}
|
|
6334
|
-
|
|
6335
|
-
// packages/coding-agent/dist/core/resource-loader.js
|
|
6336
|
-
function inlineExtensionPath(input, index) {
|
|
6337
|
-
return `<inline:${typeof input != "function" ? input.name : index + 1}>`;
|
|
6338
|
-
}
|
|
6339
|
-
function resolvePromptInput(input, description) {
|
|
6340
|
-
if (input) {
|
|
6341
|
-
if (existsSync5(input))
|
|
6342
|
-
try {
|
|
6343
|
-
return readFileSync5(input, "utf-8");
|
|
6344
|
-
} catch (error) {
|
|
6345
|
-
return console.error(chalk.yellow(`Warning: Could not read ${description} file ${input}: ${error}`)), input;
|
|
6346
|
-
}
|
|
6347
|
-
return input;
|
|
6348
|
-
}
|
|
6349
|
-
}
|
|
6350
|
-
function loadContextFileFromDir(dir) {
|
|
6351
|
-
let candidates = ["AGENTS.md", "AGENTS.MD", "CLAUDE.md", "CLAUDE.MD"];
|
|
6352
|
-
for (let filename of candidates) {
|
|
6353
|
-
let filePath = join5(dir, filename);
|
|
6354
|
-
if (existsSync5(filePath))
|
|
6355
|
-
try {
|
|
6356
|
-
return {
|
|
6357
|
-
path: filePath,
|
|
6358
|
-
content: readFileSync5(filePath, "utf-8")
|
|
6359
|
-
};
|
|
6360
|
-
} catch (error) {
|
|
6361
|
-
console.error(chalk.yellow(`Warning: Could not read ${filePath}: ${error}`));
|
|
6362
|
-
}
|
|
6363
|
-
}
|
|
6364
|
-
return null;
|
|
6365
|
-
}
|
|
6366
|
-
function loadProjectContextFiles(options) {
|
|
6367
|
-
let resolvedCwd = resolvePath(options.cwd), resolvedAgentDir = resolvePath(options.agentDir), contextFiles = [], seenPaths = /* @__PURE__ */ new Set(), userContexts = options.settingsManager ? loadSelectedUserInstructions({ agentDir: resolvedAgentDir, settingsManager: options.settingsManager }) : [getGlobalInstructionsPath(resolvedAgentDir)].map((path2) => loadContextFileFromDir(dirname5(path2))).filter((file) => file !== null);
|
|
6368
|
-
for (let userContext of userContexts)
|
|
6369
|
-
contextFiles.push(userContext), seenPaths.add(userContext.path);
|
|
6370
|
-
let ancestorContextFiles = [], currentDir = resolvedCwd;
|
|
6371
|
-
for (; ; ) {
|
|
6372
|
-
let contextFile = loadContextFileFromDir(currentDir);
|
|
6373
|
-
contextFile && !seenPaths.has(contextFile.path) && (ancestorContextFiles.unshift(contextFile), seenPaths.add(contextFile.path));
|
|
6374
|
-
let parentDir = dirname5(currentDir);
|
|
6375
|
-
if (parentDir === currentDir)
|
|
6376
|
-
break;
|
|
6377
|
-
currentDir = parentDir;
|
|
6378
|
-
}
|
|
6379
|
-
return contextFiles.push(...ancestorContextFiles), contextFiles;
|
|
6380
|
-
}
|
|
6381
|
-
var DefaultResourceLoader = class {
|
|
6382
|
-
cwd;
|
|
6383
|
-
agentDir;
|
|
6384
|
-
settingsManager;
|
|
6385
|
-
eventBus;
|
|
6386
|
-
packageManager;
|
|
6387
|
-
additionalExtensionPaths;
|
|
6388
|
-
additionalSkillPaths;
|
|
6389
|
-
additionalPromptTemplatePaths;
|
|
6390
|
-
additionalThemePaths;
|
|
6391
|
-
extensionFactories;
|
|
6392
|
-
noExtensions;
|
|
6393
|
-
noSkills;
|
|
6394
|
-
noPromptTemplates;
|
|
6395
|
-
noThemes;
|
|
6396
|
-
noContextFiles;
|
|
6397
|
-
systemPromptSource;
|
|
6398
|
-
appendSystemPromptSource;
|
|
6399
|
-
extensionsOverride;
|
|
6400
|
-
skillsOverride;
|
|
6401
|
-
promptsOverride;
|
|
6402
|
-
themesOverride;
|
|
6403
|
-
agentsFilesOverride;
|
|
6404
|
-
systemPromptOverride;
|
|
6405
|
-
appendSystemPromptOverride;
|
|
6406
|
-
extensionsResult;
|
|
6407
|
-
skills;
|
|
6408
|
-
skillDiagnostics;
|
|
6409
|
-
prompts;
|
|
6410
|
-
promptDiagnostics;
|
|
6411
|
-
themes;
|
|
6412
|
-
themeDiagnostics;
|
|
6413
|
-
agentsFiles;
|
|
6414
|
-
systemPrompt;
|
|
6415
|
-
appendSystemPrompt;
|
|
6416
|
-
lastSkillPaths;
|
|
6417
|
-
extensionSkillSourceInfos;
|
|
6418
|
-
extensionPromptSourceInfos;
|
|
6419
|
-
extensionThemeSourceInfos;
|
|
6420
|
-
lastPromptPaths;
|
|
6421
|
-
lastThemePaths;
|
|
6422
|
-
loaded;
|
|
6423
|
-
constructor(options) {
|
|
6424
|
-
this.cwd = resolvePath(options.cwd), this.agentDir = resolvePath(options.agentDir), this.settingsManager = options.settingsManager ?? SettingsManager.create(this.cwd, this.agentDir), this.eventBus = options.eventBus ?? createEventBus(), this.packageManager = new DefaultPackageManager({
|
|
6425
|
-
cwd: this.cwd,
|
|
6426
|
-
agentDir: this.agentDir,
|
|
6427
|
-
settingsManager: this.settingsManager
|
|
6428
|
-
}), this.additionalExtensionPaths = options.additionalExtensionPaths ?? [], this.additionalSkillPaths = options.additionalSkillPaths ?? [], this.additionalPromptTemplatePaths = options.additionalPromptTemplatePaths ?? [], this.additionalThemePaths = options.additionalThemePaths ?? [], this.extensionFactories = options.extensionFactories ?? [], this.noExtensions = options.noExtensions ?? !1, this.noSkills = options.noSkills ?? !1, this.noPromptTemplates = options.noPromptTemplates ?? !1, this.noThemes = options.noThemes ?? !1, this.noContextFiles = options.noContextFiles ?? !1, this.systemPromptSource = options.systemPrompt, this.appendSystemPromptSource = options.appendSystemPrompt, this.extensionsOverride = options.extensionsOverride, this.skillsOverride = options.skillsOverride, this.promptsOverride = options.promptsOverride, this.themesOverride = options.themesOverride, this.agentsFilesOverride = options.agentsFilesOverride, this.systemPromptOverride = options.systemPromptOverride, this.appendSystemPromptOverride = options.appendSystemPromptOverride, this.extensionsResult = { extensions: [], errors: [], runtime: createExtensionRuntime() }, this.skills = [], this.skillDiagnostics = [], this.prompts = [], this.promptDiagnostics = [], this.themes = [], this.themeDiagnostics = [], this.agentsFiles = [], this.appendSystemPrompt = [], this.lastSkillPaths = [], this.extensionSkillSourceInfos = /* @__PURE__ */ new Map(), this.extensionPromptSourceInfos = /* @__PURE__ */ new Map(), this.extensionThemeSourceInfos = /* @__PURE__ */ new Map(), this.lastPromptPaths = [], this.lastThemePaths = [], this.loaded = !1;
|
|
6429
|
-
}
|
|
6430
|
-
getExtensions() {
|
|
6431
|
-
return this.extensionsResult;
|
|
6432
|
-
}
|
|
6433
|
-
getSkills() {
|
|
6434
|
-
return { skills: this.skills, diagnostics: this.skillDiagnostics };
|
|
6435
|
-
}
|
|
6436
|
-
getPrompts() {
|
|
6437
|
-
return { prompts: this.prompts, diagnostics: this.promptDiagnostics };
|
|
6438
|
-
}
|
|
6439
|
-
getThemes() {
|
|
6440
|
-
return { themes: this.themes, diagnostics: this.themeDiagnostics };
|
|
6441
|
-
}
|
|
6442
|
-
getAgentsFiles() {
|
|
6443
|
-
return { agentsFiles: this.agentsFiles };
|
|
6444
|
-
}
|
|
6445
|
-
contextFilesEnabled() {
|
|
6446
|
-
return !this.noContextFiles;
|
|
6447
|
-
}
|
|
6448
|
-
getSystemPrompt() {
|
|
6449
|
-
return this.systemPrompt;
|
|
6450
|
-
}
|
|
6451
|
-
getAppendSystemPrompt() {
|
|
6452
|
-
return this.appendSystemPrompt;
|
|
6453
|
-
}
|
|
6454
|
-
async attachInlineExtensions(factories) {
|
|
6455
|
-
let loaded = new Set(this.extensionsResult.extensions.map((extension) => extension.path)), pending = factories.filter((factory, index) => {
|
|
6456
|
-
let path2 = inlineExtensionPath(factory, this.extensionFactories.length + index);
|
|
6457
|
-
return !loaded.has(path2);
|
|
6458
|
-
});
|
|
6459
|
-
if (pending.length === 0)
|
|
6460
|
-
return { extensions: [], errors: [], runtime: this.extensionsResult.runtime };
|
|
6461
|
-
let attached = await this.loadExtensionFactories(this.extensionsResult.runtime, pending);
|
|
6462
|
-
return this.extensionFactories.push(...pending), this.extensionsResult.extensions.push(...attached.extensions), this.extensionsResult.errors.push(...attached.errors), this.addExtensionConflictDiagnostics(this.extensionsResult), {
|
|
6463
|
-
extensions: attached.extensions,
|
|
6464
|
-
errors: attached.errors,
|
|
6465
|
-
runtime: this.extensionsResult.runtime
|
|
6466
|
-
};
|
|
6467
|
-
}
|
|
6468
|
-
extendResources(paths) {
|
|
6469
|
-
let skillPaths = this.normalizeExtensionPaths(paths.skillPaths ?? []), promptPaths = this.normalizeExtensionPaths(paths.promptPaths ?? []), themePaths = this.normalizeExtensionPaths(paths.themePaths ?? []);
|
|
6470
|
-
for (let entry of skillPaths)
|
|
6471
|
-
this.extensionSkillSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));
|
|
6472
|
-
for (let entry of promptPaths)
|
|
6473
|
-
this.extensionPromptSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));
|
|
6474
|
-
for (let entry of themePaths)
|
|
6475
|
-
this.extensionThemeSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));
|
|
6476
|
-
skillPaths.length > 0 && (this.lastSkillPaths = this.mergePaths(this.lastSkillPaths, skillPaths.map((entry) => entry.path)), this.updateSkillsFromPaths(this.lastSkillPaths)), promptPaths.length > 0 && (this.lastPromptPaths = this.mergePaths(this.lastPromptPaths, promptPaths.map((entry) => entry.path)), this.updatePromptsFromPaths(this.lastPromptPaths)), themePaths.length > 0 && (this.lastThemePaths = this.mergePaths(this.lastThemePaths, themePaths.map((entry) => entry.path)), this.updateThemesFromPaths(this.lastThemePaths));
|
|
6477
|
-
}
|
|
6478
|
-
resolveOnMissing(skipMissingPackageInstall) {
|
|
6479
|
-
if (skipMissingPackageInstall)
|
|
6480
|
-
return async () => "skip";
|
|
6481
|
-
}
|
|
6482
|
-
async loadProjectTrustExtensions(options) {
|
|
6483
|
-
return this.settingsManager.setProjectTrusted(!1), await this.settingsManager.reload(), this.loadCurrentExtensionSet({
|
|
6484
|
-
includeInlineFactories: !0,
|
|
6485
|
-
skipMissingPackageInstall: options?.skipMissingPackageInstall
|
|
6486
|
-
});
|
|
6487
|
-
}
|
|
6488
|
-
async reload(options) {
|
|
6489
|
-
resetTimings("extensions"), this.loaded && clearExtensionCache();
|
|
6490
|
-
let preTrustExtensions;
|
|
6491
|
-
if (options?.resolveProjectTrust) {
|
|
6492
|
-
preTrustExtensions = await this.loadProjectTrustExtensions(options);
|
|
6493
|
-
let projectTrusted = await options.resolveProjectTrust({ extensionsResult: preTrustExtensions });
|
|
6494
|
-
this.settingsManager.setProjectTrusted(projectTrusted);
|
|
6495
|
-
}
|
|
6496
|
-
await this.settingsManager.reload();
|
|
6497
|
-
let resolvedPaths = await this.packageManager.resolve(this.resolveOnMissing(options?.skipMissingPackageInstall)), cliExtensionPaths = await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths, {
|
|
6498
|
-
temporary: !0
|
|
6499
|
-
}), metadataByPath = /* @__PURE__ */ new Map();
|
|
6500
|
-
this.extensionSkillSourceInfos = /* @__PURE__ */ new Map(), this.extensionPromptSourceInfos = /* @__PURE__ */ new Map(), this.extensionThemeSourceInfos = /* @__PURE__ */ new Map();
|
|
6501
|
-
let getEnabledResources = (resources) => {
|
|
6502
|
-
for (let r of resources)
|
|
6503
|
-
metadataByPath.has(r.path) || metadataByPath.set(r.path, r.metadata);
|
|
6504
|
-
return resources.filter((r) => r.enabled);
|
|
6505
|
-
}, getEnabledPaths = (resources) => getEnabledResources(resources).map((r) => r.path), enabledExtensions = getEnabledPaths(resolvedPaths.extensions), enabledSkillResources = getEnabledResources(resolvedPaths.skills), enabledPrompts = getEnabledPaths(resolvedPaths.prompts), enabledThemes = getEnabledPaths(resolvedPaths.themes), enabledSkills = enabledSkillResources.map((resource) => this.mapSkillPath(resource, metadataByPath));
|
|
6506
|
-
for (let r of cliExtensionPaths.extensions)
|
|
6507
|
-
metadataByPath.has(r.path) || metadataByPath.set(r.path, { source: "cli", scope: "temporary", origin: "top-level" });
|
|
6508
|
-
for (let r of cliExtensionPaths.skills)
|
|
6509
|
-
metadataByPath.has(r.path) || metadataByPath.set(r.path, { source: "cli", scope: "temporary", origin: "top-level" });
|
|
6510
|
-
let cliEnabledExtensions = getEnabledPaths(cliExtensionPaths.extensions), cliEnabledSkills = getEnabledPaths(cliExtensionPaths.skills), cliEnabledPrompts = getEnabledPaths(cliExtensionPaths.prompts), cliEnabledThemes = getEnabledPaths(cliExtensionPaths.themes), extensionPaths = this.noExtensions ? cliEnabledExtensions : this.mergePaths(cliEnabledExtensions, enabledExtensions), extensionsResult = await this.loadFinalExtensionSet(extensionPaths, preTrustExtensions);
|
|
6511
|
-
for (let p of this.additionalExtensionPaths)
|
|
6512
|
-
if (isLocalPath(p)) {
|
|
6513
|
-
let resolved = this.resolveResourcePath(p);
|
|
6514
|
-
existsSync5(resolved) || extensionsResult.errors.push({ path: resolved, error: `Extension path does not exist: ${resolved}` });
|
|
6515
|
-
}
|
|
6516
|
-
this.extensionsResult = this.extensionsOverride ? this.extensionsOverride(extensionsResult) : extensionsResult, this.applyExtensionSourceInfo(this.extensionsResult.extensions, metadataByPath);
|
|
6517
|
-
let skillPaths = this.noSkills ? this.mergePaths(cliEnabledSkills, this.additionalSkillPaths) : this.mergePaths([...cliEnabledSkills, ...enabledSkills], this.additionalSkillPaths);
|
|
6518
|
-
this.lastSkillPaths = skillPaths, this.updateSkillsFromPaths(skillPaths, metadataByPath);
|
|
6519
|
-
for (let p of this.additionalSkillPaths)
|
|
6520
|
-
if (isLocalPath(p)) {
|
|
6521
|
-
let resolved = this.resolveResourcePath(p);
|
|
6522
|
-
!existsSync5(resolved) && !this.skillDiagnostics.some((d) => d.path === resolved) && this.skillDiagnostics.push({ type: "error", message: "Skill path does not exist", path: resolved });
|
|
6523
|
-
}
|
|
6524
|
-
let promptPaths = this.noPromptTemplates ? this.mergePaths(cliEnabledPrompts, this.additionalPromptTemplatePaths) : this.mergePaths([...cliEnabledPrompts, ...enabledPrompts], this.additionalPromptTemplatePaths);
|
|
6525
|
-
this.lastPromptPaths = promptPaths, this.updatePromptsFromPaths(promptPaths, metadataByPath);
|
|
6526
|
-
for (let p of this.additionalPromptTemplatePaths)
|
|
6527
|
-
if (isLocalPath(p)) {
|
|
6528
|
-
let resolved = this.resolveResourcePath(p);
|
|
6529
|
-
!existsSync5(resolved) && !this.promptDiagnostics.some((d) => d.path === resolved) && this.promptDiagnostics.push({
|
|
6530
|
-
type: "error",
|
|
6531
|
-
message: "Prompt template path does not exist",
|
|
6532
|
-
path: resolved
|
|
6533
|
-
});
|
|
6534
|
-
}
|
|
6535
|
-
let themePaths = this.noThemes ? this.mergePaths(cliEnabledThemes, this.additionalThemePaths) : this.mergePaths([...cliEnabledThemes, ...enabledThemes], this.additionalThemePaths);
|
|
6536
|
-
this.lastThemePaths = themePaths, this.updateThemesFromPaths(themePaths, metadataByPath);
|
|
6537
|
-
for (let p of this.additionalThemePaths) {
|
|
6538
|
-
let resolved = this.resolveResourcePath(p);
|
|
6539
|
-
!existsSync5(resolved) && !this.themeDiagnostics.some((d) => d.path === resolved) && this.themeDiagnostics.push({ type: "error", message: "Theme path does not exist", path: resolved });
|
|
6540
|
-
}
|
|
6541
|
-
let agentsFiles = {
|
|
6542
|
-
agentsFiles: this.noContextFiles ? [] : loadProjectContextFiles({
|
|
6543
|
-
cwd: this.cwd,
|
|
6544
|
-
agentDir: this.agentDir,
|
|
6545
|
-
settingsManager: this.settingsManager
|
|
6546
|
-
})
|
|
6547
|
-
}, resolvedAgentsFiles = this.agentsFilesOverride ? this.agentsFilesOverride(agentsFiles) : agentsFiles;
|
|
6548
|
-
this.agentsFiles = resolvedAgentsFiles.agentsFiles;
|
|
6549
|
-
let baseSystemPrompt = resolvePromptInput(this.systemPromptSource ?? this.discoverSystemPromptFile(), "system prompt");
|
|
6550
|
-
this.systemPrompt = this.systemPromptOverride ? this.systemPromptOverride(baseSystemPrompt) : baseSystemPrompt;
|
|
6551
|
-
let baseAppend = (this.appendSystemPromptSource ?? (this.discoverAppendSystemPromptFile() ? [this.discoverAppendSystemPromptFile()] : [])).map((s) => resolvePromptInput(s, "append system prompt")).filter((s) => s !== void 0);
|
|
6552
|
-
this.appendSystemPrompt = this.appendSystemPromptOverride ? this.appendSystemPromptOverride(baseAppend) : baseAppend, this.loaded = !0;
|
|
6553
|
-
}
|
|
6554
|
-
async loadCurrentExtensionSet(options) {
|
|
6555
|
-
let resolvedPaths = await this.packageManager.resolve(this.resolveOnMissing(options.skipMissingPackageInstall)), cliExtensionPaths = await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths, {
|
|
6556
|
-
temporary: !0
|
|
6557
|
-
}), enabledExtensions = resolvedPaths.extensions.filter((r) => r.enabled).map((r) => r.path), cliEnabledExtensions = cliExtensionPaths.extensions.filter((r) => r.enabled).map((r) => r.path), extensionPaths = this.noExtensions ? cliEnabledExtensions : this.mergePaths(cliEnabledExtensions, enabledExtensions), extensionsResult = await loadExtensionsCached(extensionPaths, this.cwd, this.eventBus);
|
|
6558
|
-
if (!options.includeInlineFactories)
|
|
6559
|
-
return extensionsResult;
|
|
6560
|
-
let inlineExtensions = await this.loadExtensionFactories(extensionsResult.runtime);
|
|
6561
|
-
return extensionsResult.extensions.push(...inlineExtensions.extensions), extensionsResult.errors.push(...inlineExtensions.errors), extensionsResult;
|
|
6562
|
-
}
|
|
6563
|
-
resolveExtensionLoadPath(path2) {
|
|
6564
|
-
return resolvePath(path2, this.cwd, { normalizeUnicodeSpaces: !0 });
|
|
6565
|
-
}
|
|
6566
|
-
async loadFinalExtensionSet(extensionPaths, preTrustExtensions) {
|
|
6567
|
-
if (!preTrustExtensions) {
|
|
6568
|
-
let extensionsResult2 = await loadExtensionsCached(extensionPaths, this.cwd, this.eventBus), inlineExtensions2 = await this.loadExtensionFactories(extensionsResult2.runtime);
|
|
6569
|
-
return extensionsResult2.extensions.push(...inlineExtensions2.extensions), extensionsResult2.errors.push(...inlineExtensions2.errors), this.addExtensionConflictDiagnostics(extensionsResult2), extensionsResult2;
|
|
6570
|
-
}
|
|
6571
|
-
let preloadedByPath = new Map(preTrustExtensions.extensions.filter((extension) => !extension.path.startsWith("<inline:")).map((extension) => [extension.resolvedPath, extension])), failedPreloadPaths = new Set(preTrustExtensions.errors.map((error) => this.resolveExtensionLoadPath(error.path))), remainingPaths = extensionPaths.filter((path2) => {
|
|
6572
|
-
let resolvedPath = this.resolveExtensionLoadPath(path2);
|
|
6573
|
-
return !preloadedByPath.has(resolvedPath) && !failedPreloadPaths.has(resolvedPath);
|
|
6574
|
-
}), remainingExtensions = await loadExtensionsCached(remainingPaths, this.cwd, this.eventBus, preTrustExtensions.runtime), loadedByPath = new Map(preloadedByPath);
|
|
6575
|
-
for (let extension of remainingExtensions.extensions)
|
|
6576
|
-
loadedByPath.set(extension.resolvedPath, extension);
|
|
6577
|
-
let inlineExtensions = preTrustExtensions.extensions.filter((extension) => extension.path.startsWith("<inline:")), orderedExtensions = extensionPaths.map((path2) => loadedByPath.get(this.resolveExtensionLoadPath(path2))).filter((extension) => extension !== void 0);
|
|
6578
|
-
orderedExtensions.push(...inlineExtensions);
|
|
6579
|
-
let extensionsResult = {
|
|
6580
|
-
extensions: orderedExtensions,
|
|
6581
|
-
errors: [...preTrustExtensions.errors, ...remainingExtensions.errors],
|
|
6582
|
-
runtime: preTrustExtensions.runtime
|
|
6583
|
-
};
|
|
6584
|
-
return this.addExtensionConflictDiagnostics(extensionsResult), extensionsResult;
|
|
6585
|
-
}
|
|
6586
|
-
addExtensionConflictDiagnostics(extensionsResult) {
|
|
6587
|
-
let conflicts = this.detectExtensionConflicts(extensionsResult.extensions);
|
|
6588
|
-
for (let conflict of conflicts)
|
|
6589
|
-
extensionsResult.errors.push({ path: conflict.path, error: conflict.message });
|
|
6590
|
-
}
|
|
6591
|
-
mapSkillPath(resource, metadataByPath) {
|
|
6592
|
-
if (resource.metadata.source !== "auto" && resource.metadata.origin !== "package")
|
|
6593
|
-
return resource.path;
|
|
6594
|
-
try {
|
|
6595
|
-
if (!statSync5(resource.path).isDirectory())
|
|
6596
|
-
return resource.path;
|
|
6597
|
-
} catch {
|
|
6598
|
-
return resource.path;
|
|
6599
|
-
}
|
|
6600
|
-
let skillFile = join5(resource.path, "SKILL.md");
|
|
6601
|
-
return existsSync5(skillFile) ? (metadataByPath.has(skillFile) || metadataByPath.set(skillFile, resource.metadata), skillFile) : resource.path;
|
|
6602
|
-
}
|
|
6603
|
-
normalizeExtensionPaths(entries) {
|
|
6604
|
-
return entries.map((entry) => {
|
|
6605
|
-
let metadata = entry.metadata.baseDir ? { ...entry.metadata, baseDir: this.resolveResourcePath(entry.metadata.baseDir) } : entry.metadata;
|
|
6606
|
-
return {
|
|
6607
|
-
path: this.resolveResourcePath(entry.path),
|
|
6608
|
-
metadata
|
|
6609
|
-
};
|
|
6610
|
-
});
|
|
6611
|
-
}
|
|
6612
|
-
updateSkillsFromPaths(skillPaths, metadataByPath) {
|
|
6613
|
-
let skillsResult;
|
|
6614
|
-
this.noSkills && skillPaths.length === 0 ? skillsResult = { skills: [], diagnostics: [] } : skillsResult = loadSkills({
|
|
6615
|
-
cwd: this.cwd,
|
|
6616
|
-
agentDir: this.agentDir,
|
|
6617
|
-
skillPaths,
|
|
6618
|
-
includeDefaults: !1
|
|
6619
|
-
});
|
|
6620
|
-
let resolvedSkills = this.skillsOverride ? this.skillsOverride(skillsResult) : skillsResult;
|
|
6621
|
-
this.skills = resolvedSkills.skills.map((skill) => ({
|
|
6622
|
-
...skill,
|
|
6623
|
-
sourceInfo: this.findSourceInfoForPath(skill.filePath, this.extensionSkillSourceInfos, metadataByPath) ?? skill.sourceInfo ?? this.getDefaultSourceInfoForPath(skill.filePath)
|
|
6624
|
-
})), this.skillDiagnostics = resolvedSkills.diagnostics;
|
|
6625
|
-
}
|
|
6626
|
-
updatePromptsFromPaths(promptPaths, metadataByPath) {
|
|
6627
|
-
let promptsResult;
|
|
6628
|
-
if (this.noPromptTemplates && promptPaths.length === 0)
|
|
6629
|
-
promptsResult = { prompts: [], diagnostics: [] };
|
|
6630
|
-
else {
|
|
6631
|
-
let allPrompts = loadPromptTemplates({
|
|
6632
|
-
cwd: this.cwd,
|
|
6633
|
-
agentDir: this.agentDir,
|
|
6634
|
-
promptPaths,
|
|
6635
|
-
includeDefaults: !1
|
|
6636
|
-
});
|
|
6637
|
-
promptsResult = this.dedupePrompts(allPrompts);
|
|
6638
|
-
}
|
|
6639
|
-
let resolvedPrompts = this.promptsOverride ? this.promptsOverride(promptsResult) : promptsResult;
|
|
6640
|
-
this.prompts = resolvedPrompts.prompts.map((prompt) => ({
|
|
6641
|
-
...prompt,
|
|
6642
|
-
sourceInfo: this.findSourceInfoForPath(prompt.filePath, this.extensionPromptSourceInfos, metadataByPath) ?? prompt.sourceInfo ?? this.getDefaultSourceInfoForPath(prompt.filePath)
|
|
6643
|
-
})), this.promptDiagnostics = resolvedPrompts.diagnostics;
|
|
6644
|
-
}
|
|
6645
|
-
updateThemesFromPaths(themePaths, metadataByPath) {
|
|
6646
|
-
let themesResult;
|
|
6647
|
-
if (this.noThemes && themePaths.length === 0)
|
|
6648
|
-
themesResult = { themes: [], diagnostics: [] };
|
|
6649
|
-
else {
|
|
6650
|
-
let loaded = this.loadThemes(themePaths, !1), deduped = this.dedupeThemes(loaded.themes);
|
|
6651
|
-
themesResult = { themes: deduped.themes, diagnostics: [...loaded.diagnostics, ...deduped.diagnostics] };
|
|
6652
|
-
}
|
|
6653
|
-
let resolvedThemes = this.themesOverride ? this.themesOverride(themesResult) : themesResult;
|
|
6654
|
-
this.themes = resolvedThemes.themes.map((theme) => {
|
|
6655
|
-
let sourcePath = theme.sourcePath;
|
|
6656
|
-
return theme.sourceInfo = sourcePath ? this.findSourceInfoForPath(sourcePath, this.extensionThemeSourceInfos, metadataByPath) ?? theme.sourceInfo ?? this.getDefaultSourceInfoForPath(sourcePath) : theme.sourceInfo, theme;
|
|
6657
|
-
}), this.themeDiagnostics = resolvedThemes.diagnostics;
|
|
6658
|
-
}
|
|
6659
|
-
applyExtensionSourceInfo(extensions, metadataByPath) {
|
|
6660
|
-
for (let extension of extensions) {
|
|
6661
|
-
extension.sourceInfo = this.findSourceInfoForPath(extension.path, void 0, metadataByPath) ?? this.getDefaultSourceInfoForPath(extension.path);
|
|
6662
|
-
for (let command of extension.commands.values())
|
|
6663
|
-
command.sourceInfo = extension.sourceInfo;
|
|
6664
|
-
for (let tool of extension.tools.values())
|
|
6665
|
-
tool.sourceInfo = extension.sourceInfo;
|
|
6666
|
-
}
|
|
6667
|
-
}
|
|
6668
|
-
findSourceInfoForPath(resourcePath, extraSourceInfos, metadataByPath) {
|
|
6669
|
-
if (!resourcePath)
|
|
6670
|
-
return;
|
|
6671
|
-
if (resourcePath.startsWith("<"))
|
|
6672
|
-
return this.getDefaultSourceInfoForPath(resourcePath);
|
|
6673
|
-
let normalizedResourcePath = resolve5(resourcePath);
|
|
6674
|
-
if (extraSourceInfos)
|
|
6675
|
-
for (let [sourcePath, sourceInfo] of extraSourceInfos.entries()) {
|
|
6676
|
-
let normalizedSourcePath = resolve5(sourcePath);
|
|
6677
|
-
if (normalizedResourcePath === normalizedSourcePath || normalizedResourcePath.startsWith(`${normalizedSourcePath}${sep4}`))
|
|
6678
|
-
return { ...sourceInfo, path: resourcePath };
|
|
6679
|
-
}
|
|
6680
|
-
if (metadataByPath) {
|
|
6681
|
-
let exact = metadataByPath.get(normalizedResourcePath) ?? metadataByPath.get(resourcePath);
|
|
6682
|
-
if (exact)
|
|
6683
|
-
return createSourceInfo(resourcePath, exact);
|
|
6684
|
-
for (let [sourcePath, metadata] of metadataByPath.entries()) {
|
|
6685
|
-
let normalizedSourcePath = resolve5(sourcePath);
|
|
6686
|
-
if (normalizedResourcePath === normalizedSourcePath || normalizedResourcePath.startsWith(`${normalizedSourcePath}${sep4}`))
|
|
6687
|
-
return createSourceInfo(resourcePath, metadata);
|
|
6688
|
-
}
|
|
6689
|
-
}
|
|
6690
|
-
}
|
|
6691
|
-
getDefaultSourceInfoForPath(filePath) {
|
|
6692
|
-
if (filePath.startsWith("<") && filePath.endsWith(">"))
|
|
6693
|
-
return {
|
|
6694
|
-
path: filePath,
|
|
6695
|
-
source: filePath.slice(1, -1).split(":")[0] || "temporary",
|
|
6696
|
-
scope: "temporary",
|
|
6697
|
-
origin: "top-level"
|
|
6698
|
-
};
|
|
6699
|
-
let normalizedPath = resolve5(filePath), agentRoots = [
|
|
6700
|
-
join5(this.agentDir, "skills"),
|
|
6701
|
-
join5(this.agentDir, "prompts"),
|
|
6702
|
-
join5(this.agentDir, "themes"),
|
|
6703
|
-
join5(this.agentDir, "extensions")
|
|
6704
|
-
], projectRoots = [
|
|
6705
|
-
join5(this.cwd, CONFIG_DIR_NAME, "skills"),
|
|
6706
|
-
join5(this.cwd, CONFIG_DIR_NAME, "prompts"),
|
|
6707
|
-
join5(this.cwd, CONFIG_DIR_NAME, "themes"),
|
|
6708
|
-
join5(this.cwd, CONFIG_DIR_NAME, "extensions")
|
|
6709
|
-
];
|
|
6710
|
-
for (let root of agentRoots)
|
|
6711
|
-
if (this.isUnderPath(normalizedPath, root))
|
|
6712
|
-
return { path: filePath, source: "local", scope: "user", origin: "top-level", baseDir: root };
|
|
6713
|
-
for (let root of projectRoots)
|
|
6714
|
-
if (this.isUnderPath(normalizedPath, root))
|
|
6715
|
-
return { path: filePath, source: "local", scope: "project", origin: "top-level", baseDir: root };
|
|
6716
|
-
return {
|
|
6717
|
-
path: filePath,
|
|
6718
|
-
source: "local",
|
|
6719
|
-
scope: "temporary",
|
|
6720
|
-
origin: "top-level",
|
|
6721
|
-
baseDir: statSync5(normalizedPath).isDirectory() ? normalizedPath : resolve5(normalizedPath, "..")
|
|
6722
|
-
};
|
|
6723
|
-
}
|
|
6724
|
-
mergePaths(primary, additional) {
|
|
6725
|
-
let merged = [], seen = /* @__PURE__ */ new Set();
|
|
6726
|
-
for (let p of [...primary, ...additional]) {
|
|
6727
|
-
let resolved = this.resolveResourcePath(p), canonicalPath = canonicalizePath(resolved);
|
|
6728
|
-
seen.has(canonicalPath) || (seen.add(canonicalPath), merged.push(resolved));
|
|
6729
|
-
}
|
|
6730
|
-
return merged;
|
|
6731
|
-
}
|
|
6732
|
-
resolveResourcePath(p) {
|
|
6733
|
-
return resolvePath(p, this.cwd, { trim: !0 });
|
|
6734
|
-
}
|
|
6735
|
-
loadThemes(paths, includeDefaults = !0) {
|
|
6736
|
-
let themes = [], diagnostics = [];
|
|
6737
|
-
if (includeDefaults) {
|
|
6738
|
-
let defaultDirs = [join5(this.agentDir, "themes"), join5(this.cwd, CONFIG_DIR_NAME, "themes")];
|
|
6739
|
-
for (let dir of defaultDirs)
|
|
6740
|
-
this.loadThemesFromDir(dir, themes, diagnostics);
|
|
6741
|
-
}
|
|
6742
|
-
for (let p of paths) {
|
|
6743
|
-
let resolved = this.resolveResourcePath(p);
|
|
6744
|
-
if (!existsSync5(resolved)) {
|
|
6745
|
-
diagnostics.push({ type: "warning", message: "theme path does not exist", path: resolved });
|
|
6746
|
-
continue;
|
|
6747
|
-
}
|
|
6748
|
-
try {
|
|
6749
|
-
let stats = statSync5(resolved);
|
|
6750
|
-
stats.isDirectory() ? this.loadThemesFromDir(resolved, themes, diagnostics) : stats.isFile() && resolved.endsWith(".json") ? this.loadThemeFromFile(resolved, themes, diagnostics) : diagnostics.push({ type: "warning", message: "theme path is not a json file", path: resolved });
|
|
6751
|
-
} catch (error) {
|
|
6752
|
-
let message = error instanceof Error ? error.message : "failed to read theme path";
|
|
6753
|
-
diagnostics.push({ type: "warning", message, path: resolved });
|
|
6754
|
-
}
|
|
6755
|
-
}
|
|
6756
|
-
return { themes, diagnostics };
|
|
6757
|
-
}
|
|
6758
|
-
loadThemesFromDir(dir, themes, diagnostics) {
|
|
6759
|
-
if (existsSync5(dir))
|
|
6760
|
-
try {
|
|
6761
|
-
let entries = readdirSync5(dir, { withFileTypes: !0 });
|
|
6762
|
-
for (let entry of entries) {
|
|
6763
|
-
let isFile = entry.isFile();
|
|
6764
|
-
if (entry.isSymbolicLink())
|
|
6765
|
-
try {
|
|
6766
|
-
isFile = statSync5(join5(dir, entry.name)).isFile();
|
|
6767
|
-
} catch {
|
|
6768
|
-
continue;
|
|
6769
|
-
}
|
|
6770
|
-
isFile && entry.name.endsWith(".json") && this.loadThemeFromFile(join5(dir, entry.name), themes, diagnostics);
|
|
6771
|
-
}
|
|
6772
|
-
} catch (error) {
|
|
6773
|
-
let message = error instanceof Error ? error.message : "failed to read theme directory";
|
|
6774
|
-
diagnostics.push({ type: "warning", message, path: dir });
|
|
6775
|
-
}
|
|
6776
|
-
}
|
|
6777
|
-
loadThemeFromFile(filePath, themes, diagnostics) {
|
|
6778
|
-
try {
|
|
6779
|
-
themes.push(loadThemeFromPath(filePath));
|
|
6780
|
-
} catch (error) {
|
|
6781
|
-
let message = error instanceof Error ? error.message : "failed to load theme";
|
|
6782
|
-
diagnostics.push({ type: "warning", message, path: filePath });
|
|
6783
|
-
}
|
|
6784
|
-
}
|
|
6785
|
-
async loadExtensionFactories(runtime, factories = this.extensionFactories) {
|
|
6786
|
-
let extensions = [], errors = [];
|
|
6787
|
-
for (let [index, input] of factories.entries()) {
|
|
6788
|
-
let factory = typeof input != "function" ? input.factory : input, extensionPath = inlineExtensionPath(input, index);
|
|
6789
|
-
try {
|
|
6790
|
-
let extension = await loadExtensionFromFactory(factory, this.cwd, this.eventBus, runtime, extensionPath);
|
|
6791
|
-
extensions.push(extension);
|
|
6792
|
-
} catch (error) {
|
|
6793
|
-
let message = error instanceof Error ? error.message : "failed to load extension";
|
|
6794
|
-
errors.push({ path: extensionPath, error: message });
|
|
6795
|
-
}
|
|
6796
|
-
}
|
|
6797
|
-
return { extensions, errors };
|
|
6798
|
-
}
|
|
6799
|
-
dedupePrompts(prompts) {
|
|
6800
|
-
let seen = /* @__PURE__ */ new Map(), diagnostics = [];
|
|
6801
|
-
for (let prompt of prompts) {
|
|
6802
|
-
let existing = seen.get(prompt.name);
|
|
6803
|
-
existing ? diagnostics.push({
|
|
6804
|
-
type: "collision",
|
|
6805
|
-
message: `name "/${prompt.name}" collision`,
|
|
6806
|
-
path: prompt.filePath,
|
|
6807
|
-
collision: {
|
|
6808
|
-
resourceType: "prompt",
|
|
6809
|
-
name: prompt.name,
|
|
6810
|
-
winnerPath: existing.filePath,
|
|
6811
|
-
loserPath: prompt.filePath
|
|
6812
|
-
}
|
|
6813
|
-
}) : seen.set(prompt.name, prompt);
|
|
6814
|
-
}
|
|
6815
|
-
return { prompts: Array.from(seen.values()), diagnostics };
|
|
6816
|
-
}
|
|
6817
|
-
dedupeThemes(themes) {
|
|
6818
|
-
let seen = /* @__PURE__ */ new Map(), diagnostics = [];
|
|
6819
|
-
for (let t of themes) {
|
|
6820
|
-
let name = t.name ?? "unnamed", existing = seen.get(name);
|
|
6821
|
-
existing ? diagnostics.push({
|
|
6822
|
-
type: "collision",
|
|
6823
|
-
message: `name "${name}" collision`,
|
|
6824
|
-
path: t.sourcePath,
|
|
6825
|
-
collision: {
|
|
6826
|
-
resourceType: "theme",
|
|
6827
|
-
name,
|
|
6828
|
-
winnerPath: existing.sourcePath ?? "<builtin>",
|
|
6829
|
-
loserPath: t.sourcePath ?? "<builtin>"
|
|
6830
|
-
}
|
|
6831
|
-
}) : seen.set(name, t);
|
|
6832
|
-
}
|
|
6833
|
-
return { themes: Array.from(seen.values()), diagnostics };
|
|
6834
|
-
}
|
|
6835
|
-
discoverSystemPromptFile() {
|
|
6836
|
-
let projectPath = join5(this.cwd, CONFIG_DIR_NAME, "SYSTEM.md");
|
|
6837
|
-
if (this.settingsManager.isProjectTrusted() && existsSync5(projectPath))
|
|
6838
|
-
return projectPath;
|
|
6839
|
-
let globalPath = join5(this.agentDir, "SYSTEM.md");
|
|
6840
|
-
if (existsSync5(globalPath))
|
|
6841
|
-
return globalPath;
|
|
6842
|
-
}
|
|
6843
|
-
discoverAppendSystemPromptFile() {
|
|
6844
|
-
let projectPath = join5(this.cwd, CONFIG_DIR_NAME, "APPEND_SYSTEM.md");
|
|
6845
|
-
if (this.settingsManager.isProjectTrusted() && existsSync5(projectPath))
|
|
6846
|
-
return projectPath;
|
|
6847
|
-
let globalPath = join5(this.agentDir, "APPEND_SYSTEM.md");
|
|
6848
|
-
if (existsSync5(globalPath))
|
|
6849
|
-
return globalPath;
|
|
6850
|
-
}
|
|
6851
|
-
isUnderPath(target, root) {
|
|
6852
|
-
let normalizedRoot = resolve5(root);
|
|
6853
|
-
if (target === normalizedRoot)
|
|
6854
|
-
return !0;
|
|
6855
|
-
let prefix = normalizedRoot.endsWith(sep4) ? normalizedRoot : `${normalizedRoot}${sep4}`;
|
|
6856
|
-
return target.startsWith(prefix);
|
|
6857
|
-
}
|
|
6858
|
-
detectExtensionConflicts(extensions) {
|
|
6859
|
-
let conflicts = [], toolOwners = /* @__PURE__ */ new Map(), flagOwners = /* @__PURE__ */ new Map();
|
|
6860
|
-
for (let ext of extensions) {
|
|
6861
|
-
for (let toolName of ext.tools.keys()) {
|
|
6862
|
-
let existingOwner = toolOwners.get(toolName);
|
|
6863
|
-
existingOwner && existingOwner !== ext.path ? conflicts.push({
|
|
6864
|
-
path: ext.path,
|
|
6865
|
-
message: `Tool "${toolName}" conflicts with ${existingOwner}`
|
|
6866
|
-
}) : toolOwners.set(toolName, ext.path);
|
|
6867
|
-
}
|
|
6868
|
-
for (let flagName of ext.flags.keys()) {
|
|
6869
|
-
let existingOwner = flagOwners.get(flagName);
|
|
6870
|
-
existingOwner && existingOwner !== ext.path ? conflicts.push({
|
|
6871
|
-
path: ext.path,
|
|
6872
|
-
message: `Flag "--${flagName}" conflicts with ${existingOwner}`
|
|
6873
|
-
}) : flagOwners.set(flagName, ext.path);
|
|
6874
|
-
}
|
|
6875
|
-
}
|
|
6876
|
-
return conflicts;
|
|
6877
|
-
}
|
|
6878
|
-
};
|
|
6879
|
-
|
|
6880
5546
|
export {
|
|
6881
|
-
|
|
6882
|
-
createSyntheticSourceInfo,
|
|
6883
|
-
createExtensionRuntime,
|
|
6884
|
-
discoverAndLoadExtensions,
|
|
5547
|
+
require_ignore,
|
|
6885
5548
|
parseGitUrl,
|
|
6886
|
-
DefaultPackageManager
|
|
6887
|
-
expandPromptTemplate,
|
|
6888
|
-
loadSkillsFromDir,
|
|
6889
|
-
formatSkillsForPrompt,
|
|
6890
|
-
loadSkills,
|
|
6891
|
-
loadProjectContextFiles,
|
|
6892
|
-
DefaultResourceLoader
|
|
5549
|
+
DefaultPackageManager
|
|
6893
5550
|
};
|