harnesstap 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -15
- package/dist/apply-2GRNKR5H.js +67 -0
- package/dist/apply-2GRNKR5H.js.map +1 -0
- package/dist/approve-KQNCNH2R.js +181 -0
- package/dist/approve-KQNCNH2R.js.map +1 -0
- package/dist/audit-SLYOZCMI.js +434 -0
- package/dist/audit-SLYOZCMI.js.map +1 -0
- package/dist/auth-3IEVICFT.js +220 -0
- package/dist/auth-3IEVICFT.js.map +1 -0
- package/dist/bin.js +166 -0
- package/dist/bin.js.map +1 -0
- package/dist/chunk-2EIJYDNI.js +10945 -0
- package/dist/chunk-2EIJYDNI.js.map +1 -0
- package/dist/chunk-2H7UOFLK.js +11 -0
- package/dist/chunk-2H7UOFLK.js.map +1 -0
- package/dist/chunk-37E5M4JX.js +34 -0
- package/dist/chunk-37E5M4JX.js.map +1 -0
- package/dist/chunk-3FIWOI3H.js +98 -0
- package/dist/chunk-3FIWOI3H.js.map +1 -0
- package/dist/chunk-3IWTJCPA.js +6448 -0
- package/dist/chunk-3IWTJCPA.js.map +1 -0
- package/dist/chunk-3IZ7SEGT.js +346 -0
- package/dist/chunk-3IZ7SEGT.js.map +1 -0
- package/dist/chunk-3RBYT7QN.js +540 -0
- package/dist/chunk-3RBYT7QN.js.map +1 -0
- package/dist/chunk-4KNQZDZC.js +115 -0
- package/dist/chunk-4KNQZDZC.js.map +1 -0
- package/dist/chunk-5F3LNDZG.js +9 -0
- package/dist/chunk-5F3LNDZG.js.map +1 -0
- package/dist/chunk-63U7QWNY.js +364 -0
- package/dist/chunk-63U7QWNY.js.map +1 -0
- package/dist/chunk-6BY4BV5G.js +998 -0
- package/dist/chunk-6BY4BV5G.js.map +1 -0
- package/dist/chunk-7L2K4N25.js +610 -0
- package/dist/chunk-7L2K4N25.js.map +1 -0
- package/dist/chunk-7LWH5SWH.js +18 -0
- package/dist/chunk-7LWH5SWH.js.map +1 -0
- package/dist/chunk-BIBUCC2E.js +696 -0
- package/dist/chunk-BIBUCC2E.js.map +1 -0
- package/dist/chunk-BSOBXLYI.js +172 -0
- package/dist/chunk-BSOBXLYI.js.map +1 -0
- package/dist/chunk-C4QBVVEH.js +32 -0
- package/dist/chunk-C4QBVVEH.js.map +1 -0
- package/dist/chunk-CHQGE2HF.js +283 -0
- package/dist/chunk-CHQGE2HF.js.map +1 -0
- package/dist/chunk-DV74UZJI.js +87 -0
- package/dist/chunk-DV74UZJI.js.map +1 -0
- package/dist/chunk-DWVAR4BP.js +656 -0
- package/dist/chunk-DWVAR4BP.js.map +1 -0
- package/dist/chunk-DXKAKKLP.js +302 -0
- package/dist/chunk-DXKAKKLP.js.map +1 -0
- package/dist/chunk-EIWXS4RM.js +235 -0
- package/dist/chunk-EIWXS4RM.js.map +1 -0
- package/dist/chunk-EWBCFAF3.js +681 -0
- package/dist/chunk-EWBCFAF3.js.map +1 -0
- package/dist/chunk-F2L4VNQK.js +1759 -0
- package/dist/chunk-F2L4VNQK.js.map +1 -0
- package/dist/chunk-G26HZZDJ.js +1359 -0
- package/dist/chunk-G26HZZDJ.js.map +1 -0
- package/dist/chunk-GQKKX7OE.js +818 -0
- package/dist/chunk-GQKKX7OE.js.map +1 -0
- package/dist/chunk-GRJY22U6.js +691 -0
- package/dist/chunk-GRJY22U6.js.map +1 -0
- package/dist/chunk-H6DVP2SI.js +682 -0
- package/dist/chunk-H6DVP2SI.js.map +1 -0
- package/dist/chunk-HVVPTCKR.js +1173 -0
- package/dist/chunk-HVVPTCKR.js.map +1 -0
- package/dist/chunk-I6XFZLTJ.js +9 -0
- package/dist/chunk-I6XFZLTJ.js.map +1 -0
- package/dist/chunk-IBOABSIA.js +17 -0
- package/dist/chunk-IBOABSIA.js.map +1 -0
- package/dist/chunk-IK524ZDW.js +691 -0
- package/dist/chunk-IK524ZDW.js.map +1 -0
- package/dist/chunk-IRU7NBOT.js +141 -0
- package/dist/chunk-IRU7NBOT.js.map +1 -0
- package/dist/chunk-J4CKQXQ6.js +806 -0
- package/dist/chunk-J4CKQXQ6.js.map +1 -0
- package/dist/chunk-JKGSJGCC.js +311 -0
- package/dist/chunk-JKGSJGCC.js.map +1 -0
- package/dist/chunk-JQOKQKQT.js +158 -0
- package/dist/chunk-JQOKQKQT.js.map +1 -0
- package/dist/chunk-JRFUTIEH.js +426 -0
- package/dist/chunk-JRFUTIEH.js.map +1 -0
- package/dist/chunk-K2BPYEH5.js +491 -0
- package/dist/chunk-K2BPYEH5.js.map +1 -0
- package/dist/chunk-KCQC7YBK.js +7795 -0
- package/dist/chunk-KCQC7YBK.js.map +1 -0
- package/dist/chunk-KDAV2GUT.js +1357 -0
- package/dist/chunk-KDAV2GUT.js.map +1 -0
- package/dist/chunk-KDDXZBMC.js +583 -0
- package/dist/chunk-KDDXZBMC.js.map +1 -0
- package/dist/chunk-KMWHZSEG.js +41 -0
- package/dist/chunk-KMWHZSEG.js.map +1 -0
- package/dist/chunk-KRI4R7EM.js +25 -0
- package/dist/chunk-KRI4R7EM.js.map +1 -0
- package/dist/chunk-LNJ3WZZX.js +186 -0
- package/dist/chunk-LNJ3WZZX.js.map +1 -0
- package/dist/chunk-MWXA4PFE.js +103 -0
- package/dist/chunk-MWXA4PFE.js.map +1 -0
- package/dist/chunk-MY62SSKC.js +183 -0
- package/dist/chunk-MY62SSKC.js.map +1 -0
- package/dist/chunk-NAGAJ5UM.js +145 -0
- package/dist/chunk-NAGAJ5UM.js.map +1 -0
- package/dist/chunk-NJ7WRKIQ.js +532 -0
- package/dist/chunk-NJ7WRKIQ.js.map +1 -0
- package/dist/chunk-OS6NUIBJ.js +38 -0
- package/dist/chunk-OS6NUIBJ.js.map +1 -0
- package/dist/chunk-PXU2OS26.js +238 -0
- package/dist/chunk-PXU2OS26.js.map +1 -0
- package/dist/chunk-QO4LBDVI.js +496 -0
- package/dist/chunk-QO4LBDVI.js.map +1 -0
- package/dist/chunk-QRZPQNLX.js +65 -0
- package/dist/chunk-QRZPQNLX.js.map +1 -0
- package/dist/chunk-SNVAMWB7.js +40 -0
- package/dist/chunk-SNVAMWB7.js.map +1 -0
- package/dist/chunk-SPRVUATR.js +430 -0
- package/dist/chunk-SPRVUATR.js.map +1 -0
- package/dist/chunk-SY7G5QEI.js +35 -0
- package/dist/chunk-SY7G5QEI.js.map +1 -0
- package/dist/chunk-SZNBUIDR.js +6438 -0
- package/dist/chunk-SZNBUIDR.js.map +1 -0
- package/dist/chunk-TQ2NA4Z4.js +24 -0
- package/dist/chunk-TQ2NA4Z4.js.map +1 -0
- package/dist/chunk-TYULB6ZY.js +2959 -0
- package/dist/chunk-TYULB6ZY.js.map +1 -0
- package/dist/chunk-UJYFTXHV.js +296 -0
- package/dist/chunk-UJYFTXHV.js.map +1 -0
- package/dist/chunk-VC6OKCJF.js +184 -0
- package/dist/chunk-VC6OKCJF.js.map +1 -0
- package/dist/chunk-VL2NWCZV.js +118 -0
- package/dist/chunk-VL2NWCZV.js.map +1 -0
- package/dist/chunk-VL7BGD47.js +514 -0
- package/dist/chunk-VL7BGD47.js.map +1 -0
- package/dist/chunk-VQVUJYYY.js +244 -0
- package/dist/chunk-VQVUJYYY.js.map +1 -0
- package/dist/chunk-VZQG2JDV.js +9 -0
- package/dist/chunk-VZQG2JDV.js.map +1 -0
- package/dist/chunk-XFZQVYIN.js +115 -0
- package/dist/chunk-XFZQVYIN.js.map +1 -0
- package/dist/chunk-XGTTOO4R.js +84 -0
- package/dist/chunk-XGTTOO4R.js.map +1 -0
- package/dist/chunk-XQFT4PEP.js +60 -0
- package/dist/chunk-XQFT4PEP.js.map +1 -0
- package/dist/chunk-YDD3ES2K.js +571 -0
- package/dist/chunk-YDD3ES2K.js.map +1 -0
- package/dist/chunk-ZY2MZ2KQ.js +1140 -0
- package/dist/chunk-ZY2MZ2KQ.js.map +1 -0
- package/dist/compile-57EEIUMB.js +161 -0
- package/dist/compile-57EEIUMB.js.map +1 -0
- package/dist/config-4EJ3D7QJ.js +438 -0
- package/dist/config-4EJ3D7QJ.js.map +1 -0
- package/dist/doctor-EEV6P5CH.js +111 -0
- package/dist/doctor-EEV6P5CH.js.map +1 -0
- package/dist/environment-WFEG4DAT.js +2745 -0
- package/dist/environment-WFEG4DAT.js.map +1 -0
- package/dist/github-BSMQD72A.js +114 -0
- package/dist/github-BSMQD72A.js.map +1 -0
- package/dist/harness-VX3PNVQW.js +746 -0
- package/dist/harness-VX3PNVQW.js.map +1 -0
- package/dist/help-AW2HKX63.js +2079 -0
- package/dist/help-AW2HKX63.js.map +1 -0
- package/dist/help-BVFOZD7E.js +1892 -0
- package/dist/help-BVFOZD7E.js.map +1 -0
- package/dist/index.d.ts +164 -1
- package/dist/index.js +50 -59246
- package/dist/index.js.map +1 -1
- package/dist/init-SPN2GEZ4.js +873 -0
- package/dist/init-SPN2GEZ4.js.map +1 -0
- package/dist/lock-K2LLUU7H.js +455 -0
- package/dist/lock-K2LLUU7H.js.map +1 -0
- package/dist/marketplace-VEKSWGX3.js +495 -0
- package/dist/marketplace-VEKSWGX3.js.map +1 -0
- package/dist/mcp-T6DKIKSF.js +202 -0
- package/dist/mcp-T6DKIKSF.js.map +1 -0
- package/dist/migrate-OO37WSB2.js +1043 -0
- package/dist/migrate-OO37WSB2.js.map +1 -0
- package/dist/open-3V3QK5RK.js +32 -0
- package/dist/open-3V3QK5RK.js.map +1 -0
- package/dist/pack-V32UPC7W.js +99 -0
- package/dist/pack-V32UPC7W.js.map +1 -0
- package/dist/plugin-KOBNQ7GT.js +64 -0
- package/dist/plugin-KOBNQ7GT.js.map +1 -0
- package/dist/plugin-from-project-X3VO3MB6.js +16 -0
- package/dist/plugin-from-project-X3VO3MB6.js.map +1 -0
- package/dist/policy-F5MKZNOC.js +105 -0
- package/dist/policy-F5MKZNOC.js.map +1 -0
- package/dist/profile-H4PMH4XT.js +1886 -0
- package/dist/profile-H4PMH4XT.js.map +1 -0
- package/dist/project-QVNEJJGH.js +1392 -0
- package/dist/project-QVNEJJGH.js.map +1 -0
- package/dist/resource-GL4RLSGI.js +555 -0
- package/dist/resource-GL4RLSGI.js.map +1 -0
- package/dist/version-PBHZK44K.js +17 -0
- package/dist/version-PBHZK44K.js.map +1 -0
- package/package.json +21 -14
- package/schemas/ap-package.v1.json +36 -0
- package/schemas/fixtures/catalog-missing-schema.ap.json +13 -0
- package/schemas/fixtures/confidence.ap.json +13 -0
- package/schemas/fixtures/context7.ap.json +13 -0
- package/schemas/fixtures/minimal-with-schema.ap.json +13 -0
- package/schemas/fixtures/superpowers.ap.json +13 -0
- package/schemas/fixtures/third-party-skills.ap.json +13 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
terminalColumns,
|
|
3
|
+
terminalRows
|
|
4
|
+
} from "./chunk-YDD3ES2K.js";
|
|
5
|
+
|
|
6
|
+
// src/services/wizards/prompts/hooks/use-terminal-size.ts
|
|
7
|
+
import { useEffect, useState } from "@inquirer/core";
|
|
8
|
+
var resizeSubscribers = /* @__PURE__ */ new Set();
|
|
9
|
+
function notifyResizeSubscribers() {
|
|
10
|
+
for (const subscriber of resizeSubscribers) {
|
|
11
|
+
subscriber();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function subscribeResize(onResize) {
|
|
15
|
+
resizeSubscribers.add(onResize);
|
|
16
|
+
if (resizeSubscribers.size === 1 && process.stdout.isTTY) {
|
|
17
|
+
process.stdout.on("resize", notifyResizeSubscribers);
|
|
18
|
+
}
|
|
19
|
+
return () => {
|
|
20
|
+
resizeSubscribers.delete(onResize);
|
|
21
|
+
if (resizeSubscribers.size === 0 && process.stdout.isTTY) {
|
|
22
|
+
process.stdout.off("resize", notifyResizeSubscribers);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function readTerminalSize() {
|
|
27
|
+
return {
|
|
28
|
+
width: terminalColumns(),
|
|
29
|
+
height: terminalRows()
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function useTerminalSize() {
|
|
33
|
+
const [size, setSize] = useState(readTerminalSize);
|
|
34
|
+
useEffect(() => subscribeResize(() => setSize(readTerminalSize())), []);
|
|
35
|
+
return size;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
useTerminalSize
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=chunk-KMWHZSEG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/wizards/prompts/hooks/use-terminal-size.ts"],"sourcesContent":["import { useEffect, useState } from \"@inquirer/core\";\nimport { terminalColumns, terminalRows } from \"../../../../ui/theme.js\";\n\nexport type TerminalSize = {\n width: number;\n height: number;\n};\n\nconst resizeSubscribers = new Set<() => void>();\n\nfunction notifyResizeSubscribers(): void {\n for (const subscriber of resizeSubscribers) {\n subscriber();\n }\n}\n\nfunction subscribeResize(onResize: () => void): () => void {\n resizeSubscribers.add(onResize);\n if (resizeSubscribers.size === 1 && process.stdout.isTTY) {\n process.stdout.on(\"resize\", notifyResizeSubscribers);\n }\n return () => {\n resizeSubscribers.delete(onResize);\n if (resizeSubscribers.size === 0 && process.stdout.isTTY) {\n process.stdout.off(\"resize\", notifyResizeSubscribers);\n }\n };\n}\n\nexport function readTerminalSize(): TerminalSize {\n return {\n width: terminalColumns(),\n height: terminalRows(),\n };\n}\n\nexport function useTerminalSize(): TerminalSize {\n const [size, setSize] = useState<TerminalSize>(readTerminalSize);\n useEffect(() => subscribeResize(() => setSize(readTerminalSize())), []);\n return size;\n}\n"],"mappings":";;;;;;AAAA,SAAS,WAAW,gBAAgB;AAQpC,IAAM,oBAAoB,oBAAI,IAAgB;AAE9C,SAAS,0BAAgC;AACvC,aAAW,cAAc,mBAAmB;AAC1C,eAAW;AAAA,EACb;AACF;AAEA,SAAS,gBAAgB,UAAkC;AACzD,oBAAkB,IAAI,QAAQ;AAC9B,MAAI,kBAAkB,SAAS,KAAK,QAAQ,OAAO,OAAO;AACxD,YAAQ,OAAO,GAAG,UAAU,uBAAuB;AAAA,EACrD;AACA,SAAO,MAAM;AACX,sBAAkB,OAAO,QAAQ;AACjC,QAAI,kBAAkB,SAAS,KAAK,QAAQ,OAAO,OAAO;AACxD,cAAQ,OAAO,IAAI,UAAU,uBAAuB;AAAA,IACtD;AAAA,EACF;AACF;AAEO,SAAS,mBAAiC;AAC/C,SAAO;AAAA,IACL,OAAO,gBAAgB;AAAA,IACvB,QAAQ,aAAa;AAAA,EACvB;AACF;AAEO,SAAS,kBAAgC;AAC9C,QAAM,CAAC,MAAM,OAAO,IAAI,SAAuB,gBAAgB;AAC/D,YAAU,MAAM,gBAAgB,MAAM,QAAQ,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC;AACtE,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/ui/list-search.ts
|
|
2
|
+
function parseListSearchQuery(input) {
|
|
3
|
+
const trimmed = input.trim();
|
|
4
|
+
const colonIndex = trimmed.indexOf(":");
|
|
5
|
+
if (colonIndex <= 0) {
|
|
6
|
+
return { section: void 0, text: trimmed, raw: trimmed };
|
|
7
|
+
}
|
|
8
|
+
const section = trimmed.slice(0, colonIndex);
|
|
9
|
+
const text = trimmed.slice(colonIndex + 1);
|
|
10
|
+
return { section, text, raw: trimmed };
|
|
11
|
+
}
|
|
12
|
+
function matchesListSearchQuery(haystack, query) {
|
|
13
|
+
const normalizedHaystack = haystack.toLowerCase();
|
|
14
|
+
const normalizedText = query.text.trim().toLowerCase();
|
|
15
|
+
if (normalizedText.length === 0) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return normalizedHaystack.includes(normalizedText);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
parseListSearchQuery,
|
|
23
|
+
matchesListSearchQuery
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-KRI4R7EM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ui/list-search.ts"],"sourcesContent":["export type ListSearchQuery = {\n section: string | undefined;\n text: string;\n raw: string;\n};\n\nexport function parseListSearchQuery(input: string): ListSearchQuery {\n const trimmed = input.trim();\n const colonIndex = trimmed.indexOf(\":\");\n if (colonIndex <= 0) {\n return { section: undefined, text: trimmed, raw: trimmed };\n }\n const section = trimmed.slice(0, colonIndex);\n const text = trimmed.slice(colonIndex + 1);\n return { section, text, raw: trimmed };\n}\n\nexport function matchesListSearchQuery(\n haystack: string,\n query: ListSearchQuery,\n): boolean {\n const normalizedHaystack = haystack.toLowerCase();\n const normalizedText = query.text.trim().toLowerCase();\n if (normalizedText.length === 0) {\n return true;\n }\n return normalizedHaystack.includes(normalizedText);\n}\n"],"mappings":";AAMO,SAAS,qBAAqB,OAAgC;AACnE,QAAM,UAAU,MAAM,KAAK;AAC3B,QAAM,aAAa,QAAQ,QAAQ,GAAG;AACtC,MAAI,cAAc,GAAG;AACnB,WAAO,EAAE,SAAS,QAAW,MAAM,SAAS,KAAK,QAAQ;AAAA,EAC3D;AACA,QAAM,UAAU,QAAQ,MAAM,GAAG,UAAU;AAC3C,QAAM,OAAO,QAAQ,MAAM,aAAa,CAAC;AACzC,SAAO,EAAE,SAAS,MAAM,KAAK,QAAQ;AACvC;AAEO,SAAS,uBACd,UACA,OACS;AACT,QAAM,qBAAqB,SAAS,YAAY;AAChD,QAAM,iBAAiB,MAAM,KAAK,KAAK,EAAE,YAAY;AACrD,MAAI,eAAe,WAAW,GAAG;AAC/B,WAAO;AAAA,EACT;AACA,SAAO,mBAAmB,SAAS,cAAc;AACnD;","names":[]}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addResourceTrackedDirectory,
|
|
3
|
+
listResourceTrackedDirectories,
|
|
4
|
+
removeResourceTrackedDirectory,
|
|
5
|
+
rescanResourceTrackedDirectories
|
|
6
|
+
} from "./chunk-JKGSJGCC.js";
|
|
7
|
+
import {
|
|
8
|
+
initializeSchema
|
|
9
|
+
} from "./chunk-IK524ZDW.js";
|
|
10
|
+
import {
|
|
11
|
+
COMMAND_HELP_REGISTRY,
|
|
12
|
+
configureCommandGroup
|
|
13
|
+
} from "./chunk-G26HZZDJ.js";
|
|
14
|
+
import {
|
|
15
|
+
parseOutputFormat,
|
|
16
|
+
printJson
|
|
17
|
+
} from "./chunk-TQ2NA4Z4.js";
|
|
18
|
+
import {
|
|
19
|
+
fail
|
|
20
|
+
} from "./chunk-DXKAKKLP.js";
|
|
21
|
+
import {
|
|
22
|
+
ui
|
|
23
|
+
} from "./chunk-YDD3ES2K.js";
|
|
24
|
+
import {
|
|
25
|
+
getDb
|
|
26
|
+
} from "./chunk-DWVAR4BP.js";
|
|
27
|
+
|
|
28
|
+
// src/cli/commands/resource-directories.ts
|
|
29
|
+
import { resolve } from "path";
|
|
30
|
+
function ensureLibraryDb() {
|
|
31
|
+
initializeSchema(getDb());
|
|
32
|
+
}
|
|
33
|
+
function formatDirectoryCount(count) {
|
|
34
|
+
return `${count} tracked director${count === 1 ? "y" : "ies"}`;
|
|
35
|
+
}
|
|
36
|
+
function formatImportedCount(count) {
|
|
37
|
+
return `${count} resource${count === 1 ? "" : "s"} imported`;
|
|
38
|
+
}
|
|
39
|
+
function kindLabel(kind) {
|
|
40
|
+
switch (kind) {
|
|
41
|
+
case "home_default":
|
|
42
|
+
return "home";
|
|
43
|
+
case "custom":
|
|
44
|
+
return "custom";
|
|
45
|
+
default: {
|
|
46
|
+
const _exhaustive = kind;
|
|
47
|
+
throw _exhaustive;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function platformsCell(platformIds) {
|
|
52
|
+
return platformIds.length > 0 ? platformIds.join(", ") : ": ";
|
|
53
|
+
}
|
|
54
|
+
async function withCommandErrors(run) {
|
|
55
|
+
try {
|
|
56
|
+
ensureLibraryDb();
|
|
57
|
+
await run();
|
|
58
|
+
} catch (error) {
|
|
59
|
+
process.exitCode = 1;
|
|
60
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function printResourceTrackedDirectoriesTable(directories) {
|
|
64
|
+
ui.table.print({
|
|
65
|
+
columns: [
|
|
66
|
+
{ key: "path", header: "PATH", width: 40 },
|
|
67
|
+
{ key: "resources", header: "RESOURCES", width: 11 },
|
|
68
|
+
{ key: "folders", header: "FOLDERS", width: 9 },
|
|
69
|
+
{ key: "kind", header: "KIND", width: 8 },
|
|
70
|
+
{ key: "platforms", header: "PLATFORMS", width: 24 }
|
|
71
|
+
],
|
|
72
|
+
rows: directories.map((entry) => ({
|
|
73
|
+
path: entry.display_path ?? entry.path,
|
|
74
|
+
resources: String(entry.resource_count),
|
|
75
|
+
folders: String(entry.folders.length),
|
|
76
|
+
kind: kindLabel(entry.kind),
|
|
77
|
+
platforms: platformsCell(entry.platform_ids)
|
|
78
|
+
})),
|
|
79
|
+
summary: formatDirectoryCount(directories.length)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function printResourceTrackedDirectoriesList() {
|
|
83
|
+
printResourceTrackedDirectoriesTable(listResourceTrackedDirectories());
|
|
84
|
+
}
|
|
85
|
+
async function handleList(opts) {
|
|
86
|
+
await withCommandErrors(async () => {
|
|
87
|
+
const format = parseOutputFormat(opts.format);
|
|
88
|
+
const directories = listResourceTrackedDirectories();
|
|
89
|
+
if (format === "json") {
|
|
90
|
+
printJson(directories);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
printResourceTrackedDirectoriesTable(directories);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async function handleAdd(path, opts) {
|
|
97
|
+
await withCommandErrors(async () => {
|
|
98
|
+
const format = parseOutputFormat(opts.format);
|
|
99
|
+
const result = await addResourceTrackedDirectory(path);
|
|
100
|
+
if (format === "json") {
|
|
101
|
+
printJson(result);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
ui.success(
|
|
105
|
+
`Tracking ${result.directory.path} \xB7 ${formatImportedCount(result.imported_count)}`,
|
|
106
|
+
{ hint: "Rescan later with ht resource directories rescan." }
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async function handleRemove(path, opts) {
|
|
111
|
+
await withCommandErrors(async () => {
|
|
112
|
+
const format = parseOutputFormat(opts.format);
|
|
113
|
+
const resolved = resolve(path);
|
|
114
|
+
removeResourceTrackedDirectory(path);
|
|
115
|
+
if (format === "json") {
|
|
116
|
+
printJson({ removed: true, path: resolved });
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
ui.success(`Stopped tracking ${resolved}`, {
|
|
120
|
+
hint: "Library resources from this path were not deleted."
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async function handleRescan(opts) {
|
|
125
|
+
await withCommandErrors(async () => {
|
|
126
|
+
const format = parseOutputFormat(opts.format);
|
|
127
|
+
const result = await rescanResourceTrackedDirectories();
|
|
128
|
+
if (format === "json") {
|
|
129
|
+
printJson(result);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
for (const row of result.rescanned) {
|
|
133
|
+
if (!row.skipped) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
ui.warn(`${row.path}: ${row.error ?? "skipped"}`);
|
|
137
|
+
}
|
|
138
|
+
const dirCount = result.directories.length;
|
|
139
|
+
ui.success(
|
|
140
|
+
`Rescanned ${dirCount} director${dirCount === 1 ? "y" : "ies"} \xB7 ${formatImportedCount(result.imported_count)}`
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function registerResourceDirectoriesCommand(resourceCmd) {
|
|
145
|
+
const directoriesCmd = configureCommandGroup(
|
|
146
|
+
resourceCmd.command("directories").description("Manage directories scanned into the resource library")
|
|
147
|
+
);
|
|
148
|
+
directoriesCmd.command("list").alias("ls").option("--format <mode>", "Output format: human or json", "human").description("List directories tracked for resource import").action(handleList);
|
|
149
|
+
COMMAND_HELP_REGISTRY["resource.directories.list"] = {
|
|
150
|
+
description: "List directories tracked for resource import",
|
|
151
|
+
examples: [
|
|
152
|
+
"resource directories list",
|
|
153
|
+
"resource directories list --format json"
|
|
154
|
+
]
|
|
155
|
+
};
|
|
156
|
+
directoriesCmd.command("add").argument("<path>", "Directory to track and import").option("--format <mode>", "Output format: human or json", "human").description("Track a directory and import resources (skip existing)").action(handleAdd);
|
|
157
|
+
COMMAND_HELP_REGISTRY["resource.directories.add"] = {
|
|
158
|
+
description: "Track a directory and import resources (skip existing)",
|
|
159
|
+
examples: [
|
|
160
|
+
"resource directories add ./my-project",
|
|
161
|
+
"resource directories add ./my-project --format json"
|
|
162
|
+
]
|
|
163
|
+
};
|
|
164
|
+
directoriesCmd.command("remove").alias("rm").argument("<path>", "Tracked directory to stop watching").option("--format <mode>", "Output format: human or json", "human").description("Stop tracking a directory (library resources stay)").action(handleRemove);
|
|
165
|
+
COMMAND_HELP_REGISTRY["resource.directories.remove"] = {
|
|
166
|
+
description: "Stop tracking a directory (library resources stay)",
|
|
167
|
+
examples: [
|
|
168
|
+
"resource directories remove ./my-project",
|
|
169
|
+
"resource directories rm ./my-project --format json"
|
|
170
|
+
]
|
|
171
|
+
};
|
|
172
|
+
directoriesCmd.command("rescan").option("--format <mode>", "Output format: human or json", "human").description("Re-scan home defaults and every tracked directory").action(handleRescan);
|
|
173
|
+
COMMAND_HELP_REGISTRY["resource.directories.rescan"] = {
|
|
174
|
+
description: "Re-scan home defaults and every tracked directory",
|
|
175
|
+
examples: [
|
|
176
|
+
"resource directories rescan",
|
|
177
|
+
"resource directories rescan --format json"
|
|
178
|
+
]
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export {
|
|
183
|
+
printResourceTrackedDirectoriesList,
|
|
184
|
+
registerResourceDirectoriesCommand
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=chunk-LNJ3WZZX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli/commands/resource-directories.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport type { Command } from \"commander\";\nimport { getDb } from \"../../db/connection.js\";\nimport { initializeSchema } from \"../../db/schema.js\";\nimport { COMMAND_HELP_REGISTRY } from \"../../services/cli-help-registry.js\";\nimport {\n addResourceTrackedDirectory,\n listResourceTrackedDirectories,\n removeResourceTrackedDirectory,\n rescanResourceTrackedDirectories,\n type ResourceTrackedDirectoryEntry,\n} from \"../../services/resource-tracked-directories.js\";\nimport { ui } from \"../../ui/index.js\";\nimport { parseOutputFormat, printJson } from \"../../utils/output-format.js\";\nimport { configureCommandGroup } from \"../help.js\";\nimport { fail } from \"../shared.js\";\n\nfunction ensureLibraryDb(): void {\n initializeSchema(getDb());\n}\n\nfunction formatDirectoryCount(count: number): string {\n return `${count} tracked director${count === 1 ? \"y\" : \"ies\"}`;\n}\n\nfunction formatImportedCount(count: number): string {\n return `${count} resource${count === 1 ? \"\" : \"s\"} imported`;\n}\n\nfunction kindLabel(kind: ResourceTrackedDirectoryEntry[\"kind\"]): string {\n switch (kind) {\n case \"home_default\":\n return \"home\";\n case \"custom\":\n return \"custom\";\n default: {\n const _exhaustive: never = kind;\n throw _exhaustive;\n }\n }\n}\n\nfunction platformsCell(platformIds: string[]): string {\n return platformIds.length > 0 ? platformIds.join(\", \") : \": \";\n}\n\nasync function withCommandErrors(run: () => Promise<void>): Promise<void> {\n try {\n ensureLibraryDb();\n await run();\n } catch (error) {\n process.exitCode = 1;\n fail(error instanceof Error ? error.message : String(error));\n }\n}\n\nfunction printResourceTrackedDirectoriesTable(\n directories: ResourceTrackedDirectoryEntry[],\n): void {\n ui.table.print({\n columns: [\n { key: \"path\", header: \"PATH\", width: 40 },\n { key: \"resources\", header: \"RESOURCES\", width: 11 },\n { key: \"folders\", header: \"FOLDERS\", width: 9 },\n { key: \"kind\", header: \"KIND\", width: 8 },\n { key: \"platforms\", header: \"PLATFORMS\", width: 24 },\n ],\n rows: directories.map((entry) => ({\n path: entry.display_path ?? entry.path,\n resources: String(entry.resource_count),\n folders: String(entry.folders.length),\n kind: kindLabel(entry.kind),\n platforms: platformsCell(entry.platform_ids),\n })),\n summary: formatDirectoryCount(directories.length),\n });\n}\n\nexport function printResourceTrackedDirectoriesList(): void {\n printResourceTrackedDirectoriesTable(listResourceTrackedDirectories());\n}\n\nasync function handleList(opts: { format?: string }): Promise<void> {\n await withCommandErrors(async () => {\n const format = parseOutputFormat(opts.format);\n const directories = listResourceTrackedDirectories();\n if (format === \"json\") {\n printJson(directories);\n return;\n }\n printResourceTrackedDirectoriesTable(directories);\n });\n}\n\nasync function handleAdd(path: string, opts: { format?: string }): Promise<void> {\n await withCommandErrors(async () => {\n const format = parseOutputFormat(opts.format);\n const result = await addResourceTrackedDirectory(path);\n if (format === \"json\") {\n printJson(result);\n return;\n }\n ui.success(\n `Tracking ${result.directory.path} · ${formatImportedCount(result.imported_count)}`,\n { hint: \"Rescan later with ht resource directories rescan.\" },\n );\n });\n}\n\nasync function handleRemove(path: string, opts: { format?: string }): Promise<void> {\n await withCommandErrors(async () => {\n const format = parseOutputFormat(opts.format);\n const resolved = resolve(path);\n removeResourceTrackedDirectory(path);\n if (format === \"json\") {\n printJson({ removed: true, path: resolved });\n return;\n }\n ui.success(`Stopped tracking ${resolved}`, {\n hint: \"Library resources from this path were not deleted.\",\n });\n });\n}\n\nasync function handleRescan(opts: { format?: string }): Promise<void> {\n await withCommandErrors(async () => {\n const format = parseOutputFormat(opts.format);\n const result = await rescanResourceTrackedDirectories();\n if (format === \"json\") {\n printJson(result);\n return;\n }\n for (const row of result.rescanned) {\n if (!row.skipped) {\n continue;\n }\n ui.warn(`${row.path}: ${row.error ?? \"skipped\"}`);\n }\n const dirCount = result.directories.length;\n ui.success(\n `Rescanned ${dirCount} director${dirCount === 1 ? \"y\" : \"ies\"} · ${formatImportedCount(result.imported_count)}`,\n );\n });\n}\n\nexport function registerResourceDirectoriesCommand(resourceCmd: Command): void {\n const directoriesCmd = configureCommandGroup(\n resourceCmd\n .command(\"directories\")\n .description(\"Manage directories scanned into the resource library\"),\n );\n\n directoriesCmd\n .command(\"list\")\n .alias(\"ls\")\n .option(\"--format <mode>\", \"Output format: human or json\", \"human\")\n .description(\"List directories tracked for resource import\")\n .action(handleList);\n\n COMMAND_HELP_REGISTRY[\"resource.directories.list\"] = {\n description: \"List directories tracked for resource import\",\n examples: [\n \"resource directories list\",\n \"resource directories list --format json\",\n ],\n };\n\n directoriesCmd\n .command(\"add\")\n .argument(\"<path>\", \"Directory to track and import\")\n .option(\"--format <mode>\", \"Output format: human or json\", \"human\")\n .description(\"Track a directory and import resources (skip existing)\")\n .action(handleAdd);\n\n COMMAND_HELP_REGISTRY[\"resource.directories.add\"] = {\n description: \"Track a directory and import resources (skip existing)\",\n examples: [\n \"resource directories add ./my-project\",\n \"resource directories add ./my-project --format json\",\n ],\n };\n\n directoriesCmd\n .command(\"remove\")\n .alias(\"rm\")\n .argument(\"<path>\", \"Tracked directory to stop watching\")\n .option(\"--format <mode>\", \"Output format: human or json\", \"human\")\n .description(\"Stop tracking a directory (library resources stay)\")\n .action(handleRemove);\n\n COMMAND_HELP_REGISTRY[\"resource.directories.remove\"] = {\n description: \"Stop tracking a directory (library resources stay)\",\n examples: [\n \"resource directories remove ./my-project\",\n \"resource directories rm ./my-project --format json\",\n ],\n };\n\n directoriesCmd\n .command(\"rescan\")\n .option(\"--format <mode>\", \"Output format: human or json\", \"human\")\n .description(\"Re-scan home defaults and every tracked directory\")\n .action(handleRescan);\n\n COMMAND_HELP_REGISTRY[\"resource.directories.rescan\"] = {\n description: \"Re-scan home defaults and every tracked directory\",\n examples: [\n \"resource directories rescan\",\n \"resource directories rescan --format json\",\n ],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,eAAe;AAiBxB,SAAS,kBAAwB;AAC/B,mBAAiB,MAAM,CAAC;AAC1B;AAEA,SAAS,qBAAqB,OAAuB;AACnD,SAAO,GAAG,K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U;AAAA,MACR;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {
|
|
2
|
+
persistMergedProjectScan,
|
|
3
|
+
scanProjectWithPluginSource
|
|
4
|
+
} from "./chunk-3IWTJCPA.js";
|
|
5
|
+
import {
|
|
6
|
+
addResourceToPlugin,
|
|
7
|
+
createPlugin,
|
|
8
|
+
deletePlugin,
|
|
9
|
+
getPlugin,
|
|
10
|
+
getPluginResources
|
|
11
|
+
} from "./chunk-2EIJYDNI.js";
|
|
12
|
+
|
|
13
|
+
// src/services/plugin-from-project.ts
|
|
14
|
+
async function previewPluginFromProject(input) {
|
|
15
|
+
const existingPlugin = getPlugin(input.name);
|
|
16
|
+
const { harness, plugin } = await scanProjectWithPluginSource(
|
|
17
|
+
input.projectRoot,
|
|
18
|
+
input.platform
|
|
19
|
+
);
|
|
20
|
+
const scannedResources = [
|
|
21
|
+
...harness.flatMap((result) => result.resources),
|
|
22
|
+
...plugin.flatMap((result) => result.resources)
|
|
23
|
+
];
|
|
24
|
+
if (!existingPlugin) {
|
|
25
|
+
return {
|
|
26
|
+
pluginExists: false,
|
|
27
|
+
newResources: scannedResources,
|
|
28
|
+
conflicts: [],
|
|
29
|
+
totalImports: scannedResources.length
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const existingResources = getPluginResources(existingPlugin.id);
|
|
33
|
+
const conflicts = [];
|
|
34
|
+
const newResources = [];
|
|
35
|
+
for (const scanned of scannedResources) {
|
|
36
|
+
const existing = existingResources.find(
|
|
37
|
+
(resource) => resource.name === scanned.name && resource.type === scanned.type
|
|
38
|
+
);
|
|
39
|
+
if (existing && existing.content !== scanned.content) {
|
|
40
|
+
conflicts.push({
|
|
41
|
+
existingResource: existing,
|
|
42
|
+
newContent: scanned.content,
|
|
43
|
+
newDescription: scanned.description
|
|
44
|
+
});
|
|
45
|
+
} else if (!existing) {
|
|
46
|
+
newResources.push(scanned);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
pluginExists: true,
|
|
51
|
+
existingPlugin,
|
|
52
|
+
newResources,
|
|
53
|
+
conflicts,
|
|
54
|
+
totalImports: scannedResources.length
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function createPluginFromProject(input) {
|
|
58
|
+
const existing = getPlugin(input.name);
|
|
59
|
+
if (existing && input.conflictStrategy !== "overwrite") {
|
|
60
|
+
throw new Error(`Plugin already exists: ${input.name}`);
|
|
61
|
+
}
|
|
62
|
+
const namespace = existing && input.conflictStrategy === "overwrite" ? "" : input.name;
|
|
63
|
+
const resources = (await persistMergedProjectScan(input.projectRoot, input.platform, {
|
|
64
|
+
conflictPolicy: input.conflictStrategy === "skip" ? "skip" : "overwrite",
|
|
65
|
+
originRef: input.projectRoot,
|
|
66
|
+
namespace
|
|
67
|
+
})).resources;
|
|
68
|
+
let plugin;
|
|
69
|
+
if (existing && input.conflictStrategy === "overwrite") {
|
|
70
|
+
const oldDescription = existing.description;
|
|
71
|
+
deletePlugin(existing.id);
|
|
72
|
+
plugin = createPlugin({
|
|
73
|
+
name: input.name,
|
|
74
|
+
description: input.description ?? oldDescription
|
|
75
|
+
});
|
|
76
|
+
for (const resource of resources) {
|
|
77
|
+
addResourceToPlugin(plugin.id, resource.id);
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
plugin = createPlugin({
|
|
81
|
+
name: input.name,
|
|
82
|
+
description: input.description ?? `Inferred from ${input.projectRoot}`
|
|
83
|
+
});
|
|
84
|
+
for (const resource of resources) {
|
|
85
|
+
addResourceToPlugin(plugin.id, resource.id);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const finalized = getPlugin(plugin.id);
|
|
89
|
+
if (!finalized) {
|
|
90
|
+
throw new Error(`Failed to create plugin: ${input.name}`);
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
plugin: finalized,
|
|
94
|
+
resources,
|
|
95
|
+
imported_count: resources.length
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
previewPluginFromProject,
|
|
101
|
+
createPluginFromProject
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=chunk-MWXA4PFE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/plugin-from-project.ts"],"sourcesContent":["import {\n createPlugin,\n addResourceToPlugin,\n getPlugin,\n getPluginResources,\n deletePlugin,\n} from \"../models/plugin-model.js\";\nimport {\n scanProjectWithPluginSource,\n persistMergedProjectScan,\n} from \"./scanner.js\";\nimport type { Plugin, Resource } from \"../types.js\";\n\nexport interface PluginFromProjectResult {\n plugin: Plugin;\n resources: Resource[];\n imported_count: number;\n}\n\nexport interface ConflictInfo {\n existingResource: Resource;\n newContent: string;\n newDescription?: string;\n}\n\nexport interface PluginFromProjectPreview {\n pluginExists: boolean;\n existingPlugin?: Plugin;\n newResources: Resource[];\n conflicts: ConflictInfo[];\n totalImports: number;\n}\n\n/**\n * Preview what would happen if we created a plugin from a project.\n * Does not modify database.\n */\nexport async function previewPluginFromProject(input: {\n name: string;\n projectRoot: string;\n platform?: string;\n}): Promise<PluginFromProjectPreview> {\n const existingPlugin = getPlugin(input.name);\n const { harness, plugin } = await scanProjectWithPluginSource(\n input.projectRoot,\n input.platform,\n );\n const scannedResources = [\n ...harness.flatMap((result) => result.resources),\n ...plugin.flatMap((result) => result.resources),\n ];\n\n if (!existingPlugin) {\n return {\n pluginExists: false,\n newResources: scannedResources as Resource[],\n conflicts: [],\n totalImports: scannedResources.length,\n };\n }\n\n const existingResources = getPluginResources(existingPlugin.id);\n const conflicts: ConflictInfo[] = [];\n const newResources: Resource[] = [];\n\n for (const scanned of scannedResources) {\n const existing = existingResources.find(\n (resource) => resource.name === scanned.name && resource.type === scanned.type,\n );\n if (existing && existing.content !== scanned.content) {\n conflicts.push({\n existingResource: existing,\n newContent: scanned.content,\n newDescription: scanned.description,\n });\n } else if (!existing) {\n newResources.push(scanned as Resource);\n }\n }\n\n return {\n pluginExists: true,\n existingPlugin,\n newResources,\n conflicts,\n totalImports: scannedResources.length,\n };\n}\n\n/**\n * Scan a project and create a plugin containing all imported resources.\n * Now supports conflict resolution strategies.\n */\nexport async function createPluginFromProject(input: {\n name: string;\n description?: string;\n projectRoot: string;\n platform?: string;\n conflictStrategy?: \"overwrite\" | \"skip\";\n}): Promise<PluginFromProjectResult> {\n const existing = getPlugin(input.name);\n\n if (existing && input.conflictStrategy !== \"overwrite\") {\n throw new Error(`Plugin already exists: ${input.name}`);\n }\n\n const namespace =\n existing && input.conflictStrategy === \"overwrite\" ? \"\" : input.name;\n const resources = (\n await persistMergedProjectScan(input.projectRoot, input.platform, {\n conflictPolicy: input.conflictStrategy === \"skip\" ? \"skip\" : \"overwrite\",\n originRef: input.projectRoot,\n namespace,\n })\n ).resources;\n\n let plugin: Plugin;\n if (existing && input.conflictStrategy === \"overwrite\") {\n const oldDescription = existing.description;\n deletePlugin(existing.id);\n\n plugin = createPlugin({\n name: input.name,\n description: input.description ?? oldDescription,\n });\n\n for (const resource of resources) {\n addResourceToPlugin(plugin.id, resource.id);\n }\n } else {\n plugin = createPlugin({\n name: input.name,\n description: input.description ?? `Inferred from ${input.projectRoot}`,\n });\n\n for (const resource of resources) {\n addResourceToPlugin(plugin.id, resource.id);\n }\n }\n\n const finalized = getPlugin(plugin.id);\n if (!finalized) {\n throw new Error(`Failed to create plugin: ${input.name}`);\n }\n\n return {\n plugin: finalized,\n resources,\n imported_count: resources.length,\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAqCA,eAAsB,yBAAyB,OAIT;AACpC,QAAM,iBAAiB,UAAU,MAAM,IAAI;AAC3C,QAAM,EAAE,SAAS,OAAO,IAAI,MAAM;AAAA,IAChC,MAAM;AAAA,IACN,MAAM;AAAA,EACR;AACA,QAAM,mBAAmB;AAAA,IACvB,GAAG,QAAQ,QAAQ,CAAC,WAAW,OAAO,SAAS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SAAS;AAChC,iBAAa,SAAS,EAAE;AAExB,aAAS,aAAa;AAAA,MACpB,MAAM,MAAM;AAAA,MACZ,aAAa,MAAM,eAAe;AAAA,IACpC,CAAC;AAED,eAAW,YAAY,WAAW;AAChC,0BAAoB,OAAO,IAAI,SAAS,EAAE;AAAA,IAC5C;AAAA,EACF,OAAO;AACL,aAAS,aAAa;AAAA,MACpB,MAAM,MAAM;AAAA,MACZ,aAAa,MAAM,eAAe,iBAAiB,MAAM,WAAW;AAAA,IACtE,CAAC;AAED,eAAW,YAAY,WAAW;AAChC,0BAAoB,OAAO,IAAI,SAAS,EAAE;AAAA,IAC5C;AAAA,EACF;AAEA,QAAM,YAAY,UAAU,OAAO,EAAE;AACrC,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,4BAA4B,MAAM,IAAI,EAAE;AAAA,EAC1D;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA,gBAAgB,UAAU;AAAA,EAC5B;AACF;","names":[]}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PACK_LOCKFILE_NAME,
|
|
3
|
+
normalizeSha256,
|
|
4
|
+
readZipArchive,
|
|
5
|
+
sha256Hex
|
|
6
|
+
} from "./chunk-GRJY22U6.js";
|
|
7
|
+
import {
|
|
8
|
+
BundleSymlinkError,
|
|
9
|
+
isApEnvelopePath,
|
|
10
|
+
listContainedRegularFiles,
|
|
11
|
+
packageFileFromBytes,
|
|
12
|
+
readApEnvelope
|
|
13
|
+
} from "./chunk-2EIJYDNI.js";
|
|
14
|
+
|
|
15
|
+
// src/services/legacy-toml-transport.ts
|
|
16
|
+
var LEGACY_PLUGIN_SUFFIX = `.harnesstap${".toml"}`;
|
|
17
|
+
var LEGACY_ENVIRONMENT_SUFFIX = `.environment${".toml"}`;
|
|
18
|
+
function isLegacyPluginTomlPath(filePath) {
|
|
19
|
+
return filePath.toLowerCase().endsWith(LEGACY_PLUGIN_SUFFIX);
|
|
20
|
+
}
|
|
21
|
+
function isLegacyEnvironmentTomlPath(filePath) {
|
|
22
|
+
return filePath.toLowerCase().endsWith(LEGACY_ENVIRONMENT_SUFFIX);
|
|
23
|
+
}
|
|
24
|
+
function isLegacyTomlTransportPath(filePath) {
|
|
25
|
+
return isLegacyPluginTomlPath(filePath) || isLegacyEnvironmentTomlPath(filePath);
|
|
26
|
+
}
|
|
27
|
+
function legacyTomlTransportRejection(filePath) {
|
|
28
|
+
return `${filePath} is a HarnessTap TOML transport file, which is no longer supported. Portable artifacts are Agent Plugins packages: a directory with a plugin.json, or a single .ap.json envelope.`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/services/apm-bundle.ts
|
|
32
|
+
import { existsSync, lstatSync, readFileSync, statSync } from "fs";
|
|
33
|
+
import { join, resolve } from "path";
|
|
34
|
+
import { parse as parseYaml } from "yaml";
|
|
35
|
+
var BundleIntegrityError = class extends Error {
|
|
36
|
+
constructor(message) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = "BundleIntegrityError";
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
function isRecord(value) {
|
|
42
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
43
|
+
}
|
|
44
|
+
function readBundleLock(files) {
|
|
45
|
+
const lockBytes = files[PACK_LOCKFILE_NAME];
|
|
46
|
+
if (!lockBytes) return void 0;
|
|
47
|
+
const parsed = parseYaml(lockBytes.toString("utf8"));
|
|
48
|
+
return isRecord(parsed) ? parsed : void 0;
|
|
49
|
+
}
|
|
50
|
+
function bundleFileMap(lock) {
|
|
51
|
+
const pack = lock?.pack;
|
|
52
|
+
if (!isRecord(pack) || !isRecord(pack.bundle_files)) {
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
return Object.fromEntries(
|
|
56
|
+
Object.entries(pack.bundle_files).map(([path, hash]) => [path, String(hash)])
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
function verifyPackedBundleBytes(files) {
|
|
60
|
+
const listed = bundleFileMap(readBundleLock(files));
|
|
61
|
+
if (!listed) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const listedPaths = Object.keys(listed).sort();
|
|
65
|
+
const presentPaths = Object.keys(files).filter((path) => path !== PACK_LOCKFILE_NAME).sort();
|
|
66
|
+
for (const relativePath of listedPaths) {
|
|
67
|
+
if (relativePath.split("/").includes("..") || relativePath.startsWith("/")) {
|
|
68
|
+
throw new BundleIntegrityError(
|
|
69
|
+
`Unsafe pack.bundle_files path ${relativePath}: pack aborted closed`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
const bytes = files[relativePath];
|
|
73
|
+
if (!bytes) {
|
|
74
|
+
throw new BundleIntegrityError(
|
|
75
|
+
`Bundle is missing ${relativePath} listed in pack.bundle_files`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
const expected = listed[relativePath];
|
|
79
|
+
if (!expected) continue;
|
|
80
|
+
const actual = sha256Hex(bytes);
|
|
81
|
+
if (normalizeSha256(expected) !== actual) {
|
|
82
|
+
throw new BundleIntegrityError(
|
|
83
|
+
`Bundle hash mismatch for ${relativePath}: lockfile records ${normalizeSha256(expected)}, file is ${actual}`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const relativePath of presentPaths) {
|
|
88
|
+
if (listed[relativePath] === void 0) {
|
|
89
|
+
throw new BundleIntegrityError(
|
|
90
|
+
`Bundle contains extra file ${relativePath} that is not listed in pack.bundle_files`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function filesFromDirectory(packageDir) {
|
|
96
|
+
if (lstatSync(packageDir).isSymbolicLink()) {
|
|
97
|
+
throw new BundleSymlinkError(".");
|
|
98
|
+
}
|
|
99
|
+
const files = {};
|
|
100
|
+
for (const relativePath of listContainedRegularFiles(packageDir).sort()) {
|
|
101
|
+
files[relativePath] = readFileSync(join(packageDir, relativePath));
|
|
102
|
+
}
|
|
103
|
+
return files;
|
|
104
|
+
}
|
|
105
|
+
function filesFromZip(archivePath) {
|
|
106
|
+
const members = readZipArchive(readFileSync(archivePath));
|
|
107
|
+
const files = {};
|
|
108
|
+
for (const member of members) {
|
|
109
|
+
files[member.path] = member.data;
|
|
110
|
+
}
|
|
111
|
+
return files;
|
|
112
|
+
}
|
|
113
|
+
function toPackageFiles(files) {
|
|
114
|
+
const result = {};
|
|
115
|
+
for (const relativePath of Object.keys(files).sort()) {
|
|
116
|
+
const bytes = files[relativePath];
|
|
117
|
+
if (!bytes) continue;
|
|
118
|
+
result[relativePath] = packageFileFromBytes(bytes);
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
function bytesFromPackageFiles(files) {
|
|
123
|
+
const result = {};
|
|
124
|
+
for (const [relativePath, entry] of Object.entries(files)) {
|
|
125
|
+
if (!entry) continue;
|
|
126
|
+
result[relativePath] = entry.encoding === "base64" ? Buffer.from(entry.content, "base64") : Buffer.from(entry.content, "utf8");
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
function isZipBundlePath(source) {
|
|
131
|
+
return source.toLowerCase().endsWith(".zip");
|
|
132
|
+
}
|
|
133
|
+
function looksLikeFilesystemPath(source) {
|
|
134
|
+
return source.includes("/") || source.includes("\\") || source.startsWith(".");
|
|
135
|
+
}
|
|
136
|
+
function isPluginPackageDirectory(source) {
|
|
137
|
+
try {
|
|
138
|
+
const resolved = resolve(source);
|
|
139
|
+
return existsSync(resolved) && statSync(resolved).isDirectory() && existsSync(join(resolved, "plugin.json"));
|
|
140
|
+
} catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function loadVerifiedPackageFiles(filePath) {
|
|
145
|
+
const resolved = resolve(filePath);
|
|
146
|
+
if (isLegacyTomlTransportPath(resolved)) {
|
|
147
|
+
throw new Error(legacyTomlTransportRejection(resolved));
|
|
148
|
+
}
|
|
149
|
+
if (isApEnvelopePath(resolved)) {
|
|
150
|
+
const files = readApEnvelope(resolved);
|
|
151
|
+
verifyPackedBundleBytes(bytesFromPackageFiles(files));
|
|
152
|
+
return files;
|
|
153
|
+
}
|
|
154
|
+
if (isZipBundlePath(resolved)) {
|
|
155
|
+
const files = filesFromZip(resolved);
|
|
156
|
+
verifyPackedBundleBytes(files);
|
|
157
|
+
return toPackageFiles(files);
|
|
158
|
+
}
|
|
159
|
+
if (existsSync(resolved) && statSync(resolved).isDirectory()) {
|
|
160
|
+
if (!existsSync(join(resolved, "plugin.json"))) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
`${resolved} is a directory but has no plugin.json: expected an Agent Plugins package.`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
const files = filesFromDirectory(resolved);
|
|
166
|
+
verifyPackedBundleBytes(files);
|
|
167
|
+
return toPackageFiles(files);
|
|
168
|
+
}
|
|
169
|
+
throw new Error(
|
|
170
|
+
`Cannot tell what ${resolved} is. Pass an Agent Plugins package directory, a .zip bundle, or an .ap.json envelope.`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
isLegacyPluginTomlPath,
|
|
176
|
+
isLegacyTomlTransportPath,
|
|
177
|
+
legacyTomlTransportRejection,
|
|
178
|
+
isZipBundlePath,
|
|
179
|
+
looksLikeFilesystemPath,
|
|
180
|
+
isPluginPackageDirectory,
|
|
181
|
+
loadVerifiedPackageFiles
|
|
182
|
+
};
|
|
183
|
+
//# sourceMappingURL=chunk-MY62SSKC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/legacy-toml-transport.ts","../src/services/apm-bundle.ts"],"sourcesContent":["/** Suffixes for deleted TOML transport formats (kept for clear rejection errors). */\nconst LEGACY_PLUGIN_SUFFIX = `.harnesstap${\".toml\"}`;\nconst LEGACY_ENVIRONMENT_SUFFIX = `.environment${\".toml\"}`;\n\nexport function isLegacyPluginTomlPath(filePath: string): boolean {\n return filePath.toLowerCase().endsWith(LEGACY_PLUGIN_SUFFIX);\n}\n\nexport function isLegacyEnvironmentTomlPath(filePath: string): boolean {\n return filePath.toLowerCase().endsWith(LEGACY_ENVIRONMENT_SUFFIX);\n}\n\nexport function isLegacyTomlTransportPath(filePath: string): boolean {\n return isLegacyPluginTomlPath(filePath) || isLegacyEnvironmentTomlPath(filePath);\n}\n\nexport function legacyTomlTransportRejection(filePath: string): string {\n return (\n `${filePath} is a HarnessTap TOML transport file, which is no longer supported. ` +\n \"Portable artifacts are Agent Plugins packages: a directory with a plugin.json, \" +\n \"or a single .ap.json envelope.\"\n );\n}\n","import { existsSync, lstatSync, readFileSync, statSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport { parse as parseYaml } from \"yaml\";\nimport {\n packageFileFromBytes,\n type ApPackageFiles,\n} from \"./agent-plugins/files.js\";\nimport { isApEnvelopePath, readApEnvelope } from \"./agent-plugins/envelope.js\";\nimport { PACK_LOCKFILE_NAME, normalizeSha256, sha256Hex } from \"./apm-pack.js\";\nimport {\n isLegacyTomlTransportPath,\n legacyTomlTransportRejection,\n} from \"./legacy-toml-transport.js\";\nimport {\n BundleSymlinkError,\n listContainedRegularFiles,\n} from \"../utils/path-containment.js\";\nimport { readZipArchive } from \"../utils/zip-archive.js\";\n\nexport class BundleIntegrityError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"BundleIntegrityError\";\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction readBundleLock(files: Record<string, Buffer>): Record<string, unknown> | undefined {\n const lockBytes = files[PACK_LOCKFILE_NAME];\n if (!lockBytes) return undefined;\n const parsed = parseYaml(lockBytes.toString(\"utf8\"));\n return isRecord(parsed) ? parsed : undefined;\n}\n\nfunction bundleFileMap(lock: Record<string, unknown> | undefined): Record<string, string> | undefined {\n const pack = lock?.pack;\n if (!isRecord(pack) || !isRecord(pack.bundle_files)) {\n return undefined;\n }\n return Object.fromEntries(\n Object.entries(pack.bundle_files).map(([path, hash]) => [path, String(hash)]),\n );\n}\n\nexport function verifyPackedBundleBytes(files: Record<string, Buffer>): void {\n const listed = bundleFileMap(readBundleLock(files));\n if (!listed) {\n return;\n }\n\n const listedPaths = Object.keys(listed).sort();\n const presentPaths = Object.keys(files)\n .filter((path) => path !== PACK_LOCKFILE_NAME)\n .sort();\n\n for (const relativePath of listedPaths) {\n if (relativePath.split(\"/\").includes(\"..\") || relativePath.startsWith(\"/\")) {\n throw new BundleIntegrityError(\n `Unsafe pack.bundle_files path ${relativePath}: pack aborted closed`,\n );\n }\n const bytes = files[relativePath];\n if (!bytes) {\n throw new BundleIntegrityError(\n `Bundle is missing ${relativePath} listed in pack.bundle_files`,\n );\n }\n const expected = listed[relativePath];\n if (!expected) continue;\n const actual = sha256Hex(bytes);\n if (normalizeSha256(expected) !== actual) {\n throw new BundleIntegrityError(\n `Bundle hash mismatch for ${relativePath}: lockfile records ${normalizeSha256(expected)}, file is ${actual}`,\n );\n }\n }\n\n for (const relativePath of presentPaths) {\n if (listed[relativePath] === undefined) {\n throw new BundleIntegrityError(\n `Bundle contains extra file ${relativePath} that is not listed in pack.bundle_files`,\n );\n }\n }\n}\n\nfunction filesFromDirectory(packageDir: string): Record<string, Buffer> {\n if (lstatSync(packageDir).isSymbolicLink()) {\n throw new BundleSymlinkError(\".\");\n }\n const files: Record<string, Buffer> = {};\n for (const relativePath of listContainedRegularFiles(packageDir).sort()) {\n files[relativePath] = readFileSync(join(packageDir, relativePath));\n }\n return files;\n}\n\nfunction filesFromZip(archivePath: string): Record<string, Buffer> {\n const members = readZipArchive(readFileSync(archivePath));\n const files: Record<string, Buffer> = {};\n for (const member of members) {\n files[member.path] = member.data;\n }\n return files;\n}\n\nfunction toPackageFiles(files: Record<string, Buffer>): ApPackageFiles {\n const result: ApPackageFiles = {};\n for (const relativePath of Object.keys(files).sort()) {\n const bytes = files[relativePath];\n if (!bytes) continue;\n result[relativePath] = packageFileFromBytes(bytes);\n }\n return result;\n}\n\nfunction bytesFromPackageFiles(files: ApPackageFiles): Record<string, Buffer> {\n const result: Record<string, Buffer> = {};\n for (const [relativePath, entry] of Object.entries(files)) {\n if (!entry) continue;\n result[relativePath] =\n entry.encoding === \"base64\"\n ? Buffer.from(entry.content, \"base64\")\n : Buffer.from(entry.content, \"utf8\");\n }\n return result;\n}\n\nexport function isZipBundlePath(source: string): boolean {\n return source.toLowerCase().endsWith(\".zip\");\n}\n\nexport function looksLikeFilesystemPath(source: string): boolean {\n return source.includes(\"/\") || source.includes(\"\\\\\") || source.startsWith(\".\");\n}\n\nexport function isPluginPackageDirectory(source: string): boolean {\n try {\n const resolved = resolve(source);\n return (\n existsSync(resolved)\n && statSync(resolved).isDirectory()\n && existsSync(join(resolved, \"plugin.json\"))\n );\n } catch {\n return false;\n }\n}\n\nexport function loadVerifiedPackageFiles(filePath: string): ApPackageFiles {\n const resolved = resolve(filePath);\n if (isLegacyTomlTransportPath(resolved)) {\n throw new Error(legacyTomlTransportRejection(resolved));\n }\n\n if (isApEnvelopePath(resolved)) {\n const files = readApEnvelope(resolved);\n verifyPackedBundleBytes(bytesFromPackageFiles(files));\n return files;\n }\n\n if (isZipBundlePath(resolved)) {\n const files = filesFromZip(resolved);\n verifyPackedBundleBytes(files);\n return toPackageFiles(files);\n }\n\n if (existsSync(resolved) && statSync(resolved).isDirectory()) {\n if (!existsSync(join(resolved, \"plugin.json\"))) {\n throw new Error(\n `${resolved} is a directory but has no plugin.json: expected an Agent Plugins package.`,\n );\n }\n const files = filesFromDirectory(resolved);\n verifyPackedBundleBytes(files);\n return toPackageFiles(files);\n }\n\n throw new Error(\n `Cannot tell what ${resolved} is. Pass an Agent Plugins package directory, a .zip bundle, or an .ap.json envelope.`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AACA,IAAM,uBAAuB,cAAc,OAAO;AAClD,IAAM,4BAA4B,eAAe,OAAO;A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