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,244 @@
|
|
|
1
|
+
// src/services/plugin-resource-mode.ts
|
|
2
|
+
var DEFAULT_PLUGIN_RESOURCE_MODE = "symlink";
|
|
3
|
+
function isPluginResourceMode(value) {
|
|
4
|
+
return value === "symlink" || value === "copy" || value === "clone";
|
|
5
|
+
}
|
|
6
|
+
function parsePluginResourceMode(value) {
|
|
7
|
+
if (isPluginResourceMode(value)) return value;
|
|
8
|
+
throw new Error(
|
|
9
|
+
`Invalid plugin resource mode: ${value}. Use symlink, copy, or clone.`
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/config/settings.ts
|
|
14
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
15
|
+
import { join } from "path";
|
|
16
|
+
var VALID_PLATFORMS = /* @__PURE__ */ new Set([
|
|
17
|
+
"claude-code",
|
|
18
|
+
"cursor",
|
|
19
|
+
"goose",
|
|
20
|
+
"copilot-cli"
|
|
21
|
+
]);
|
|
22
|
+
var DEFAULT_MARKETPLACE_REFRESH_MAX_AGE_MINUTES = 60;
|
|
23
|
+
function marketplaceRefreshMaxAgeMs(minutes) {
|
|
24
|
+
return minutes * 60 * 1e3;
|
|
25
|
+
}
|
|
26
|
+
var DEFAULTS = {
|
|
27
|
+
plugins: {
|
|
28
|
+
refreshMaxAgeHours: 24,
|
|
29
|
+
marketplaceRefreshMaxAgeMinutes: DEFAULT_MARKETPLACE_REFRESH_MAX_AGE_MINUTES,
|
|
30
|
+
marketplaces: []
|
|
31
|
+
},
|
|
32
|
+
pluginVersionHistoryLimit: 10,
|
|
33
|
+
harnessSync: { pluginResources: DEFAULT_PLUGIN_RESOURCE_MODE }
|
|
34
|
+
};
|
|
35
|
+
function isPluginMarketplacePlatform(value) {
|
|
36
|
+
return typeof value === "string" && VALID_PLATFORMS.has(value);
|
|
37
|
+
}
|
|
38
|
+
function parseTrackedBranches(value) {
|
|
39
|
+
if (!Array.isArray(value)) return [];
|
|
40
|
+
const seen = /* @__PURE__ */ new Set();
|
|
41
|
+
const branches = [];
|
|
42
|
+
for (const item of value) {
|
|
43
|
+
if (typeof item !== "string") continue;
|
|
44
|
+
const trimmed = item.trim();
|
|
45
|
+
if (!trimmed || seen.has(trimmed)) continue;
|
|
46
|
+
seen.add(trimmed);
|
|
47
|
+
branches.push(trimmed);
|
|
48
|
+
}
|
|
49
|
+
return branches;
|
|
50
|
+
}
|
|
51
|
+
function settingsPath(harnesstapDir) {
|
|
52
|
+
return existsSync(join(harnesstapDir, "config.jsonc")) ? join(harnesstapDir, "config.jsonc") : join(harnesstapDir, "config.json");
|
|
53
|
+
}
|
|
54
|
+
function parseMarketplaces(value) {
|
|
55
|
+
if (!Array.isArray(value)) return [];
|
|
56
|
+
const marketplaces = [];
|
|
57
|
+
for (const row of value) {
|
|
58
|
+
if (typeof row !== "object" || row === null) continue;
|
|
59
|
+
const record = row;
|
|
60
|
+
const name = record.name;
|
|
61
|
+
const url = record.url;
|
|
62
|
+
const platforms = record.platforms;
|
|
63
|
+
if (typeof name !== "string") continue;
|
|
64
|
+
const trimmedName = name.trim();
|
|
65
|
+
if (trimmedName.length === 0) continue;
|
|
66
|
+
if (typeof url !== "string") continue;
|
|
67
|
+
const trimmedUrl = url.trim();
|
|
68
|
+
if (trimmedUrl.length === 0) continue;
|
|
69
|
+
if (!Array.isArray(platforms)) continue;
|
|
70
|
+
const parsedPlatforms = platforms.filter(isPluginMarketplacePlatform);
|
|
71
|
+
if (parsedPlatforms.length === 0) continue;
|
|
72
|
+
const trackedBranches = parseTrackedBranches(record.trackedBranches);
|
|
73
|
+
marketplaces.push({
|
|
74
|
+
name: trimmedName,
|
|
75
|
+
url: trimmedUrl,
|
|
76
|
+
platforms: parsedPlatforms,
|
|
77
|
+
...trackedBranches.length > 0 ? { trackedBranches } : {}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return marketplaces;
|
|
81
|
+
}
|
|
82
|
+
function parseJsonc(content) {
|
|
83
|
+
let normalized = "";
|
|
84
|
+
let inString = false;
|
|
85
|
+
let stringQuote = '"';
|
|
86
|
+
let escaping = false;
|
|
87
|
+
let inLineComment = false;
|
|
88
|
+
let inBlockComment = false;
|
|
89
|
+
for (let index = 0; index < content.length; index++) {
|
|
90
|
+
const char = content[index];
|
|
91
|
+
const nextChar = content[index + 1];
|
|
92
|
+
if (inLineComment) {
|
|
93
|
+
if (char === "\n") {
|
|
94
|
+
inLineComment = false;
|
|
95
|
+
normalized += char;
|
|
96
|
+
}
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (inBlockComment) {
|
|
100
|
+
if (char === "*" && nextChar === "/") {
|
|
101
|
+
inBlockComment = false;
|
|
102
|
+
index++;
|
|
103
|
+
}
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (inString) {
|
|
107
|
+
normalized += char;
|
|
108
|
+
if (escaping) {
|
|
109
|
+
escaping = false;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (char === "\\") {
|
|
113
|
+
escaping = true;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (char === stringQuote) {
|
|
117
|
+
inString = false;
|
|
118
|
+
}
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if ((char === '"' || char === "'") && !inString) {
|
|
122
|
+
inString = true;
|
|
123
|
+
stringQuote = char;
|
|
124
|
+
normalized += char;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (char === "/" && nextChar === "/") {
|
|
128
|
+
inLineComment = true;
|
|
129
|
+
index++;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (char === "/" && nextChar === "*") {
|
|
133
|
+
inBlockComment = true;
|
|
134
|
+
index++;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (char === ",") {
|
|
138
|
+
let lookahead = index + 1;
|
|
139
|
+
while (lookahead < content.length) {
|
|
140
|
+
const lookaheadChar = content[lookahead];
|
|
141
|
+
const lookaheadNextChar = content[lookahead + 1];
|
|
142
|
+
if (lookaheadChar !== void 0 && /\s/.test(lookaheadChar)) {
|
|
143
|
+
lookahead++;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (lookaheadChar === "/" && lookaheadNextChar === "/") {
|
|
147
|
+
lookahead += 2;
|
|
148
|
+
while (lookahead < content.length && content[lookahead] !== "\n") {
|
|
149
|
+
lookahead++;
|
|
150
|
+
}
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (lookaheadChar === "/" && lookaheadNextChar === "*") {
|
|
154
|
+
lookahead += 2;
|
|
155
|
+
while (lookahead < content.length && !(content[lookahead] === "*" && content[lookahead + 1] === "/")) {
|
|
156
|
+
lookahead++;
|
|
157
|
+
}
|
|
158
|
+
lookahead += 2;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (lookaheadChar === "}" || lookaheadChar === "]") {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
normalized += char;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
if (lookahead >= content.length) {
|
|
168
|
+
normalized += char;
|
|
169
|
+
}
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
normalized += char;
|
|
173
|
+
}
|
|
174
|
+
return JSON.parse(normalized);
|
|
175
|
+
}
|
|
176
|
+
function loadSettings(harnesstapDir) {
|
|
177
|
+
const path = settingsPath(harnesstapDir);
|
|
178
|
+
if (!existsSync(path)) return DEFAULTS;
|
|
179
|
+
try {
|
|
180
|
+
const raw = parseJsonc(readFileSync(path, "utf-8"));
|
|
181
|
+
const hours = raw.plugins?.refreshMaxAgeHours;
|
|
182
|
+
const marketplaceMinutes = raw.plugins?.marketplaceRefreshMaxAgeMinutes;
|
|
183
|
+
const limit = raw.pluginVersionHistoryLimit;
|
|
184
|
+
const pluginResources = raw.harnessSync?.pluginResources;
|
|
185
|
+
return {
|
|
186
|
+
plugins: {
|
|
187
|
+
refreshMaxAgeHours: typeof hours === "number" && hours > 0 ? hours : DEFAULTS.plugins.refreshMaxAgeHours,
|
|
188
|
+
marketplaceRefreshMaxAgeMinutes: typeof marketplaceMinutes === "number" && marketplaceMinutes > 0 ? marketplaceMinutes : DEFAULTS.plugins.marketplaceRefreshMaxAgeMinutes,
|
|
189
|
+
marketplaces: parseMarketplaces(raw.plugins?.marketplaces)
|
|
190
|
+
},
|
|
191
|
+
pluginVersionHistoryLimit: typeof limit === "number" && Number.isInteger(limit) && limit >= 1 ? limit : DEFAULTS.pluginVersionHistoryLimit,
|
|
192
|
+
harnessSync: {
|
|
193
|
+
pluginResources: isPluginResourceMode(pluginResources) ? pluginResources : DEFAULTS.harnessSync.pluginResources
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
} catch {
|
|
197
|
+
return DEFAULTS;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function readToolkitConfigRecord(harnesstapDir, path = settingsPath(harnesstapDir)) {
|
|
201
|
+
if (!existsSync(path)) {
|
|
202
|
+
return {};
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
const parsed = parseJsonc(readFileSync(path, "utf-8"));
|
|
206
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
207
|
+
return parsed;
|
|
208
|
+
}
|
|
209
|
+
return {};
|
|
210
|
+
} catch {
|
|
211
|
+
return {};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function writeToolkitConfigRecord(harnesstapDir, record, path = settingsPath(harnesstapDir)) {
|
|
215
|
+
mkdirSync(harnesstapDir, { recursive: true });
|
|
216
|
+
writeFileSync(path, `${JSON.stringify(record, null, 2)}
|
|
217
|
+
`, "utf-8");
|
|
218
|
+
}
|
|
219
|
+
function saveSettings(harnesstapDir, settings) {
|
|
220
|
+
const path = settingsPath(harnesstapDir);
|
|
221
|
+
const existing = readToolkitConfigRecord(harnesstapDir, path);
|
|
222
|
+
writeToolkitConfigRecord(
|
|
223
|
+
harnesstapDir,
|
|
224
|
+
{
|
|
225
|
+
...existing,
|
|
226
|
+
plugins: settings.plugins,
|
|
227
|
+
pluginVersionHistoryLimit: settings.pluginVersionHistoryLimit,
|
|
228
|
+
harnessSync: settings.harnessSync
|
|
229
|
+
},
|
|
230
|
+
path
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export {
|
|
235
|
+
DEFAULT_PLUGIN_RESOURCE_MODE,
|
|
236
|
+
parsePluginResourceMode,
|
|
237
|
+
DEFAULT_MARKETPLACE_REFRESH_MAX_AGE_MINUTES,
|
|
238
|
+
marketplaceRefreshMaxAgeMs,
|
|
239
|
+
parseTrackedBranches,
|
|
240
|
+
parseJsonc,
|
|
241
|
+
loadSettings,
|
|
242
|
+
saveSettings
|
|
243
|
+
};
|
|
244
|
+
//# sourceMappingURL=chunk-VQVUJYYY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/plugin-resource-mode.ts","../src/config/settings.ts"],"sourcesContent":["export const PLUGIN_RESOURCE_MODES = [\"symlink\", \"copy\", \"clone\"] as const;\n\nexport type PluginResourceMode = (typeof PLUGIN_RESOURCE_MODES)[number];\n\nexport const DEFAULT_PLUGIN_RESOURCE_MODE: PluginResourceMode = \"symlink\";\n\nexport function isPluginResourceMode(value: unknown): value is PluginResourceMode {\n return value === \"symlink\" || value === \"copy\" || value === \"clone\";\n}\n\nexport function parsePluginResourceMode(\n value: string | undefined,\n): PluginResourceMode {\n if (isPluginResourceMode(value)) return value;\n throw new Error(\n `Invalid plugin resource mode: ${value}. Use symlink, copy, or clone.`,\n );\n}\n","import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport {\n DEFAULT_PLUGIN_RESOURCE_MODE,\n isPluginResourceMode,\n type PluginResourceMode,\n} from \"../services/plugin-resource-mode.js\";\n\nexport type PluginMarketplacePlatform =\n | \"claude-code\"\n | \"cursor\"\n | \"goose\"\n | \"copilot-cli\";\n\nexport interface PluginMarketplaceEntry {\n name: string;\n url: string;\n platforms: PluginMarketplacePlatform[];\n /** Extra git branches to catalog. Empty/omitted tracks only the default branch. */\n trackedBranches?: string[];\n}\n\nexport interface HarnesstapSettings {\n plugins: {\n refreshMaxAgeHours: number;\n marketplaceRefreshMaxAgeMinutes: number;\n marketplaces: PluginMarketplaceEntry[];\n };\n pluginVersionHistoryLimit: number;\n harnessSync: {\n pluginResources: PluginResourceMode;\n };\n}\n\nconst VALID_PLATFORMS = new Set<PluginMarketplacePlatform>([\n \"claude-code\",\n \"cursor\",\n \"goose\",\n \"copilot-cli\",\n]);\n\nexport const DEFAULT_MARKETPLACE_REFRESH_MAX_AGE_MINUTES = 60;\n\nexport function marketplaceRefreshMaxAgeMs(minutes: number): number {\n return minutes * 60 * 1000;\n}\n\nconst DEFAULTS: HarnesstapSettings = {\n plugins: {\n refreshMaxAgeHours: 24,\n marketplaceRefreshMaxAgeMinutes: DEFAULT_MARKETPLACE_REFRESH_MAX_AGE_MINUTES,\n marketplaces: [],\n },\n pluginVersionHistoryLimit: 10,\n harnessSync: { pluginResources: DEFAULT_PLUGIN_RESOURCE_MODE },\n};\n\nfunction isPluginMarketplacePlatform(\n value: unknown,\n): value is PluginMarketplacePlatform {\n return (\n typeof value === \"string\" &&\n VALID_PLATFORMS.has(value as PluginMarketplacePlatform)\n );\n}\n\nexport function parseTrackedBranches(value: unknown): string[] {\n if (!Array.isArray(value)) return [];\n\n const seen = new Set<string>();\n const branches: string[] = [];\n for (const item of value) {\n if (typeof item !== \"string\") continue;\n const trimmed = item.trim();\n if (!trimmed || seen.has(trimmed)) continue;\n seen.add(trimmed);\n branches.push(trimmed);\n }\n return branches;\n}\n\nexport function settingsPath(harnesstapDir: string): string {\n return existsSync(join(harnesstapDir, \"config.jsonc\"))\n ? join(harnesstapDir, \"config.jsonc\")\n : join(harnesstapDir, \"config.json\");\n}\n\nexport function parseMarketplaces(value: unknown): PluginMarketplaceEntry[] {\n if (!Array.isArray(value)) return [];\n\n const marketplaces: PluginMarketplaceEntry[] = [];\n for (const row of value) {\n if (typeof row !== \"object\" || row === null) continue;\n\n const record = row as Record<string, unknown>;\n const name = record.name;\n const url = record.url;\n const platforms = record.platforms;\n\n if (typeof name !== \"string\") continue;\n const trimmedName = name.trim();\n if (trimmedName.length === 0) continue;\n if (typeof url !== \"string\") continue;\n const trimmedUrl = url.trim();\n if (trimmedUrl.length === 0) continue;\n if (!Array.isArray(platforms)) continue;\n\n const parsedPlatforms = platforms.filter(isPluginMarketplacePlatform);\n if (parsedPlatforms.length === 0) continue;\n\n const trackedBranches = parseTrackedBranches(record.trackedBranches);\n marketplaces.push({\n name: trimmedName,\n url: trimmedUrl,\n platforms: parsedPlatforms,\n ...(trackedBranches.length > 0 ? { trackedBranches } : {}),\n });\n }\n\n return marketplaces;\n}\n\nexport function parseJsonc(content: string): unknown {\n let normalized = \"\";\n let inString = false;\n let stringQuote = '\"';\n let escaping = false;\n let inLineComment = false;\n let inBlockComment = false;\n\n for (let index = 0; index < content.length; index++) {\n const char = content[index];\n const nextChar = content[index + 1];\n\n if (inLineComment) {\n if (char === \"\\n\") {\n inLineComment = false;\n normalized += char;\n }\n continue;\n }\n\n if (inBlockComment) {\n if (char === \"*\" && nextChar === \"/\") {\n inBlockComment = false;\n index++;\n }\n continue;\n }\n\n if (inString) {\n normalized += char;\n if (escaping) {\n escaping = false;\n continue;\n }\n if (char === \"\\\\\") {\n escaping = true;\n continue;\n }\n if (char === stringQuote) {\n inString = false;\n }\n continue;\n }\n\n if ((char === '\"' || char === \"'\") && !inString) {\n inString = true;\n stringQuote = char;\n normalized += char;\n continue;\n }\n\n if (char === \"/\" && nextChar === \"/\") {\n inLineComment = true;\n index++;\n continue;\n }\n\n if (char === \"/\" && nextChar === \"*\") {\n inBlockComment = true;\n index++;\n continue;\n }\n\n if (char === \",\") {\n let lookahead = index + 1;\n while (lookahead < content.length) {\n const lookaheadChar = content[lookahead];\n const lookaheadNextChar = content[lookahead + 1];\n\n if (lookaheadChar !== undefined && /\\s/.test(lookaheadChar)) {\n lookahead++;\n continue;\n }\n\n if (lookaheadChar === \"/\" && lookaheadNextChar === \"/\") {\n lookahead += 2;\n while (lookahead < content.length && content[lookahead] !== \"\\n\") {\n lookahead++;\n }\n continue;\n }\n\n if (lookaheadChar === \"/\" && lookaheadNextChar === \"*\") {\n lookahead += 2;\n while (\n lookahead < content.length &&\n !(content[lookahead] === \"*\" && content[lookahead + 1] === \"/\")\n ) {\n lookahead++;\n }\n lookahead += 2;\n continue;\n }\n\n if (lookaheadChar === \"}\" || lookaheadChar === \"]\") {\n break;\n }\n\n normalized += char;\n break;\n }\n\n if (lookahead >= content.length) {\n normalized += char;\n }\n continue;\n }\n\n normalized += char;\n }\n\n return JSON.parse(normalized);\n}\n\nexport function loadSettings(harnesstapDir: string): HarnesstapSettings {\n const path = settingsPath(harnesstapDir);\n if (!existsSync(path)) return DEFAULTS;\n try {\n const raw = parseJsonc(readFileSync(path, \"utf-8\")) as Partial<HarnesstapSettings> & {\n harnessSync?: { pluginResources?: unknown };\n };\n const hours = raw.plugins?.refreshMaxAgeHours;\n const marketplaceMinutes = raw.plugins?.marketplaceRefreshMaxAgeMinutes;\n const limit = raw.pluginVersionHistoryLimit;\n const pluginResources = raw.harnessSync?.pluginResources;\n return {\n plugins: {\n refreshMaxAgeHours:\n typeof hours === \"number\" && hours > 0\n ? hours\n : DEFAULTS.plugins.refreshMaxAgeHours,\n marketplaceRefreshMaxAgeMinutes:\n typeof marketplaceMinutes === \"number\" && marketplaceMinutes > 0\n ? marketplaceMinutes\n : DEFAULTS.plugins.marketplaceRefreshMaxAgeMinutes,\n marketplaces: parseMarketplaces(raw.plugins?.marketplaces),\n },\n pluginVersionHistoryLimit:\n typeof limit === \"number\" && Number.isInteger(limit) && limit >= 1\n ? limit\n : DEFAULTS.pluginVersionHistoryLimit,\n harnessSync: {\n pluginResources: isPluginResourceMode(pluginResources)\n ? pluginResources\n : DEFAULTS.harnessSync.pluginResources,\n },\n };\n } catch {\n return DEFAULTS;\n }\n}\n\nexport function readToolkitConfigRecord(\n harnesstapDir: string,\n path = settingsPath(harnesstapDir),\n): Record<string, unknown> {\n if (!existsSync(path)) {\n return {};\n }\n try {\n const parsed = parseJsonc(readFileSync(path, \"utf-8\"));\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed as Record<string, unknown>;\n }\n return {};\n } catch {\n return {};\n }\n}\n\nexport function writeToolkitConfigRecord(\n harnesstapDir: string,\n record: Record<string, unknown>,\n path = settingsPath(harnesstapDir),\n): void {\n mkdirSync(harnesstapDir, { recursive: true });\n writeFileSync(path, `${JSON.stringify(record, null, 2)}\\n`, \"utf-8\");\n}\n\nexport function saveSettings(\n harnesstapDir: string,\n settings: HarnesstapSettings,\n): void {\n const path = settingsPath(harnesstapDir);\n const existing = readToolkitConfigRecord(harnesstapDir, path);\n writeToolkitConfigRecord(\n harnesstapDir,\n {\n ...existing,\n plugins: settings.plugins,\n pluginVersionHistoryLimit: settings.pluginVersionHistoryLimit,\n harnessSync: settings.harnessSync,\n },\n path,\n );\n}\n"],"mappings":";AAIO,IAAM,+BAAmD;AAEzD,SAAS,qBAAqB,OAA6C;AAChF,SAAO,UAAU,aAAa,UAAU,UAAU,UAAU;AAC9D;AAEO,SAAS,wBACd,OACoB;AACpB,MAAI,qBAAqB,KAAK,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AAS,SAAS;AAAA,MAClB,2BAA2B,SAAS;AAAA,MACpC,aAAa,SAAS;AAAA,IACxB;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// src/services/project-config-messages.ts
|
|
2
|
+
var MISSING_PROJECT_CONFIG_MESSAGE = "No project config found. Run `ht config init` to create `apm.yml`.";
|
|
3
|
+
var PROJECT_CONFIG_EXISTS_MESSAGE = "Project config already exists. Pass --force to overwrite, or edit `apm.yml` directly.";
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
MISSING_PROJECT_CONFIG_MESSAGE,
|
|
7
|
+
PROJECT_CONFIG_EXISTS_MESSAGE
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=chunk-VZQG2JDV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/project-config-messages.ts"],"sourcesContent":["export const MISSING_PROJECT_CONFIG_MESSAGE =\n \"No project config found. Run `ht config init` to create `apm.yml`.\";\n\nexport const PROJECT_CONFIG_EXISTS_MESSAGE =\n \"Project config already exists. Pass --force to overwrite, or edit `apm.yml` directly.\";\n"],"mappings":";AAAO,IAAM,iCACX;AAEK,IAAM,gCACX;","names":[]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProfileCommand,
|
|
3
|
+
getActiveProfileName,
|
|
4
|
+
getGlobalActiveEnvironmentName,
|
|
5
|
+
renameProfileCommand,
|
|
6
|
+
setActiveProfileName,
|
|
7
|
+
setGlobalActiveEnvironment
|
|
8
|
+
} from "./chunk-KCQC7YBK.js";
|
|
9
|
+
import {
|
|
10
|
+
GLOBAL_DEFAULT_PROFILE_NAME,
|
|
11
|
+
LEGACY_DEFAULT_PROFILE_NAME,
|
|
12
|
+
PROFILE_PLUGIN_TAG,
|
|
13
|
+
isProfilePlugin,
|
|
14
|
+
listProfilePlugins
|
|
15
|
+
} from "./chunk-SY7G5QEI.js";
|
|
16
|
+
import {
|
|
17
|
+
addResourceToPlugin,
|
|
18
|
+
createEnvironment,
|
|
19
|
+
createPlugin,
|
|
20
|
+
diskCaptureHarnessScope,
|
|
21
|
+
getPluginResources,
|
|
22
|
+
listEnvironments,
|
|
23
|
+
listPlugins,
|
|
24
|
+
listResources
|
|
25
|
+
} from "./chunk-2EIJYDNI.js";
|
|
26
|
+
|
|
27
|
+
// src/services/ensure-default-environment.ts
|
|
28
|
+
function ensureDefaultEnvironment() {
|
|
29
|
+
const existing = listEnvironments();
|
|
30
|
+
const [first] = existing;
|
|
31
|
+
if (first) {
|
|
32
|
+
return { environment: first, created: false };
|
|
33
|
+
}
|
|
34
|
+
const environment = createEnvironment({
|
|
35
|
+
name: "default",
|
|
36
|
+
description: "Default environment"
|
|
37
|
+
});
|
|
38
|
+
if (!getGlobalActiveEnvironmentName()) {
|
|
39
|
+
setGlobalActiveEnvironment(environment.name);
|
|
40
|
+
}
|
|
41
|
+
return { environment, created: true };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/services/ensure-default-profile.ts
|
|
45
|
+
function findProfileByName(name) {
|
|
46
|
+
return listPlugins().find((entry) => entry.name === name && isProfilePlugin(entry));
|
|
47
|
+
}
|
|
48
|
+
function migrateLegacyDefaultProfile() {
|
|
49
|
+
const already = findProfileByName(GLOBAL_DEFAULT_PROFILE_NAME);
|
|
50
|
+
if (already) {
|
|
51
|
+
return already;
|
|
52
|
+
}
|
|
53
|
+
const legacy = findProfileByName(LEGACY_DEFAULT_PROFILE_NAME);
|
|
54
|
+
if (!legacy) {
|
|
55
|
+
return void 0;
|
|
56
|
+
}
|
|
57
|
+
renameProfileCommand(legacy.name, GLOBAL_DEFAULT_PROFILE_NAME);
|
|
58
|
+
return findProfileByName(GLOBAL_DEFAULT_PROFILE_NAME);
|
|
59
|
+
}
|
|
60
|
+
function ensureDefaultProfilePlugin() {
|
|
61
|
+
migrateLegacyDefaultProfile();
|
|
62
|
+
const existing = listProfilePlugins();
|
|
63
|
+
const [first] = existing;
|
|
64
|
+
if (first) {
|
|
65
|
+
return { plugin: first, created: false };
|
|
66
|
+
}
|
|
67
|
+
const { plugin, created } = createProfileCommand({
|
|
68
|
+
name: GLOBAL_DEFAULT_PROFILE_NAME,
|
|
69
|
+
description: "Global default profile"
|
|
70
|
+
});
|
|
71
|
+
if (!getActiveProfileName()) {
|
|
72
|
+
setActiveProfileName(plugin.name);
|
|
73
|
+
}
|
|
74
|
+
return { plugin, created };
|
|
75
|
+
}
|
|
76
|
+
function libraryResourcesForDefaultProfile() {
|
|
77
|
+
return listResources().filter((resource) => resource.type !== "plugin");
|
|
78
|
+
}
|
|
79
|
+
function seedDefaultProfileFromLibrary() {
|
|
80
|
+
migrateLegacyDefaultProfile();
|
|
81
|
+
let plugin = findProfileByName(GLOBAL_DEFAULT_PROFILE_NAME);
|
|
82
|
+
let created = false;
|
|
83
|
+
if (!plugin) {
|
|
84
|
+
const [existing] = listProfilePlugins();
|
|
85
|
+
if (existing) {
|
|
86
|
+
return { plugin: existing, created: false };
|
|
87
|
+
}
|
|
88
|
+
plugin = createPlugin({
|
|
89
|
+
name: GLOBAL_DEFAULT_PROFILE_NAME,
|
|
90
|
+
version: "1.0.0",
|
|
91
|
+
description: "Bootstrap profile from init",
|
|
92
|
+
tags: [PROFILE_PLUGIN_TAG]
|
|
93
|
+
});
|
|
94
|
+
created = true;
|
|
95
|
+
}
|
|
96
|
+
const attachedMaterial = getPluginResources(plugin.id).filter(
|
|
97
|
+
(resource) => resource.type !== "plugin"
|
|
98
|
+
);
|
|
99
|
+
if (attachedMaterial.length === 0) {
|
|
100
|
+
for (const resource of libraryResourcesForDefaultProfile()) {
|
|
101
|
+
addResourceToPlugin(plugin.id, resource.id, diskCaptureHarnessScope(resource));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (created || !getActiveProfileName()) {
|
|
105
|
+
setActiveProfileName(plugin.name);
|
|
106
|
+
}
|
|
107
|
+
return { plugin, created };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export {
|
|
111
|
+
ensureDefaultEnvironment,
|
|
112
|
+
ensureDefaultProfilePlugin,
|
|
113
|
+
seedDefaultProfileFromLibrary
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=chunk-XFZQVYIN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/ensure-default-environment.ts","../src/services/ensure-default-profile.ts"],"sourcesContent":["import {\n createEnvironment,\n listEnvironments,\n} from \"../models/environment.js\";\nimport type { Environment } from \"../types.js\";\nimport {\n getGlobalActiveEnvironmentName,\n setGlobalActiveEnvironment,\n} from \"./environment-session.js\";\n\nexport interface EnsureDefaultEnvironmentResult {\n environment: Environment;\n created: boolean;\n}\n\n/**\n * When no environments exist, seed a `default` environment and point the home\n * active environment at it if unset.\n */\nexport function ensureDefaultEnvironment(): EnsureDefaultEnvironmentResult {\n const existing = listEnvironments();\n const [first] = existing;\n if (first) {\n return { environment: first, created: false };\n }\n\n const environment = createEnvironment({\n name: \"default\",\n description: \"Default environment\",\n });\n\n if (!getGlobalActiveEnvironmentName()) {\n setGlobalActiveEnvironment(environment.name);\n }\n\n return { environment, created: true };\n}\n","import {\n GLOBAL_DEFAULT_PROFILE_NAME,\n LEGACY_DEFAULT_PROFILE_NAME,\n PROFILE_PLUGIN_TAG,\n isProfilePlugin,\n listProfilePlugins,\n} from \"../constants/profile.js\";\nimport {\n addResourceToPlugin,\n createPlugin,\n getPluginResources,\n listPlugins,\n} from \"../models/plugin-model.js\";\nimport { listResources } from \"../models/resource.js\";\nimport type { Plugin } from \"../types.js\";\nimport {\n getActiveProfileName,\n setActiveProfileName,\n} from \"./active-profile.js\";\nimport { createProfileCommand, renameProfileCommand } from \"./profile-commands.js\";\nimport { diskCaptureHarnessScope } from \"./harness-scope.js\";\n\nexport interface EnsureDefaultProfileResult {\n plugin: Plugin;\n created: boolean;\n}\n\nfunction findProfileByName(name: string): Plugin | undefined {\n return listPlugins().find((entry) => entry.name === name && isProfilePlugin(entry));\n}\n\n/**\n * Rename a leftover `default` profile plugin to `global default` when the\n * new name is free.\n */\nexport function migrateLegacyDefaultProfile(): Plugin | undefined {\n const already = findProfileByName(GLOBAL_DEFAULT_PROFILE_NAME);\n if (already) {\n return already;\n }\n const legacy = findProfileByName(LEGACY_DEFAULT_PROFILE_NAME);\n if (!legacy) {\n return undefined;\n }\n renameProfileCommand(legacy.name, GLOBAL_DEFAULT_PROFILE_NAME);\n return findProfileByName(GLOBAL_DEFAULT_PROFILE_NAME);\n}\n\n/**\n * When no profile plugins exist, seed a `global default` profile (same name as\n * `ht init`) and point the active-profile pointer at it if unset.\n */\nexport function ensureDefaultProfilePlugin(): EnsureDefaultProfileResult {\n migrateLegacyDefaultProfile();\n const existing = listProfilePlugins();\n const [first] = existing;\n if (first) {\n return { plugin: first, created: false };\n }\n\n const { plugin, created } = createProfileCommand({\n name: GLOBAL_DEFAULT_PROFILE_NAME,\n description: \"Global default profile\",\n });\n\n if (!getActiveProfileName()) {\n setActiveProfileName(plugin.name);\n }\n\n return { plugin, created };\n}\n\nfunction libraryResourcesForDefaultProfile() {\n return listResources().filter((resource) => resource.type !== \"plugin\");\n}\n\n/**\n * Seed `global default` only when no profile plugins exist (first start).\n * If that profile is already present and empty, attach library resources.\n * Do not recreate it after a rename or when any other profile is present.\n */\nexport function seedDefaultProfileFromLibrary(): EnsureDefaultProfileResult {\n migrateLegacyDefaultProfile();\n let plugin = findProfileByName(GLOBAL_DEFAULT_PROFILE_NAME);\n let created = false;\n if (!plugin) {\n const [existing] = listProfilePlugins();\n if (existing) {\n return { plugin: existing, created: false };\n }\n plugin = createPlugin({\n name: GLOBAL_DEFAULT_PROFILE_NAME,\n version: \"1.0.0\",\n description: \"Bootstrap profile from init\",\n tags: [PROFILE_PLUGIN_TAG],\n });\n created = true;\n }\n\n const attachedMaterial = getPluginResources(plugin.id).filter(\n (resource) => resource.type !== \"plugin\",\n );\n if (attachedMaterial.length === 0) {\n for (const resource of libraryResourcesForDefaultProfile()) {\n addResourceToPlugin(plugin.id, resource.id, diskCaptureHarnessScope(resource));\n }\n }\n\n if (created || !getActiveProfileName()) {\n setActiveProfileName(plugin.name);\n }\n return { plugin, created };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBO,SAAS,2BAA2D;AACzE,QAAM,WAAW,iBAAiB;AAClC,QAAM,CAAC,KAAK,IAAI;AAChB,MAAI,OAAO;AACT,WAAO,EAAE,aAAa,OAAO,SAAS,MAAM;AAAA,EAC9C;AAEA,QAAM,cAAc,kBAAkB;AAAA,IACpC,MAAM;AAAA,IACN,aAAa;AAAA,EACf,CAAC;AAED,MAAI,CAAC,+BAA+B,GAAG;AACrC,+BAA2B,YAAY,IAAI;AAAA,EAC7C;AAEA,SAAO,EAAE,aAAa,SAAS,KAAK;AACtC;;;ACTA,SAAS,kBAAkB,MAAkC;AAC3D,SAAO,YAAY,EAAE,KAAK,CAAC,UAAU,MAAM,SAAS,QAAQ,gBAAgB,KAAK,CAAC;AACpF;AAMO,SAAS,8BAAkD;AAChE,QAAM,UAAU,kBAAkB,2BAA2B;AAC7D,MAAI,SAAS;AACX,WAAO;AAAA,EACT;AACA,QAAM,SAAS,kBAAkB,2BAA2B;AAC5D,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AACA,uBAAqB,OAAO,MAAM,2BAA2B;AAC7D,SAAO,kBAAkB,2BAA2B;AACtD;AAMO,SAAS,6BAAyD;AACvE,8BAA4B;AAC5B,QAAM,WAAW,mBAAmB;AACpC,QAAM,CAAC,KAAK,IAAI;AAChB,MAAI,OAAO;AACT,WAAO,EAAE,QAAQ,OAAO,SAAS,MAAM;AAAA,EACzC;AAEA,QAAM,EAAE,QAAQ,QAAQ,IAAI,qBAAqB;AAAA,IAC/C,MAAM;AAAA,IACN,aAAa;AAAA,EACf,CAAC;AAED,MAAI,CAAC,qBAAqB,GAAG;AAC3B,yBAAqB,OAAO,IAAI;AAAA,EAClC;AAEA,SAAO,EAAE,QAAQ,QAAQ;AAC3B;AAEA,SAAS,oCAAoC;AAC3C,SAAO,cAAc,EAAE,OAAO,CAAC,aAAa,SAAS,SAAS,QAAQ;AACxE;AAOO,SAAS,gCAA4D;AAC1E,8BAA4B;AAC5B,MAAI,SAAS,kBAAkB,2BAA2B;AAC1D,MAAI,UAAU;AACd,MAAI,CAAC,QAAQ;AACX,UAAM,CAAC,QAAQ,IAAI,mBAAmB;AACtC,QAAI,UAAU;AACZ,aAAO,EAAE,QAAQ,UAAU,SAAS,MAAM;AAAA,IAC5C;AACA,aAAS,aAAa;AAAA,MACpB,MAAM;AAAA,MACN,SAAS;AAAA,MACT,aAAa;AAAA,MACb,MAAM,CAAC,kBAAkB;AAAA,IAC3B,CAAC;AACD,cAAU;AAAA,EACZ;AAEA,QAAM,mBAAmB,mBAAmB,OAAO,EAAE,EAAE;AAAA,IACrD,CAAC,aAAa,SAAS,SAAS;AAAA,EAClC;AACA,MAAI,iBAAiB,WAAW,GAAG;AACjC,eAAW,YAAY,kCAAkC,GAAG;AAC1D,0BAAoB,OAAO,IAAI,SAAS,IAAI,wBAAwB,QAAQ,CAAC;AAAA,IAC/E;AAAA,EACF;AAEA,MAAI,WAAW,CAAC,qBAAqB,GAAG;AACtC,yBAAqB,OAAO,IAAI;AAAA,EAClC;AACA,SAAO,EAAE,QAAQ,QAAQ;AAC3B;","names":[]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/ui/list-viewport.ts
|
|
2
|
+
var DEFAULT_SECTION_TABLE_OVERHEAD_LINES = 5;
|
|
3
|
+
var BORDERED_TABLE_LINES_PER_ROW = 2;
|
|
4
|
+
var VIEWPORT_CHROME_LINES = {
|
|
5
|
+
resourceList: 5,
|
|
6
|
+
catalogBrowse: 8,
|
|
7
|
+
catalogSearch: 10,
|
|
8
|
+
pluginEdit: 7,
|
|
9
|
+
environmentEdit: 5,
|
|
10
|
+
environmentList: 5,
|
|
11
|
+
pluginListBrowse: 6
|
|
12
|
+
};
|
|
13
|
+
function computeRemoteListFetchLimit(terminalRowCount, chromeLines, opts) {
|
|
14
|
+
const visible = computeMaxVisibleTableRows(terminalRowCount, chromeLines);
|
|
15
|
+
const min = opts?.min ?? 10;
|
|
16
|
+
if (opts?.search) {
|
|
17
|
+
return Math.max(min, 25, visible + 5);
|
|
18
|
+
}
|
|
19
|
+
return Math.max(min, visible + 5);
|
|
20
|
+
}
|
|
21
|
+
function computeMaxVisibleRows(terminalRowCount, chromeLines = VIEWPORT_CHROME_LINES.resourceList, sectionOverhead = DEFAULT_SECTION_TABLE_OVERHEAD_LINES) {
|
|
22
|
+
const budget = terminalRowCount - chromeLines - sectionOverhead;
|
|
23
|
+
return Math.max(3, budget - 1);
|
|
24
|
+
}
|
|
25
|
+
function computeMaxVisibleTableRows(terminalRowCount, chromeLines = VIEWPORT_CHROME_LINES.resourceList, opts) {
|
|
26
|
+
const sectionOverhead = opts?.sectionOverhead ?? DEFAULT_SECTION_TABLE_OVERHEAD_LINES;
|
|
27
|
+
const linesPerRow = (opts?.linesPerRow ?? BORDERED_TABLE_LINES_PER_ROW) + (opts?.wrapReservePerRow ?? 1);
|
|
28
|
+
const bodyBudget = terminalRowCount - chromeLines - sectionOverhead;
|
|
29
|
+
if (bodyBudget <= linesPerRow) {
|
|
30
|
+
return 2;
|
|
31
|
+
}
|
|
32
|
+
return Math.max(2, Math.floor(bodyBudget / linesPerRow) - 1);
|
|
33
|
+
}
|
|
34
|
+
function resolveSectionViewport(sectionLength, activeIndex, maxVisibleRows) {
|
|
35
|
+
if (sectionLength <= maxVisibleRows) {
|
|
36
|
+
return { start: 0, end: sectionLength };
|
|
37
|
+
}
|
|
38
|
+
const middle = Math.floor(maxVisibleRows / 2);
|
|
39
|
+
let start = activeIndex - middle;
|
|
40
|
+
if (start < 0) start = 0;
|
|
41
|
+
if (start + maxVisibleRows > sectionLength) {
|
|
42
|
+
start = sectionLength - maxVisibleRows;
|
|
43
|
+
}
|
|
44
|
+
return { start, end: start + maxVisibleRows };
|
|
45
|
+
}
|
|
46
|
+
var HINT_SEPARATOR = " \xB7 ";
|
|
47
|
+
var HINT_INDENT = " ";
|
|
48
|
+
function renderFoldedHintLine(segments, maxWidth) {
|
|
49
|
+
if (segments.length === 0) {
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
const normalizedWidth = Math.max(10, maxWidth);
|
|
53
|
+
const lines = [];
|
|
54
|
+
let current = HINT_INDENT;
|
|
55
|
+
for (const segment of segments) {
|
|
56
|
+
const piece = segment.length > normalizedWidth - HINT_INDENT.length ? `${segment.slice(0, Math.max(0, normalizedWidth - HINT_INDENT.length - 3))}...` : segment;
|
|
57
|
+
const candidate = current === HINT_INDENT ? `${current}${piece}` : `${current}${HINT_SEPARATOR}${piece}`;
|
|
58
|
+
if (candidate.length <= normalizedWidth) {
|
|
59
|
+
current = candidate;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (current !== HINT_INDENT) {
|
|
63
|
+
lines.push(current);
|
|
64
|
+
current = `${HINT_INDENT}${piece}`;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
lines.push(candidate);
|
|
68
|
+
current = HINT_INDENT;
|
|
69
|
+
}
|
|
70
|
+
if (current !== HINT_INDENT) {
|
|
71
|
+
lines.push(current);
|
|
72
|
+
}
|
|
73
|
+
return lines.join("\n");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
VIEWPORT_CHROME_LINES,
|
|
78
|
+
computeRemoteListFetchLimit,
|
|
79
|
+
computeMaxVisibleRows,
|
|
80
|
+
computeMaxVisibleTableRows,
|
|
81
|
+
resolveSectionViewport,
|
|
82
|
+
renderFoldedHintLine
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=chunk-XGTTOO4R.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ui/list-viewport.ts"],"sourcesContent":["export type SectionViewport = {\n start: number;\n end: number;\n};\n\nexport const DEFAULT_SECTION_TABLE_OVERHEAD_LINES = 5;\n\n/** cli-table3 bordered rows use a horizontal rule plus content (~2 lines each). */\nexport const BORDERED_TABLE_LINES_PER_ROW = 2;\n\nexport const VIEWPORT_CHROME_LINES = {\n resourceList: 5,\n catalogBrowse: 8,\n catalogSearch: 10,\n pluginEdit: 7,\n environmentEdit: 5,\n environmentList: 5,\n pluginListBrowse: 6,\n} as const;\n\nexport function computeRemoteListFetchLimit(\n terminalRowCount: number,\n chromeLines: number,\n opts?: { min?: number; search?: boolean },\n): number {\n const visible = computeMaxVisibleTableRows(terminalRowCount, chromeLines);\n const min = opts?.min ?? 10;\n if (opts?.search) {\n return Math.max(min, 25, visible + 5);\n }\n return Math.max(min, visible + 5);\n}\n\nexport function computeMaxVisibleRows(\n terminalRowCount: number,\n chromeLines: number = VIEWPORT_CHROME_LINES.resourceList,\n sectionOverhead: number = DEFAULT_SECTION_TABLE_OVERHEAD_LINES,\n): number {\n const budget = terminalRowCount - chromeLines - sectionOverhead;\n return Math.max(3, budget - 1);\n}\n\nexport function computeMaxVisibleTableRows(\n terminalRowCount: number,\n chromeLines: number = VIEWPORT_CHROME_LINES.resourceList,\n opts?: {\n sectionOverhead?: number;\n linesPerRow?: number;\n wrapReservePerRow?: number;\n },\n): number {\n const sectionOverhead = opts?.sectionOverhead ?? DEFAULT_SECTION_TABLE_OVERHEAD_LINES;\n const linesPerRow =\n (opts?.linesPerRow ?? BORDERED_TABLE_LINES_PER_ROW)\n + (opts?.wrapReservePerRow ?? 1);\n const bodyBudget = terminalRowCount - chromeLines - sectionOverhead;\n if (bodyBudget <= linesPerRow) {\n return 2;\n }\n return Math.max(2, Math.floor(bodyBudget / linesPerRow) - 1);\n}\n\nexport function resolveSectionViewport(\n sectionLength: number,\n activeIndex: number,\n maxVisibleRows: number,\n): SectionViewport {\n if (sectionLength <= maxVisibleRows) {\n return { start: 0, end: sectionLength };\n }\n const middle = Math.floor(maxVisibleRows / 2);\n let start = activeIndex - middle;\n if (start < 0) start = 0;\n if (start + maxVisibleRows > sectionLength) {\n start = sectionLength - maxVisibleRows;\n }\n return { start, end: start + maxVisibleRows };\n}\n\nexport function renderFlatOverflowHints(\n viewport: SectionViewport,\n totalLength: number,\n): string[] {\n const hints: string[] = [];\n if (viewport.start > 0) {\n hints.push(` ↑ ${viewport.start} above`);\n }\n if (viewport.end < totalLength) {\n hints.push(` ↓ ${totalLength - viewport.end} more`);\n }\n return hints;\n}\n\nconst HINT_SEPARATOR = \" · \";\nconst HINT_INDENT = \" \";\n\nexport function renderFoldedHintLine(segments: string[], maxWidth: number): string {\n if (segments.length === 0) {\n return \"\";\n }\n\n const normalizedWidth = Math.max(10, maxWidth);\n const lines: string[] = [];\n let current = HINT_INDENT;\n\n for (const segment of segments) {\n const piece =\n segment.length > normalizedWidth - HINT_INDENT.length\n ? `${segment.slice(0, Math.max(0, normalizedWidth - HINT_INDENT.length - 3))}...`\n : segment;\n\n const candidate =\n current === HINT_INDENT\n ? `${current}${piece}`\n : `${current}${HINT_SEPARATOR}${piece}`;\n\n if (candidate.length <= normalizedWidth) {\n current = candidate;\n continue;\n }\n\n if (current !== HINT_INDENT) {\n lines.push(current);\n current = `${HINT_INDENT}${piece}`;\n continue;\n }\n\n lines.push(candidate);\n current = HINT_INDENT;\n }\n\n if (current !== HINT_INDENT) {\n lines.push(current);\n }\n\n return lines.join(\"\\n\");\n}\n"],"mappings":";AAKO,IAAM,uCAAuC;AAG7C,IAAM,+BAA+B;AAErC,IAAM,wBAAwB;AAAA,EACnC,cAAc;AAAA,EACd,eAAe;AAAA,EACf,eAAe;AAAA,EACf,YAAY;AAAA,EACZ,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,kBAAkB;AACpB;AAEO,SAAS,4BACd,kBACA,aACA,MACQ;AACR,QAAM,UAAU,2BAA2B,kBAAkB,WAAW;AACxE,QAAM,MAAM,MAAM,OAAO;AACzB,MAAI,MAAM,QAAQ;AAChB,WAAO,KAAK,IA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,CAAC,QAC1E;AAEN,UAAM,YACJ,YAAY,cACR,GAAG,OAAO,GAAG,KAAK,KAClB,GAAG,OAAO,GAAG,cAAc,GAAG,KAAK;AAEzC,QAAI,UAAU,UAAU,iBAAiB;AACvC,gBAAU;AACV;AAAA,IACF;AAEA,QAAI,YAAY,aAAa;AAC3B,YAAM,KAAK,OAAO;AAClB,gBAAU,GAAG,WAAW,GAAG,KAAK;AAChC;AAAA,IACF;AAEA,UAAM,KAAK,SAAS;AACpB,cAAU;AAAA,EACZ;AAEA,MAAI,YAAY,aAAa;AAC3B,UAAM,KAAK,OAAO;AAAA,EACpB;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;","names":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDb
|
|
3
|
+
} from "./chunk-DWVAR4BP.js";
|
|
4
|
+
|
|
5
|
+
// src/models/snapshot.ts
|
|
6
|
+
import { ulid } from "ulid";
|
|
7
|
+
function rowToSnapshot(row) {
|
|
8
|
+
return {
|
|
9
|
+
...row,
|
|
10
|
+
state: JSON.parse(row.state)
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function createSnapshot(input) {
|
|
14
|
+
const db = getDb();
|
|
15
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
16
|
+
const id = ulid();
|
|
17
|
+
db.prepare(
|
|
18
|
+
`INSERT INTO snapshots (id, project_id, label, state, created_at)
|
|
19
|
+
VALUES (?, ?, ?, ?, ?)`
|
|
20
|
+
).run(id, input.project_id, input.label, JSON.stringify(input.state), now);
|
|
21
|
+
return { id, ...input, created_at: now };
|
|
22
|
+
}
|
|
23
|
+
function getSnapshot(id) {
|
|
24
|
+
const db = getDb();
|
|
25
|
+
const row = db.prepare("SELECT * FROM snapshots WHERE id = ?").get(id);
|
|
26
|
+
return row ? rowToSnapshot(row) : void 0;
|
|
27
|
+
}
|
|
28
|
+
function findSnapshotById(id, minPrefix = 8) {
|
|
29
|
+
const exact = getSnapshot(id);
|
|
30
|
+
if (exact) {
|
|
31
|
+
return exact;
|
|
32
|
+
}
|
|
33
|
+
if (id.length < minPrefix) {
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
const db = getDb();
|
|
37
|
+
const rows = db.prepare("SELECT * FROM snapshots WHERE id LIKE ?").all(`${id}%`);
|
|
38
|
+
if (rows.length !== 1) {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
const row = rows[0];
|
|
42
|
+
return row ? rowToSnapshot(row) : void 0;
|
|
43
|
+
}
|
|
44
|
+
function listSnapshots(projectId) {
|
|
45
|
+
const db = getDb();
|
|
46
|
+
const rows = db.prepare("SELECT * FROM snapshots WHERE project_id = ? ORDER BY created_at DESC").all(projectId);
|
|
47
|
+
return rows.map(rowToSnapshot);
|
|
48
|
+
}
|
|
49
|
+
function getLatestSnapshot(projectId) {
|
|
50
|
+
const snapshots = listSnapshots(projectId);
|
|
51
|
+
return snapshots[0];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
createSnapshot,
|
|
56
|
+
findSnapshotById,
|
|
57
|
+
listSnapshots,
|
|
58
|
+
getLatestSnapshot
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=chunk-XQFT4PEP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/models/snapshot.ts"],"sourcesContent":["import { getDb } from \"../db/connection.js\";\nimport { ulid } from \"ulid\";\nimport type { Snapshot, SnapshotState } from \"../types.js\";\n\ninterface SnapshotRow {\n id: string;\n project_id: string;\n label: string;\n state: string;\n created_at: string;\n}\n\nfunction rowToSnapshot(row: SnapshotRow): Snapshot {\n return {\n ...row,\n state: JSON.parse(row.state) as SnapshotState,\n };\n}\n\nexport function createSnapshot(input: {\n project_id: string;\n label: string;\n state: SnapshotState;\n}): Snapshot {\n const db = getDb();\n const now = new Date().toISOString();\n const id = ulid();\n\n db.prepare(\n `INSERT INTO snapshots (id, project_id, label, state, created_at)\n VALUES (?, ?, ?, ?, ?)`,\n ).run(id, input.project_id, input.label, JSON.stringify(input.state), now);\n\n return { id, ...input, created_at: now };\n}\n\nexport function getSnapshot(id: string): Snapshot | undefined {\n const db = getDb();\n const row = db.prepare(\"SELECT * FROM snapshots WHERE id = ?\").get(id) as\n | SnapshotRow\n | undefined;\n return row ? rowToSnapshot(row) : undefined;\n}\n\n/** Exact id, or a unique prefix of at least `minPrefix` characters. */\nexport function findSnapshotById(id: string, minPrefix = 8): Snapshot | undefined {\n const exact = getSnapshot(id);\n if (exact) {\n return exact;\n }\n if (id.length < minPrefix) {\n return undefined;\n }\n const db = getDb();\n const rows = db\n .prepare(\"SELECT * FROM snapshots WHERE id LIKE ?\")\n .all(`${id}%`) as SnapshotRow[];\n if (rows.length !== 1) {\n return undefined;\n }\n const row = rows[0];\n return row ? rowToSnapshot(row) : undefined;\n}\n\nexport function listSnapshots(projectId: string): Snapshot[] {\n const db = getDb();\n const rows = db\n .prepare(\"SELECT * FROM snapshots WHERE project_id = ? ORDER BY created_at DESC\")\n .all(projectId) as SnapshotRow[];\n return rows.map(rowToSnapshot);\n}\n\nexport function getLatestSnapshot(projectId: string): Snapshot | undefined {\n const snapshots = listSnapshots(projectId);\n return snapshots[0];\n}\n"],"mappings":";;;;;AACA,SAAS,YAAY;AAWrB,SAAS,cAAc,KAA4B;AACjD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,OAAO,KAAK,MAAM,IAAI,KAAK;AAAA,EAC7B;AACF;AAEO,SAAS,eAAe,OAIlB;AACX,QAAM,KAAK,MAAM;AACjB,QAAM,OAAM,oBAAI,KAAK,GAAE,YAAY;AACnC,QAAM,KAAK,KAAK;AAEhB,KAAG;AAAA,IACD;AAAA;AAAA,EAEF,EAAE,IAAI,IAAI,MAAM,YAAY,MAAM,OAAO,KAAK,UAAU,MAAM,KAAK,GAAG,GAAG;AAEzE,SAAO,EAAE,IAAI,GAAG,OAAO,YAAY,IAAI;AACzC;A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