@wrongstack/core 0.313.0 → 0.313.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/dist/chronicle/index.js +84 -6391
- package/dist/chronicle/project-server.js +84 -4868
- package/dist/chunk-2BUUIMQB.js +225 -0
- package/dist/chunk-2FK4WTFF.js +207 -0
- package/dist/chunk-2FQL4PDC.js +292 -0
- package/dist/chunk-2KKODIQU.js +2256 -0
- package/dist/chunk-2YU4WVBW.js +134 -0
- package/dist/chunk-3E244UDA.js +356 -0
- package/dist/chunk-3XPVB7BA.js +135 -0
- package/dist/chunk-4LJJYBAU.js +388 -0
- package/dist/chunk-4VWO3ZXL.js +342 -0
- package/dist/chunk-4XV6IR37.js +187 -0
- package/dist/chunk-4ZHTKJHM.js +183 -0
- package/dist/chunk-52RTVH4M.js +361 -0
- package/dist/chunk-57GEWK5X.js +26 -0
- package/dist/chunk-5DSMEVA4.js +931 -0
- package/dist/chunk-5RP3QTRL.js +1223 -0
- package/dist/chunk-5S437PRC.js +50 -0
- package/dist/chunk-5XDUGTKN.js +511 -0
- package/dist/chunk-62V2AFVG.js +422 -0
- package/dist/chunk-65RDIOR2.js +2470 -0
- package/dist/chunk-6AKOTGLM.js +597 -0
- package/dist/chunk-7ZHZE5EO.js +28 -0
- package/dist/chunk-A455ATZB.js +140 -0
- package/dist/chunk-AD7ZFZCS.js +46 -0
- package/dist/chunk-AI4LLQ2U.js +856 -0
- package/dist/chunk-ASX6AW36.js +789 -0
- package/dist/chunk-AT4V4XGI.js +3522 -0
- package/dist/chunk-AWNQ6ED6.js +311 -0
- package/dist/chunk-B4AMLZPB.js +9 -0
- package/dist/chunk-BAKVJLEV.js +417 -0
- package/dist/chunk-BJHVULHO.js +55 -0
- package/dist/chunk-CB2HFKTP.js +9 -0
- package/dist/chunk-CE4ZOCOI.js +1640 -0
- package/dist/chunk-CQQL4ZOQ.js +151 -0
- package/dist/chunk-DEIQMBD2.js +65 -0
- package/dist/chunk-E6I5RXVK.js +58 -0
- package/dist/chunk-EFEHDQGY.js +1589 -0
- package/dist/chunk-EODDVJBM.js +82 -0
- package/dist/chunk-EPC3GZD4.js +308 -0
- package/dist/chunk-FAYRX2AD.js +13 -0
- package/dist/chunk-FFSX2QDQ.js +362 -0
- package/dist/chunk-FHAMQS7Q.js +5856 -0
- package/dist/chunk-FIV4IJL7.js +2263 -0
- package/dist/chunk-FNXVT7HF.js +52 -0
- package/dist/chunk-FSWCWSTS.js +395 -0
- package/dist/chunk-FW5LDDMJ.js +16464 -0
- package/dist/chunk-FXQLIX3K.js +211 -0
- package/dist/chunk-G5AAKEEZ.js +228 -0
- package/dist/chunk-G5S3S5ZN.js +38 -0
- package/dist/chunk-GAZEWQEZ.js +231 -0
- package/dist/chunk-GFJOMSHG.js +125 -0
- package/dist/chunk-GFXZTHNI.js +158 -0
- package/dist/chunk-GM54GJBU.js +960 -0
- package/dist/chunk-GPQ3NJPR.js +900 -0
- package/dist/chunk-GTCU6DZ3.js +1 -0
- package/dist/chunk-H5E77KUJ.js +15 -0
- package/dist/chunk-H72H4XDU.js +1023 -0
- package/dist/chunk-HA4ZYA6T.js +178 -0
- package/dist/chunk-I45KAW2N.js +5020 -0
- package/dist/chunk-IQ35HMQL.js +1396 -0
- package/dist/chunk-IYFBFX34.js +86 -0
- package/dist/chunk-JJPMWPB6.js +109 -0
- package/dist/chunk-JTHKOYWU.js +663 -0
- package/dist/chunk-JVGPR3TS.js +365 -0
- package/dist/chunk-JVKB2TBL.js +48 -0
- package/dist/chunk-JX7VBZDK.js +31 -0
- package/dist/chunk-K3G6JBUC.js +5232 -0
- package/dist/chunk-K4YUNKU7.js +589 -0
- package/dist/chunk-KBZGE6LN.js +710 -0
- package/dist/chunk-KDQJCT2J.js +45 -0
- package/dist/chunk-KI4L2DUL.js +560 -0
- package/dist/chunk-KJ2ZTQSL.js +47 -0
- package/dist/chunk-KSJ5UTP7.js +154 -0
- package/dist/chunk-LHOA5DWA.js +28 -0
- package/dist/chunk-LX5QWLBL.js +27 -0
- package/dist/chunk-LZDDLNCZ.js +279 -0
- package/dist/chunk-M2WF6AXG.js +115 -0
- package/dist/chunk-M7BS2K6U.js +1 -0
- package/dist/chunk-NDBIPFNY.js +102 -0
- package/dist/chunk-NEMIWEXC.js +1199 -0
- package/dist/chunk-NFAYHPRH.js +323 -0
- package/dist/chunk-O37BQ65S.js +21 -0
- package/dist/chunk-O74MJHXU.js +187 -0
- package/dist/chunk-OJZEX73F.js +112 -0
- package/dist/chunk-PAAWLLZX.js +74 -0
- package/dist/chunk-PFXFQQRT.js +339 -0
- package/dist/chunk-PFZO3C6H.js +14 -0
- package/dist/chunk-PHH7LD45.js +113 -0
- package/dist/chunk-QRTG4XTI.js +188 -0
- package/dist/chunk-QVOVMXJR.js +1351 -0
- package/dist/chunk-RCQYT2I4.js +757 -0
- package/dist/chunk-RD6DEE36.js +1178 -0
- package/dist/chunk-RJIZEJ42.js +30 -0
- package/dist/chunk-RPOA7IAE.js +150 -0
- package/dist/chunk-SN2DQRL6.js +1172 -0
- package/dist/chunk-SQJVFEBV.js +41 -0
- package/dist/chunk-SQP64RCS.js +5391 -0
- package/dist/chunk-SVT4RNTR.js +49 -0
- package/dist/chunk-SWUFN7XM.js +43 -0
- package/dist/chunk-SXMVYC5H.js +174 -0
- package/dist/chunk-SZ6AYUIZ.js +23 -0
- package/dist/chunk-T3KGZBU5.js +3171 -0
- package/dist/chunk-TBRL2RCC.js +9 -0
- package/dist/chunk-TRT2HRWZ.js +18 -0
- package/dist/chunk-TYW2GI5I.js +1077 -0
- package/dist/chunk-UIWONWVG.js +4959 -0
- package/dist/chunk-VB3H5WWB.js +151 -0
- package/dist/chunk-W4A6QA3D.js +258 -0
- package/dist/chunk-WBPVKEEE.js +227 -0
- package/dist/chunk-WEBMSQP2.js +123 -0
- package/dist/chunk-WOEZV3Q4.js +333 -0
- package/dist/chunk-WQQON3SV.js +473 -0
- package/dist/chunk-WQTOVMGV.js +119 -0
- package/dist/chunk-WZO23AWO.js +2779 -0
- package/dist/chunk-XBDP4QPW.js +7 -0
- package/dist/chunk-XEBHSJLT.js +103 -0
- package/dist/chunk-XQ2ECNK3.js +1 -0
- package/dist/chunk-XQ2XGIBF.js +2086 -0
- package/dist/chunk-Y2GE5TSI.js +355 -0
- package/dist/chunk-YBUJCZ57.js +351 -0
- package/dist/chunk-YNCVSFGF.js +149 -0
- package/dist/chunk-YUPMXOGP.js +282 -0
- package/dist/chunk-YY6APYUM.js +49 -0
- package/dist/chunk-Z2IJUO45.js +691 -0
- package/dist/chunk-ZEHUCJHY.js +129 -0
- package/dist/chunk-ZYU2YOJ6.js +1496 -0
- package/dist/chunk-ZZ4V3WIZ.js +163 -0
- package/dist/coordination/agents/index.js +145 -6260
- package/dist/coordination/index.js +365 -34324
- package/dist/coordination/mailbox-project-server.js +48 -3276
- package/dist/coordination/provider-status-tracker.d.ts +4 -0
- package/dist/core/agent.d.ts +14 -1
- package/dist/core/index.js +267 -12480
- package/dist/core/model-ref.js +5 -23
- package/dist/core/provider-runner.d.ts +36 -1
- package/dist/design/index.js +50 -1087
- package/dist/execution/index.d.ts +1 -1
- package/dist/execution/index.js +1599 -21888
- package/dist/execution/prompt-enhancer.js +16 -535
- package/dist/execution/retry-policy.d.ts +31 -1
- package/dist/extension/index.js +7 -311
- package/dist/goal/index.js +33 -3435
- package/dist/hooks/index.js +14 -1138
- package/dist/hq/index.js +112 -5139
- package/dist/hq/protocol.js +21 -668
- package/dist/index.js +1410 -92656
- package/dist/infrastructure/index.js +64 -4811
- package/dist/kernel/events/provider-events.d.ts +15 -0
- package/dist/kernel/index.js +14 -992
- package/dist/models/index.js +40 -1117
- package/dist/notifications/index.js +3 -108
- package/dist/observability/index.js +17 -279
- package/dist/plugin/index.js +584 -14835
- package/dist/prompts/index.js +14 -948
- package/dist/registry/index.js +9 -822
- package/dist/registry-R23UBE7H.js +14 -0
- package/dist/replay/index.js +6 -84
- package/dist/review-finding-store-DKAV3AS6.js +21 -0
- package/dist/review-report-store-OWY3EC3N.js +19 -0
- package/dist/security/index.js +114 -2202
- package/dist/session-catalog/index.js +36 -2103
- package/dist/session-catalog/project-server.js +42 -1435
- package/dist/skills/index.js +35 -1578
- package/dist/storage/index.js +182 -15600
- package/dist/tasking/index.js +10 -676
- package/dist/tools/index.js +52 -9590
- package/dist/types/config/autonomy.d.ts +5 -0
- package/dist/types/config/ui.d.ts +1 -1
- package/dist/types/errors.d.ts +18 -0
- package/dist/types/index.js +121 -1342
- package/dist/types/provider-runner.d.ts +8 -0
- package/dist/types/session-markers.js +8 -144
- package/dist/utils/error.js +3 -4
- package/dist/utils/expect-defined.js +3 -9
- package/dist/utils/heap-watchdog.js +6 -706
- package/dist/utils/index.js +269 -5685
- package/dist/utils/sage-output-block.js +5 -42
- package/dist/wiring/proxy-rewrite.d.ts +18 -0
- package/dist/wiring/proxy-rewrite.js +18 -121
- package/dist/worktree/index.js +6 -887
- package/package.json +4 -4
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DefaultPromptStore,
|
|
3
|
+
migratePromptEntry
|
|
4
|
+
} from "./chunk-GFXZTHNI.js";
|
|
5
|
+
import {
|
|
6
|
+
PROMPT_CATEGORY_LABELS,
|
|
7
|
+
isBuiltinCategory
|
|
8
|
+
} from "./chunk-KDQJCT2J.js";
|
|
9
|
+
|
|
10
|
+
// src/execution/prompt-loader.ts
|
|
11
|
+
import * as fs from "node:fs/promises";
|
|
12
|
+
import * as path from "node:path";
|
|
13
|
+
var DefaultPromptLoader = class {
|
|
14
|
+
projectStore;
|
|
15
|
+
userStore;
|
|
16
|
+
builtinDir;
|
|
17
|
+
cache;
|
|
18
|
+
builtinCache;
|
|
19
|
+
constructor(opts) {
|
|
20
|
+
this.projectStore = typeof opts.paths.inProjectPrompts === "string" ? new DefaultPromptStore(opts.paths.inProjectPrompts) : void 0;
|
|
21
|
+
this.userStore = typeof opts.paths.globalPrompts === "string" ? new DefaultPromptStore(opts.paths.globalPrompts) : void 0;
|
|
22
|
+
this.builtinDir = opts.bundledDir ? path.join(opts.bundledDir, "prompts") : void 0;
|
|
23
|
+
}
|
|
24
|
+
async list() {
|
|
25
|
+
if (this.cache) return this.cache;
|
|
26
|
+
const seen = /* @__PURE__ */ new Set();
|
|
27
|
+
const out = [];
|
|
28
|
+
const layers = [
|
|
29
|
+
(await (this.projectStore?.list() ?? Promise.resolve([]))).map((e) => ({
|
|
30
|
+
...e,
|
|
31
|
+
source: "project"
|
|
32
|
+
})),
|
|
33
|
+
await (this.userStore?.list() ?? Promise.resolve([])),
|
|
34
|
+
// keeps stored source ('user' or 'synced')
|
|
35
|
+
await this.readBuiltin()
|
|
36
|
+
];
|
|
37
|
+
for (const layer of layers) {
|
|
38
|
+
for (const e of layer) {
|
|
39
|
+
if (seen.has(e.slug)) continue;
|
|
40
|
+
seen.add(e.slug);
|
|
41
|
+
out.push(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.cache = out;
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
async find(slugOrId) {
|
|
48
|
+
const all = await this.list();
|
|
49
|
+
return all.find((e) => e.slug === slugOrId) ?? all.find((e) => e.id === slugOrId);
|
|
50
|
+
}
|
|
51
|
+
async search(query, opts = {}) {
|
|
52
|
+
let pool = await this.list();
|
|
53
|
+
if (opts.category) pool = pool.filter((e) => e.category === opts.category);
|
|
54
|
+
const q = query.trim().toLowerCase();
|
|
55
|
+
let results;
|
|
56
|
+
if (!q) {
|
|
57
|
+
results = pool;
|
|
58
|
+
} else {
|
|
59
|
+
const tokens = q.split(/\s+/).filter(Boolean);
|
|
60
|
+
results = pool.map((e) => ({ e, score: scorePrompt(e, tokens) })).filter((r) => r.score > 0).sort((a, b) => b.score - a.score).map((r) => r.e);
|
|
61
|
+
}
|
|
62
|
+
return typeof opts.limit === "number" ? results.slice(0, opts.limit) : results;
|
|
63
|
+
}
|
|
64
|
+
async categories() {
|
|
65
|
+
const all = await this.list();
|
|
66
|
+
const counts = /* @__PURE__ */ new Map();
|
|
67
|
+
for (const e of all) counts.set(e.category, (counts.get(e.category) ?? 0) + 1);
|
|
68
|
+
return [...counts.entries()].map(([id, count]) => ({
|
|
69
|
+
id,
|
|
70
|
+
label: isBuiltinCategory(id) ? PROMPT_CATEGORY_LABELS[id] : id,
|
|
71
|
+
count
|
|
72
|
+
})).sort((a, b) => b.count - a.count || a.label.localeCompare(b.label));
|
|
73
|
+
}
|
|
74
|
+
async save(entry, opts = {}) {
|
|
75
|
+
const store = opts.scope === "project" ? this.projectStore : this.userStore;
|
|
76
|
+
if (!store)
|
|
77
|
+
throw new Error(`Prompt ${opts.scope ?? "user"} layer is not writable (no directory).`);
|
|
78
|
+
const normalized = entry.source === "builtin" ? {
|
|
79
|
+
...entry,
|
|
80
|
+
source: opts.scope === "project" ? "project" : "user",
|
|
81
|
+
forkedFrom: entry.forkedFrom ?? entry.slug
|
|
82
|
+
} : entry;
|
|
83
|
+
await store.save(normalized);
|
|
84
|
+
this.invalidateCache();
|
|
85
|
+
}
|
|
86
|
+
async delete(slugOrId) {
|
|
87
|
+
const entry = await this.find(slugOrId);
|
|
88
|
+
if (!entry) return false;
|
|
89
|
+
if (entry.source === "builtin") return false;
|
|
90
|
+
const store = entry.source === "project" ? this.projectStore : this.userStore;
|
|
91
|
+
if (!store) return false;
|
|
92
|
+
const ok = await store.delete(entry.id);
|
|
93
|
+
if (ok) this.invalidateCache();
|
|
94
|
+
return ok;
|
|
95
|
+
}
|
|
96
|
+
async setFavorite(slugOrId, favorite) {
|
|
97
|
+
const entry = await this.find(slugOrId);
|
|
98
|
+
if (!entry) return void 0;
|
|
99
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
100
|
+
if (entry.source === "builtin") {
|
|
101
|
+
if (!this.userStore) return void 0;
|
|
102
|
+
const copy = {
|
|
103
|
+
...entry,
|
|
104
|
+
favorite,
|
|
105
|
+
source: "user",
|
|
106
|
+
forkedFrom: entry.slug,
|
|
107
|
+
updatedAt: now
|
|
108
|
+
};
|
|
109
|
+
await this.userStore.save(copy);
|
|
110
|
+
this.invalidateCache();
|
|
111
|
+
return copy;
|
|
112
|
+
}
|
|
113
|
+
const updated = { ...entry, favorite, updatedAt: now };
|
|
114
|
+
const store = entry.source === "project" ? this.projectStore : this.userStore;
|
|
115
|
+
if (!store) return void 0;
|
|
116
|
+
await store.save(updated);
|
|
117
|
+
this.invalidateCache();
|
|
118
|
+
return updated;
|
|
119
|
+
}
|
|
120
|
+
invalidateCache() {
|
|
121
|
+
this.cache = void 0;
|
|
122
|
+
this.builtinCache = void 0;
|
|
123
|
+
}
|
|
124
|
+
async readBuiltin() {
|
|
125
|
+
if (this.builtinCache) return this.builtinCache;
|
|
126
|
+
const dir = this.builtinDir;
|
|
127
|
+
if (!dir) {
|
|
128
|
+
this.builtinCache = [];
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
const out = [];
|
|
132
|
+
const files = await walkJson(dir);
|
|
133
|
+
for (const file of files) {
|
|
134
|
+
try {
|
|
135
|
+
const parsed = JSON.parse(await fs.readFile(file, "utf8"));
|
|
136
|
+
const migrated = migratePromptEntry(parsed);
|
|
137
|
+
if (migrated) out.push({ ...migrated, source: "builtin" });
|
|
138
|
+
} catch {
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
this.builtinCache = out;
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
async function walkJson(dir) {
|
|
146
|
+
const out = [];
|
|
147
|
+
let entries;
|
|
148
|
+
try {
|
|
149
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
150
|
+
} catch {
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
for (const e of entries) {
|
|
154
|
+
const full = path.join(dir, e.name);
|
|
155
|
+
if (e.isDirectory()) {
|
|
156
|
+
out.push(...await walkJson(full));
|
|
157
|
+
} else if (e.name.endsWith(".json") && e.name !== "index.json" && e.name !== "schema.json") {
|
|
158
|
+
out.push(full);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
function scorePrompt(e, tokens) {
|
|
164
|
+
const title = e.title.toLowerCase();
|
|
165
|
+
const slug = e.slug.toLowerCase();
|
|
166
|
+
const desc = e.description.toLowerCase();
|
|
167
|
+
const cat = e.category.toLowerCase();
|
|
168
|
+
const tags = e.tags.map((t) => t.toLowerCase());
|
|
169
|
+
const content = e.content.toLowerCase();
|
|
170
|
+
let score = 0;
|
|
171
|
+
for (const tok of tokens) {
|
|
172
|
+
let hit = 0;
|
|
173
|
+
if (title.includes(tok)) hit += 5;
|
|
174
|
+
if (slug.includes(tok)) hit += 4;
|
|
175
|
+
if (tags.some((t) => t.includes(tok))) hit += 3;
|
|
176
|
+
if (desc.includes(tok)) hit += 2;
|
|
177
|
+
if (cat.includes(tok)) hit += 2;
|
|
178
|
+
if (content.includes(tok)) hit += 1;
|
|
179
|
+
if (hit === 0 && tok.length >= 3) {
|
|
180
|
+
if (isSubsequence(tok, title)) hit += 2;
|
|
181
|
+
else if (isSubsequence(tok, slug)) hit += 2;
|
|
182
|
+
else if (tags.some((t) => isSubsequence(tok, t))) hit += 1;
|
|
183
|
+
}
|
|
184
|
+
if (hit === 0) return 0;
|
|
185
|
+
score += hit;
|
|
186
|
+
}
|
|
187
|
+
if (e.favorite) score += 1;
|
|
188
|
+
return score;
|
|
189
|
+
}
|
|
190
|
+
function isSubsequence(needle, hay) {
|
|
191
|
+
let i = 0;
|
|
192
|
+
for (let j = 0; j < hay.length && i < needle.length; j++) {
|
|
193
|
+
if (hay[j] === needle[i]) i++;
|
|
194
|
+
}
|
|
195
|
+
return i === needle.length;
|
|
196
|
+
}
|
|
197
|
+
function renderPrompt(entry, values = {}) {
|
|
198
|
+
const declared = new Map((entry.variables ?? []).map((v) => [v.name, v]));
|
|
199
|
+
const missing = [];
|
|
200
|
+
const invalid = [];
|
|
201
|
+
const text = entry.content.replace(/\{\{\s*([\w.-]+)\s*\}\}/g, (whole, rawName) => {
|
|
202
|
+
const name = rawName.trim();
|
|
203
|
+
if (Object.hasOwn(values, name) && values[name] !== void 0) {
|
|
204
|
+
return values[name];
|
|
205
|
+
}
|
|
206
|
+
const decl = declared.get(name);
|
|
207
|
+
if (decl?.default !== void 0) return decl.default;
|
|
208
|
+
if (decl?.required) missing.push(name);
|
|
209
|
+
return whole;
|
|
210
|
+
});
|
|
211
|
+
for (const v of entry.variables ?? []) {
|
|
212
|
+
if (v.required && !(v.name in values) && v.default === void 0 && !missing.includes(v.name)) {
|
|
213
|
+
if (new RegExp(`\\{\\{\\s*${escapeRegExp(v.name)}\\s*\\}\\}`).test(entry.content)) {
|
|
214
|
+
missing.push(v.name);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (v.enum && v.enum.length > 0 && Object.hasOwn(values, v.name) && values[v.name] !== void 0 && values[v.name] !== "" && !v.enum.includes(values[v.name])) {
|
|
218
|
+
invalid.push(v.name);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return { text, missing, invalid };
|
|
222
|
+
}
|
|
223
|
+
function escapeRegExp(s) {
|
|
224
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export {
|
|
228
|
+
DefaultPromptLoader,
|
|
229
|
+
renderPrompt
|
|
230
|
+
};
|
|
231
|
+
//# sourceMappingURL=chunk-GAZEWQEZ.js.map
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// src/utils/ip-guard.ts
|
|
2
|
+
import * as dns from "node:dns/promises";
|
|
3
|
+
import * as net from "node:net";
|
|
4
|
+
function isPrivateIPv4(addr) {
|
|
5
|
+
const parts = addr.split(".").map((p) => Number.parseInt(p, 10));
|
|
6
|
+
if (parts.length !== 4 || parts.some((n) => Number.isNaN(n) || n < 0 || n > 255)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
const [a, b, c] = parts;
|
|
10
|
+
if (a === 0) return true;
|
|
11
|
+
if (a === 10) return true;
|
|
12
|
+
if (a === 127) return true;
|
|
13
|
+
if (a === 169 && b === 254) return true;
|
|
14
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
15
|
+
if (a === 192 && b === 168) return true;
|
|
16
|
+
if (a === 192 && b === 0 && c === 0) return true;
|
|
17
|
+
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
18
|
+
if (a >= 224) return true;
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
function isPrivateIPv6(raw) {
|
|
22
|
+
const lower = raw.toLowerCase();
|
|
23
|
+
if (lower === "::" || lower === "::1") return true;
|
|
24
|
+
const groups = expandIPv6(lower);
|
|
25
|
+
if (!groups) return true;
|
|
26
|
+
if (groups[0] === 100 && groups[1] === 65435 && groups[2] === 1) return true;
|
|
27
|
+
if (groups[0] === 0 && groups[1] === 0 && groups[2] === 0 && groups[3] === 0 && groups[4] === 0 && groups[5] === 65535) {
|
|
28
|
+
const a = (groups[6] ?? 0) >> 8;
|
|
29
|
+
const b = (groups[6] ?? 0) & 255;
|
|
30
|
+
const c = (groups[7] ?? 0) >> 8;
|
|
31
|
+
const d = (groups[7] ?? 0) & 255;
|
|
32
|
+
return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
|
|
33
|
+
}
|
|
34
|
+
const embedded = embeddedIPv4(groups);
|
|
35
|
+
if (embedded) return isPrivateIPv4(embedded);
|
|
36
|
+
const high = groups[0] ?? 0;
|
|
37
|
+
if ((high & 65024) === 64512) return true;
|
|
38
|
+
if ((high & 65472) === 65152) return true;
|
|
39
|
+
if ((high & 65280) === 65280) return true;
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
function quad(hi, lo) {
|
|
43
|
+
return `${(hi ?? 0) >> 8}.${(hi ?? 0) & 255}.${(lo ?? 0) >> 8}.${(lo ?? 0) & 255}`;
|
|
44
|
+
}
|
|
45
|
+
function embeddedIPv4(groups) {
|
|
46
|
+
const g = (i) => groups[i] ?? 0;
|
|
47
|
+
if (g(0) === 100 && g(1) === 65435) {
|
|
48
|
+
if (g(2) === 0 && g(3) === 0 && g(4) === 0 && g(5) === 0) {
|
|
49
|
+
return quad(g(6), g(7));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (g(0) === 8194) return quad(g(1), g(2));
|
|
53
|
+
if (g(0) === 8193 && g(1) === 0) {
|
|
54
|
+
return quad(~g(6) & 65535, ~g(7) & 65535);
|
|
55
|
+
}
|
|
56
|
+
if ((g(4) === 0 || g(4) === 512) && g(5) === 24318) {
|
|
57
|
+
return quad(g(6), g(7));
|
|
58
|
+
}
|
|
59
|
+
const highZero = g(0) === 0 && g(1) === 0 && g(2) === 0 && g(3) === 0;
|
|
60
|
+
if (highZero && g(4) === 65535 && g(5) === 0) return quad(g(6), g(7));
|
|
61
|
+
if (highZero && g(4) === 0 && g(5) === 0) return quad(g(6), g(7));
|
|
62
|
+
return void 0;
|
|
63
|
+
}
|
|
64
|
+
function expandIPv6(addr) {
|
|
65
|
+
const parts = addr.split("::");
|
|
66
|
+
if (parts.length > 2) return null;
|
|
67
|
+
const parseGroups = (s) => {
|
|
68
|
+
if (s === "") return [];
|
|
69
|
+
const out = [];
|
|
70
|
+
for (const g of s.split(":")) {
|
|
71
|
+
if (g.length === 0 || g.length > 4) return null;
|
|
72
|
+
const n = Number.parseInt(g, 16);
|
|
73
|
+
if (Number.isNaN(n) || n < 0 || n > 65535) return null;
|
|
74
|
+
out.push(n);
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
};
|
|
78
|
+
if (parts.length === 1) {
|
|
79
|
+
const groups = parseGroups(parts[0] ?? "");
|
|
80
|
+
if (groups?.length !== 8) return null;
|
|
81
|
+
return groups;
|
|
82
|
+
}
|
|
83
|
+
const head = parseGroups(parts[0] ?? "");
|
|
84
|
+
const tail = parseGroups(parts[1] ?? "");
|
|
85
|
+
if (!head || !tail) return null;
|
|
86
|
+
const fill = 8 - head.length - tail.length;
|
|
87
|
+
if (fill < 0) return null;
|
|
88
|
+
return [...head, ...new Array(fill).fill(0), ...tail];
|
|
89
|
+
}
|
|
90
|
+
async function assertNotPrivateHost(hostname) {
|
|
91
|
+
const host = hostname.startsWith("[") && hostname.endsWith("]") ? hostname.slice(1, -1) : hostname;
|
|
92
|
+
if (host === "localhost" || host.endsWith(".localhost")) {
|
|
93
|
+
throw new Error("fetch: blocked localhost target");
|
|
94
|
+
}
|
|
95
|
+
const ipVersion = net.isIP(host);
|
|
96
|
+
if (ipVersion === 4) {
|
|
97
|
+
if (isPrivateIPv4(host)) {
|
|
98
|
+
throw new Error(`fetch: blocked private/loopback address "${host}"`);
|
|
99
|
+
}
|
|
100
|
+
} else if (ipVersion === 6) {
|
|
101
|
+
if (isPrivateIPv6(host)) {
|
|
102
|
+
throw new Error(`fetch: blocked private/loopback address "${host}"`);
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
try {
|
|
106
|
+
const records = await dns.lookup(host, { all: true });
|
|
107
|
+
for (const r of records) {
|
|
108
|
+
const bad = r.family === 4 ? isPrivateIPv4(r.address) : isPrivateIPv6(r.address);
|
|
109
|
+
if (bad) {
|
|
110
|
+
throw new Error(`fetch: resolved to private address ${r.address}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} catch (err) {
|
|
114
|
+
if (err instanceof Error && err.message.startsWith("fetch:")) throw err;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
isPrivateIPv4,
|
|
121
|
+
isPrivateIPv6,
|
|
122
|
+
expandIPv6,
|
|
123
|
+
assertNotPrivateHost
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=chunk-GFJOMSHG.js.map
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import {
|
|
2
|
+
slugify
|
|
3
|
+
} from "./chunk-TYW2GI5I.js";
|
|
4
|
+
import {
|
|
5
|
+
ulid
|
|
6
|
+
} from "./chunk-4XV6IR37.js";
|
|
7
|
+
import {
|
|
8
|
+
atomicWrite,
|
|
9
|
+
ensureDir
|
|
10
|
+
} from "./chunk-7ZHZE5EO.js";
|
|
11
|
+
|
|
12
|
+
// src/storage/prompt-store.ts
|
|
13
|
+
import { createHash } from "node:crypto";
|
|
14
|
+
import * as fs from "node:fs/promises";
|
|
15
|
+
import * as path from "node:path";
|
|
16
|
+
var SCHEMA_VERSION = 2;
|
|
17
|
+
function promptChecksum(content) {
|
|
18
|
+
return createHash("sha256").update(content, "utf8").digest("hex");
|
|
19
|
+
}
|
|
20
|
+
function migratePromptEntry(raw) {
|
|
21
|
+
if (!raw || typeof raw !== "object") return null;
|
|
22
|
+
const r = raw;
|
|
23
|
+
if (typeof r["id"] !== "string" || typeof r["title"] !== "string") return null;
|
|
24
|
+
const title = r["title"];
|
|
25
|
+
const content = typeof r["content"] === "string" ? r["content"] : "";
|
|
26
|
+
const now = typeof r["createdAt"] === "string" ? r["createdAt"] : (/* @__PURE__ */ new Date(0)).toISOString();
|
|
27
|
+
const tags = Array.isArray(r["tags"]) ? r["tags"].filter((t) => typeof t === "string") : [];
|
|
28
|
+
return {
|
|
29
|
+
id: r["id"],
|
|
30
|
+
slug: typeof r["slug"] === "string" && r["slug"].length > 0 ? r["slug"] : slugify(title),
|
|
31
|
+
title,
|
|
32
|
+
description: typeof r["description"] === "string" ? r["description"] : "",
|
|
33
|
+
content,
|
|
34
|
+
category: typeof r["category"] === "string" && r["category"].length > 0 ? r["category"] : "uncategorized",
|
|
35
|
+
tags,
|
|
36
|
+
source: isPromptSource(r["source"]) ? r["source"] : "user",
|
|
37
|
+
favorite: r["favorite"] === true,
|
|
38
|
+
variables: normalizeVariables(r["variables"]),
|
|
39
|
+
author: typeof r["author"] === "string" ? r["author"] : void 0,
|
|
40
|
+
version: typeof r["version"] === "string" ? r["version"] : void 0,
|
|
41
|
+
license: typeof r["license"] === "string" ? r["license"] : void 0,
|
|
42
|
+
checksum: typeof r["checksum"] === "string" ? r["checksum"] : void 0,
|
|
43
|
+
forkedFrom: typeof r["forkedFrom"] === "string" ? r["forkedFrom"] : void 0,
|
|
44
|
+
createdAt: now,
|
|
45
|
+
updatedAt: typeof r["updatedAt"] === "string" ? r["updatedAt"] : now
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function isPromptSource(v) {
|
|
49
|
+
return v === "builtin" || v === "user" || v === "project" || v === "synced";
|
|
50
|
+
}
|
|
51
|
+
function normalizeVariables(v) {
|
|
52
|
+
if (!Array.isArray(v)) return void 0;
|
|
53
|
+
const out = [];
|
|
54
|
+
for (const item of v) {
|
|
55
|
+
if (item && typeof item === "object" && typeof item["name"] === "string") {
|
|
56
|
+
const o = item;
|
|
57
|
+
const enumVals = Array.isArray(o["enum"]) && o["enum"].every((x) => typeof x === "string") ? o["enum"] : void 0;
|
|
58
|
+
out.push({
|
|
59
|
+
name: o["name"],
|
|
60
|
+
description: typeof o["description"] === "string" ? o["description"] : void 0,
|
|
61
|
+
default: typeof o["default"] === "string" ? o["default"] : void 0,
|
|
62
|
+
required: o["required"] === true ? true : void 0,
|
|
63
|
+
enum: enumVals && enumVals.length > 0 ? enumVals : void 0,
|
|
64
|
+
multiline: o["multiline"] === true ? true : void 0
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return out.length > 0 ? out : void 0;
|
|
69
|
+
}
|
|
70
|
+
var DefaultPromptStore = class {
|
|
71
|
+
dir;
|
|
72
|
+
constructor(pathsOrDir) {
|
|
73
|
+
this.dir = typeof pathsOrDir === "string" ? pathsOrDir : pathsOrDir.globalPrompts;
|
|
74
|
+
}
|
|
75
|
+
async list() {
|
|
76
|
+
await ensureDir(this.dir);
|
|
77
|
+
const entries = [];
|
|
78
|
+
try {
|
|
79
|
+
const files = await fs.readdir(this.dir);
|
|
80
|
+
for (const file of files) {
|
|
81
|
+
if (!file.endsWith(".json")) continue;
|
|
82
|
+
try {
|
|
83
|
+
const raw = JSON.parse(
|
|
84
|
+
await fs.readFile(path.join(this.dir, file), "utf8")
|
|
85
|
+
);
|
|
86
|
+
const migrated = migratePromptEntry(raw.entry);
|
|
87
|
+
if (migrated) entries.push(migrated);
|
|
88
|
+
} catch {
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
return entries.sort(
|
|
94
|
+
(a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
async get(id) {
|
|
98
|
+
const file = path.join(this.dir, `${id}.json`);
|
|
99
|
+
try {
|
|
100
|
+
const raw = JSON.parse(await fs.readFile(file, "utf8"));
|
|
101
|
+
return migratePromptEntry(raw.entry);
|
|
102
|
+
} catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async save(entry) {
|
|
107
|
+
await ensureDir(this.dir);
|
|
108
|
+
const file = path.join(this.dir, `${entry.id}.json`);
|
|
109
|
+
const raw = { version: SCHEMA_VERSION, entry };
|
|
110
|
+
await atomicWrite(file, JSON.stringify(raw, null, 2));
|
|
111
|
+
}
|
|
112
|
+
async delete(id) {
|
|
113
|
+
const file = path.join(this.dir, `${id}.json`);
|
|
114
|
+
try {
|
|
115
|
+
await fs.unlink(file);
|
|
116
|
+
return true;
|
|
117
|
+
} catch {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async find(query) {
|
|
122
|
+
const all = await this.list();
|
|
123
|
+
const lower = query.toLowerCase();
|
|
124
|
+
return all.filter(
|
|
125
|
+
(e) => e.title.toLowerCase().includes(lower) || e.description.toLowerCase().includes(lower) || e.content.toLowerCase().includes(lower) || e.category.toLowerCase().includes(lower) || e.tags.some((t) => t.toLowerCase().includes(lower))
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
/** Create a new v2 entry and return it. Does NOT persist — call save() afterwards. */
|
|
129
|
+
createNew(title, content, tags = [], extra = {}) {
|
|
130
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
131
|
+
return {
|
|
132
|
+
id: ulid(),
|
|
133
|
+
slug: extra.slug && extra.slug.length > 0 ? extra.slug : slugify(title),
|
|
134
|
+
title,
|
|
135
|
+
description: extra.description ?? "",
|
|
136
|
+
content,
|
|
137
|
+
category: extra.category ?? "uncategorized",
|
|
138
|
+
tags,
|
|
139
|
+
source: extra.source ?? "user",
|
|
140
|
+
favorite: extra.favorite ?? false,
|
|
141
|
+
variables: extra.variables,
|
|
142
|
+
author: extra.author,
|
|
143
|
+
version: extra.version,
|
|
144
|
+
license: extra.license,
|
|
145
|
+
checksum: extra.checksum,
|
|
146
|
+
forkedFrom: extra.forkedFrom,
|
|
147
|
+
createdAt: now,
|
|
148
|
+
updatedAt: now
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export {
|
|
154
|
+
promptChecksum,
|
|
155
|
+
migratePromptEntry,
|
|
156
|
+
DefaultPromptStore
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=chunk-GFXZTHNI.js.map
|