@wirecat/drive-cli 0.44.0 → 0.45.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/bin/drive.js +35 -40
- package/dist/bundle/all-profiles-O7CNQ7FO.js +26 -0
- package/dist/bundle/anthropic-6T67J2CE.js +71 -0
- package/dist/bundle/app-server-BVBZT3UY.js +237 -0
- package/dist/bundle/bun-O6RL6LRQ.js +169 -0
- package/dist/bundle/bun-sqlite-54W7JUY3.js +70 -0
- package/dist/bundle/chunk-2DLAJGRN.js +62 -0
- package/dist/bundle/chunk-37MAA6F2.js +5624 -0
- package/dist/bundle/chunk-3HRDEJJW.js +161 -0
- package/dist/bundle/chunk-3Z7WSD2A.js +433 -0
- package/dist/bundle/chunk-44FV5JAS.js +1855 -0
- package/dist/bundle/chunk-4DW6QGEV.js +164 -0
- package/dist/bundle/chunk-4NGLRHWO.js +24 -0
- package/dist/bundle/chunk-5DPV7X27.js +663 -0
- package/dist/bundle/chunk-5FONRUG6.js +24805 -0
- package/dist/bundle/chunk-5MGIL5LW.js +846 -0
- package/dist/bundle/chunk-5TC3NCAF.js +42 -0
- package/dist/bundle/chunk-6Y2BYFXQ.js +65 -0
- package/dist/bundle/chunk-A3FU4RR6.js +150 -0
- package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
- package/dist/bundle/chunk-AIXLOMH4.js +63 -0
- package/dist/bundle/chunk-AOOD3RMK.js +384 -0
- package/dist/bundle/chunk-AUS6TKP5.js +1975 -0
- package/dist/bundle/chunk-B2J6FJNL.js +19 -0
- package/dist/bundle/chunk-BEXHAGXH.js +3542 -0
- package/dist/bundle/chunk-BHE7ZY2N.js +2352 -0
- package/dist/bundle/chunk-BJ3JRO34.js +2356 -0
- package/dist/bundle/chunk-BQUPOB5H.js +2315 -0
- package/dist/bundle/chunk-CFZWPIVC.js +1092 -0
- package/dist/bundle/chunk-CKR3DVUK.js +754 -0
- package/dist/bundle/chunk-CVIKKIGE.js +76 -0
- package/dist/bundle/chunk-D67JGWSC.js +190 -0
- package/dist/bundle/chunk-DDYR6DYL.js +78 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DL7D6Y3B.js +18102 -0
- package/dist/bundle/chunk-DORXXBFC.js +484 -0
- package/dist/bundle/chunk-DXKVEOSS.js +53 -0
- package/dist/bundle/chunk-DXQEJWI3.js +522 -0
- package/dist/bundle/chunk-FEULDMWM.js +35598 -0
- package/dist/bundle/chunk-G3FAOS52.js +630 -0
- package/dist/bundle/chunk-GHOWRW7E.js +237 -0
- package/dist/bundle/chunk-GNFHZZ55.js +264 -0
- package/dist/bundle/chunk-GNI7INK6.js +18 -0
- package/dist/bundle/chunk-GOR3Z2FR.js +17 -0
- package/dist/bundle/chunk-GQW4GRYR.js +886 -0
- package/dist/bundle/chunk-GWPKIRNQ.js +220 -0
- package/dist/bundle/chunk-GYCUY4CL.js +9 -0
- package/dist/bundle/chunk-HEPIOCHN.js +8181 -0
- package/dist/bundle/chunk-HTQTIKWP.js +928 -0
- package/dist/bundle/chunk-IAW5A7OR.js +1913 -0
- package/dist/bundle/chunk-IGMRWQP3.js +1071 -0
- package/dist/bundle/chunk-IKNU5A5Y.js +82 -0
- package/dist/bundle/chunk-JVTVAZ5X.js +1054 -0
- package/dist/bundle/chunk-K74PQVQZ.js +168 -0
- package/dist/bundle/chunk-K7FRUB33.js +795 -0
- package/dist/bundle/chunk-KADPV4YA.js +45 -0
- package/dist/bundle/chunk-KJMBV574.js +16225 -0
- package/dist/bundle/chunk-LHIL46I3.js +31 -0
- package/dist/bundle/chunk-LJARCTGL.js +60 -0
- package/dist/bundle/chunk-LOTQ2HMT.js +3954 -0
- package/dist/bundle/chunk-MAXN7COO.js +99 -0
- package/dist/bundle/chunk-MFS52LTZ.js +570 -0
- package/dist/bundle/chunk-MFSIOSUM.js +1714 -0
- package/dist/bundle/chunk-NB2N6L3R.js +138 -0
- package/dist/bundle/chunk-NDNTLUPS.js +58 -0
- package/dist/bundle/chunk-NLEB26GA.js +288 -0
- package/dist/bundle/chunk-NP3XLLN3.js +73 -0
- package/dist/bundle/chunk-NW7IMGRR.js +6848 -0
- package/dist/bundle/chunk-O5EHUB2V.js +2 -0
- package/dist/bundle/chunk-OWXTPXIQ.js +215 -0
- package/dist/bundle/chunk-PDBBBUY7.js +166 -0
- package/dist/bundle/chunk-PH74B2VZ.js +122 -0
- package/dist/bundle/chunk-PJ7IQVOM.js +421 -0
- package/dist/bundle/chunk-Q2Z3VCM4.js +2 -0
- package/dist/bundle/chunk-QTJUH3LS.js +15572 -0
- package/dist/bundle/chunk-QW36EOAM.js +106 -0
- package/dist/bundle/chunk-QWSRPXCJ.js +281 -0
- package/dist/bundle/chunk-R2A3K7ZF.js +193 -0
- package/dist/bundle/chunk-R2QRP7EJ.js +835 -0
- package/dist/bundle/chunk-RCS2SCX5.js +375 -0
- package/dist/bundle/chunk-RJ633GFA.js +25 -0
- package/dist/bundle/chunk-SBZB7HMU.js +1055 -0
- package/dist/bundle/chunk-SMHQA5J6.js +459 -0
- package/dist/bundle/chunk-SWMMR3FR.js +48 -0
- package/dist/bundle/chunk-TRMIV3OA.js +18 -0
- package/dist/bundle/chunk-VAGF723Z.js +74 -0
- package/dist/bundle/chunk-VCYFEWPD.js +18078 -0
- package/dist/bundle/chunk-VHQNVG3J.js +263 -0
- package/dist/bundle/chunk-VHT2WI4I.js +2941 -0
- package/dist/bundle/chunk-VYBOYBLX.js +100 -0
- package/dist/bundle/chunk-WUFCYDKB.js +71 -0
- package/dist/bundle/chunk-XAZQTJXR.js +3402 -0
- package/dist/bundle/chunk-XEBFFKXO.js +111 -0
- package/dist/bundle/chunk-XF5MFUEB.js +498 -0
- package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-ZBM4GEV2.js +120 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/command-contract-MXCBV3GJ.js +38 -0
- package/dist/bundle/dist-MWTMOYWT.js +7577 -0
- package/dist/bundle/dist-PY3MVR3G.js +21 -0
- package/dist/bundle/drive.js +50 -0
- package/dist/bundle/echarts-LD3AI55P.js +42501 -0
- package/dist/bundle/embed-FJKIIM43.js +37 -0
- package/dist/bundle/embedder-NNQ5ZC25.js +110 -0
- package/dist/bundle/entry-ZYSNPDSD.js +15 -0
- package/dist/bundle/failure-MJJXFR63.js +37 -0
- package/dist/bundle/first-run-KA2UPZAU.js +24 -0
- package/dist/bundle/first-screen-VQ3RXDMF.js +36 -0
- package/dist/bundle/google-ZYDFTHLN.js +32 -0
- package/dist/bundle/google-api-2GT5PAW2.js +82 -0
- package/dist/bundle/identity-JQFQXQIR.js +10 -0
- package/dist/bundle/instructions-RZMSW3OC.js +11 -0
- package/dist/bundle/login-JU6NKW5P.js +158 -0
- package/dist/bundle/mcp-2PZDI7WE.js +501 -0
- package/dist/bundle/mcp-JOQMFGBC.js +95 -0
- package/dist/bundle/mcp-OQBZXELQ.js +165 -0
- package/dist/bundle/mdast-util-from-markdown-FXEPSNER.js +1958 -0
- package/dist/bundle/mdast-util-gfm-SZM5GBDF.js +2103 -0
- package/dist/bundle/micromark-extension-gfm-GRL24TU6.js +1838 -0
- package/dist/bundle/node-P4E63KXA.js +2340 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-ZRLYQL7J.js +176 -0
- package/dist/bundle/node-sqlite-TXPSRROT.js +46 -0
- package/dist/bundle/oauth-NAIBKERJ.js +18 -0
- package/dist/bundle/open-3P5EPXPV.js +20 -0
- package/dist/bundle/process-LL77573L.js +91 -0
- package/dist/bundle/program-CZ55L6EW.js +24078 -0
- package/dist/bundle/prompt-3TX2SWOY.js +13 -0
- package/dist/bundle/reasons-GF2TYGX6.js +11 -0
- package/dist/bundle/recognize-IFXOJHEA.js +191 -0
- package/dist/bundle/remote-663M42Y5.js +28 -0
- package/dist/bundle/rerank-OT2F2DBV.js +51 -0
- package/dist/bundle/serve-PDNNI6O6.js +20 -0
- package/dist/bundle/server-BFOEPMR7.js +56 -0
- package/dist/bundle/server-K566PJ7H.js +69 -0
- package/dist/bundle/services-5MCTECBU.js +333 -0
- package/dist/bundle/sqlite-runtime-BF3KDM7W.js +17 -0
- package/dist/bundle/state-SZX65E74.js +34 -0
- package/dist/bundle/store-TCWNLA3V.js +125 -0
- package/dist/bundle/store-UKPGGAPW.js +142 -0
- package/dist/bundle/store-maintenance-command-QHLUVBTJ.js +57 -0
- package/dist/bundle/terminal-TFCTWLOS.js +11 -0
- package/dist/bundle/tokens-DFCFRF7I.js +103 -0
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +82 -36
- package/dist/commands/mcp.js.map +1 -1
- package/dist/contract-overrides.d.ts.map +1 -1
- package/dist/contract-overrides.js +59 -53
- package/dist/contract-overrides.js.map +1 -1
- package/dist/mcp.d.ts +6 -5
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +13 -10
- package/dist/mcp.js.map +1 -1
- package/dist/program.js +4 -4
- package/dist/program.js.map +1 -1
- package/dist/registry.d.ts +2 -2
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +3 -3
- package/dist/registry.js.map +1 -1
- package/dist/state.d.ts +13 -2
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +12 -2
- package/dist/state.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -5
- package/skills/drive-cli/SKILL.md +1 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
CliError
|
|
5
|
+
} from "./chunk-BJ3JRO34.js";
|
|
6
|
+
import {
|
|
7
|
+
__name
|
|
8
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
9
|
+
|
|
10
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/tasks/model.js
|
|
11
|
+
var TASK_KINDS = ["question", "request", "mention", "promise"];
|
|
12
|
+
var TASK_STATES = ["open", "done", "dismissed"];
|
|
13
|
+
var TASK_ORIGINS = ["rule", "agent", "owner"];
|
|
14
|
+
var TASK_VERDICTS = ["useful", "not_useful"];
|
|
15
|
+
function closeTask(task, state, by, at, reason) {
|
|
16
|
+
if (task.state !== "open")
|
|
17
|
+
throw new CliError("validation_error", `task ${task.id} is already ${task.state}`, { reason: "task.closed" });
|
|
18
|
+
const { claimedBy: _by, claimedUntil: _until, ...unclaimed } = task;
|
|
19
|
+
return { ...unclaimed, state, closedAt: at, closedBy: by, ...reason === void 0 ? {} : { reason } };
|
|
20
|
+
}
|
|
21
|
+
__name(closeTask, "closeTask");
|
|
22
|
+
|
|
23
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/tasks/service.js
|
|
24
|
+
function createTaskService({ store, now = /* @__PURE__ */ __name(() => /* @__PURE__ */ new Date(), "now"), newId = /* @__PURE__ */ __name(() => crypto.randomUUID(), "newId") }) {
|
|
25
|
+
async function find(id) {
|
|
26
|
+
const task = await store.get(id);
|
|
27
|
+
if (!task)
|
|
28
|
+
throw new CliError("not_found", `no task ${id}`);
|
|
29
|
+
return task;
|
|
30
|
+
}
|
|
31
|
+
__name(find, "find");
|
|
32
|
+
return {
|
|
33
|
+
/**
|
|
34
|
+
* A rule never makes a second task from a source it has seen, whatever that task's state, so a
|
|
35
|
+
* dismissed one stays dismissed — nor from a message attached or merged into a task. A person or an agent may
|
|
36
|
+
* add a task of another kind to it. A task a rule opens goes through the host's duplicate check.
|
|
37
|
+
*/
|
|
38
|
+
async add(input) {
|
|
39
|
+
const rule = input.origin === "rule";
|
|
40
|
+
const existing = await store.findBySource(input.account, input.source, rule ? { linked: true } : void 0);
|
|
41
|
+
const same = rule ? existing[0] : existing.find((task2) => task2.kind === input.kind);
|
|
42
|
+
if (same)
|
|
43
|
+
return { task: same, created: false };
|
|
44
|
+
const task = { ...input, id: newId(), state: "open", createdAt: now() };
|
|
45
|
+
await store.insert(task);
|
|
46
|
+
if (!rule || !store.reviewDuplicates)
|
|
47
|
+
return { task, created: true };
|
|
48
|
+
return { task, created: true, review: await store.reviewDuplicates(task.id) };
|
|
49
|
+
},
|
|
50
|
+
async close(id, { as, by, reason }) {
|
|
51
|
+
const task = closeTask(await find(id), as, by, now(), reason);
|
|
52
|
+
await store.update(task);
|
|
53
|
+
return task;
|
|
54
|
+
},
|
|
55
|
+
list: /* @__PURE__ */ __name((filter = {}) => store.list(filter), "list"),
|
|
56
|
+
async stats(filter = {}) {
|
|
57
|
+
const byGroup = /* @__PURE__ */ new Map();
|
|
58
|
+
for (const task of await store.list(filter))
|
|
59
|
+
byGroup.set(task.group, [...byGroup.get(task.group) ?? [], task]);
|
|
60
|
+
return [...byGroup].map(([group, tasks]) => {
|
|
61
|
+
const open = tasks.filter((task) => task.state === "open");
|
|
62
|
+
const closeMs = tasks.flatMap((task) => task.closedAt ? [task.closedAt.getTime() - task.createdAt.getTime()] : []);
|
|
63
|
+
const oldestOpenAt = open.map((task) => task.createdAt).sort((a, b) => a.getTime() - b.getTime())[0];
|
|
64
|
+
return {
|
|
65
|
+
group,
|
|
66
|
+
open: open.length,
|
|
67
|
+
...oldestOpenAt ? { oldestOpenAt } : {},
|
|
68
|
+
...closeMs.length > 0 ? { medianCloseMs: median(closeMs) } : {}
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
__name(createTaskService, "createTaskService");
|
|
75
|
+
function median(values) {
|
|
76
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
77
|
+
const middle = Math.floor(sorted.length / 2);
|
|
78
|
+
const upper = sorted[middle] ?? 0;
|
|
79
|
+
return sorted.length % 2 === 1 ? upper : ((sorted[middle - 1] ?? 0) + upper) / 2;
|
|
80
|
+
}
|
|
81
|
+
__name(median, "median");
|
|
82
|
+
|
|
83
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/tasks/store.js
|
|
84
|
+
function matches(task, filter) {
|
|
85
|
+
return (filter.account === void 0 || task.account === filter.account) && (filter.state === void 0 || task.state === filter.state) && (filter.group === void 0 || task.group === filter.group) && (filter.kind === void 0 || task.kind === filter.kind) && (filter.createdBefore === void 0 || task.createdAt < filter.createdBefore);
|
|
86
|
+
}
|
|
87
|
+
__name(matches, "matches");
|
|
88
|
+
|
|
89
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/domain/knowledge.js
|
|
90
|
+
var FACT_TYPES = ["fact", "statement", "question", "decision", "promise"];
|
|
91
|
+
var FACT_STATUSES = ["proposed", "accepted", "superseded", "reversed"];
|
|
92
|
+
var MEMORY_KINDS = ["summary", "digest", "preference"];
|
|
93
|
+
var MEMORY_STATUSES = ["proposed", "confirmed", "stale", "superseded"];
|
|
94
|
+
var MEMORY_SCOPES = ["personal", "work"];
|
|
95
|
+
var WORK_TASK_TYPES = ["bug", "feature", "chore"];
|
|
96
|
+
var TASK_TYPES = [...WORK_TASK_TYPES, ...TASK_KINDS];
|
|
97
|
+
|
|
98
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/store/sqlite/link-kinds.js
|
|
99
|
+
var LINK_KINDS = [
|
|
100
|
+
"links-to",
|
|
101
|
+
"blocked-by",
|
|
102
|
+
"follow-up-of",
|
|
103
|
+
"about",
|
|
104
|
+
"member-of",
|
|
105
|
+
"labelled",
|
|
106
|
+
"answered-by",
|
|
107
|
+
"evidence",
|
|
108
|
+
"created-from",
|
|
109
|
+
"duplicate-of",
|
|
110
|
+
"related-to",
|
|
111
|
+
"assigned-to",
|
|
112
|
+
"attached"
|
|
113
|
+
];
|
|
114
|
+
var LINK_ORIGINS = ["file", "owner", "suggested", "message"];
|
|
115
|
+
var LINK_SOURCES = [...LINK_ORIGINS, "calendar"];
|
|
116
|
+
var RELATION_KINDS = ["member-of", "related-to"];
|
|
117
|
+
var linkKind = /* @__PURE__ */ __name((kind) => `'${kind}'`, "linkKind");
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
LINK_KINDS,
|
|
121
|
+
LINK_ORIGINS,
|
|
122
|
+
LINK_SOURCES,
|
|
123
|
+
RELATION_KINDS,
|
|
124
|
+
linkKind,
|
|
125
|
+
TASK_KINDS,
|
|
126
|
+
TASK_STATES,
|
|
127
|
+
TASK_ORIGINS,
|
|
128
|
+
TASK_VERDICTS,
|
|
129
|
+
createTaskService,
|
|
130
|
+
matches,
|
|
131
|
+
FACT_TYPES,
|
|
132
|
+
FACT_STATUSES,
|
|
133
|
+
MEMORY_KINDS,
|
|
134
|
+
MEMORY_STATUSES,
|
|
135
|
+
MEMORY_SCOPES,
|
|
136
|
+
WORK_TASK_TYPES,
|
|
137
|
+
TASK_TYPES
|
|
138
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
CliError
|
|
5
|
+
} from "./chunk-BJ3JRO34.js";
|
|
6
|
+
import {
|
|
7
|
+
importFrom
|
|
8
|
+
} from "./chunk-Y5E2WNWB.js";
|
|
9
|
+
import {
|
|
10
|
+
__name
|
|
11
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
12
|
+
|
|
13
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/store/vector-extension.js
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
var musl = /* @__PURE__ */ __name(() => {
|
|
16
|
+
if (process.platform !== "linux")
|
|
17
|
+
return false;
|
|
18
|
+
try {
|
|
19
|
+
return readFileSync("/proc/self/maps", "utf8").includes("ld-musl");
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}, "musl");
|
|
24
|
+
var found;
|
|
25
|
+
var vectorExtension = /* @__PURE__ */ __name(() => {
|
|
26
|
+
found ??= locate();
|
|
27
|
+
return found;
|
|
28
|
+
}, "vectorExtension");
|
|
29
|
+
var locate = /* @__PURE__ */ __name(async () => {
|
|
30
|
+
const onMusl = musl();
|
|
31
|
+
const target = `${process.platform}-${process.arch}${onMusl ? "-musl" : ""}`;
|
|
32
|
+
let path;
|
|
33
|
+
try {
|
|
34
|
+
const { extensionFor } = await importFrom(new URL("store/vector-extension.js", import.meta.resolve("@wirecat/cli-core")).href, "@wirecat/cli-core-sqlite");
|
|
35
|
+
path = extensionFor({ musl: onMusl });
|
|
36
|
+
} catch {
|
|
37
|
+
path = void 0;
|
|
38
|
+
}
|
|
39
|
+
if (path === void 0) {
|
|
40
|
+
found = void 0;
|
|
41
|
+
throw new CliError("configuration_error", `the message store needs the sqlite-vec extension, and @wirecat/cli-core-sqlite has none for ${target} \u2014 reinstall the CLI so its dependencies install with it (an install that skips optional or native packages leaves it out)`, { reason: "store.vector-extension-missing", target });
|
|
42
|
+
}
|
|
43
|
+
return path;
|
|
44
|
+
}, "locate");
|
|
45
|
+
var loadVectorExtension = /* @__PURE__ */ __name((database, path) => {
|
|
46
|
+
try {
|
|
47
|
+
database.loadExtension(path);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw new CliError("configuration_error", `the sqlite-vec extension did not load on ${process.platform}-${process.arch} \u2014 reinstall the CLI; on macOS under Bun, @wirecat/cli-core-sqlite's SQLite must be installed, since the system's cannot load extensions`, { reason: "store.vector-extension-failed", cause: error instanceof Error ? error.message : String(error) });
|
|
50
|
+
} finally {
|
|
51
|
+
database.enableLoadExtension?.(false);
|
|
52
|
+
}
|
|
53
|
+
}, "loadVectorExtension");
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
vectorExtension,
|
|
57
|
+
loadVectorExtension
|
|
58
|
+
};
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
OAuthError,
|
|
5
|
+
OAuthErrorCode
|
|
6
|
+
} from "./chunk-5FONRUG6.js";
|
|
7
|
+
import {
|
|
8
|
+
ACCESS_SECONDS,
|
|
9
|
+
REFRESH_SECONDS,
|
|
10
|
+
readStored
|
|
11
|
+
} from "./chunk-3HRDEJJW.js";
|
|
12
|
+
import {
|
|
13
|
+
__name
|
|
14
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
15
|
+
|
|
16
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/mcp/http/oauth.js
|
|
17
|
+
import { createHash, randomBytes, randomInt, timingSafeEqual } from "node:crypto";
|
|
18
|
+
import { chmodSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { dirname } from "node:path";
|
|
20
|
+
var AUTH_CODE_MS = 60 * 1e3;
|
|
21
|
+
var LOGIN_CODE_MS = 10 * 60 * 1e3;
|
|
22
|
+
var WRONG_TRIES = 5;
|
|
23
|
+
var WRONG_CODE_WAIT_MS = 3e4;
|
|
24
|
+
var MAX_CLIENTS = 10;
|
|
25
|
+
var CODE_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
26
|
+
var hash = /* @__PURE__ */ __name((value) => createHash("sha256").update(value).digest("base64url"), "hash");
|
|
27
|
+
var secret = /* @__PURE__ */ __name(() => randomBytes(32).toString("base64url"), "secret");
|
|
28
|
+
var same = /* @__PURE__ */ __name((given, expected) => {
|
|
29
|
+
const left = Buffer.from(given);
|
|
30
|
+
const right = Buffer.from(expected);
|
|
31
|
+
return left.byteLength === right.byteLength && timingSafeEqual(left, right);
|
|
32
|
+
}, "same");
|
|
33
|
+
var tokenFile = /* @__PURE__ */ __name((path) => ({
|
|
34
|
+
read: /* @__PURE__ */ __name(() => readStored(path), "read"),
|
|
35
|
+
write: /* @__PURE__ */ __name((stored) => {
|
|
36
|
+
mkdirSync(dirname(path), { recursive: true, mode: 448 });
|
|
37
|
+
const temporary = `${path}.${randomBytes(16).toString("hex")}.tmp`;
|
|
38
|
+
writeFileSync(temporary, JSON.stringify(stored), { mode: 384, flag: "wx" });
|
|
39
|
+
chmodSync(temporary, 384);
|
|
40
|
+
renameSync(temporary, path);
|
|
41
|
+
}, "write")
|
|
42
|
+
}), "tokenFile");
|
|
43
|
+
var revokeAll = /* @__PURE__ */ __name((path) => rmSync(path, { force: true }), "revokeAll");
|
|
44
|
+
var json = /* @__PURE__ */ __name((body, status = 200) => new Response(JSON.stringify(body), {
|
|
45
|
+
status,
|
|
46
|
+
headers: { "content-type": "application/json", "cache-control": "no-store" }
|
|
47
|
+
}), "json");
|
|
48
|
+
var oauthError = /* @__PURE__ */ __name((error, description, status = 400) => json({ error, error_description: description }, status), "oauthError");
|
|
49
|
+
var escapeHtml = /* @__PURE__ */ __name((value) => value.replace(/[&<>"']/g, (character) => `&#${character.charCodeAt(0)};`), "escapeHtml");
|
|
50
|
+
var redirectAllowed = /* @__PURE__ */ __name((uri) => {
|
|
51
|
+
try {
|
|
52
|
+
const url = new URL(uri);
|
|
53
|
+
if (url.hash)
|
|
54
|
+
return false;
|
|
55
|
+
return url.protocol === "https:" || url.protocol === "http:" && ["localhost", "127.0.0.1"].includes(url.hostname);
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}, "redirectAllowed");
|
|
60
|
+
var ownerLogin = /* @__PURE__ */ __name(({ issuer, resource, file, appName, onCode, now = /* @__PURE__ */ __name(() => Date.now(), "now") }) => {
|
|
61
|
+
const store = tokenFile(file);
|
|
62
|
+
const codes = /* @__PURE__ */ new Map();
|
|
63
|
+
let login = { value: "", expires: 0 };
|
|
64
|
+
let wrong = 0;
|
|
65
|
+
let retryAt = 0;
|
|
66
|
+
let renewal;
|
|
67
|
+
const freshCode = /* @__PURE__ */ __name(() => {
|
|
68
|
+
const part = /* @__PURE__ */ __name(() => Array.from({ length: 4 }, () => CODE_ALPHABET[randomInt(CODE_ALPHABET.length)]).join(""), "part");
|
|
69
|
+
login = { value: `${part()}-${part()}`, expires: now() + LOGIN_CODE_MS };
|
|
70
|
+
clearTimeout(renewal);
|
|
71
|
+
renewal = setTimeout(freshCode, LOGIN_CODE_MS);
|
|
72
|
+
renewal.unref();
|
|
73
|
+
onCode(login.value, new Date(login.expires));
|
|
74
|
+
}, "freshCode");
|
|
75
|
+
freshCode();
|
|
76
|
+
const base = issuer.pathname.replace(/\/+$/, "");
|
|
77
|
+
const endpoint = /* @__PURE__ */ __name((path) => new URL(`${base}${path}`, issuer.origin).href, "endpoint");
|
|
78
|
+
const metadata = {
|
|
79
|
+
issuer: issuer.href,
|
|
80
|
+
authorization_endpoint: endpoint("/authorize"),
|
|
81
|
+
token_endpoint: endpoint("/token"),
|
|
82
|
+
registration_endpoint: endpoint("/register"),
|
|
83
|
+
response_types_supported: ["code"],
|
|
84
|
+
grant_types_supported: ["authorization_code", "refresh_token"],
|
|
85
|
+
code_challenge_methods_supported: ["S256"],
|
|
86
|
+
token_endpoint_auth_methods_supported: ["none", "client_secret_post", "client_secret_basic"]
|
|
87
|
+
};
|
|
88
|
+
const issue = /* @__PURE__ */ __name((stored, clientId) => {
|
|
89
|
+
const access = secret();
|
|
90
|
+
const refresh = secret();
|
|
91
|
+
const seconds = Math.floor(now() / 1e3);
|
|
92
|
+
stored.tokens = stored.tokens.filter((one) => one.expiresAt > seconds);
|
|
93
|
+
stored.tokens.push({ hash: hash(access), kind: "access", clientId, expiresAt: seconds + ACCESS_SECONDS }, { hash: hash(refresh), kind: "refresh", clientId, expiresAt: seconds + REFRESH_SECONDS });
|
|
94
|
+
store.write(stored);
|
|
95
|
+
return json({ access_token: access, token_type: "Bearer", expires_in: ACCESS_SECONDS, refresh_token: refresh });
|
|
96
|
+
}, "issue");
|
|
97
|
+
const clientOf = /* @__PURE__ */ __name((stored, request, form) => {
|
|
98
|
+
let id = form.get("client_id") ?? "";
|
|
99
|
+
let given = form.get("client_secret") ?? void 0;
|
|
100
|
+
const basic = request.headers.get("authorization");
|
|
101
|
+
if (basic?.startsWith("Basic ")) {
|
|
102
|
+
const [user = "", password = ""] = Buffer.from(basic.slice(6), "base64").toString().split(":");
|
|
103
|
+
id = decodeURIComponent(user);
|
|
104
|
+
given = decodeURIComponent(password);
|
|
105
|
+
}
|
|
106
|
+
const client = stored.clients.find((one) => one.id === id);
|
|
107
|
+
if (!client)
|
|
108
|
+
return void 0;
|
|
109
|
+
if (client.authMethod === "none")
|
|
110
|
+
return client;
|
|
111
|
+
return given !== void 0 && client.secretHash && same(hash(given), client.secretHash) ? client : void 0;
|
|
112
|
+
}, "clientOf");
|
|
113
|
+
const register = /* @__PURE__ */ __name(async (request) => {
|
|
114
|
+
const body = await request.json().catch(() => null);
|
|
115
|
+
const uris = Array.isArray(body?.redirect_uris) ? body.redirect_uris.filter((one) => typeof one === "string") : [];
|
|
116
|
+
if (uris.length === 0 || !uris.every(redirectAllowed))
|
|
117
|
+
return oauthError("invalid_redirect_uri", "redirect_uris must be https URLs");
|
|
118
|
+
const requested = body?.token_endpoint_auth_method;
|
|
119
|
+
const authMethod = requested === "client_secret_post" || requested === "client_secret_basic" ? requested : "none";
|
|
120
|
+
const clientSecret = authMethod === "none" ? void 0 : secret();
|
|
121
|
+
const name = typeof body?.client_name === "string" ? body.client_name.slice(0, 100) : void 0;
|
|
122
|
+
const client = {
|
|
123
|
+
id: secret(),
|
|
124
|
+
redirectUris: uris,
|
|
125
|
+
authMethod,
|
|
126
|
+
issuedAt: Math.floor(now() / 1e3),
|
|
127
|
+
...name ? { name } : {},
|
|
128
|
+
...clientSecret ? { secretHash: hash(clientSecret) } : {}
|
|
129
|
+
};
|
|
130
|
+
const stored = store.read();
|
|
131
|
+
const seconds = Math.floor(now() / 1e3);
|
|
132
|
+
const holding = new Set(stored.tokens.filter((one) => one.expiresAt > seconds).map((one) => one.clientId));
|
|
133
|
+
stored.clients.push(client);
|
|
134
|
+
while (stored.clients.length > MAX_CLIENTS) {
|
|
135
|
+
const idle = stored.clients.findIndex((one) => !holding.has(one.id));
|
|
136
|
+
if (idle === -1)
|
|
137
|
+
return oauthError("invalid_client_metadata", "too many logged-in apps \u2014 run mcp revoke first");
|
|
138
|
+
stored.clients.splice(idle, 1);
|
|
139
|
+
}
|
|
140
|
+
store.write(stored);
|
|
141
|
+
return json({
|
|
142
|
+
client_id: client.id,
|
|
143
|
+
client_id_issued_at: client.issuedAt,
|
|
144
|
+
redirect_uris: uris,
|
|
145
|
+
token_endpoint_auth_method: authMethod,
|
|
146
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
147
|
+
response_types: ["code"],
|
|
148
|
+
...name ? { client_name: name } : {},
|
|
149
|
+
...clientSecret ? { client_secret: clientSecret, client_secret_expires_at: 0 } : {}
|
|
150
|
+
}, 201);
|
|
151
|
+
}, "register");
|
|
152
|
+
const page = /* @__PURE__ */ __name((params, client, message) => {
|
|
153
|
+
const hidden = ["response_type", "client_id", "redirect_uri", "code_challenge", "code_challenge_method", "state"].map((name) => `<input type="hidden" name="${name}" value="${escapeHtml(params.get(name) ?? "")}">`).join("");
|
|
154
|
+
const who = escapeHtml(client.name ?? "an application");
|
|
155
|
+
const target = new URL(params.get("redirect_uri") ?? "");
|
|
156
|
+
const html = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escapeHtml(appName)} login</title><style>body{font:16px system-ui,sans-serif;max-width:28rem;margin:3rem auto;padding:0 1rem;color:#1d2430}input[type=text]{font:20px ui-monospace,monospace;letter-spacing:.1em;width:100%;padding:.5rem;margin:.5rem 0 1rem;box-sizing:border-box}button{font:inherit;padding:.5rem 1rem}.error{color:#b42318}</style></head><body><h1>${escapeHtml(appName)}</h1><p>An app that calls itself <strong>${who}</strong> asks to reach your messages through <code>${escapeHtml(appName)} mcp --http</code>.</p><p>After you allow it, the login goes to <strong>${escapeHtml(target.host)}</strong>. Allow only if that is the app you are connecting, such as chatgpt.com or claude.ai.</p><p>Type the code shown in WireCat Desktop, or in the terminal where the server runs. If you did not start this login, close this page.</p>${message ? `<p class="error">${escapeHtml(message)}</p>` : ""}<form method="post" action="${escapeHtml(`${base}/authorize`)}">${hidden}<label>Login code<input type="text" name="login_code" autocomplete="off" autofocus required></label><button type="submit">Allow</button></form></body></html>`;
|
|
157
|
+
return new Response(html, {
|
|
158
|
+
status: message ? 400 : 200,
|
|
159
|
+
headers: {
|
|
160
|
+
"content-type": "text/html; charset=utf-8",
|
|
161
|
+
"cache-control": "no-store",
|
|
162
|
+
"x-frame-options": "DENY",
|
|
163
|
+
"content-security-policy": `default-src 'none'; style-src 'unsafe-inline'; form-action 'self' ${target.origin}; frame-ancestors 'none'`,
|
|
164
|
+
// no-referrer makes the browser post this form with `Origin: null`, which the Origin check refuses.
|
|
165
|
+
"referrer-policy": "same-origin"
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}, "page");
|
|
169
|
+
const authorize = /* @__PURE__ */ __name(async (request) => {
|
|
170
|
+
const params = request.method === "POST" ? new URLSearchParams(await request.text()) : new URL(request.url).searchParams;
|
|
171
|
+
const stored = store.read();
|
|
172
|
+
const client = stored.clients.find((one) => one.id === params.get("client_id"));
|
|
173
|
+
const redirectUri = params.get("redirect_uri") ?? "";
|
|
174
|
+
if (!client?.redirectUris.includes(redirectUri))
|
|
175
|
+
return new Response("Unknown client or redirect address.", { status: 400 });
|
|
176
|
+
if (params.get("response_type") !== "code" || params.get("code_challenge_method") !== "S256" || !params.get("code_challenge"))
|
|
177
|
+
return new Response("This server needs response_type=code and PKCE with S256.", { status: 400 });
|
|
178
|
+
if (request.method !== "POST")
|
|
179
|
+
return page(params, client);
|
|
180
|
+
const throttled = /* @__PURE__ */ __name(() => new Response("Too many wrong codes. Wait, then try the new code.", {
|
|
181
|
+
status: 429,
|
|
182
|
+
headers: { "retry-after": String(Math.ceil((retryAt - now()) / 1e3)) }
|
|
183
|
+
}), "throttled");
|
|
184
|
+
if (wrong >= WRONG_TRIES) {
|
|
185
|
+
if (now() < retryAt)
|
|
186
|
+
return throttled();
|
|
187
|
+
wrong = 0;
|
|
188
|
+
freshCode();
|
|
189
|
+
}
|
|
190
|
+
const typed = (params.get("login_code") ?? "").trim().toUpperCase();
|
|
191
|
+
if (login.expires < now()) {
|
|
192
|
+
freshCode();
|
|
193
|
+
return page(params, client, "The code expired. A new one is shown in WireCat Desktop and in the terminal.");
|
|
194
|
+
}
|
|
195
|
+
if (!same(typed, login.value)) {
|
|
196
|
+
wrong += 1;
|
|
197
|
+
if (wrong >= WRONG_TRIES) {
|
|
198
|
+
retryAt = now() + WRONG_CODE_WAIT_MS;
|
|
199
|
+
return throttled();
|
|
200
|
+
}
|
|
201
|
+
return page(params, client, `Wrong code. Each code works for one login: after an app logs in, a new one appears in WireCat Desktop and in "${appName} mcp server status". ${WRONG_TRIES - wrong} tries left.`);
|
|
202
|
+
}
|
|
203
|
+
wrong = 0;
|
|
204
|
+
freshCode();
|
|
205
|
+
const code = secret();
|
|
206
|
+
codes.set(hash(code), {
|
|
207
|
+
clientId: client.id,
|
|
208
|
+
redirectUri,
|
|
209
|
+
challenge: params.get("code_challenge") ?? "",
|
|
210
|
+
expires: now() + AUTH_CODE_MS
|
|
211
|
+
});
|
|
212
|
+
const target = new URL(redirectUri);
|
|
213
|
+
target.searchParams.set("code", code);
|
|
214
|
+
const state = params.get("state");
|
|
215
|
+
if (state)
|
|
216
|
+
target.searchParams.set("state", state);
|
|
217
|
+
target.searchParams.set("iss", issuer.href);
|
|
218
|
+
return new Response(null, { status: 302, headers: { location: target.href, "cache-control": "no-store" } });
|
|
219
|
+
}, "authorize");
|
|
220
|
+
const token = /* @__PURE__ */ __name(async (request) => {
|
|
221
|
+
const form = new URLSearchParams(await request.text());
|
|
222
|
+
const stored = store.read();
|
|
223
|
+
const client = clientOf(stored, request, form);
|
|
224
|
+
if (!client)
|
|
225
|
+
return oauthError("invalid_client", "unknown client or wrong secret", 401);
|
|
226
|
+
const requestedResource = form.get("resource");
|
|
227
|
+
if (requestedResource && requestedResource !== resource.href)
|
|
228
|
+
return oauthError("invalid_target", "this server issues tokens only for its own MCP endpoint");
|
|
229
|
+
if (form.get("grant_type") === "authorization_code") {
|
|
230
|
+
const key = hash(form.get("code") ?? "");
|
|
231
|
+
const entry = codes.get(key);
|
|
232
|
+
codes.delete(key);
|
|
233
|
+
const verifier2 = form.get("code_verifier") ?? "";
|
|
234
|
+
const challenge = createHash("sha256").update(verifier2).digest("base64url");
|
|
235
|
+
if (!entry || entry.expires < now() || entry.clientId !== client.id || entry.redirectUri !== form.get("redirect_uri") || !same(challenge, entry.challenge))
|
|
236
|
+
return oauthError("invalid_grant", "the code is wrong, used or expired");
|
|
237
|
+
return issue(stored, client.id);
|
|
238
|
+
}
|
|
239
|
+
if (form.get("grant_type") === "refresh_token") {
|
|
240
|
+
const key = hash(form.get("refresh_token") ?? "");
|
|
241
|
+
const seconds = Math.floor(now() / 1e3);
|
|
242
|
+
const found = stored.tokens.find((one) => one.kind === "refresh" && one.hash === key);
|
|
243
|
+
if (!found || found.clientId !== client.id || found.expiresAt <= seconds)
|
|
244
|
+
return oauthError("invalid_grant", "the refresh token is wrong, used or expired");
|
|
245
|
+
stored.tokens = stored.tokens.filter((one) => one !== found);
|
|
246
|
+
return issue(stored, client.id);
|
|
247
|
+
}
|
|
248
|
+
return oauthError("unsupported_grant_type", "use authorization_code or refresh_token");
|
|
249
|
+
}, "token");
|
|
250
|
+
const verifier = {
|
|
251
|
+
verifyAccessToken: /* @__PURE__ */ __name(async (presented) => {
|
|
252
|
+
const seconds = Math.floor(now() / 1e3);
|
|
253
|
+
const stored = store.read();
|
|
254
|
+
const found = stored.tokens.find((one) => one.kind === "access" && one.hash === hash(presented));
|
|
255
|
+
if (!found || found.expiresAt <= seconds)
|
|
256
|
+
throw new OAuthError(OAuthErrorCode.InvalidToken, "the token is unknown or expired");
|
|
257
|
+
const clientName = stored.clients.find((one) => one.id === found.clientId)?.name;
|
|
258
|
+
return {
|
|
259
|
+
token: presented,
|
|
260
|
+
clientId: found.clientId,
|
|
261
|
+
scopes: [],
|
|
262
|
+
expiresAt: found.expiresAt,
|
|
263
|
+
resource,
|
|
264
|
+
...clientName ? { extra: { clientName } } : {}
|
|
265
|
+
};
|
|
266
|
+
}, "verifyAccessToken")
|
|
267
|
+
};
|
|
268
|
+
return {
|
|
269
|
+
code: /* @__PURE__ */ __name(() => login.value, "code"),
|
|
270
|
+
close: /* @__PURE__ */ __name(() => clearTimeout(renewal), "close"),
|
|
271
|
+
metadata,
|
|
272
|
+
verifier,
|
|
273
|
+
handle: /* @__PURE__ */ __name(async (request, path = new URL(request.url).pathname) => {
|
|
274
|
+
if (path === `${base}/register` && request.method === "POST")
|
|
275
|
+
return register(request);
|
|
276
|
+
if (path === `${base}/authorize` && (request.method === "GET" || request.method === "POST"))
|
|
277
|
+
return authorize(request);
|
|
278
|
+
if (path === `${base}/token` && request.method === "POST")
|
|
279
|
+
return token(request);
|
|
280
|
+
return void 0;
|
|
281
|
+
}, "handle")
|
|
282
|
+
};
|
|
283
|
+
}, "ownerLogin");
|
|
284
|
+
|
|
285
|
+
export {
|
|
286
|
+
revokeAll,
|
|
287
|
+
ownerLogin
|
|
288
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
alive
|
|
5
|
+
} from "./chunk-AIXLOMH4.js";
|
|
6
|
+
import {
|
|
7
|
+
resolvePaths,
|
|
8
|
+
writeSecurely
|
|
9
|
+
} from "./chunk-VHT2WI4I.js";
|
|
10
|
+
import {
|
|
11
|
+
__name
|
|
12
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
13
|
+
|
|
14
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.473.0_@wirecat+cli-base@0.65.0_commander@15.0.0_esbuild@0.28.2_type_39633e3162553a2c86dde989a9811fcb/node_modules/@wirecat/cli-core/dist/background/lock.js
|
|
15
|
+
import { existsSync, linkSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { dirname, join } from "node:path";
|
|
17
|
+
var lockPath = /* @__PURE__ */ __name((app, profile, env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "serve", `${profile}.lock`), "lockPath");
|
|
18
|
+
var readLock = /* @__PURE__ */ __name((path) => {
|
|
19
|
+
try {
|
|
20
|
+
const lock = JSON.parse(readFileSync(path, "utf8"));
|
|
21
|
+
return typeof lock.pid === "number" && typeof lock.startedAt === "string" ? lock : void 0;
|
|
22
|
+
} catch {
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
}, "readLock");
|
|
26
|
+
var holdLock = /* @__PURE__ */ __name((path, lock) => writeSecurely(path, `${JSON.stringify(lock)}
|
|
27
|
+
`, 384), "holdLock");
|
|
28
|
+
var takeLock = /* @__PURE__ */ __name((path, lock) => {
|
|
29
|
+
mkdirSync(dirname(path), { recursive: true, mode: 448 });
|
|
30
|
+
const draft = `${path}.${lock.pid}.tmp`;
|
|
31
|
+
writeFileSync(draft, `${JSON.stringify(lock)}
|
|
32
|
+
`, { mode: 384 });
|
|
33
|
+
try {
|
|
34
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
35
|
+
try {
|
|
36
|
+
linkSync(draft, path);
|
|
37
|
+
return void 0;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (error.code !== "EEXIST")
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
const held = readLock(path);
|
|
43
|
+
if (held && held.pid !== lock.pid && alive(held.pid))
|
|
44
|
+
return held;
|
|
45
|
+
rmSync(path, { force: true });
|
|
46
|
+
}
|
|
47
|
+
throw new Error(`could not take the lock ${path}: it keeps changing`);
|
|
48
|
+
} finally {
|
|
49
|
+
rmSync(draft, { force: true });
|
|
50
|
+
}
|
|
51
|
+
}, "takeLock");
|
|
52
|
+
var releaseLock = /* @__PURE__ */ __name((path, pid = process.pid) => {
|
|
53
|
+
if (readLock(path)?.pid === pid)
|
|
54
|
+
rmSync(path, { force: true });
|
|
55
|
+
}, "releaseLock");
|
|
56
|
+
var servingProfiles = /* @__PURE__ */ __name((app, env) => {
|
|
57
|
+
const dir = dirname(lockPath(app, "default", env));
|
|
58
|
+
if (!existsSync(dir))
|
|
59
|
+
return [];
|
|
60
|
+
return readdirSync(dir).filter((name) => name.endsWith(".lock")).map((name) => name.slice(0, -".lock".length)).filter((profile) => {
|
|
61
|
+
const lock = readLock(lockPath(app, profile, env));
|
|
62
|
+
return lock !== void 0 && alive(lock.pid);
|
|
63
|
+
});
|
|
64
|
+
}, "servingProfiles");
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
lockPath,
|
|
68
|
+
readLock,
|
|
69
|
+
holdLock,
|
|
70
|
+
takeLock,
|
|
71
|
+
releaseLock,
|
|
72
|
+
servingProfiles
|
|
73
|
+
};
|