@cydm/pie 2.7.19 → 2.8.0
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 +6 -6
- package/dist/builtin/extensions/ask-user/README.md +117 -0
- package/dist/builtin/extensions/ask-user/index.js +3 -3
- package/dist/builtin/extensions/cron/index.js +166 -23
- package/dist/builtin/extensions/im-forward/README.md +297 -0
- package/dist/builtin/extensions/im-forward/index.js +319 -42
- package/dist/builtin/extensions/init/index.js +0 -6
- package/dist/builtin/extensions/mcp-adapter/README.md +27 -0
- package/dist/builtin/extensions/memory/index.js +323 -0
- package/dist/builtin/extensions/memory/package.json +18 -0
- package/dist/builtin/extensions/pie-ipc/README.md +21 -0
- package/dist/builtin/extensions/pie-ipc/index.js +16 -16
- package/dist/builtin/extensions/plan-mode/METHOD.md +70 -0
- package/dist/builtin/extensions/plan-mode/index.js +149 -82
- package/dist/builtin/extensions/subagent/README.md +315 -0
- package/dist/builtin/extensions/subagent/index.js +7 -5
- package/dist/builtin/extensions/todo/index.js +3 -3
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/{chunk-U75F4DPF.js → chunk-BNSAEVRT.js} +201 -77
- package/dist/builtin/skills/chrome-devtools-axi/{cli-4ITIR57L.js → cli-AO2ZTPRM.js} +57 -202
- package/dist/chunks/chunk-5353DEEC.js +130 -0
- package/dist/chunks/{chunk-2H2DD22Z.js → chunk-HGC25NYB.js} +1 -1
- package/dist/chunks/{chunk-X7UO6BA6.js → chunk-JNOFHHLZ.js} +156 -65
- package/dist/chunks/{chunk-UDCGB3LZ.js → chunk-LJXHECZ7.js} +12183 -10951
- package/dist/chunks/{chunk-TGCI5M6R.js → chunk-NEES4EBX.js} +19 -141
- package/dist/chunks/{src-GX4UBAYF.js → src-5XOKRS6F.js} +2 -2
- package/dist/chunks/{test-stream-AKIZNFCM.js → test-stream-5SDHKKDB.js} +1 -1
- package/dist/cli.js +127 -96
- package/package.json +2 -2
|
@@ -6,16 +6,20 @@ import {
|
|
|
6
6
|
BRIDGE_PORT_IN_USE_EXIT_CODE,
|
|
7
7
|
PAGE_IDENTITY_CHANGED_ERROR,
|
|
8
8
|
clearSelectedPageId,
|
|
9
|
+
createdPageIdFromPageLists,
|
|
9
10
|
getSelectedPageId,
|
|
10
11
|
inspectProcessIdentity,
|
|
12
|
+
needsPageId,
|
|
11
13
|
overlaySessionSelected,
|
|
14
|
+
parsePagesList,
|
|
12
15
|
rememberToolRouting,
|
|
13
16
|
resolveBridgeScript,
|
|
14
17
|
resolveSessionName,
|
|
15
18
|
resolveSessionPidFile,
|
|
16
19
|
resolveSessionPort,
|
|
17
|
-
resolveSessionStateDir
|
|
18
|
-
|
|
20
|
+
resolveSessionStateDir,
|
|
21
|
+
setSelectedPageId
|
|
22
|
+
} from "./chunk-BNSAEVRT.js";
|
|
19
23
|
import "./chunk-OJ6N23UZ.js";
|
|
20
24
|
|
|
21
25
|
// ../../node_modules/chrome-devtools-axi/node_modules/@toon-format/toon/dist/index.mjs
|
|
@@ -1616,199 +1620,6 @@ import { execFileSync, spawn as spawn2 } from "node:child_process";
|
|
|
1616
1620
|
import { readFileSync as readFileSync3, existsSync as existsSync3, unlinkSync } from "node:fs";
|
|
1617
1621
|
import { request } from "node:http";
|
|
1618
1622
|
import { dirname as dirname3 } from "node:path";
|
|
1619
|
-
|
|
1620
|
-
// vendor/chrome-devtools-axi/src/pages.ts
|
|
1621
|
-
var PAGE_SCOPED_TOOLS = /* @__PURE__ */ new Set([
|
|
1622
|
-
"click",
|
|
1623
|
-
"drag",
|
|
1624
|
-
"emulate",
|
|
1625
|
-
"evaluate_script",
|
|
1626
|
-
"fill",
|
|
1627
|
-
"fill_form",
|
|
1628
|
-
"get_console_message",
|
|
1629
|
-
"get_network_request",
|
|
1630
|
-
"handle_dialog",
|
|
1631
|
-
"hover",
|
|
1632
|
-
"lighthouse_audit",
|
|
1633
|
-
"list_console_messages",
|
|
1634
|
-
"list_network_requests",
|
|
1635
|
-
"navigate_page",
|
|
1636
|
-
"performance_analyze_insight",
|
|
1637
|
-
"performance_start_trace",
|
|
1638
|
-
"performance_stop_trace",
|
|
1639
|
-
"press_key",
|
|
1640
|
-
"resize_page",
|
|
1641
|
-
"take_heapsnapshot",
|
|
1642
|
-
"take_screenshot",
|
|
1643
|
-
"take_snapshot",
|
|
1644
|
-
"type_text",
|
|
1645
|
-
"upload_file",
|
|
1646
|
-
"wait_for"
|
|
1647
|
-
]);
|
|
1648
|
-
function needsPageId(name, args = {}) {
|
|
1649
|
-
if (typeof args.pageId === "number") return false;
|
|
1650
|
-
if (name === "evaluate_script" && typeof args.serviceWorkerId === "string" && args.serviceWorkerId.length > 0) {
|
|
1651
|
-
return false;
|
|
1652
|
-
}
|
|
1653
|
-
return PAGE_SCOPED_TOOLS.has(name);
|
|
1654
|
-
}
|
|
1655
|
-
var GENERIC_SCHEME_SLASH_URL = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
1656
|
-
var COLON_ONLY_SCHEME_URL = /^(?:about:|data:|view-source:|blob:)/i;
|
|
1657
|
-
function isPageSchemeUrl(label) {
|
|
1658
|
-
return GENERIC_SCHEME_SLASH_URL.test(label) || COLON_ONLY_SCHEME_URL.test(label);
|
|
1659
|
-
}
|
|
1660
|
-
var MCP_SECTION_HEADER = /^##\s+(Pages|Extension Pages|Extension Service Workers|Third-party developer tools|WebMCP tools)$/;
|
|
1661
|
-
var PAGE_ID_LINE = /^\d+:(?:\s+|$)/;
|
|
1662
|
-
var OPEN_DIALOG_HEADER = /^# Open dialog$/;
|
|
1663
|
-
var HANDLE_DIALOG_FOOTER = /^Call handle_dialog to handle it before continuing\.$/;
|
|
1664
|
-
function stripTrailingIsolatedContext(label) {
|
|
1665
|
-
const match = label.match(/^(.*)\s+isolatedContext=.*$/);
|
|
1666
|
-
if (!match) return label;
|
|
1667
|
-
const before = match[1];
|
|
1668
|
-
const withoutSelected = before.replace(/\s*\[selected\]\s*$/, "").trimEnd();
|
|
1669
|
-
if (matchTrailingUrl(withoutSelected) !== null) return before;
|
|
1670
|
-
if (isPageSchemeUrl(withoutSelected)) return before;
|
|
1671
|
-
return label;
|
|
1672
|
-
}
|
|
1673
|
-
function stripPageSuffixes(rest) {
|
|
1674
|
-
let label = stripTrailingIsolatedContext(rest);
|
|
1675
|
-
if (/(?:^|\s)\[selected\]\s*$/.test(label)) {
|
|
1676
|
-
label = label.replace(/\s*\[selected\]\s*$/, "").trimEnd();
|
|
1677
|
-
}
|
|
1678
|
-
return label;
|
|
1679
|
-
}
|
|
1680
|
-
function matchTrailingUrl(label) {
|
|
1681
|
-
const trimmed = label.trimEnd();
|
|
1682
|
-
if (!trimmed.endsWith(")")) return null;
|
|
1683
|
-
const close = trimmed.length - 1;
|
|
1684
|
-
let from = close;
|
|
1685
|
-
while (from > 0) {
|
|
1686
|
-
const open = trimmed.lastIndexOf(" (", from - 1);
|
|
1687
|
-
if (open === -1) return null;
|
|
1688
|
-
const url = trimmed.slice(open + 2, close);
|
|
1689
|
-
if (isPageSchemeUrl(url)) {
|
|
1690
|
-
return { title: trimmed.slice(0, open), url };
|
|
1691
|
-
}
|
|
1692
|
-
from = open;
|
|
1693
|
-
}
|
|
1694
|
-
return null;
|
|
1695
|
-
}
|
|
1696
|
-
function hasSchemeUrl(label) {
|
|
1697
|
-
const rest = stripPageSuffixes(label);
|
|
1698
|
-
return matchTrailingUrl(rest) !== null || isPageSchemeUrl(rest);
|
|
1699
|
-
}
|
|
1700
|
-
function isCompletePageRow(row) {
|
|
1701
|
-
return hasSchemeUrl(row.replace(/^\d+:\s*/, ""));
|
|
1702
|
-
}
|
|
1703
|
-
function isTitleContinuationLine(line) {
|
|
1704
|
-
const m = line.match(/^(\d+):\s+(.+)$/);
|
|
1705
|
-
if (!m) return false;
|
|
1706
|
-
const rest = stripPageSuffixes(m[2]);
|
|
1707
|
-
if (matchTrailingUrl(rest) !== null) return false;
|
|
1708
|
-
if (isPageSchemeUrl(rest)) return false;
|
|
1709
|
-
return /(?:^|\s)\[selected\]\s*$/.test(stripTrailingIsolatedContext(m[2]));
|
|
1710
|
-
}
|
|
1711
|
-
function extractPageUrl(label) {
|
|
1712
|
-
const match = matchTrailingUrl(label);
|
|
1713
|
-
return match ? match.url : label.trim();
|
|
1714
|
-
}
|
|
1715
|
-
function pageRowRest(row) {
|
|
1716
|
-
return stripPageSuffixes(row.replace(/^\d+:\s*/, ""));
|
|
1717
|
-
}
|
|
1718
|
-
function stripDialogPreamble(text) {
|
|
1719
|
-
const lines = text.split(/\r?\n/);
|
|
1720
|
-
const kept = [];
|
|
1721
|
-
for (let i = 0; i < lines.length; ) {
|
|
1722
|
-
if (OPEN_DIALOG_HEADER.test(lines[i].trim())) {
|
|
1723
|
-
let end = -1;
|
|
1724
|
-
for (let idx = i + 1; idx < lines.length; idx++) {
|
|
1725
|
-
if (HANDLE_DIALOG_FOOTER.test(lines[idx].trim())) end = idx;
|
|
1726
|
-
}
|
|
1727
|
-
if (end !== -1) {
|
|
1728
|
-
i = end + 1;
|
|
1729
|
-
continue;
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
kept.push(lines[i]);
|
|
1733
|
-
i++;
|
|
1734
|
-
}
|
|
1735
|
-
return kept.join("\n");
|
|
1736
|
-
}
|
|
1737
|
-
function followingLinesCompleteTitle(rawLines, headerIndex, currentRow) {
|
|
1738
|
-
let acc = `${currentRow} ## Pages`;
|
|
1739
|
-
for (let i = headerIndex + 1; i < rawLines.length; i++) {
|
|
1740
|
-
const next = rawLines[i].trim();
|
|
1741
|
-
if (next.length === 0) continue;
|
|
1742
|
-
if (next.match(MCP_SECTION_HEADER) !== null) return false;
|
|
1743
|
-
if (PAGE_ID_LINE.test(next)) {
|
|
1744
|
-
const rest = stripPageSuffixes(next.replace(/^\d+:\s*/, ""));
|
|
1745
|
-
if (isPageSchemeUrl(rest) && matchTrailingUrl(rest) === null) {
|
|
1746
|
-
return false;
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
acc += ` ${next}`;
|
|
1750
|
-
if (matchTrailingUrl(pageRowRest(acc)) !== null) return true;
|
|
1751
|
-
}
|
|
1752
|
-
return false;
|
|
1753
|
-
}
|
|
1754
|
-
function collapsePageRows(text) {
|
|
1755
|
-
const rows = [];
|
|
1756
|
-
let inPageBlock = false;
|
|
1757
|
-
const rawLines = stripDialogPreamble(text).split(/\r?\n/);
|
|
1758
|
-
for (let index = 0; index < rawLines.length; index++) {
|
|
1759
|
-
const line = rawLines[index].trim();
|
|
1760
|
-
if (line.length === 0) continue;
|
|
1761
|
-
const section = line.match(MCP_SECTION_HEADER)?.[1];
|
|
1762
|
-
if (section !== void 0) {
|
|
1763
|
-
const prev = rows[rows.length - 1];
|
|
1764
|
-
if (section === "Pages" && inPageBlock && prev !== void 0 && !isCompletePageRow(prev) && followingLinesCompleteTitle(rawLines, index, prev)) {
|
|
1765
|
-
rows[rows.length - 1] += ` ${line}`;
|
|
1766
|
-
continue;
|
|
1767
|
-
}
|
|
1768
|
-
if (section === "Pages") {
|
|
1769
|
-
rows.length = 0;
|
|
1770
|
-
inPageBlock = true;
|
|
1771
|
-
} else if (section === "Extension Pages") {
|
|
1772
|
-
inPageBlock = true;
|
|
1773
|
-
} else {
|
|
1774
|
-
inPageBlock = false;
|
|
1775
|
-
}
|
|
1776
|
-
continue;
|
|
1777
|
-
}
|
|
1778
|
-
if (!inPageBlock) continue;
|
|
1779
|
-
if (PAGE_ID_LINE.test(line)) {
|
|
1780
|
-
const prev = rows[rows.length - 1];
|
|
1781
|
-
if (prev !== void 0 && (!isCompletePageRow(prev) || isTitleContinuationLine(line))) {
|
|
1782
|
-
rows[rows.length - 1] += ` ${line}`;
|
|
1783
|
-
} else {
|
|
1784
|
-
rows.push(line);
|
|
1785
|
-
}
|
|
1786
|
-
continue;
|
|
1787
|
-
}
|
|
1788
|
-
if (rows.length > 0) {
|
|
1789
|
-
rows[rows.length - 1] += ` ${line}`;
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
return rows.map((row) => row.replace(/\s+/g, " "));
|
|
1793
|
-
}
|
|
1794
|
-
function parsePagesList(text) {
|
|
1795
|
-
const pages = [];
|
|
1796
|
-
for (const line of collapsePageRows(text)) {
|
|
1797
|
-
const m = line.match(/^(\d+):\s+(.+)$/);
|
|
1798
|
-
if (!m) continue;
|
|
1799
|
-
const id = Number.parseInt(m[1], 10);
|
|
1800
|
-
let rest = stripTrailingIsolatedContext(m[2]);
|
|
1801
|
-
const selected = /(?:^|\s)\[selected\]\s*$/.test(rest);
|
|
1802
|
-
if (selected) {
|
|
1803
|
-
rest = rest.replace(/\s*\[selected\]\s*$/, "").trimEnd();
|
|
1804
|
-
}
|
|
1805
|
-
const url = extractPageUrl(rest);
|
|
1806
|
-
pages.push({ id, url, selected });
|
|
1807
|
-
}
|
|
1808
|
-
return pages;
|
|
1809
|
-
}
|
|
1810
|
-
|
|
1811
|
-
// vendor/chrome-devtools-axi/src/client.ts
|
|
1812
1623
|
var DEFAULT_BRIDGE_TIMEOUT_MS = 3e4;
|
|
1813
1624
|
var MIN_BRIDGE_TIMEOUT_MS = 1e3;
|
|
1814
1625
|
var HEALTH_TIMEOUT_MS = 2e3;
|
|
@@ -2385,14 +2196,38 @@ async function callTool(name, args = {}) {
|
|
|
2385
2196
|
const notice = { pageIdentityChanged: false };
|
|
2386
2197
|
const port = await ensureBridge(void 0, notice);
|
|
2387
2198
|
let resolved = args;
|
|
2199
|
+
let newPageCreated = false;
|
|
2388
2200
|
try {
|
|
2389
2201
|
resolved = resolveToolArgs(name, args, notice.pageIdentityChanged);
|
|
2202
|
+
const pagesBeforeNewPage = name === "new_page" ? await postTool(port, "list_pages", {}) : null;
|
|
2390
2203
|
const result = await postTool(port, name, resolved, {
|
|
2391
2204
|
roots: collectRootDirs(name, resolved)
|
|
2392
2205
|
});
|
|
2393
|
-
|
|
2206
|
+
newPageCreated = name === "new_page";
|
|
2207
|
+
if (name === "new_page") {
|
|
2208
|
+
const pagesAfterNewPage = await postTool(port, "list_pages", {});
|
|
2209
|
+
const created = createdPageIdFromPageLists(
|
|
2210
|
+
pagesBeforeNewPage,
|
|
2211
|
+
pagesAfterNewPage
|
|
2212
|
+
);
|
|
2213
|
+
if (created === null) {
|
|
2214
|
+
clearSelectedPageId();
|
|
2215
|
+
throw new CdpError(
|
|
2216
|
+
"A new page was created, but its page id could not be determined uniquely; no page was selected",
|
|
2217
|
+
"BROWSER_ERROR",
|
|
2218
|
+
[
|
|
2219
|
+
"Run `chrome-devtools-axi pages` to inspect the current tabs before selecting one",
|
|
2220
|
+
"Do not retry new_page until you have reviewed the current tabs; another tab may have been created concurrently"
|
|
2221
|
+
]
|
|
2222
|
+
);
|
|
2223
|
+
}
|
|
2224
|
+
setSelectedPageId(created);
|
|
2225
|
+
} else {
|
|
2226
|
+
rememberToolRouting(name, resolved);
|
|
2227
|
+
}
|
|
2394
2228
|
return result;
|
|
2395
2229
|
} catch (err) {
|
|
2230
|
+
if (newPageCreated) clearSelectedPageId();
|
|
2396
2231
|
if (err instanceof CdpError) throw err;
|
|
2397
2232
|
const message = err instanceof Error ? err.message : String(err);
|
|
2398
2233
|
if (isMissingPageError(message)) {
|
|
@@ -2720,6 +2555,18 @@ async function parseUidFresh(arg, caller) {
|
|
|
2720
2555
|
}
|
|
2721
2556
|
|
|
2722
2557
|
// vendor/chrome-devtools-axi/src/run.ts
|
|
2558
|
+
function parseRunPageId(args) {
|
|
2559
|
+
if (args.length === 0) return null;
|
|
2560
|
+
if (args.length === 2 && args[0] === "--page-id" && /^\d+$/.test(args[1])) {
|
|
2561
|
+
const pageId = Number(args[1]);
|
|
2562
|
+
if (Number.isSafeInteger(pageId)) return pageId;
|
|
2563
|
+
}
|
|
2564
|
+
throw new CdpError(
|
|
2565
|
+
"Usage: chrome-devtools-axi run [--page-id <id>]",
|
|
2566
|
+
"VALIDATION_ERROR",
|
|
2567
|
+
["Use `chrome-devtools-axi pages` to find the target page id"]
|
|
2568
|
+
);
|
|
2569
|
+
}
|
|
2723
2570
|
function unwrapNoArgIIFE(s) {
|
|
2724
2571
|
const candidate = s.endsWith(";") ? s.slice(0, -1).trimEnd() : s;
|
|
2725
2572
|
if (candidate.length < 4 || candidate[0] !== "(" || !candidate.endsWith(")")) {
|
|
@@ -3267,13 +3114,14 @@ examples:
|
|
|
3267
3114
|
chrome-devtools-axi eval "document.title"
|
|
3268
3115
|
chrome-devtools-axi eval "document.querySelectorAll('a').length"
|
|
3269
3116
|
chrome-devtools-axi eval "() => { const rows = [...document.querySelectorAll('tr')]; return rows.map(r => r.textContent) }"`,
|
|
3270
|
-
run: `usage: chrome-devtools-axi run <<'EOF'
|
|
3117
|
+
run: `usage: chrome-devtools-axi run [--page-id <id>] <<'EOF'
|
|
3271
3118
|
...script...
|
|
3272
3119
|
EOF
|
|
3273
3120
|
|
|
3274
3121
|
Execute a JavaScript script from stdin against the current browser session.
|
|
3275
|
-
|
|
3276
|
-
|
|
3122
|
+
Use --page-id to explicitly select an existing tab before running; no new tab
|
|
3123
|
+
is created for this option. The script gets a global \`page\` object. Only the
|
|
3124
|
+
script's stdout is returned. Pipe a script via heredoc or stdin \u2014 no file path needed.
|
|
3277
3125
|
|
|
3278
3126
|
script API (available as global \`page\`):
|
|
3279
3127
|
await page.open(url) Navigate, returns { url, status }
|
|
@@ -3309,6 +3157,10 @@ examples:
|
|
|
3309
3157
|
chrome-devtools-axi run <<'EOF'
|
|
3310
3158
|
const { status } = await page.open("https://httpbin.org/status/404");
|
|
3311
3159
|
console.log("status:", status);
|
|
3160
|
+
EOF
|
|
3161
|
+
|
|
3162
|
+
chrome-devtools-axi run --page-id 12 <<'EOF'
|
|
3163
|
+
console.log(await page.eval(() => document.title));
|
|
3312
3164
|
EOF`,
|
|
3313
3165
|
start: `usage: chrome-devtools-axi start
|
|
3314
3166
|
Start the bridge server (launches headless Chrome).
|
|
@@ -4365,7 +4217,8 @@ async function handleHeap(args) {
|
|
|
4365
4217
|
await callTool("take_heapsnapshot", { filePath });
|
|
4366
4218
|
return encode({ heap: filePath });
|
|
4367
4219
|
}
|
|
4368
|
-
async function handleRun() {
|
|
4220
|
+
async function handleRun(args) {
|
|
4221
|
+
const pageId = parseRunPageId(args);
|
|
4369
4222
|
if (process.stdin.isTTY) {
|
|
4370
4223
|
throw new CdpError("No script provided on stdin", "VALIDATION_ERROR", [
|
|
4371
4224
|
"Pipe a script: chrome-devtools-axi run <<'EOF'\\n...\\nEOF"
|
|
@@ -4377,6 +4230,7 @@ async function handleRun() {
|
|
|
4377
4230
|
"Pipe a script: chrome-devtools-axi run <<'EOF'\\n...\\nEOF"
|
|
4378
4231
|
]);
|
|
4379
4232
|
}
|
|
4233
|
+
if (pageId !== null) await callTool("select_page", { pageId });
|
|
4380
4234
|
const result = await runScript(content, callTool);
|
|
4381
4235
|
return RAW_STDOUT_MARKER + trimSingleTrailingNewline(result.stdout);
|
|
4382
4236
|
}
|
|
@@ -4455,7 +4309,7 @@ var COMMAND_HANDLERS = {
|
|
|
4455
4309
|
back: async (args) => handleBack(splitFullFlag(args).full),
|
|
4456
4310
|
wait: withoutFullFlag(handleWait),
|
|
4457
4311
|
eval: withFullFlag(handleEval),
|
|
4458
|
-
run: async () => handleRun(),
|
|
4312
|
+
run: async (args) => handleRun(args),
|
|
4459
4313
|
hover: withFullFlag(handleHover),
|
|
4460
4314
|
drag: withFullFlag(handleDrag),
|
|
4461
4315
|
fillform: withFullFlag(handleFillForm),
|
|
@@ -4492,7 +4346,7 @@ var COMMAND_FLAGS = {
|
|
|
4492
4346
|
back: ["--full"],
|
|
4493
4347
|
wait: [],
|
|
4494
4348
|
eval: ["--full"],
|
|
4495
|
-
run: [],
|
|
4349
|
+
run: ["--page-id"],
|
|
4496
4350
|
hover: ["--full"],
|
|
4497
4351
|
drag: ["--full"],
|
|
4498
4352
|
fillform: ["--full"],
|
|
@@ -4525,6 +4379,7 @@ var COMMAND_FLAGS = {
|
|
|
4525
4379
|
setup: []
|
|
4526
4380
|
};
|
|
4527
4381
|
var COMMAND_VALUE_FLAGS = {
|
|
4382
|
+
run: ["--page-id"],
|
|
4528
4383
|
screenshot: ["--uid", "--format"],
|
|
4529
4384
|
emulate: COMMAND_FLAGS.emulate,
|
|
4530
4385
|
console: COMMAND_FLAGS.console,
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/config.ts
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, renameSync } from "fs";
|
|
5
|
+
import { homedir } from "os";
|
|
6
|
+
import { dirname, join } from "path";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
8
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
var __dirname = dirname(__filename);
|
|
10
|
+
var isBunRuntime = !!process.versions.bun;
|
|
11
|
+
function getPackageDir() {
|
|
12
|
+
const envDir = process.env.PIE_PACKAGE_DIR;
|
|
13
|
+
if (envDir) {
|
|
14
|
+
if (envDir === "~") return homedir();
|
|
15
|
+
if (envDir.startsWith("~/")) return homedir() + envDir.slice(1);
|
|
16
|
+
return envDir;
|
|
17
|
+
}
|
|
18
|
+
let dir = __dirname;
|
|
19
|
+
while (dir !== dirname(dir)) {
|
|
20
|
+
if (existsSync(join(dir, "package.json"))) {
|
|
21
|
+
return dir;
|
|
22
|
+
}
|
|
23
|
+
dir = dirname(dir);
|
|
24
|
+
}
|
|
25
|
+
return __dirname;
|
|
26
|
+
}
|
|
27
|
+
function getThemesDir() {
|
|
28
|
+
const packageDir = getPackageDir();
|
|
29
|
+
const srcOrDist = existsSync(join(packageDir, "src")) ? "src" : "dist";
|
|
30
|
+
return join(packageDir, srcOrDist, "theme");
|
|
31
|
+
}
|
|
32
|
+
function getBuiltinDir() {
|
|
33
|
+
const packageDir = getPackageDir();
|
|
34
|
+
const distBuiltinDir = join(packageDir, "dist", "builtin");
|
|
35
|
+
if (existsSync(distBuiltinDir)) {
|
|
36
|
+
return distBuiltinDir;
|
|
37
|
+
}
|
|
38
|
+
return join(packageDir, "builtin");
|
|
39
|
+
}
|
|
40
|
+
function getPackageJsonPath() {
|
|
41
|
+
return join(getPackageDir(), "package.json");
|
|
42
|
+
}
|
|
43
|
+
var pkg = JSON.parse(readFileSync(getPackageJsonPath(), "utf-8"));
|
|
44
|
+
var CONFIG_DIR_NAME = ".pie";
|
|
45
|
+
var VERSION = pkg.version;
|
|
46
|
+
var ENV_AGENT_DIR = "PIE_CODING_AGENT_DIR";
|
|
47
|
+
function getConfigDir() {
|
|
48
|
+
const envDir = process.env[ENV_AGENT_DIR];
|
|
49
|
+
if (envDir) {
|
|
50
|
+
if (envDir === "~") return homedir();
|
|
51
|
+
if (envDir.startsWith("~/")) return homedir() + envDir.slice(1);
|
|
52
|
+
return envDir;
|
|
53
|
+
}
|
|
54
|
+
return join(homedir(), CONFIG_DIR_NAME);
|
|
55
|
+
}
|
|
56
|
+
function getAgentDir() {
|
|
57
|
+
return getConfigDir();
|
|
58
|
+
}
|
|
59
|
+
function getCustomThemesDir() {
|
|
60
|
+
return join(getConfigDir(), "themes");
|
|
61
|
+
}
|
|
62
|
+
function getSettingsPath() {
|
|
63
|
+
return join(getConfigDir(), "settings.json");
|
|
64
|
+
}
|
|
65
|
+
function getProjectSettingsPath(cwd) {
|
|
66
|
+
return join(cwd, CONFIG_DIR_NAME, "settings.json");
|
|
67
|
+
}
|
|
68
|
+
function getSessionsDir() {
|
|
69
|
+
return join(getConfigDir(), "sessions");
|
|
70
|
+
}
|
|
71
|
+
function getLogsDir() {
|
|
72
|
+
return join(getConfigDir(), "logs");
|
|
73
|
+
}
|
|
74
|
+
function getRuntimeLogPath() {
|
|
75
|
+
return join(getLogsDir(), "pie-cli.log");
|
|
76
|
+
}
|
|
77
|
+
function migrateConfigFromAgentDir() {
|
|
78
|
+
const oldAgentDir = join(homedir(), CONFIG_DIR_NAME, "agent");
|
|
79
|
+
const newConfigDir = getConfigDir();
|
|
80
|
+
if (!existsSync(oldAgentDir)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (!existsSync(newConfigDir)) {
|
|
84
|
+
mkdirSync(newConfigDir, { recursive: true });
|
|
85
|
+
}
|
|
86
|
+
const filesToMigrate = [
|
|
87
|
+
"keybindings.json",
|
|
88
|
+
"settings.json",
|
|
89
|
+
"pie-debug.log"
|
|
90
|
+
];
|
|
91
|
+
for (const file of filesToMigrate) {
|
|
92
|
+
const oldPath = join(oldAgentDir, file);
|
|
93
|
+
const newPath = file === "pie-debug.log" ? getRuntimeLogPath() : join(newConfigDir, file);
|
|
94
|
+
if (existsSync(oldPath) && !existsSync(newPath)) {
|
|
95
|
+
try {
|
|
96
|
+
if (file === "pie-debug.log") {
|
|
97
|
+
mkdirSync(getLogsDir(), { recursive: true });
|
|
98
|
+
}
|
|
99
|
+
renameSync(oldPath, newPath);
|
|
100
|
+
console.log(`[Config] Migrated ${file} to ${newPath}`);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const oldThemesDir = join(oldAgentDir, "themes");
|
|
106
|
+
const newThemesDir = getCustomThemesDir();
|
|
107
|
+
if (existsSync(oldThemesDir) && !existsSync(newThemesDir)) {
|
|
108
|
+
try {
|
|
109
|
+
renameSync(oldThemesDir, newThemesDir);
|
|
110
|
+
console.log(`[Config] Migrated themes to ${newThemesDir}`);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export {
|
|
117
|
+
getPackageDir,
|
|
118
|
+
getThemesDir,
|
|
119
|
+
getBuiltinDir,
|
|
120
|
+
VERSION,
|
|
121
|
+
getConfigDir,
|
|
122
|
+
getAgentDir,
|
|
123
|
+
getCustomThemesDir,
|
|
124
|
+
getSettingsPath,
|
|
125
|
+
getProjectSettingsPath,
|
|
126
|
+
getSessionsDir,
|
|
127
|
+
getLogsDir,
|
|
128
|
+
getRuntimeLogPath,
|
|
129
|
+
migrateConfigFromAgentDir
|
|
130
|
+
};
|