@desplega.ai/agent-swarm 1.161.0 → 1.162.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 +3 -2
- package/dist/{acp-adapter-xx489vvb.js → acp-adapter-74m73ae9.js} +1 -1
- package/dist/{actions-ykjkn0m9.js → actions-4sr14gnt.js} +34 -31
- package/dist/{anthropic-messages-5qx80j9k.js → anthropic-messages-8xxrzky9.js} +22 -26
- package/dist/{app-0hdqa4k1.js → app-pt68fbwp.js} +13 -11
- package/dist/{artifact-3v5t9jtg.js → artifact-fey7dvj9.js} +3 -2
- package/dist/{assistant-am2g5g8a.js → assistant-cv3jytks.js} +37 -34
- package/dist/{azure-openai-responses-fszbkp0e.js → azure-openai-responses-f5cqsyj8.js} +15 -10
- package/dist/{boot-reembed-xy9t7avg.js → boot-reembed-4ht4gqth.js} +13 -11
- package/dist/{boot-reembed-gt5gjkt4.js → boot-reembed-nxpcvpj9.js} +12 -10
- package/dist/{boot-scrub-logs-9x0985y5.js → boot-scrub-logs-k93kyw8k.js} +9 -7
- package/dist/{boot-seeds-trv0d4vg.js → boot-seeds-1skcrs0e.js} +13 -10
- package/dist/{claude-adapter-jb6e1e54.js → claude-adapter-r5g0tzge.js} +23 -20
- package/dist/{claude-managed-setup-d1q9hv2b.js → claude-managed-setup-pkyrgshb.js} +3 -2
- package/dist/{claude-sdk-session-zga700s2.js → claude-sdk-session-jxyxnrwd.js} +5565 -5512
- package/dist/{cli-we0q7t0e.js → cli-2zy95vhm.js} +137 -64
- package/dist/{cli-35pj2yva.js → cli-4cwxn7gp.js} +38 -11
- package/dist/{cli-ad4qxm6j.js → cli-4dcpaefp.js} +2 -2
- package/dist/{cli-82c1pacn.js → cli-4x0csdjq.js} +71 -37
- package/dist/{cli-sqm3r5ps.js → cli-5bcd7sfy.js} +14 -18
- package/dist/{cli-d56tgd45.js → cli-5k6k8ta3.js} +2 -2
- package/dist/{cli-1er0rhz8.js → cli-5xhpb3kv.js} +15 -15
- package/dist/{cli-yrg7c73k.js → cli-7af8yhav.js} +10 -183
- package/dist/{cli-r6fsxc76.js → cli-7tre70zp.js} +513 -961
- package/dist/{cli-bh7jed3k.js → cli-8ev9xqnx.js} +34 -18
- package/dist/cli-bsky8g7w.js +449 -0
- package/dist/{cli-hn04t9db.js → cli-cebmgwsc.js} +14 -10
- package/dist/{cli-cfkrztza.js → cli-cvatsam7.js} +2 -2
- package/dist/{cli-2658f6at.js → cli-cvk6yzw5.js} +6 -8
- package/dist/{cli-ptr8h7kp.js → cli-eg0b3p0k.js} +5 -218
- package/dist/{cli-zb6xbk61.js → cli-g739zqzt.js} +4 -4
- package/dist/{cli-dv6cdjs2.js → cli-gd4favx9.js} +28 -7
- package/dist/{cli-5p3x4zna.js → cli-gpqpmns7.js} +2 -2
- package/dist/{cli-5nbmpy8w.js → cli-hb5c2x5y.js} +1 -1
- package/dist/{cli-jpf7e1zq.js → cli-hmsw1gpy.js} +3 -3
- package/dist/{cli-1cz0c18q.js → cli-jf7wmv1r.js} +2521 -733
- package/dist/{cli-qwsnmjdd.js → cli-jxs2ygaw.js} +168 -61
- package/dist/cli-kdkwd3yr.js +615 -0
- package/dist/{cli-hgmnf38m.js → cli-kh04eqwe.js} +1 -1
- package/dist/{cli-0383bp7f.js → cli-kp42yek0.js} +425 -90
- package/dist/{cli-ybgv4kw2.js → cli-mbssg1xv.js} +9 -2
- package/dist/{cli-jsp14b6c.js → cli-mzfth0bp.js} +38 -1
- package/dist/{cli-8g6mc14k.js → cli-nq7yqw7b.js} +16 -5
- package/dist/{cli-ee8bc46j.js → cli-nt8hecg9.js} +33 -32
- package/dist/{cli-9s68w752.js → cli-p0r8sxj5.js} +1 -1
- package/dist/{cli-58e8yr0d.js → cli-pkd6s2wy.js} +4 -2
- package/dist/{cli-17xpf7cm.js → cli-q24re23n.js} +6 -4
- package/dist/cli-qjjvzwzd.js +222 -0
- package/dist/cli-qrgt5bqf.js +189 -0
- package/dist/{cli-et8m9xsv.js → cli-rfjw9jw2.js} +22 -10
- package/dist/{cli-798vkbks.js → cli-rj0gqwwp.js} +2 -2
- package/dist/{cli-121ph74b.js → cli-rnyzn44p.js} +1 -1
- package/dist/{cli-vnnz5ncg.js → cli-s3hwpt9v.js} +95 -16
- package/dist/{cli-7119ja3w.js → cli-sptrj5f5.js} +2 -2
- package/dist/{cli-a8c82p2t.js → cli-sqvfa090.js} +13 -6
- package/dist/{cli-phfg8vy8.js → cli-swfmp1fx.js} +26 -26
- package/dist/{cli-nsdxtcbg.js → cli-tcen9p5w.js} +8 -5
- package/dist/{cli-9m03pzga.js → cli-vc9bp061.js} +5 -5
- package/dist/{cli-rtx9dygp.js → cli-vxe6qa4h.js} +1 -1
- package/dist/{cli-ecfxwnyb.js → cli-vy3ed88x.js} +1 -1
- package/dist/{cli-0c7ata9h.js → cli-vyqs9ya8.js} +6 -6
- package/dist/cli-wbvnn6tk.js +861 -0
- package/dist/{cli-kgd3p0bm.js → cli-wjgs5wxe.js} +6 -6
- package/dist/cli-wxkkd0e0.js +33 -0
- package/dist/{cli-akfj32vj.js → cli-xqpk3rp7.js} +5 -4
- package/dist/cli-zp38xvtm.js +9487 -0
- package/dist/{cli-3zc55ctx.js → cli-zvhd3f64.js} +2 -2
- package/dist/{cli-ze1d3wzv.js → cli-zxqx25nz.js} +5 -5
- package/dist/cli.js +32 -25
- package/dist/{cloudflare-workers-ai-system-one-k6fbxw9d.js → cloudflare-workers-ai-system-one-k8ddqjkq.js} +8 -6
- package/dist/{codex-adapter-04v97vep.js → codex-adapter-esvmnhn7.js} +13 -13
- package/dist/{codex-hook-20me6byw.js → codex-hook-m73jmqgx.js} +19 -3
- package/dist/{codex-session-runner-ax69mqq3.js → codex-session-runner-ban9excr.js} +13 -13
- package/dist/{commands-18gy08n1.js → commands-75413p2n.js} +9 -7
- package/dist/{db-d2pvjpyt.js → db-7f5pecwg.js} +11 -7
- package/dist/{dispatcher-8wbwyzjg.js → dispatcher-fh9at8nz.js} +33 -30
- package/dist/{dsh-adapter-ysqk9snv.js → dsh-adapter-wpze65d4.js} +3 -3
- package/dist/{e2b-esmt1r16.js → e2b-gjgdjp91.js} +10 -9
- package/dist/{pi-logo-animation-e9a0t68z.js → easter-egg-3d-3w5c2n4c.js} +122 -68
- package/dist/{execute-cmagrbrz.js → execute-f50wg9nh.js} +29 -6
- package/dist/{google-generative-ai-k6n5nbpp.js → google-generative-ai-jxxpnegy.js} +2 -2
- package/dist/{google-vertex-44xxtcvp.js → google-vertex-x7q1angm.js} +5 -5
- package/dist/{handlers-6b69m5kp.js → handlers-w13787bb.js} +36 -33
- package/dist/{hook-srnkt0hb.js → hook-46g1jrvx.js} +28 -15
- package/dist/{hook-k3mydf2n.js → hook-4tpts2ry.js} +20 -17
- package/dist/{http-hrf80ca1.js → http-19pzbfrt.js} +964 -176
- package/dist/{index-9rxdvj6w.js → index-8fd4dm4h.js} +34 -31
- package/dist/{index-1asbaj62.js → index-dqmp15bq.js} +35 -32
- package/dist/{index-45evq4ee.js → index-qb4q1y3e.js} +33 -30
- package/dist/{index-k4nj18qs.js → index-s75wc4wd.js} +12 -10
- package/dist/{index-xmevk2b9.js → index-scptvdxg.js} +27 -25
- package/dist/{keepalive-sfdz6ksp.js → keepalive-xa5ts9cd.js} +11 -9
- package/dist/{lead-ej91e9hw.js → lead-qp4xkvjq.js} +45 -41
- package/dist/{maintenance-80dnd7ke.js → maintenance-rm5885hm.js} +13 -11
- package/dist/{mistral-conversations-pc3ntnxt.js → mistral-conversations-rw7fbt22.js} +4 -4
- package/dist/{node-a5e00qhp.js → node-8zkdq42h.js} +834 -833
- package/dist/{oauth-refresh-sweep-m1etk2mx.js → oauth-refresh-sweep-1csdfebf.js} +10 -8
- package/dist/{onboard-0q8sdfqc.js → onboard-r6b78cs4.js} +10 -10
- package/dist/{openai-codex-responses-n7n683p2.js → openai-codex-responses-efvrgrq3.js} +4 -4
- package/dist/{openai-completions-jpaj5g2b.js → openai-completions-bbbrrz4z.js} +12 -8
- package/dist/{openai-responses-9a3nme9j.js → openai-responses-9jjyrcm1.js} +15 -10
- package/dist/{opencode-adapter-4wcgmvgf.js → opencode-adapter-kb3g6pkf.js} +2 -2
- package/dist/{otel-impl-hnqm9mxq.js → otel-impl-0y9knpky.js} +5 -5
- package/dist/{pi-mono-adapter-d6sqm9wr.js → pi-mono-adapter-z6s1bme2.js} +100 -19
- package/dist/{pricing-refresh-y60z64pm.js → pricing-refresh-mth26tgp.js} +11 -9
- package/dist/{rbac-roles-8pa0754b.js → rbac-roles-kwntb23q.js} +13 -9
- package/dist/rbac-roles-vpk4ebm8.js +45 -0
- package/dist/{registry-v5wytg0s.js → registry-km6t1jd2.js} +1 -1
- package/dist/{render-v2-418s1vj7.js → render-v2-hcm7h00y.js} +13 -11
- package/dist/{runtime-3pknc168.js → runtime-vfjsfsc5.js} +4 -4
- package/dist/{setup-yghdkj4x.js → setup-hbyzd65h.js} +2 -2
- package/dist/{virtual-modules-jcceevt5.js → virtual-modules-9bv7ry91.js} +9 -8
- package/dist/{work-objects-j1sz20v9.js → work-objects-m09sxnhe.js} +36 -33
- package/dist/{worker-d4gcvkjt.js → worker-0h35rvk4.js} +45 -41
- package/openapi.json +491 -12
- package/package.json +13 -6
- package/src/be/api-drain.ts +184 -0
- package/src/be/db/tasks/read.ts +31 -6
- package/src/be/db/tasks/write.ts +5 -4
- package/src/be/db.ts +42 -18
- package/src/be/memory/link-resolver.ts +29 -3
- package/src/be/migrations/192_favorites_agent_fs_path.sql +36 -0
- package/src/be/onboarding.ts +7 -1
- package/src/be/seed-prompt-templates.ts +1 -0
- package/src/be/swarm-config-guard.ts +35 -16
- package/src/be/task-citations.ts +11 -5
- package/src/be/users.ts +3 -0
- package/src/cli.tsx +3 -2
- package/src/comb/agent-fs.ts +39 -0
- package/src/comb/config.ts +37 -0
- package/src/comb/markers.ts +37 -0
- package/src/comb/review-batch.ts +486 -0
- package/src/comb/templates.ts +88 -0
- package/src/commands/context-preamble.ts +4 -1
- package/src/commands/hook.ts +2 -1
- package/src/commands/runner.ts +262 -68
- package/src/commands/templates.ts +10 -0
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/fs/agent-fs-provider.ts +106 -2
- package/src/heartbeat/heartbeat.ts +4 -0
- package/src/hooks/codex-hook.ts +25 -1
- package/src/hooks/hook.ts +13 -0
- package/src/hooks/pr-body-guard.ts +983 -0
- package/src/http/all-routes.ts +1 -0
- package/src/http/assets.ts +5 -17
- package/src/http/comb.ts +131 -0
- package/src/http/core.ts +2 -1
- package/src/http/fs.ts +9 -17
- package/src/http/index.ts +23 -9
- package/src/http/onboarding.ts +21 -2
- package/src/http/poll.ts +30 -3
- package/src/http/realtime.ts +62 -0
- package/src/http/request-principal.ts +22 -0
- package/src/http/status.ts +34 -2
- package/src/kv-reserved-namespaces.ts +10 -5
- package/src/providers/dsh-adapter.ts +1 -1
- package/src/providers/pi-mono-adapter.ts +123 -0
- package/src/rbac/legacy-policy.ts +1 -0
- package/src/rbac/permissions.ts +4 -0
- package/src/realtime/auth.ts +63 -1
- package/src/realtime/tickets.ts +52 -0
- package/src/realtime/transport.ts +51 -22
- package/src/scripts-runtime/types/swarm-extension.d.ts +3 -1
- package/src/telemetry-context.ts +175 -0
- package/src/telemetry-contract/EVENTS.md +81 -0
- package/src/telemetry-contract/SOURCE.json +9 -0
- package/src/telemetry-contract/catalog.json +1335 -0
- package/src/telemetry-contract/index.ts +60 -0
- package/src/telemetry-contract/types.gen.ts +1971 -0
- package/src/telemetry-identity.ts +129 -0
- package/src/telemetry-snapshot.ts +211 -0
- package/src/telemetry-trigger.ts +125 -0
- package/src/telemetry-types.typetest.ts +40 -0
- package/src/telemetry.ts +271 -67
- package/src/tests/api-drain-e2e.test.ts +249 -0
- package/src/tests/api-drain-worker-e2e.test.ts +216 -0
- package/src/tests/api-drain.test.ts +351 -0
- package/src/tests/comb-config-guard.test.ts +38 -0
- package/src/tests/comb-links.test.ts +162 -0
- package/src/tests/comb-markers.test.ts +68 -0
- package/src/tests/comb-review-batch.test.ts +770 -0
- package/src/tests/comb-status.test.ts +152 -0
- package/src/tests/db-task-read-contract.test.ts +2 -0
- package/src/tests/db-task-write-contract.test.ts +1 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/dsh-adapter.test.ts +1 -1
- package/src/tests/favorites-agent-fs-path.test.ts +226 -0
- package/src/tests/memory-link-resolver.test.ts +34 -0
- package/src/tests/onboarding.test.ts +108 -0
- package/src/tests/pi-mono-adapter.test.ts +265 -2
- package/src/tests/pr-body-leaks.test.ts +789 -0
- package/src/tests/preload.ts +8 -0
- package/src/tests/rbac-engine.test.ts +19 -0
- package/src/tests/realtime-room-auth.test.ts +104 -1
- package/src/tests/realtime-tickets.test.ts +74 -0
- package/src/tests/realtime-transport.test.ts +131 -4
- package/src/tests/runner-api-drain.test.ts +301 -0
- package/src/tests/runner-fallback-output.test.ts +61 -0
- package/src/tests/runner-fenced-json-output.test.ts +178 -0
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/send-task-requested-by.test.ts +133 -15
- package/src/tests/task-lifecycle-telemetry.test.ts +8 -3
- package/src/tests/telemetry-context.test.ts +314 -0
- package/src/tests/telemetry-init.test.ts +51 -19
- package/src/tests/telemetry-snapshot.test.ts +229 -0
- package/src/tests/telemetry-trigger.test.ts +200 -0
- package/src/tests/template-registry-helpers.ts +1 -0
- package/src/tests/workflow-agent-task-retry.test.ts +363 -0
- package/src/tests/workflow-definition-telemetry.test.ts +4 -4
- package/src/tools/poll-task.ts +20 -1
- package/src/tools/send-task.ts +9 -1
- package/src/tools/task-action.ts +11 -0
- package/src/types.ts +2 -1
- package/src/utils/api-drain.ts +24 -0
- package/src/utils/constants.ts +57 -16
- package/src/utils/pr-body-leaks.ts +172 -0
- package/src/utils/task-attachment-links.ts +14 -8
- package/src/workflows/recovery.ts +26 -1
- package/src/workflows/resume.ts +31 -4
- package/src/workflows/task-step-routing.ts +75 -2
- package/tsconfig.json +3 -0
- package/dist/cli-tjf4cn8z.js +0 -9119
- package/dist/cli-tsk3nz8a.js +0 -582
- package/dist/{cli-t6v2ah3r.js → cli-twrh04ap.js} +3 -3
|
@@ -0,0 +1,861 @@
|
|
|
1
|
+
// src/hooks/pr-body-guard.ts
|
|
2
|
+
import { isAbsolute, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
// src/utils/pr-body-leaks.ts
|
|
5
|
+
var AGENT_FS_PATH_RULE_ENABLED = false;
|
|
6
|
+
var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
7
|
+
var CHAT = String.raw`(?<![\w/.-])(?:Slack|DMs?|direct message|private (?:chat|message))(?![\w-]|\.\w)`;
|
|
8
|
+
var SPEECH = String.raw`(?::|\b(?:said|says|wrote|writes|asked|asks|verbatim)\b)`;
|
|
9
|
+
var LEAK_RULES = [
|
|
10
|
+
{
|
|
11
|
+
category: "slack-id",
|
|
12
|
+
pattern: /\b[CDGUW]0(?=[A-Z0-9]*[A-Z])(?=[A-Z0-9]*\d)[A-Z0-9]{8,10}\b/,
|
|
13
|
+
enabled: true
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
category: "slack-ts",
|
|
17
|
+
pattern: /\b1[6-9]\d{8}\.\d{6}\b/,
|
|
18
|
+
enabled: true
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
category: "slack-link",
|
|
22
|
+
pattern: /\bslack\.com\/(?:archives|client)\//i,
|
|
23
|
+
enabled: true
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
category: "swarm-dashboard-link",
|
|
27
|
+
pattern: /\bapp\.agent-swarm\.dev\/[^\s)"'<>]*[0-9a-f]{8}/i,
|
|
28
|
+
enabled: true
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
category: "agent-fs-link",
|
|
32
|
+
pattern: /\blive\.agent-fs\.dev\b/i,
|
|
33
|
+
enabled: true
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
category: "swarm-task-ref",
|
|
37
|
+
pattern: /\b(?:swarm\s+)?(?:task|memory|schedule)s?(?:[\s_-]*id)?\s*[:#=]?\s*[`'"]?(?=[0-9]*[a-f])[0-9a-f]{8}\b/i,
|
|
38
|
+
enabled: true,
|
|
39
|
+
proseOnly: true
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
category: "swarm-task-ref",
|
|
43
|
+
pattern: /\b(?:(?:swarm|workflow)\s+runs?(?:[\s_-]*id)?|runs?[\s_-]*id)\s*[:#=]?\s*[`'"]?(?=[0-9]*[a-f])[0-9a-f]{8}\b/i,
|
|
44
|
+
enabled: true,
|
|
45
|
+
proseOnly: true
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
category: "swarm-task-ref",
|
|
49
|
+
pattern: /(?:Task|Run|Memory|Schedule)Ids?\s*[:=]?\s*[`'"]?(?=[0-9]*[a-f])[0-9a-f]{8}\b/,
|
|
50
|
+
enabled: true,
|
|
51
|
+
proseOnly: true
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
category: "private-chat-quote",
|
|
55
|
+
pattern: new RegExp(String.raw`${CHAT}[^\n"“]{0,60}?${SPEECH}[^\n"“]{0,20}["“][^"”\n]{12,}`, "i"),
|
|
56
|
+
enabled: true
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
category: "private-chat-quote",
|
|
60
|
+
pattern: new RegExp(String.raw`${CHAT}[^\n]{0,60}${SPEECH}[ \t]*\n[ \t]*>`, "i"),
|
|
61
|
+
enabled: true
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
category: "agent-fs-path",
|
|
65
|
+
pattern: new RegExp(String.raw`\bthoughts/${UUID}/`, "i"),
|
|
66
|
+
enabled: AGENT_FS_PATH_RULE_ENABLED
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
var PRESIGNED_URL = /https?:\/\/[^\s)"'<>]*[?&]X-Amz-(?:Signature|Credential)=[^\s)"'<>]*/gi;
|
|
70
|
+
var PLACEHOLDER_UUIDS = new RegExp([
|
|
71
|
+
String.raw`\b([0-9a-f])\1{7}-\1{4}-\1{4}-\1{4}-\1{12}\b`,
|
|
72
|
+
String.raw`\b123e4567-e89b-12d3-a456-426614174000\b`,
|
|
73
|
+
String.raw`\b550e8400-e29b-41d4-a716-446655440000\b`
|
|
74
|
+
].join("|"), "gi");
|
|
75
|
+
var FENCED_CODE = /^[ \t]*(`{3,}|~{3,})[^\n]*\n[\s\S]*?(?:^[ \t]*\1[`~]*[ \t]*$|$(?![\s\S]))/gm;
|
|
76
|
+
function findPrBodyLeaks(body) {
|
|
77
|
+
const text = body.replace(/\r\n/g, `
|
|
78
|
+
`).replace(PRESIGNED_URL, "<presigned-url>").replace(PLACEHOLDER_UUIDS, "<placeholder-uuid>");
|
|
79
|
+
const prose = text.replace(FENCED_CODE, "<code-block>");
|
|
80
|
+
const found = [];
|
|
81
|
+
for (const rule of LEAK_RULES) {
|
|
82
|
+
if (rule.enabled && !found.includes(rule.category) && rule.pattern.test(rule.proseOnly ? prose : text)) {
|
|
83
|
+
found.push(rule.category);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return found;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/hooks/pr-body-guard.ts
|
|
90
|
+
var SEPARATORS = ["&&", "||", ";", "|", "&", `
|
|
91
|
+
`, "(", ")"];
|
|
92
|
+
var COMMAND_WRAPPERS = new Set(["env", "command", "exec", "time", "sudo", "nohup"]);
|
|
93
|
+
function tokenizeShell(command) {
|
|
94
|
+
let depth = 0;
|
|
95
|
+
const segments = [{ words: [], stdin: [], depth, async: false, ops: [] }];
|
|
96
|
+
const current = () => segments[segments.length - 1];
|
|
97
|
+
const listStarts = [0];
|
|
98
|
+
let continued = false;
|
|
99
|
+
const heredocs = [];
|
|
100
|
+
let hereString = false;
|
|
101
|
+
let word = "";
|
|
102
|
+
let inWord = false;
|
|
103
|
+
let quote = null;
|
|
104
|
+
const push = () => {
|
|
105
|
+
if (inWord) {
|
|
106
|
+
if (hereString)
|
|
107
|
+
current().stdin.push(word);
|
|
108
|
+
else
|
|
109
|
+
current().words.push(word);
|
|
110
|
+
hereString = false;
|
|
111
|
+
continued = false;
|
|
112
|
+
}
|
|
113
|
+
word = "";
|
|
114
|
+
inWord = false;
|
|
115
|
+
};
|
|
116
|
+
for (let i = 0;i < command.length; i++) {
|
|
117
|
+
const ch = command[i];
|
|
118
|
+
if (quote === "'") {
|
|
119
|
+
if (ch === "'")
|
|
120
|
+
quote = null;
|
|
121
|
+
else
|
|
122
|
+
word += ch;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (quote === '"') {
|
|
126
|
+
if (ch === '"')
|
|
127
|
+
quote = null;
|
|
128
|
+
else if (ch === "\\" && i + 1 < command.length && '"\\$`'.includes(command[i + 1])) {
|
|
129
|
+
word += command[++i];
|
|
130
|
+
} else
|
|
131
|
+
word += ch;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (ch === "'" || ch === '"') {
|
|
135
|
+
quote = ch;
|
|
136
|
+
inWord = true;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (ch === "\\" && i + 1 < command.length) {
|
|
140
|
+
if (command[i + 1] !== `
|
|
141
|
+
`) {
|
|
142
|
+
word += command[i + 1];
|
|
143
|
+
inWord = true;
|
|
144
|
+
}
|
|
145
|
+
i++;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (ch === "#" && !inWord) {
|
|
149
|
+
while (i + 1 < command.length && command[i + 1] !== `
|
|
150
|
+
`)
|
|
151
|
+
i++;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (command.startsWith("<<<", i)) {
|
|
155
|
+
push();
|
|
156
|
+
hereString = true;
|
|
157
|
+
i += 2;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (command.startsWith("<<", i)) {
|
|
161
|
+
push();
|
|
162
|
+
let j = i + 2;
|
|
163
|
+
const stripTabs = command[j] === "-";
|
|
164
|
+
if (stripTabs)
|
|
165
|
+
j++;
|
|
166
|
+
while (command[j] === " " || command[j] === "\t")
|
|
167
|
+
j++;
|
|
168
|
+
let delimiter = "";
|
|
169
|
+
while (j < command.length && !/[\s;&|()<>]/.test(command[j])) {
|
|
170
|
+
if (!`'"\\`.includes(command[j]))
|
|
171
|
+
delimiter += command[j];
|
|
172
|
+
j++;
|
|
173
|
+
}
|
|
174
|
+
if (delimiter)
|
|
175
|
+
heredocs.push({ delimiter, stripTabs, segment: current() });
|
|
176
|
+
i = j - 1;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (ch === `
|
|
180
|
+
` && heredocs.length > 0) {
|
|
181
|
+
push();
|
|
182
|
+
let j = i + 1;
|
|
183
|
+
for (const doc of heredocs) {
|
|
184
|
+
const lines = [];
|
|
185
|
+
while (j < command.length) {
|
|
186
|
+
const newline = command.indexOf(`
|
|
187
|
+
`, j);
|
|
188
|
+
const lineEnd = newline === -1 ? command.length : newline;
|
|
189
|
+
const line = command.slice(j, lineEnd);
|
|
190
|
+
j = lineEnd + 1;
|
|
191
|
+
if ((doc.stripTabs ? line.replace(/^\t+/, "") : line) === doc.delimiter)
|
|
192
|
+
break;
|
|
193
|
+
lines.push(line);
|
|
194
|
+
}
|
|
195
|
+
doc.segment.stdin.push(lines.join(`
|
|
196
|
+
`));
|
|
197
|
+
}
|
|
198
|
+
heredocs.length = 0;
|
|
199
|
+
segments.push({ words: [], stdin: [], depth, async: false, ops: [`
|
|
200
|
+
`] });
|
|
201
|
+
if (!continued)
|
|
202
|
+
listStarts[listStarts.length - 1] = segments.length - 1;
|
|
203
|
+
i = j - 1;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const sep = SEPARATORS.find((s) => command.startsWith(s, i));
|
|
207
|
+
if (sep) {
|
|
208
|
+
push();
|
|
209
|
+
if (sep === "|")
|
|
210
|
+
current().async = true;
|
|
211
|
+
if (sep === "&") {
|
|
212
|
+
for (let k = listStarts[listStarts.length - 1];k < segments.length; k++) {
|
|
213
|
+
segments[k].async = true;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (sep === "(")
|
|
217
|
+
depth++;
|
|
218
|
+
if (sep === ")")
|
|
219
|
+
depth--;
|
|
220
|
+
segments.push({ words: [], stdin: [], depth, async: sep === "|", ops: [sep] });
|
|
221
|
+
if (sep === "(")
|
|
222
|
+
listStarts.push(segments.length - 1);
|
|
223
|
+
else if (sep === ")") {
|
|
224
|
+
if (listStarts.length > 1)
|
|
225
|
+
listStarts.pop();
|
|
226
|
+
} else if (sep === ";" || sep === "&" || sep === `
|
|
227
|
+
` && !continued) {
|
|
228
|
+
listStarts[listStarts.length - 1] = segments.length - 1;
|
|
229
|
+
}
|
|
230
|
+
continued = sep === "&&" || sep === "||" || sep === "|" || sep === `
|
|
231
|
+
` && continued;
|
|
232
|
+
i += sep.length - 1;
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (ch === " " || ch === "\t") {
|
|
236
|
+
push();
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
word += ch;
|
|
240
|
+
inWord = true;
|
|
241
|
+
}
|
|
242
|
+
push();
|
|
243
|
+
for (const doc of heredocs)
|
|
244
|
+
doc.segment.stdin.push("");
|
|
245
|
+
let ops = [];
|
|
246
|
+
return segments.filter((s) => {
|
|
247
|
+
ops.push(...s.ops);
|
|
248
|
+
if (s.words.length === 0)
|
|
249
|
+
return false;
|
|
250
|
+
s.ops = ops;
|
|
251
|
+
ops = [];
|
|
252
|
+
return true;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
function expandPath(path, env) {
|
|
256
|
+
let unresolved = false;
|
|
257
|
+
const expanded = path.replace(/^~(?=\/|$)/, env.HOME ?? "~").replace(/\$\{(\w+)\}|\$(\w+)/g, (_, braced, bare) => {
|
|
258
|
+
const value = env[braced ?? bare];
|
|
259
|
+
if (value === undefined)
|
|
260
|
+
unresolved = true;
|
|
261
|
+
return value ?? "";
|
|
262
|
+
});
|
|
263
|
+
return unresolved ? null : expanded;
|
|
264
|
+
}
|
|
265
|
+
var VALUE_FLAGS = new Set([
|
|
266
|
+
"repo",
|
|
267
|
+
"body",
|
|
268
|
+
"body-file",
|
|
269
|
+
"title",
|
|
270
|
+
"base",
|
|
271
|
+
"head",
|
|
272
|
+
"assignee",
|
|
273
|
+
"label",
|
|
274
|
+
"milestone",
|
|
275
|
+
"project",
|
|
276
|
+
"reviewer",
|
|
277
|
+
"template",
|
|
278
|
+
"recover",
|
|
279
|
+
"add-assignee",
|
|
280
|
+
"add-label",
|
|
281
|
+
"add-project",
|
|
282
|
+
"add-reviewer",
|
|
283
|
+
"remove-assignee",
|
|
284
|
+
"remove-label",
|
|
285
|
+
"remove-project",
|
|
286
|
+
"remove-reviewer"
|
|
287
|
+
]);
|
|
288
|
+
var SHORT_FLAGS = {
|
|
289
|
+
R: "repo",
|
|
290
|
+
b: "body",
|
|
291
|
+
F: "body-file",
|
|
292
|
+
t: "title",
|
|
293
|
+
B: "base",
|
|
294
|
+
H: "head",
|
|
295
|
+
a: "assignee",
|
|
296
|
+
l: "label",
|
|
297
|
+
m: "milestone",
|
|
298
|
+
p: "project",
|
|
299
|
+
r: "reviewer",
|
|
300
|
+
T: "template"
|
|
301
|
+
};
|
|
302
|
+
function parseGhArgs(args) {
|
|
303
|
+
const parsed = { positionals: [], flags: [] };
|
|
304
|
+
for (let i = 0;i < args.length; i++) {
|
|
305
|
+
const arg = args[i];
|
|
306
|
+
const redirect = /^\d*(<|>>?|>\|)(&?)(.*)$/.exec(arg);
|
|
307
|
+
if (redirect) {
|
|
308
|
+
const target = redirect[3] || (args[++i] ?? "");
|
|
309
|
+
if (redirect[1] === "<" && !redirect[2])
|
|
310
|
+
parsed.stdinFile = target;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (arg === "--") {
|
|
314
|
+
parsed.positionals.push(...args.slice(i + 1));
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
if (arg.startsWith("--")) {
|
|
318
|
+
const eq = arg.indexOf("=");
|
|
319
|
+
const name = arg.slice(2, eq === -1 ? undefined : eq);
|
|
320
|
+
if (eq !== -1)
|
|
321
|
+
parsed.flags.push([name, arg.slice(eq + 1)]);
|
|
322
|
+
else
|
|
323
|
+
parsed.flags.push([name, VALUE_FLAGS.has(name) ? args[++i] ?? "" : ""]);
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
if (arg.startsWith("-") && arg.length > 1) {
|
|
327
|
+
for (let k = 1;k < arg.length; k++) {
|
|
328
|
+
const name = SHORT_FLAGS[arg[k]] ?? arg[k];
|
|
329
|
+
if (!VALUE_FLAGS.has(name)) {
|
|
330
|
+
parsed.flags.push([name, ""]);
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
const attached = arg.slice(k + 1).replace(/^=/, "");
|
|
334
|
+
parsed.flags.push([name, k + 1 < arg.length ? attached : args[++i] ?? ""]);
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
parsed.positionals.push(arg);
|
|
340
|
+
}
|
|
341
|
+
return parsed;
|
|
342
|
+
}
|
|
343
|
+
function repoFromPrUrl(target) {
|
|
344
|
+
const match = /^https?:\/\/([^/]+)\/([^/]+)\/([^/]+)\/pull\/\d+/.exec(target ?? "");
|
|
345
|
+
if (!match)
|
|
346
|
+
return;
|
|
347
|
+
const [, host, owner, name] = match;
|
|
348
|
+
return host === "github.com" ? `${owner}/${name}` : `${host}/${owner}/${name}`;
|
|
349
|
+
}
|
|
350
|
+
function classifyEditTarget(target, expand) {
|
|
351
|
+
if (target === undefined)
|
|
352
|
+
return { kind: "local" };
|
|
353
|
+
if (target.includes("`") || target.includes("$("))
|
|
354
|
+
return { kind: "unknown" };
|
|
355
|
+
const expanded = expand(target);
|
|
356
|
+
if (expanded === null)
|
|
357
|
+
return { kind: "unknown" };
|
|
358
|
+
const repo = repoFromPrUrl(expanded);
|
|
359
|
+
if (repo)
|
|
360
|
+
return { kind: "url", repo };
|
|
361
|
+
if (/^#?\d+$/.test(expanded))
|
|
362
|
+
return { kind: "local" };
|
|
363
|
+
if (/^[\w.+@:/-]+$/.test(expanded) && !expanded.startsWith("-") && !expanded.includes("://")) {
|
|
364
|
+
return { kind: "local" };
|
|
365
|
+
}
|
|
366
|
+
return { kind: "unknown" };
|
|
367
|
+
}
|
|
368
|
+
var newFrame = (kind) => ({ kind, tail: "none", list: [], block: [] });
|
|
369
|
+
var isCompound = (frame) => frame.kind !== "top" && frame.kind !== "paren";
|
|
370
|
+
function scanReservedWords(words) {
|
|
371
|
+
const actions = [];
|
|
372
|
+
let functionKeyword = false;
|
|
373
|
+
let k = 0;
|
|
374
|
+
for (;k < words.length; k++) {
|
|
375
|
+
const word = words[k];
|
|
376
|
+
if (word === "if")
|
|
377
|
+
actions.push("if");
|
|
378
|
+
else if (word === "while" || word === "until")
|
|
379
|
+
actions.push("loop");
|
|
380
|
+
else if (word === "{")
|
|
381
|
+
actions.push("brace");
|
|
382
|
+
else if (word === "else" || word === "elif")
|
|
383
|
+
actions.push("branch");
|
|
384
|
+
else if (word === "fi" || word === "done" || word === "esac" || word === "}") {
|
|
385
|
+
actions.push("close");
|
|
386
|
+
} else if (word === "function" && k + 1 < words.length) {
|
|
387
|
+
functionKeyword = true;
|
|
388
|
+
k++;
|
|
389
|
+
} else if (word !== "then" && word !== "do" && word !== "!")
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
if (words[k] === "for" || words[k] === "select")
|
|
393
|
+
actions.push("loop");
|
|
394
|
+
if (words[k] === "case")
|
|
395
|
+
actions.push("case");
|
|
396
|
+
return { start: k, actions, functionKeyword };
|
|
397
|
+
}
|
|
398
|
+
function loopEnds(segments) {
|
|
399
|
+
const ends = [];
|
|
400
|
+
const open = [];
|
|
401
|
+
segments.forEach((segment, index) => {
|
|
402
|
+
for (const action of scanReservedWords(segment.words).actions) {
|
|
403
|
+
if (action === "close") {
|
|
404
|
+
const opened = open.pop();
|
|
405
|
+
if (opened?.kind === "loop")
|
|
406
|
+
ends[opened.index] = index;
|
|
407
|
+
} else if (action !== "branch")
|
|
408
|
+
open.push({ kind: action, index });
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
for (const opened of open) {
|
|
412
|
+
if (opened.kind === "loop")
|
|
413
|
+
ends[opened.index] = segments.length - 1;
|
|
414
|
+
}
|
|
415
|
+
return ends;
|
|
416
|
+
}
|
|
417
|
+
var UNMODELED_VARIABLE_COMMANDS = new Set([
|
|
418
|
+
"read",
|
|
419
|
+
"source",
|
|
420
|
+
".",
|
|
421
|
+
"eval",
|
|
422
|
+
"declare",
|
|
423
|
+
"typeset",
|
|
424
|
+
"local",
|
|
425
|
+
"readonly",
|
|
426
|
+
"mapfile",
|
|
427
|
+
"readarray",
|
|
428
|
+
"getopts",
|
|
429
|
+
"let",
|
|
430
|
+
"case"
|
|
431
|
+
]);
|
|
432
|
+
var SPECIAL_BUILTINS = new Set([
|
|
433
|
+
":",
|
|
434
|
+
".",
|
|
435
|
+
"break",
|
|
436
|
+
"continue",
|
|
437
|
+
"eval",
|
|
438
|
+
"exec",
|
|
439
|
+
"exit",
|
|
440
|
+
"export",
|
|
441
|
+
"readonly",
|
|
442
|
+
"return",
|
|
443
|
+
"set",
|
|
444
|
+
"shift",
|
|
445
|
+
"times",
|
|
446
|
+
"trap",
|
|
447
|
+
"unset"
|
|
448
|
+
]);
|
|
449
|
+
var ASSIGNMENT = /^([A-Za-z_]\w*)(\[[^\]]*\])?(\+?)=([\s\S]*)$/;
|
|
450
|
+
function parseGhPrCommands(command, cwd, env = process.env) {
|
|
451
|
+
return parseWithState(command, {
|
|
452
|
+
env: { ...env },
|
|
453
|
+
exported: new Set(Object.keys(env).filter((name) => env[name] !== undefined)),
|
|
454
|
+
unknownVars: new Set,
|
|
455
|
+
dir: cwd
|
|
456
|
+
}, { allUnknown: false, dirUnknown: false });
|
|
457
|
+
}
|
|
458
|
+
var copyState = (s) => ({
|
|
459
|
+
env: { ...s.env },
|
|
460
|
+
exported: new Set(s.exported),
|
|
461
|
+
unknownVars: new Set(s.unknownVars),
|
|
462
|
+
dir: s.dir
|
|
463
|
+
});
|
|
464
|
+
var copyFrame = (f) => ({ ...f, list: [...f.list], block: [...f.block] });
|
|
465
|
+
var isGhWord = (word) => word === "gh" || word?.endsWith("/gh") === true;
|
|
466
|
+
var isShellWord = (word) => /(^|\/)(ba|da|k|z)?sh$/.test(word ?? "");
|
|
467
|
+
function parseWithState(command, initial, initialFlags) {
|
|
468
|
+
const found = [];
|
|
469
|
+
let state = initial;
|
|
470
|
+
let { allUnknown, dirUnknown } = initialFlags;
|
|
471
|
+
const scopes = [];
|
|
472
|
+
let frames = [newFrame("top")];
|
|
473
|
+
const top = () => frames[frames.length - 1];
|
|
474
|
+
const copy = copyState;
|
|
475
|
+
const expand = (word) => {
|
|
476
|
+
const names = [...word.matchAll(/\$\{(\w+)\}|\$(\w+)/g)].map((m) => m[1] ?? m[2]);
|
|
477
|
+
if (/^~(?=\/|$)/.test(word)) {
|
|
478
|
+
if (state.env.HOME === undefined)
|
|
479
|
+
return null;
|
|
480
|
+
names.push("HOME");
|
|
481
|
+
}
|
|
482
|
+
if (names.length > 0 && (allUnknown || names.some((name) => state.unknownVars.has(name)))) {
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
const expanded = expandPath(word, state.env);
|
|
486
|
+
return expanded === null || /[$`]/.test(expanded) ? null : expanded;
|
|
487
|
+
};
|
|
488
|
+
const forget = (writes) => {
|
|
489
|
+
for (const write of writes) {
|
|
490
|
+
if ("dir" in write)
|
|
491
|
+
state.dir = null;
|
|
492
|
+
else
|
|
493
|
+
state.unknownVars.add(write.name);
|
|
494
|
+
}
|
|
495
|
+
writes.length = 0;
|
|
496
|
+
};
|
|
497
|
+
const applied = (write) => {
|
|
498
|
+
const frame = top();
|
|
499
|
+
if (frame.tail === "and")
|
|
500
|
+
frame.list.push(write);
|
|
501
|
+
if (isCompound(frame))
|
|
502
|
+
frame.block.push(write);
|
|
503
|
+
};
|
|
504
|
+
const step = (segment, dry) => {
|
|
505
|
+
const { words, stdin, depth, ops } = segment;
|
|
506
|
+
while (scopes.length < depth)
|
|
507
|
+
scopes.push(copy(state));
|
|
508
|
+
while (scopes.length > Math.max(depth, 0)) {
|
|
509
|
+
const outer = scopes.pop();
|
|
510
|
+
outer.unknownVars = new Set([...outer.unknownVars, ...state.unknownVars]);
|
|
511
|
+
state = outer;
|
|
512
|
+
}
|
|
513
|
+
if (depth < 0) {
|
|
514
|
+
allUnknown = true;
|
|
515
|
+
state.dir = null;
|
|
516
|
+
}
|
|
517
|
+
let continued = false;
|
|
518
|
+
for (const op of ops) {
|
|
519
|
+
const frame = top();
|
|
520
|
+
if (op === "&&" || op === "||") {
|
|
521
|
+
if (op === "||")
|
|
522
|
+
forget(frame.list);
|
|
523
|
+
frame.tail = op === "&&" ? "and" : "or";
|
|
524
|
+
continued = true;
|
|
525
|
+
} else if (op === "|") {
|
|
526
|
+
continued = true;
|
|
527
|
+
} else if (op === "(") {
|
|
528
|
+
frames.push(newFrame("paren"));
|
|
529
|
+
continued = false;
|
|
530
|
+
} else if (op === ")") {
|
|
531
|
+
if (frame.kind === "paren")
|
|
532
|
+
frames.pop();
|
|
533
|
+
else if (frame.kind === "case") {
|
|
534
|
+
forget(frame.block);
|
|
535
|
+
forget(frame.list);
|
|
536
|
+
frame.tail = "none";
|
|
537
|
+
}
|
|
538
|
+
continued = false;
|
|
539
|
+
} else if (!(op === `
|
|
540
|
+
` && continued)) {
|
|
541
|
+
forget(frame.list);
|
|
542
|
+
frame.tail = "none";
|
|
543
|
+
continued = false;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
const reserved = scanReservedWords(words);
|
|
547
|
+
if (reserved.functionKeyword || ops.some((op, k) => op === "(" && ops[k + 1] === ")")) {
|
|
548
|
+
allUnknown = true;
|
|
549
|
+
dirUnknown = true;
|
|
550
|
+
}
|
|
551
|
+
for (const action2 of reserved.actions) {
|
|
552
|
+
const frame = top();
|
|
553
|
+
if (action2 === "branch" || action2 === "close") {
|
|
554
|
+
forget(frame.block);
|
|
555
|
+
forget(frame.list);
|
|
556
|
+
frame.tail = "none";
|
|
557
|
+
if (action2 === "close" && isCompound(frame))
|
|
558
|
+
frames.pop();
|
|
559
|
+
} else
|
|
560
|
+
frames.push(newFrame(action2));
|
|
561
|
+
}
|
|
562
|
+
const uncertain = dry || segment.async || top().tail === "or";
|
|
563
|
+
const assign = (name, value) => {
|
|
564
|
+
if (uncertain || value === null || /[$`]|^~|:~/.test(value)) {
|
|
565
|
+
state.unknownVars.add(name);
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
state.env[name] = value;
|
|
569
|
+
state.unknownVars.delete(name);
|
|
570
|
+
applied({ name });
|
|
571
|
+
};
|
|
572
|
+
for (const word of words) {
|
|
573
|
+
for (const match of word.matchAll(/\$\{(\w+):?=/g))
|
|
574
|
+
state.unknownVars.add(match[1]);
|
|
575
|
+
}
|
|
576
|
+
const start = reserved.start;
|
|
577
|
+
let i = start;
|
|
578
|
+
while (i < words.length && ASSIGNMENT.test(words[i]))
|
|
579
|
+
i++;
|
|
580
|
+
const assignments = words.slice(start, i).map((w) => ASSIGNMENT.exec(w));
|
|
581
|
+
const rest = words.slice(i);
|
|
582
|
+
const cmd = rest[0];
|
|
583
|
+
if (cmd === undefined) {
|
|
584
|
+
for (const [, name, index, append, value] of assignments) {
|
|
585
|
+
assign(name, index || append ? null : value);
|
|
586
|
+
}
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
if (SPECIAL_BUILTINS.has(cmd)) {
|
|
590
|
+
for (const [, name] of assignments)
|
|
591
|
+
state.unknownVars.add(name);
|
|
592
|
+
}
|
|
593
|
+
if (cmd === "cd" || cmd === "pushd") {
|
|
594
|
+
const operands = rest.slice(1);
|
|
595
|
+
while (operands[0] !== undefined && /^-[LPe@]+$/.test(operands[0]))
|
|
596
|
+
operands.shift();
|
|
597
|
+
if (operands[0] === "--")
|
|
598
|
+
operands.shift();
|
|
599
|
+
if (operands.length > 1)
|
|
600
|
+
return;
|
|
601
|
+
const operand = operands[0] ?? "~";
|
|
602
|
+
const target2 = operand === "-" ? null : expand(operand);
|
|
603
|
+
const dir = state.dir;
|
|
604
|
+
if (uncertain || target2 === null)
|
|
605
|
+
state.dir = null;
|
|
606
|
+
else {
|
|
607
|
+
state.dir = isAbsolute(target2) ? target2 : dir === null ? null : resolve(dir, target2);
|
|
608
|
+
applied({ dir: true });
|
|
609
|
+
}
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
if (cmd === "popd") {
|
|
613
|
+
state.dir = null;
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (cmd === "export") {
|
|
617
|
+
for (const word of rest.slice(1)) {
|
|
618
|
+
if (word.startsWith("-")) {
|
|
619
|
+
allUnknown = true;
|
|
620
|
+
continue;
|
|
621
|
+
}
|
|
622
|
+
const match = ASSIGNMENT.exec(word);
|
|
623
|
+
const name = match?.[1] ?? word;
|
|
624
|
+
if (match)
|
|
625
|
+
assign(name, match[2] || match[3] ? null : match[4]);
|
|
626
|
+
if (uncertain)
|
|
627
|
+
state.unknownVars.add(name);
|
|
628
|
+
else {
|
|
629
|
+
state.exported.add(name);
|
|
630
|
+
applied({ name });
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
if (cmd === "unset") {
|
|
636
|
+
const operands = rest.slice(1);
|
|
637
|
+
if (operands.some((w) => /^-\w*f/.test(w)))
|
|
638
|
+
return;
|
|
639
|
+
for (const name of operands.filter((w) => !w.startsWith("-"))) {
|
|
640
|
+
if (uncertain) {
|
|
641
|
+
state.unknownVars.add(name);
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
state.env[name] = undefined;
|
|
645
|
+
state.exported.delete(name);
|
|
646
|
+
state.unknownVars.delete(name);
|
|
647
|
+
applied({ name });
|
|
648
|
+
}
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
if (cmd === "for" || cmd === "select") {
|
|
652
|
+
const name = rest[1] ?? "";
|
|
653
|
+
if (/^[A-Za-z_]\w*$/.test(name))
|
|
654
|
+
state.unknownVars.add(name);
|
|
655
|
+
else
|
|
656
|
+
allUnknown = true;
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
if (UNMODELED_VARIABLE_COMMANDS.has(cmd) || cmd === "printf" && rest.some((w) => /^-v/.test(w))) {
|
|
660
|
+
if (cmd === "eval" && !dry) {
|
|
661
|
+
found.push(...parseWithState(rest.slice(1).join(" "), copy(state), { allUnknown, dirUnknown }));
|
|
662
|
+
}
|
|
663
|
+
allUnknown = true;
|
|
664
|
+
if (cmd === "source" || cmd === "." || cmd === "eval")
|
|
665
|
+
state.dir = null;
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
const offset = rest.findIndex((w) => !ASSIGNMENT.test(w) && !COMMAND_WRAPPERS.has(w));
|
|
669
|
+
let gh = offset === -1 ? -1 : i + offset;
|
|
670
|
+
if (COMMAND_WRAPPERS.has(cmd) && !isGhWord(words[gh]) && !isShellWord(words[gh])) {
|
|
671
|
+
gh = words.findIndex((w, k) => k > i && (isGhWord(w) || isShellWord(w)));
|
|
672
|
+
}
|
|
673
|
+
const wrapperFlags = gh > i && words.slice(i, gh).some((w) => w.startsWith("-"));
|
|
674
|
+
if (isShellWord(words[gh])) {
|
|
675
|
+
const flag = words.findIndex((w, k) => k > gh && /^-\w*c\w*$/.test(w));
|
|
676
|
+
const script = flag === -1 ? undefined : words[flag + 1];
|
|
677
|
+
if (script !== undefined && !dry) {
|
|
678
|
+
const child = copy(state);
|
|
679
|
+
for (const name of Object.keys(child.env)) {
|
|
680
|
+
if (!child.exported.has(name))
|
|
681
|
+
child.env[name] = undefined;
|
|
682
|
+
}
|
|
683
|
+
for (const w of words.slice(start, gh)) {
|
|
684
|
+
const match = ASSIGNMENT.exec(w);
|
|
685
|
+
if (!match)
|
|
686
|
+
continue;
|
|
687
|
+
const name = match[1];
|
|
688
|
+
child.exported.add(name);
|
|
689
|
+
if (match[2] || match[3] || /[$`]|^~|:~/.test(match[4]))
|
|
690
|
+
child.unknownVars.add(name);
|
|
691
|
+
else
|
|
692
|
+
child.env[name] = match[4];
|
|
693
|
+
}
|
|
694
|
+
if (wrapperFlags)
|
|
695
|
+
child.dir = null;
|
|
696
|
+
found.push(...parseWithState(script, child, {
|
|
697
|
+
allUnknown: allUnknown || wrapperFlags,
|
|
698
|
+
dirUnknown
|
|
699
|
+
}));
|
|
700
|
+
}
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
if (!isGhWord(words[gh])) {
|
|
704
|
+
if (words.some((w) => w.includes("`")))
|
|
705
|
+
allUnknown = true;
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
if (dry)
|
|
709
|
+
return;
|
|
710
|
+
const args = parseGhArgs(words.slice(gh + 1));
|
|
711
|
+
const [group, action, target] = args.positionals;
|
|
712
|
+
if (group !== "pr" || action !== "create" && action !== "edit")
|
|
713
|
+
return;
|
|
714
|
+
const values = (...names) => args.flags.filter(([name]) => names.includes(name)).map(([, value]) => value);
|
|
715
|
+
const prefixRepo = words.slice(start, gh).find((w) => w.startsWith("GH_REPO="))?.slice("GH_REPO=".length);
|
|
716
|
+
const editTarget = action === "edit" ? classifyEditTarget(target, expand) : { kind: "local" };
|
|
717
|
+
let repos = [...values("repo"), ...editTarget.kind === "url" ? [editTarget.repo] : []];
|
|
718
|
+
let unknownTarget = editTarget.kind === "unknown";
|
|
719
|
+
let alsoCheckout = false;
|
|
720
|
+
if (repos.length === 0) {
|
|
721
|
+
if (prefixRepo)
|
|
722
|
+
repos = [prefixRepo];
|
|
723
|
+
else if (allUnknown || wrapperFlags || state.unknownVars.has("GH_REPO"))
|
|
724
|
+
unknownTarget = true;
|
|
725
|
+
else if (state.env.GH_REPO) {
|
|
726
|
+
repos = [state.env.GH_REPO];
|
|
727
|
+
alsoCheckout = !state.exported.has("GH_REPO");
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
const inline = values("title", "body");
|
|
731
|
+
const files = values("body-file").filter((file) => file !== "-");
|
|
732
|
+
const fromStdin = values("body-file").includes("-");
|
|
733
|
+
if (fromStdin && args.stdinFile !== undefined)
|
|
734
|
+
files.push(args.stdinFile);
|
|
735
|
+
const bodyFiles = [];
|
|
736
|
+
const unresolvedBodyFiles = [];
|
|
737
|
+
for (const file of files) {
|
|
738
|
+
const expanded = expand(file);
|
|
739
|
+
if (expanded === null)
|
|
740
|
+
unresolvedBodyFiles.push(file);
|
|
741
|
+
else
|
|
742
|
+
bodyFiles.push(expanded);
|
|
743
|
+
}
|
|
744
|
+
found.push({
|
|
745
|
+
cwd: wrapperFlags || dirUnknown ? null : state.dir,
|
|
746
|
+
repos: [...new Set(repos)],
|
|
747
|
+
alsoCheckout,
|
|
748
|
+
unknownTarget,
|
|
749
|
+
texts: [...inline, ...fromStdin ? stdin : []],
|
|
750
|
+
bodyFiles,
|
|
751
|
+
unresolvedBodyFiles,
|
|
752
|
+
opaqueBody: inline.some((value) => value.endsWith("$")) || action === "edit" && target?.endsWith("$") === true || fromStdin && stdin.length === 0 && args.stdinFile === undefined
|
|
753
|
+
});
|
|
754
|
+
};
|
|
755
|
+
const segments = tokenizeShell(command);
|
|
756
|
+
const ends = loopEnds(segments);
|
|
757
|
+
segments.forEach((segment, index) => {
|
|
758
|
+
const end = ends[index];
|
|
759
|
+
if (end !== undefined) {
|
|
760
|
+
const saved = frames.map(copyFrame);
|
|
761
|
+
for (let k = index;k <= end; k++)
|
|
762
|
+
step(segments[k], true);
|
|
763
|
+
frames = saved;
|
|
764
|
+
}
|
|
765
|
+
step(segment, false);
|
|
766
|
+
});
|
|
767
|
+
return found;
|
|
768
|
+
}
|
|
769
|
+
var BLOCK_ADVICE = "Paraphrase the motivation ('a maintainer asked for X') and link only public sources (Fixes #N, a public PR or issue). Internal provenance stays in the swarm task.";
|
|
770
|
+
async function checkGhPrCommand(command, cwd, deps) {
|
|
771
|
+
if (!/\bgh\b[\s\S]*\bpr\b/.test(command))
|
|
772
|
+
return null;
|
|
773
|
+
for (const call of parseGhPrCommands(command, cwd, deps.env)) {
|
|
774
|
+
const leaks = new Set;
|
|
775
|
+
for (const text of call.opaqueBody ? [...call.texts, command] : call.texts) {
|
|
776
|
+
for (const leak of findPrBodyLeaks(text))
|
|
777
|
+
leaks.add(leak);
|
|
778
|
+
}
|
|
779
|
+
let unreadable = call.unresolvedBodyFiles[0];
|
|
780
|
+
for (const bodyFile of call.bodyFiles) {
|
|
781
|
+
try {
|
|
782
|
+
const base = isAbsolute(bodyFile) ? "/" : call.cwd;
|
|
783
|
+
if (base === null)
|
|
784
|
+
throw new Error("unknown working directory");
|
|
785
|
+
for (const leak of findPrBodyLeaks(await deps.readFile(resolve(base, bodyFile)))) {
|
|
786
|
+
leaks.add(leak);
|
|
787
|
+
}
|
|
788
|
+
} catch {
|
|
789
|
+
unreadable ??= bodyFile;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
if (leaks.size === 0 && unreadable === undefined)
|
|
793
|
+
continue;
|
|
794
|
+
const targets = call.unknownTarget ? [null] : call.repos.length > 0 ? [...call.repos, ...call.alsoCheckout ? [undefined] : []] : [undefined];
|
|
795
|
+
for (const repo of targets) {
|
|
796
|
+
let visibility = "UNKNOWN";
|
|
797
|
+
if (repo !== null && (repo !== undefined || call.cwd !== null)) {
|
|
798
|
+
try {
|
|
799
|
+
visibility = (await deps.repoVisibility({ cwd: call.cwd ?? cwd, repo })).trim();
|
|
800
|
+
} catch {
|
|
801
|
+
visibility = "UNKNOWN";
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
if (visibility === "PRIVATE" || visibility === "INTERNAL")
|
|
805
|
+
continue;
|
|
806
|
+
const where = repo === null ? "a gh pr edit target that could not be resolved" : visibility === "PUBLIC" ? "this public repo" : "a repo whose visibility could not be confirmed";
|
|
807
|
+
if (leaks.size > 0) {
|
|
808
|
+
return `PR body leak check: the PR body for ${where} contains internal identifiers (${[...leaks].join(", ")}). ${BLOCK_ADVICE}`;
|
|
809
|
+
}
|
|
810
|
+
return `PR body leak check: could not read --body-file ${unreadable} for ${where}, so the body was not checked. Pass a literal path to a file that exists.`;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
var defaultPrBodyGuardDeps = (env = process.env) => ({
|
|
816
|
+
env,
|
|
817
|
+
readFile: (path) => Bun.file(path).text(),
|
|
818
|
+
repoVisibility: async ({ cwd, repo }) => {
|
|
819
|
+
const proc = Bun.spawn([
|
|
820
|
+
"gh",
|
|
821
|
+
"repo",
|
|
822
|
+
"view",
|
|
823
|
+
...repo ? [repo] : [],
|
|
824
|
+
"--json",
|
|
825
|
+
"visibility",
|
|
826
|
+
"--jq",
|
|
827
|
+
".visibility"
|
|
828
|
+
], { cwd, stdout: "pipe", stderr: "ignore", stdin: "ignore" });
|
|
829
|
+
const timer = setTimeout(() => proc.kill(), 1e4);
|
|
830
|
+
try {
|
|
831
|
+
const [out, code] = await Promise.all([new Response(proc.stdout).text(), proc.exited]);
|
|
832
|
+
if (code !== 0)
|
|
833
|
+
throw new Error(`gh repo view exited ${code}`);
|
|
834
|
+
return out.trim();
|
|
835
|
+
} finally {
|
|
836
|
+
clearTimeout(timer);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
function shellCommandOf(toolInput) {
|
|
841
|
+
const command = toolInput?.command;
|
|
842
|
+
if (typeof command === "string")
|
|
843
|
+
return command;
|
|
844
|
+
if (Array.isArray(command) && command.every((part) => typeof part === "string")) {
|
|
845
|
+
if (command.length >= 3 && /^-\w*c$/.test(command[1])) {
|
|
846
|
+
return command[command.length - 1];
|
|
847
|
+
}
|
|
848
|
+
return command.join(" ");
|
|
849
|
+
}
|
|
850
|
+
return null;
|
|
851
|
+
}
|
|
852
|
+
async function guardGhPrBody(toolInput, cwd, deps = defaultPrBodyGuardDeps()) {
|
|
853
|
+
try {
|
|
854
|
+
const command = shellCommandOf(toolInput);
|
|
855
|
+
return command === null ? null : await checkGhPrCommand(command, cwd, deps);
|
|
856
|
+
} catch {
|
|
857
|
+
return null;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
export { guardGhPrBody };
|