@sortedyuan/maybecode 0.3.2 → 0.5.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 +166 -55
- package/README.zh-CN.md +267 -0
- package/dist/application.d.ts +40 -34
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +290 -170
- package/dist/application.js.map +1 -1
- package/dist/args.d.ts +2 -2
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +50 -27
- package/dist/args.js.map +1 -1
- package/dist/bin.js +82 -71
- package/dist/bin.js.map +4 -4
- package/dist/cli/chunk-3IORPKBL.js +3572 -0
- package/dist/cli/chunk-3IORPKBL.js.map +7 -0
- package/dist/cli/{chunk-LVTRXPDS.js → chunk-4B2Z6KW7.js} +1547 -1536
- package/dist/cli/chunk-4B2Z6KW7.js.map +7 -0
- package/dist/cli/{chunk-JT6VBKOM.js → chunk-4WG6JIJJ.js} +127 -33
- package/dist/cli/{chunk-JT6VBKOM.js.map → chunk-4WG6JIJJ.js.map} +3 -3
- package/dist/cli/{chunk-K5JWPNSY.js → chunk-5SLWALZK.js} +3521 -16164
- package/dist/cli/chunk-5SLWALZK.js.map +7 -0
- package/dist/cli/chunk-MNBYXL5Y.js +132 -0
- package/dist/cli/chunk-MNBYXL5Y.js.map +7 -0
- package/dist/cli/{chunk-F4XRPLUM.js → chunk-SLWLUEHQ.js} +226 -86
- package/dist/cli/chunk-SLWLUEHQ.js.map +7 -0
- package/dist/cli/chunk-UQDZ55LQ.js +199 -0
- package/dist/cli/chunk-UQDZ55LQ.js.map +7 -0
- package/dist/cli/{chunk-7ISOHFS7.js → chunk-WMSG5ZTR.js} +717 -388
- package/dist/cli/chunk-WMSG5ZTR.js.map +7 -0
- package/dist/cli/chunk-WVIRS76R.js +4057 -0
- package/dist/cli/chunk-WVIRS76R.js.map +7 -0
- package/dist/cli/{chunk-HOU5ITUK.js → chunk-XTEMRAQW.js} +1 -1
- package/dist/cli/chunk-XTEMRAQW.js.map +7 -0
- package/dist/cli/chunk-Z3BOPBVU.js +91 -0
- package/dist/cli/chunk-Z3BOPBVU.js.map +7 -0
- package/dist/cli/{configured-WHY3GGAJ.js → configured-ACNM6TRQ.js} +10 -9
- package/dist/cli/{file-type-R2T7TBHI.js → file-type-HLHPV7WC.js} +817 -13
- package/dist/cli/file-type-HLHPV7WC.js.map +7 -0
- package/dist/cli/mcp-auth-XD5U7WCV.js +74 -0
- package/dist/cli/mcp-auth-XD5U7WCV.js.map +7 -0
- package/dist/cli/onboarding-WQWCPYEO.js +530 -0
- package/dist/cli/onboarding-WQWCPYEO.js.map +7 -0
- package/dist/cli/onboarding-check-HRRI5OJ7.js +32 -0
- package/dist/cli/onboarding-check-HRRI5OJ7.js.map +7 -0
- package/dist/cli/{retained-tui-VJ3VX4R3.js → retained-tui-QF5VMYLC.js} +788 -332
- package/dist/cli/retained-tui-QF5VMYLC.js.map +7 -0
- package/dist/cli/{sixel-LWTCM76G.js → sixel-ISZ4FZ3U.js} +37 -37
- package/dist/cli/{sixel-LWTCM76G.js.map → sixel-ISZ4FZ3U.js.map} +1 -1
- package/dist/cli/{team-T7G7PPNN.js → team-O2I5BXHM.js} +7 -6
- package/dist/cli/{team-v2-JGBBQ7FR.js → team-v2-YYO2G7DJ.js} +816 -390
- package/dist/cli/team-v2-YYO2G7DJ.js.map +7 -0
- package/dist/cli/{web-server-FOMNPY7Q.js → web-server-SXMH6FGA.js} +55 -19
- package/dist/cli/web-server-SXMH6FGA.js.map +7 -0
- package/dist/cli/{web-ui-COB6PKC5.js → web-ui-UWQUFE4W.js} +7 -6
- package/dist/config-schema.json +337 -0
- package/dist/configured.d.ts +18 -11
- package/dist/configured.d.ts.map +1 -1
- package/dist/configured.js +213 -390
- package/dist/configured.js.map +1 -1
- package/dist/controller.d.ts +19 -18
- package/dist/controller.d.ts.map +1 -1
- package/dist/delegation-commands.d.ts +1 -1
- package/dist/delegation-commands.d.ts.map +1 -1
- package/dist/delegation-commands.js +8 -8
- package/dist/delegation-commands.js.map +1 -1
- package/dist/errors.d.ts +2 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -1
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +8 -6
- package/dist/events.d.ts.map +1 -1
- package/dist/fork-picker.d.ts.map +1 -1
- package/dist/fork-picker.js +19 -5
- package/dist/fork-picker.js.map +1 -1
- package/dist/git-request.d.ts +6 -6
- package/dist/git-request.d.ts.map +1 -1
- package/dist/git-request.js +28 -15
- package/dist/git-request.js.map +1 -1
- package/dist/goal-commands.d.ts +1 -1
- package/dist/goal-commands.d.ts.map +1 -1
- package/dist/goal-commands.js +12 -5
- package/dist/goal-commands.js.map +1 -1
- package/dist/index.d.ts +5 -37
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -36
- package/dist/index.js.map +1 -1
- package/dist/instructions.d.ts +2 -7
- package/dist/instructions.d.ts.map +1 -1
- package/dist/instructions.js +7 -15
- package/dist/instructions.js.map +1 -1
- package/dist/keymap.d.ts +2 -2
- package/dist/keymap.d.ts.map +1 -1
- package/dist/keymap.js +2 -2
- package/dist/keymap.js.map +1 -1
- package/dist/maybecode-config.schema.json +1765 -0
- package/dist/mcp-auth.d.ts +1 -1
- package/dist/mcp-auth.d.ts.map +1 -1
- package/dist/mcp-auth.js +11 -8
- package/dist/mcp-auth.js.map +1 -1
- package/dist/mcp-commands.d.ts.map +1 -1
- package/dist/mcp-commands.js +18 -4
- package/dist/mcp-commands.js.map +1 -1
- package/dist/mcp-interaction-ui.d.ts.map +1 -1
- package/dist/mcp-interaction-ui.js +11 -4
- package/dist/mcp-interaction-ui.js.map +1 -1
- package/dist/media-history.d.ts +1 -1
- package/dist/media-history.d.ts.map +1 -1
- package/dist/media-history.js +8 -2
- package/dist/media-history.js.map +1 -1
- package/dist/model-picker.d.ts.map +1 -1
- package/dist/model-picker.js +10 -11
- package/dist/model-picker.js.map +1 -1
- package/dist/model-transition.d.ts +11 -0
- package/dist/model-transition.d.ts.map +1 -0
- package/dist/model-transition.js +48 -0
- package/dist/model-transition.js.map +1 -0
- package/dist/model.d.ts +2 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +8 -4
- package/dist/model.js.map +1 -1
- package/dist/onboarding-check.d.ts +3 -0
- package/dist/onboarding-check.d.ts.map +1 -0
- package/dist/onboarding-check.js +22 -0
- package/dist/onboarding-check.js.map +1 -0
- package/dist/onboarding.d.ts +6 -0
- package/dist/onboarding.d.ts.map +1 -0
- package/dist/onboarding.js +463 -0
- package/dist/onboarding.js.map +1 -0
- package/dist/plugins/application.d.ts +6 -4
- package/dist/plugins/application.d.ts.map +1 -1
- package/dist/plugins/application.js +106 -52
- package/dist/plugins/application.js.map +1 -1
- package/dist/plugins/instructions.d.ts +1 -1
- package/dist/plugins/instructions.d.ts.map +1 -1
- package/dist/plugins/instructions.js +24 -11
- package/dist/plugins/instructions.js.map +1 -1
- package/dist/plugins/resources.d.ts +2 -2
- package/dist/plugins/resources.d.ts.map +1 -1
- package/dist/plugins/resources.js +22 -12
- package/dist/plugins/resources.js.map +1 -1
- package/dist/policy.d.ts +1 -1
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +59 -11
- package/dist/policy.js.map +1 -1
- package/dist/run.d.ts +2 -0
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +38 -33
- package/dist/run.js.map +1 -1
- package/dist/runtime-instructions.d.ts +1 -1
- package/dist/runtime-instructions.d.ts.map +1 -1
- package/dist/runtime-instructions.js +15 -7
- package/dist/runtime-instructions.js.map +1 -1
- package/dist/session-navigation.d.ts +6 -0
- package/dist/session-navigation.d.ts.map +1 -0
- package/dist/session-navigation.js +64 -0
- package/dist/session-navigation.js.map +1 -0
- package/dist/session-picker.d.ts +1 -1
- package/dist/session-picker.d.ts.map +1 -1
- package/dist/session-picker.js +23 -32
- package/dist/session-picker.js.map +1 -1
- package/dist/settings.d.ts +718 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +14 -0
- package/dist/settings.js.map +1 -0
- package/dist/skills.d.ts +1 -1
- package/dist/skills.d.ts.map +1 -1
- package/dist/skills.js +10 -12
- package/dist/skills.js.map +1 -1
- package/dist/slash-commands.d.ts +2 -2
- package/dist/slash-commands.d.ts.map +1 -1
- package/dist/slash-commands.js +149 -67
- package/dist/slash-commands.js.map +1 -1
- package/dist/team-execution.d.ts +10 -0
- package/dist/team-execution.d.ts.map +1 -0
- package/dist/team-execution.js +29 -0
- package/dist/team-execution.js.map +1 -0
- package/dist/team-patches.d.ts.map +1 -1
- package/dist/team-patches.js +149 -52
- package/dist/team-patches.js.map +1 -1
- package/dist/team-plan.d.ts +2 -2
- package/dist/team-plan.d.ts.map +1 -1
- package/dist/team-plan.js +115 -34
- package/dist/team-plan.js.map +1 -1
- package/dist/team-recovery.d.ts +1 -1
- package/dist/team-recovery.d.ts.map +1 -1
- package/dist/team-recovery.js +40 -10
- package/dist/team-recovery.js.map +1 -1
- package/dist/team-v2.d.ts.map +1 -1
- package/dist/team-v2.js +335 -104
- package/dist/team-v2.js.map +1 -1
- package/dist/team-verification.d.ts +4 -2
- package/dist/team-verification.d.ts.map +1 -1
- package/dist/team-verification.js +300 -97
- package/dist/team-verification.js.map +1 -1
- package/dist/team.d.ts +2 -2
- package/dist/team.d.ts.map +1 -1
- package/dist/team.js +172 -62
- package/dist/team.js.map +1 -1
- package/dist/terminal-web.d.ts +1 -0
- package/dist/terminal-web.d.ts.map +1 -1
- package/dist/terminal-web.js +28 -10
- package/dist/terminal-web.js.map +1 -1
- package/dist/ui/actions.d.ts.map +1 -1
- package/dist/ui/actions.js.map +1 -1
- package/dist/ui/retained-tui.d.ts.map +1 -1
- package/dist/ui/retained-tui.js +231 -173
- package/dist/ui/retained-tui.js.map +1 -1
- package/dist/ui/{prototype-view.d.ts → terminal-view.d.ts} +7 -7
- package/dist/ui/terminal-view.d.ts.map +1 -0
- package/dist/ui/{prototype-view.js → terminal-view.js} +185 -98
- package/dist/ui/terminal-view.js.map +1 -0
- package/dist/web-commands.d.ts.map +1 -1
- package/dist/web-commands.js +160 -57
- package/dist/web-commands.js.map +1 -1
- package/dist/web-extension.d.ts.map +1 -1
- package/dist/web-extension.js +14 -4
- package/dist/web-extension.js.map +1 -1
- package/dist/web-server.d.ts.map +1 -1
- package/dist/web-server.js +2 -1
- package/dist/web-server.js.map +1 -1
- package/dist/web-ui.d.ts.map +1 -1
- package/dist/web-ui.js +167 -40
- package/dist/web-ui.js.map +1 -1
- package/dist/workspace-configuration.d.ts +7 -0
- package/dist/workspace-configuration.d.ts.map +1 -0
- package/dist/workspace-configuration.js +134 -0
- package/dist/workspace-configuration.js.map +1 -0
- package/dist/workspace-state.d.ts +20 -0
- package/dist/workspace-state.d.ts.map +1 -0
- package/dist/workspace-state.js +2 -0
- package/dist/workspace-state.js.map +1 -0
- package/dist/workspace.d.ts +26 -43
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +261 -323
- package/dist/workspace.js.map +1 -1
- package/package.json +21 -31
- package/dist/cli/chunk-7ISOHFS7.js.map +0 -7
- package/dist/cli/chunk-F4XRPLUM.js.map +0 -7
- package/dist/cli/chunk-H7SNBFO4.js +0 -5522
- package/dist/cli/chunk-H7SNBFO4.js.map +0 -7
- package/dist/cli/chunk-HOU5ITUK.js.map +0 -7
- package/dist/cli/chunk-K5JWPNSY.js.map +0 -7
- package/dist/cli/chunk-LVTRXPDS.js.map +0 -7
- package/dist/cli/chunk-VAZMCNBB.js +0 -686
- package/dist/cli/chunk-VAZMCNBB.js.map +0 -7
- package/dist/cli/chunk-WOFEI42C.js +0 -7820
- package/dist/cli/chunk-WOFEI42C.js.map +0 -7
- package/dist/cli/file-type-R2T7TBHI.js.map +0 -7
- package/dist/cli/mcp-auth-UNRHSIKJ.js +0 -63
- package/dist/cli/mcp-auth-UNRHSIKJ.js.map +0 -7
- package/dist/cli/retained-tui-VJ3VX4R3.js.map +0 -7
- package/dist/cli/team-v2-JGBBQ7FR.js.map +0 -7
- package/dist/cli/tui-SA74DKMA.js +0 -1705
- package/dist/cli/tui-SA74DKMA.js.map +0 -7
- package/dist/cli/web-server-FOMNPY7Q.js.map +0 -7
- package/dist/delegation.d.ts +0 -2
- package/dist/delegation.d.ts.map +0 -1
- package/dist/delegation.js +0 -2
- package/dist/delegation.js.map +0 -1
- package/dist/history-memory.d.ts +0 -2
- package/dist/history-memory.d.ts.map +0 -1
- package/dist/history-memory.js +0 -2
- package/dist/history-memory.js.map +0 -1
- package/dist/subagent-budget.d.ts +0 -2
- package/dist/subagent-budget.d.ts.map +0 -1
- package/dist/subagent-budget.js +0 -2
- package/dist/subagent-budget.js.map +0 -1
- package/dist/subagent-files.d.ts +0 -2
- package/dist/subagent-files.d.ts.map +0 -1
- package/dist/subagent-files.js +0 -2
- package/dist/subagent-files.js.map +0 -1
- package/dist/subagent-host.d.ts +0 -2
- package/dist/subagent-host.d.ts.map +0 -1
- package/dist/subagent-host.js +0 -2
- package/dist/subagent-host.js.map +0 -1
- package/dist/subagent-instructions.d.ts +0 -2
- package/dist/subagent-instructions.d.ts.map +0 -1
- package/dist/subagent-instructions.js +0 -2
- package/dist/subagent-instructions.js.map +0 -1
- package/dist/subagents.d.ts +0 -2
- package/dist/subagents.d.ts.map +0 -1
- package/dist/subagents.js +0 -2
- package/dist/subagents.js.map +0 -1
- package/dist/summarizer.d.ts +0 -2
- package/dist/summarizer.d.ts.map +0 -1
- package/dist/summarizer.js +0 -2
- package/dist/summarizer.js.map +0 -1
- package/dist/tui.d.ts +0 -7
- package/dist/tui.d.ts.map +0 -1
- package/dist/tui.js +0 -1109
- package/dist/tui.js.map +0 -1
- package/dist/ui/prototype-view.d.ts.map +0 -1
- package/dist/ui/prototype-view.js.map +0 -1
- /package/dist/cli/{configured-WHY3GGAJ.js.map → configured-ACNM6TRQ.js.map} +0 -0
- /package/dist/cli/{team-T7G7PPNN.js.map → team-O2I5BXHM.js.map} +0 -0
- /package/dist/cli/{web-ui-COB6PKC5.js.map → web-ui-UWQUFE4W.js.map} +0 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
__name
|
|
4
|
+
} from "./chunk-E732GDOI.js";
|
|
5
|
+
|
|
6
|
+
// apps/maybecode/src/policy.ts
|
|
7
|
+
import { resolveWritableWorkspacePath } from "@sortedyuan/coding-tools";
|
|
8
|
+
import { realpath } from "node:fs/promises";
|
|
9
|
+
import { relative } from "node:path";
|
|
10
|
+
function parsePermissionMode(value) {
|
|
11
|
+
if (value === "default" || value === "yolo") return value;
|
|
12
|
+
throw new TypeError('permissionMode must be "default" or "yolo"');
|
|
13
|
+
}
|
|
14
|
+
__name(parsePermissionMode, "parsePermissionMode");
|
|
15
|
+
function createCodingPermissionPolicy(options = {}) {
|
|
16
|
+
const policy = options.policy ?? defaultCodingPermission;
|
|
17
|
+
return async (check) => {
|
|
18
|
+
if (options.readOnly && ![
|
|
19
|
+
"read",
|
|
20
|
+
"glob",
|
|
21
|
+
"grep",
|
|
22
|
+
"skill_read",
|
|
23
|
+
"session_history",
|
|
24
|
+
"session_history_search",
|
|
25
|
+
"session_history_read",
|
|
26
|
+
"get_context_remaining",
|
|
27
|
+
"context_notes",
|
|
28
|
+
"new_context",
|
|
29
|
+
"get_goal"
|
|
30
|
+
].includes(check.tool.name))
|
|
31
|
+
return "deny";
|
|
32
|
+
let decision = await policy(check);
|
|
33
|
+
if (options.persistent && check.tool.name === "fetch" && options.policy === void 0) {
|
|
34
|
+
const url = stringField(check.input, "url");
|
|
35
|
+
if (url !== void 0) {
|
|
36
|
+
const origin = new URL(url).origin;
|
|
37
|
+
decision = {
|
|
38
|
+
decision: "ask",
|
|
39
|
+
grantKey: `network:${origin}`,
|
|
40
|
+
persistent: { scopeId: options.persistent.scopeId, description: `network \xB7 ${origin}` }
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (options.persistent && ["read", "edit", "write"].includes(check.tool.name)) {
|
|
45
|
+
const path = stringField(check.input, "path");
|
|
46
|
+
if (path !== void 0) {
|
|
47
|
+
const target = await resolveWritableWorkspacePath(options.persistent.workspace, path);
|
|
48
|
+
const root = await realpath(options.persistent.workspace);
|
|
49
|
+
const normalized = relative(root, target.absolute).replace(/\\/gu, "/");
|
|
50
|
+
const key = process.platform === "win32" ? normalized.toLowerCase() : normalized;
|
|
51
|
+
const rules = await resolveWritableWorkspacePath(options.persistent.workspace, ".may/permission-rules.json");
|
|
52
|
+
const rulesRelative = relative(root, rules.absolute).replace(/\\/gu, "/");
|
|
53
|
+
const rulesKey = process.platform === "win32" ? rulesRelative.toLowerCase() : rulesRelative;
|
|
54
|
+
if (key === rulesKey || key.startsWith(`${rulesKey}.`)) return "deny";
|
|
55
|
+
if (options.policy === void 0 && check.tool.name !== "read" && decision !== "deny" && !(typeof decision === "object" && decision.decision === "deny")) {
|
|
56
|
+
const scoped = typeof decision === "object" ? decision : { decision };
|
|
57
|
+
const persistent = typeof decision === "object" ? decision.persistent : void 0;
|
|
58
|
+
decision = {
|
|
59
|
+
...scoped,
|
|
60
|
+
grantKey: persistent && typeof decision === "object" ? decision.grantKey : `${check.tool.name}:${key}`,
|
|
61
|
+
persistent: persistent ?? {
|
|
62
|
+
scopeId: options.persistent.scopeId,
|
|
63
|
+
description: `${check.tool.name} \xB7 ${root} \xB7 ${key}`
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const asks = decision === "ask" || typeof decision === "object" && decision !== null && decision.decision === "ask" && typeof decision.grantKey === "string" && decision.grantKey.trim() !== "";
|
|
70
|
+
if (options.mode?.() === "yolo" && asks && !(typeof decision === "object" && decision.requireApproval)) {
|
|
71
|
+
return typeof decision === "object" ? { ...decision, decision: "allow" } : "allow";
|
|
72
|
+
}
|
|
73
|
+
return decision;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
__name(createCodingPermissionPolicy, "createCodingPermissionPolicy");
|
|
77
|
+
function defaultCodingPermission(check) {
|
|
78
|
+
if ([
|
|
79
|
+
"read",
|
|
80
|
+
"glob",
|
|
81
|
+
"grep",
|
|
82
|
+
"skill_read",
|
|
83
|
+
"session_history",
|
|
84
|
+
"session_history_search",
|
|
85
|
+
"session_history_read",
|
|
86
|
+
"get_context_remaining",
|
|
87
|
+
"context_notes",
|
|
88
|
+
"new_context",
|
|
89
|
+
"get_goal",
|
|
90
|
+
"update_goal",
|
|
91
|
+
"delegate_tasks"
|
|
92
|
+
].includes(check.tool.name)) {
|
|
93
|
+
return "allow";
|
|
94
|
+
}
|
|
95
|
+
if (check.tool.name === "shell" || check.tool.name === "bash") {
|
|
96
|
+
const command = stringField(check.input, "command");
|
|
97
|
+
return command === void 0 ? "ask" : { decision: "ask", grantKey: `${check.tool.name}:${command}` };
|
|
98
|
+
}
|
|
99
|
+
if (check.tool.name === "edit" || check.tool.name === "write") {
|
|
100
|
+
const path = stringField(check.input, "path");
|
|
101
|
+
return path === void 0 ? "ask" : {
|
|
102
|
+
decision: "ask",
|
|
103
|
+
grantKey: `${check.tool.name}:${path}`
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
if (check.tool.name.startsWith("mcp__")) {
|
|
107
|
+
return {
|
|
108
|
+
decision: "ask",
|
|
109
|
+
grantKey: `mcp:${check.tool.name}`
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (check.tool.name === "fetch") {
|
|
113
|
+
const url = stringField(check.input, "url");
|
|
114
|
+
return url === void 0 ? "ask" : { decision: "ask", grantKey: `network:${new URL(url).origin}` };
|
|
115
|
+
}
|
|
116
|
+
return "ask";
|
|
117
|
+
}
|
|
118
|
+
__name(defaultCodingPermission, "defaultCodingPermission");
|
|
119
|
+
function stringField(value, name) {
|
|
120
|
+
if (typeof value !== "object" || value === null || !(name in value)) {
|
|
121
|
+
return void 0;
|
|
122
|
+
}
|
|
123
|
+
const field = value[name];
|
|
124
|
+
return typeof field === "string" && field !== "" ? field : void 0;
|
|
125
|
+
}
|
|
126
|
+
__name(stringField, "stringField");
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
parsePermissionMode,
|
|
130
|
+
createCodingPermissionPolicy
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=chunk-MNBYXL5Y.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/policy.ts"],
|
|
4
|
+
"sourcesContent": ["import type { PermissionCheck, PermissionDecision, PermissionPolicy } from \"@sortedyuan/may/permissions\";\nimport { resolveWritableWorkspacePath } from \"@sortedyuan/coding-tools\";\nimport { realpath } from \"node:fs/promises\";\nimport { relative } from \"node:path\";\n\nexport type MaybeCodePermissionMode = \"default\" | \"yolo\";\n\nexport function parsePermissionMode(value: unknown): MaybeCodePermissionMode {\n if (value === \"default\" || value === \"yolo\") return value;\n throw new TypeError('permissionMode must be \"default\" or \"yolo\"');\n}\n\nexport function createCodingPermissionPolicy(\n options: {\n readonly mode?: () => MaybeCodePermissionMode;\n readonly readOnly?: boolean;\n readonly policy?: PermissionPolicy;\n readonly persistent?: { readonly workspace: string; readonly scopeId: string };\n } = {},\n): PermissionPolicy {\n const policy = options.policy ?? defaultCodingPermission;\n return async (check) => {\n if (\n options.readOnly &&\n ![\n \"read\",\n \"glob\",\n \"grep\",\n \"skill_read\",\n \"session_history\",\n \"session_history_search\",\n \"session_history_read\",\n \"get_context_remaining\",\n \"context_notes\",\n \"new_context\",\n \"get_goal\",\n ].includes(check.tool.name)\n )\n return \"deny\";\n let decision = await policy(check);\n if (options.persistent && check.tool.name === \"fetch\" && options.policy === undefined) {\n const url = stringField(check.input, \"url\");\n if (url !== undefined) {\n const origin = new URL(url).origin;\n decision = {\n decision: \"ask\",\n grantKey: `network:${origin}`,\n persistent: { scopeId: options.persistent.scopeId, description: `network \u00B7 ${origin}` },\n };\n }\n }\n if (options.persistent && [\"read\", \"edit\", \"write\"].includes(check.tool.name)) {\n const path = stringField(check.input, \"path\");\n if (path !== undefined) {\n const target = await resolveWritableWorkspacePath(options.persistent.workspace, path);\n const root = await realpath(options.persistent.workspace);\n const normalized = relative(root, target.absolute).replace(/\\\\/gu, \"/\");\n const key = process.platform === \"win32\" ? normalized.toLowerCase() : normalized;\n const rules = await resolveWritableWorkspacePath(options.persistent.workspace, \".may/permission-rules.json\");\n const rulesRelative = relative(root, rules.absolute).replace(/\\\\/gu, \"/\");\n const rulesKey = process.platform === \"win32\" ? rulesRelative.toLowerCase() : rulesRelative;\n if (key === rulesKey || key.startsWith(`${rulesKey}.`)) return \"deny\";\n if (\n options.policy === undefined &&\n check.tool.name !== \"read\" &&\n decision !== \"deny\" &&\n !(typeof decision === \"object\" && decision.decision === \"deny\")\n ) {\n const scoped = typeof decision === \"object\" ? decision : { decision };\n const persistent = typeof decision === \"object\" ? decision.persistent : undefined;\n decision = {\n ...scoped,\n grantKey: persistent && typeof decision === \"object\" ? decision.grantKey : `${check.tool.name}:${key}`,\n persistent: persistent ?? {\n scopeId: options.persistent.scopeId,\n description: `${check.tool.name} \u00B7 ${root} \u00B7 ${key}`,\n },\n };\n }\n }\n }\n const asks =\n decision === \"ask\" ||\n (typeof decision === \"object\" &&\n decision !== null &&\n decision.decision === \"ask\" &&\n typeof decision.grantKey === \"string\" &&\n decision.grantKey.trim() !== \"\");\n if (options.mode?.() === \"yolo\" && asks && !(typeof decision === \"object\" && decision.requireApproval)) {\n return typeof decision === \"object\" ? { ...decision, decision: \"allow\" } : \"allow\";\n }\n return decision;\n };\n}\n\nfunction defaultCodingPermission(check: PermissionCheck): PermissionDecision {\n if (\n [\n \"read\",\n \"glob\",\n \"grep\",\n \"skill_read\",\n \"session_history\",\n \"session_history_search\",\n \"session_history_read\",\n \"get_context_remaining\",\n \"context_notes\",\n \"new_context\",\n \"get_goal\",\n \"update_goal\",\n \"delegate_tasks\",\n ].includes(check.tool.name)\n ) {\n // \u59D4\u6D3E\u662F\u5426\u88AB\u5141\u8BB8\u7531\u5BBF\u4E3B\u7684\u89D2\u8272\u6388\u6743\u51B3\u5B9A\uFF1A\u53EA\u6709\u5DF2\u6CE8\u518C\u4E14\u5BBF\u4E3B\u6388\u6743\u7684\u89D2\u8272\u80FD\u88AB\u521B\u5EFA\uFF0C\n // \u8D85\u51FA\u6388\u6743\u8303\u56F4\u7684\u59D4\u6D3E\u4F1A\u5728\u5DE5\u5177\u6267\u884C\u65F6\u5931\u8D25\u3002\u663E\u5F0F\u63D0\u4F9B deny \u7684\u81EA\u5B9A\u4E49\u7B56\u7565\u4F9D\u7136\u6709\u6548\u3002\n return \"allow\";\n }\n\n if (check.tool.name === \"shell\" || check.tool.name === \"bash\") {\n const command = stringField(check.input, \"command\");\n return command === undefined ? \"ask\" : { decision: \"ask\", grantKey: `${check.tool.name}:${command}` };\n }\n\n if (check.tool.name === \"edit\" || check.tool.name === \"write\") {\n const path = stringField(check.input, \"path\");\n return path === undefined\n ? \"ask\"\n : {\n decision: \"ask\",\n grantKey: `${check.tool.name}:${path}`,\n };\n }\n\n if (check.tool.name.startsWith(\"mcp__\")) {\n return {\n decision: \"ask\",\n grantKey: `mcp:${check.tool.name}`,\n };\n }\n\n if (check.tool.name === \"fetch\") {\n const url = stringField(check.input, \"url\");\n return url === undefined ? \"ask\" : { decision: \"ask\", grantKey: `network:${new URL(url).origin}` };\n }\n\n return \"ask\";\n}\n\nfunction stringField(value: unknown, name: string): string | undefined {\n if (typeof value !== \"object\" || value === null || !(name in value)) {\n return undefined;\n }\n const field = value[name as keyof typeof value];\n return typeof field === \"string\" && field !== \"\" ? field : undefined;\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -2,9 +2,10 @@ import { createRequire as __createRequire } from "node:module"; const require =
|
|
|
2
2
|
import {
|
|
3
3
|
createMaybeCodeModel,
|
|
4
4
|
getDefaultMaybeCodeDataDirectory,
|
|
5
|
-
|
|
5
|
+
readMaybeCodeSettings,
|
|
6
|
+
resolveMaybeCodeRecording,
|
|
6
7
|
selectMaybeCodeModel
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-3IORPKBL.js";
|
|
8
9
|
import {
|
|
9
10
|
CoordinationRuntime,
|
|
10
11
|
FileArtifactStore,
|
|
@@ -13,35 +14,89 @@ import {
|
|
|
13
14
|
MaybeCodeUsageError,
|
|
14
15
|
TaskWorkspaceManager,
|
|
15
16
|
createApplicationAgent,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from "./chunk-K5JWPNSY.js";
|
|
17
|
+
require_lib
|
|
18
|
+
} from "./chunk-5SLWALZK.js";
|
|
19
19
|
import {
|
|
20
|
-
__name
|
|
20
|
+
__name,
|
|
21
|
+
__toESM
|
|
21
22
|
} from "./chunk-E732GDOI.js";
|
|
22
23
|
|
|
23
24
|
// apps/maybecode/src/team.ts
|
|
24
|
-
import { createHash
|
|
25
|
-
import { lstat, open, readFile, readdir, realpath,
|
|
26
|
-
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
|
|
25
|
+
import { createHash } from "node:crypto";
|
|
26
|
+
import { lstat, open, readFile, readdir, realpath, stat } from "node:fs/promises";
|
|
27
|
+
import { isAbsolute, join, relative, resolve as resolve2, sep } from "node:path";
|
|
28
|
+
import { defineAgent } from "@sortedyuan/may";
|
|
29
|
+
import { createReadTool, createGlobTool, createGrepTool } from "@sortedyuan/coding-tools";
|
|
30
|
+
|
|
31
|
+
// apps/maybecode/src/team-execution.ts
|
|
32
|
+
import { resolve } from "node:path";
|
|
33
|
+
import {
|
|
34
|
+
openCodingExecutionEnvironment
|
|
35
|
+
} from "@sortedyuan/coding-tools";
|
|
36
|
+
var TeamExecutionEnvironments = class {
|
|
37
|
+
constructor(isolation = { mode: "host" }) {
|
|
38
|
+
this.isolation = isolation;
|
|
39
|
+
}
|
|
40
|
+
isolation;
|
|
41
|
+
static {
|
|
42
|
+
__name(this, "TeamExecutionEnvironments");
|
|
43
|
+
}
|
|
44
|
+
environments = /* @__PURE__ */ new Map();
|
|
45
|
+
closed = false;
|
|
46
|
+
get(workspace) {
|
|
47
|
+
if (this.closed) throw new Error("Team execution environments are closed");
|
|
48
|
+
const directory = resolve(workspace);
|
|
49
|
+
let environment = this.environments.get(directory);
|
|
50
|
+
if (environment === void 0) {
|
|
51
|
+
environment = openCodingExecutionEnvironment({ workspace: directory, isolation: this.isolation });
|
|
52
|
+
this.environments.set(directory, environment);
|
|
53
|
+
}
|
|
54
|
+
return environment;
|
|
55
|
+
}
|
|
56
|
+
async close() {
|
|
57
|
+
this.closed = true;
|
|
58
|
+
const results = await Promise.allSettled(
|
|
59
|
+
[...this.environments.values()].map(async (environment) => (await environment).close())
|
|
60
|
+
);
|
|
61
|
+
const failures = results.flatMap((result) => result.status === "rejected" ? [result.reason] : []);
|
|
62
|
+
if (failures.length) throw new AggregateError(failures, "Unable to close team execution environments");
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// apps/maybecode/src/team.ts
|
|
67
|
+
import { loadMayConfig } from "@sortedyuan/may/config";
|
|
68
|
+
var import_write_file_atomic = __toESM(require_lib(), 1);
|
|
69
|
+
import { resolveRunBudget } from "@sortedyuan/may/core";
|
|
70
|
+
import { FileSessionStore } from "@sortedyuan/may/session/file-store";
|
|
71
|
+
import { hasErrorCode, withFileAccess } from "@sortedyuan/may/storage";
|
|
30
72
|
var VERSION = "maybecode-team-v1";
|
|
31
73
|
var RESERVATION_TOKENS = 32768;
|
|
32
74
|
async function runMaybeCodeTeamCommand(command, dependencies) {
|
|
33
|
-
if (command.action === "run") return (await import("./team-v2-
|
|
75
|
+
if (command.action === "run") return (await import("./team-v2-YYO2G7DJ.js")).runTeamV2Command(command, dependencies);
|
|
34
76
|
if (!/^[A-Za-z0-9_-]{1,128}$/u.test(command.value)) throw new MaybeCodeUsageError("Invalid team id");
|
|
35
|
-
const path = join(
|
|
36
|
-
|
|
37
|
-
|
|
77
|
+
const path = join(
|
|
78
|
+
resolve2(command.dataDirectory ?? getDefaultMaybeCodeDataDirectory()),
|
|
79
|
+
"teams",
|
|
80
|
+
command.value,
|
|
81
|
+
"manifest.json"
|
|
82
|
+
);
|
|
83
|
+
const manifest = await withFileAccess(
|
|
84
|
+
path,
|
|
85
|
+
"shared",
|
|
86
|
+
async () => JSON.parse(await readFile(path, "utf8"))
|
|
87
|
+
);
|
|
88
|
+
if (manifest.version === "maybecode-team-v2")
|
|
89
|
+
return (await import("./team-v2-YYO2G7DJ.js")).runTeamV2Command(command, dependencies);
|
|
38
90
|
const action = command.action;
|
|
39
|
-
if (action !== "resume" && action !== "status" && action !== "cancel")
|
|
91
|
+
if (action !== "resume" && action !== "status" && action !== "cancel")
|
|
92
|
+
throw new MaybeCodeUsageError(
|
|
93
|
+
"Legacy v1 teams retain read-only resume/status/cancel. New controls require a new v2 team; authority is never silently upgraded."
|
|
94
|
+
);
|
|
40
95
|
return runLegacyMaybeCodeTeamCommand({ ...command, action }, dependencies);
|
|
41
96
|
}
|
|
42
97
|
__name(runMaybeCodeTeamCommand, "runMaybeCodeTeamCommand");
|
|
43
98
|
async function runLegacyMaybeCodeTeamCommand(command, dependencies) {
|
|
44
|
-
const data =
|
|
99
|
+
const data = resolve2(command.dataDirectory ?? getDefaultMaybeCodeDataDirectory(), "teams");
|
|
45
100
|
const id = command.value;
|
|
46
101
|
if (!/^[A-Za-z0-9_-]{1,128}$/u.test(id)) throw new MaybeCodeUsageError("Invalid team id");
|
|
47
102
|
const directory = join(data, id);
|
|
@@ -58,7 +113,7 @@ Model profile: ${manifest.model}
|
|
|
58
113
|
write(`${await withFileAccess(path, "shared", () => readFile(path, "utf8"))}
|
|
59
114
|
`);
|
|
60
115
|
} catch (error) {
|
|
61
|
-
if (!
|
|
116
|
+
if (!hasErrorCode(error, "ENOENT")) throw error;
|
|
62
117
|
write("No execution snapshot yet.\n");
|
|
63
118
|
}
|
|
64
119
|
write(`Records: ${directory}
|
|
@@ -67,14 +122,19 @@ Model profile: ${manifest.model}
|
|
|
67
122
|
}
|
|
68
123
|
if (command.action === "cancel") {
|
|
69
124
|
await writeDurable(join(directory, "cancel.request.json"), { id, requestedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
70
|
-
write(
|
|
71
|
-
`
|
|
125
|
+
write(
|
|
126
|
+
`Cancellation requested for ${id}. The active owner will consume it; otherwise resume the team to record cancellation.
|
|
127
|
+
`
|
|
128
|
+
);
|
|
72
129
|
return 0;
|
|
73
130
|
}
|
|
74
131
|
const config = await (dependencies.loadConfig ?? loadMayConfig)({ path: manifest.configPath });
|
|
75
132
|
const selected = selectMaybeCodeModel(config, { model: manifest.model });
|
|
76
|
-
|
|
77
|
-
const
|
|
133
|
+
const recording = resolveMaybeCodeRecording(config);
|
|
134
|
+
const executionEnvironments = new TeamExecutionEnvironments(readMaybeCodeSettings(config).execution);
|
|
135
|
+
if (fingerprint(selected) !== manifest.modelFingerprint)
|
|
136
|
+
throw new Error("Team model configuration changed; restore the original profile before resuming");
|
|
137
|
+
const runBudget = resolveRunBudget(readMaybeCodeSettings(config).runBudget, {
|
|
78
138
|
maxSteps: 10,
|
|
79
139
|
maxModelCalls: 10,
|
|
80
140
|
maxToolCalls: 24,
|
|
@@ -83,7 +143,9 @@ Model profile: ${manifest.model}
|
|
|
83
143
|
const outputLimit = Math.min(
|
|
84
144
|
4096,
|
|
85
145
|
selected.limits?.maxOutputTokens ?? 4096,
|
|
86
|
-
...[selected.options.maxTokens, selected.options.maxOutputTokens].filter(
|
|
146
|
+
...[selected.options.maxTokens, selected.options.maxOutputTokens].filter(
|
|
147
|
+
(value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0
|
|
148
|
+
)
|
|
87
149
|
);
|
|
88
150
|
const selection = {
|
|
89
151
|
...selected,
|
|
@@ -100,9 +162,31 @@ Model profile: ${manifest.model}
|
|
|
100
162
|
let relay;
|
|
101
163
|
let cancellationTimer;
|
|
102
164
|
let cancelling;
|
|
165
|
+
const backgroundTasks = /* @__PURE__ */ new Set();
|
|
166
|
+
const backgroundErrors = [];
|
|
167
|
+
let failBackground;
|
|
168
|
+
const backgroundFailed = new Promise((resolve3) => {
|
|
169
|
+
failBackground = resolve3;
|
|
170
|
+
});
|
|
171
|
+
const trackBackground = /* @__PURE__ */ __name((operation) => {
|
|
172
|
+
const task = operation.then(
|
|
173
|
+
() => {
|
|
174
|
+
backgroundTasks.delete(task);
|
|
175
|
+
},
|
|
176
|
+
(error) => {
|
|
177
|
+
backgroundTasks.delete(task);
|
|
178
|
+
backgroundErrors.push(error);
|
|
179
|
+
failBackground(error);
|
|
180
|
+
cancel();
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
backgroundTasks.add(task);
|
|
184
|
+
}, "trackBackground");
|
|
103
185
|
const cancel = /* @__PURE__ */ __name(() => {
|
|
104
|
-
if (runtime
|
|
105
|
-
|
|
186
|
+
if (runtime && !cancelling) {
|
|
187
|
+
cancelling = runtime.cancel(`cancel-${id}`);
|
|
188
|
+
trackBackground(cancelling);
|
|
189
|
+
}
|
|
106
190
|
}, "cancel");
|
|
107
191
|
try {
|
|
108
192
|
artifacts = await FileArtifactStore.open(join(directory, "artifacts"), id, {
|
|
@@ -112,24 +196,50 @@ Model profile: ${manifest.model}
|
|
|
112
196
|
maxArtifactBytes: 262144,
|
|
113
197
|
maxTotalBytes: 2097152
|
|
114
198
|
});
|
|
115
|
-
workspaces = await TaskWorkspaceManager.open({
|
|
116
|
-
|
|
199
|
+
workspaces = await TaskWorkspaceManager.open({
|
|
200
|
+
sourceDirectory: manifest.workspace,
|
|
201
|
+
directory: join(directory, "workspaces")
|
|
202
|
+
});
|
|
203
|
+
const model = ledger.wrapModel((dependencies.createModel ?? createMaybeCodeModel)(selection), {
|
|
204
|
+
reservation: { totalTokens: RESERVATION_TOKENS }
|
|
205
|
+
});
|
|
117
206
|
const store = new FileSessionStore(join(directory, "sessions"));
|
|
118
207
|
const createRole = /* @__PURE__ */ __name((role) => {
|
|
119
|
-
const adapter = /* @__PURE__ */ __name((execution, workspace) =>
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
208
|
+
const adapter = /* @__PURE__ */ __name(async (execution, workspace) => {
|
|
209
|
+
const environment = await executionEnvironments.get(workspace);
|
|
210
|
+
return createApplicationAgent({
|
|
211
|
+
version: VERSION,
|
|
212
|
+
store,
|
|
213
|
+
delegation: role === "supervisor",
|
|
214
|
+
messaging: true,
|
|
215
|
+
definition: /* @__PURE__ */ __name(({ tools }) => defineAgent({
|
|
216
|
+
...recording,
|
|
217
|
+
model,
|
|
218
|
+
instructions: roleInstructions(role),
|
|
219
|
+
tools: [
|
|
220
|
+
createReadTool({ cwd: workspace, maxBytes: 262144, maxLines: 160 }),
|
|
221
|
+
createGlobTool({ cwd: workspace, execution: environment }),
|
|
222
|
+
createGrepTool({ cwd: workspace, execution: environment }),
|
|
223
|
+
createListTool(workspace),
|
|
224
|
+
...artifacts.forTask(execution.task.id).tools(),
|
|
225
|
+
...tools
|
|
226
|
+
],
|
|
227
|
+
toolScope: { workspaceId: workspace },
|
|
228
|
+
runBudget,
|
|
229
|
+
permissionPolicy: /* @__PURE__ */ __name((check) => [
|
|
230
|
+
"read",
|
|
231
|
+
"glob",
|
|
232
|
+
"grep",
|
|
233
|
+
"list_files",
|
|
234
|
+
"publish_artifact",
|
|
235
|
+
"read_artifact",
|
|
236
|
+
"delegate_tasks",
|
|
237
|
+
"send_message",
|
|
238
|
+
"wait_for_messages"
|
|
239
|
+
].includes(check.tool.name) ? "allow" : "deny", "permissionPolicy")
|
|
240
|
+
}), "definition")
|
|
241
|
+
});
|
|
242
|
+
}, "adapter");
|
|
133
243
|
const publish = /* @__PURE__ */ __name(async (execution, output) => {
|
|
134
244
|
await artifacts.forTask(execution.task.id).publish(`${execution.task.dispatchId}-${execution.task.turn ?? 0}-final`, {
|
|
135
245
|
name: `${execution.task.id.slice(0, 100)}-result.md`,
|
|
@@ -141,12 +251,12 @@ Model profile: ${manifest.model}
|
|
|
141
251
|
version: VERSION,
|
|
142
252
|
async execute(execution, context) {
|
|
143
253
|
const isolated = await workspaces.prepare(execution.task.id);
|
|
144
|
-
const result2 = await adapter(execution, isolated.directory).execute(execution, context);
|
|
254
|
+
const result2 = await (await adapter(execution, isolated.directory)).execute(execution, context);
|
|
145
255
|
if (!("yielded" in result2)) await publish(execution, result2);
|
|
146
256
|
return result2;
|
|
147
257
|
},
|
|
148
258
|
async recover(execution) {
|
|
149
|
-
const result2 = await adapter(execution, manifest.workspace).recover(execution);
|
|
259
|
+
const result2 = await (await adapter(execution, manifest.workspace)).recover(execution);
|
|
150
260
|
if (result2.status === "completed") await publish(execution, result2.output);
|
|
151
261
|
return result2;
|
|
152
262
|
}
|
|
@@ -164,11 +274,13 @@ Model profile: ${manifest.model}
|
|
|
164
274
|
}
|
|
165
275
|
};
|
|
166
276
|
runtime = await CoordinationRuntime.resume(options);
|
|
167
|
-
write(
|
|
277
|
+
write(
|
|
278
|
+
`Team ${id}
|
|
168
279
|
Model profile: ${manifest.model}
|
|
169
280
|
Mode: read-only, isolated workspaces; shell/MCP/source writes disabled.
|
|
170
281
|
Records: ${directory}
|
|
171
|
-
`
|
|
282
|
+
`
|
|
283
|
+
);
|
|
172
284
|
const statuses = /* @__PURE__ */ new Map();
|
|
173
285
|
relay = (async () => {
|
|
174
286
|
for await (const event of runtime.events) {
|
|
@@ -187,14 +299,14 @@ Records: ${directory}
|
|
|
187
299
|
} else if (event.type === "runtime.failed") write("Team runtime failed; inspect its local recovery records.\n");
|
|
188
300
|
}
|
|
189
301
|
})();
|
|
190
|
-
|
|
302
|
+
trackBackground(relay);
|
|
191
303
|
const checkCancellation = /* @__PURE__ */ __name(async () => {
|
|
192
304
|
const path = join(directory, "cancel.request.json");
|
|
193
305
|
try {
|
|
194
306
|
await withFileAccess(path, "shared", () => stat(path));
|
|
195
307
|
cancel();
|
|
196
308
|
} catch (error) {
|
|
197
|
-
if (!
|
|
309
|
+
if (!hasErrorCode(error, "ENOENT")) {
|
|
198
310
|
cancel();
|
|
199
311
|
throw error;
|
|
200
312
|
}
|
|
@@ -204,10 +316,15 @@ Records: ${directory}
|
|
|
204
316
|
await checkCancellation();
|
|
205
317
|
if (dependencies.signal?.aborted) cancel();
|
|
206
318
|
cancellationTimer = setInterval(() => {
|
|
207
|
-
|
|
319
|
+
trackBackground(checkCancellation());
|
|
208
320
|
}, 300);
|
|
209
321
|
await cancelling;
|
|
210
|
-
const result = await
|
|
322
|
+
const result = await Promise.race([
|
|
323
|
+
runtime.wait(),
|
|
324
|
+
backgroundFailed.then((error) => {
|
|
325
|
+
throw error;
|
|
326
|
+
})
|
|
327
|
+
]);
|
|
211
328
|
await cancelling;
|
|
212
329
|
await writeStatus(directory, result);
|
|
213
330
|
const summary = result.tasks.find((task) => task.id === "summary");
|
|
@@ -224,19 +341,29 @@ Team ${complete ? "completed" : "stopped with unfinished or failed tasks"}.
|
|
|
224
341
|
`);
|
|
225
342
|
for (const ref of await artifacts.snapshot()) write(`Artifact [${ref.ownerTaskId}]: ${JSON.stringify(ref)}
|
|
226
343
|
`);
|
|
227
|
-
if (!complete)
|
|
344
|
+
if (!complete)
|
|
345
|
+
write(
|
|
346
|
+
`Inspect: maybecode team status ${id}
|
|
228
347
|
Resume: maybecode team resume ${id}
|
|
229
348
|
Unknown side effects or usage require verified host reconciliation; resume never blindly repeats them.
|
|
230
|
-
`
|
|
349
|
+
`
|
|
350
|
+
);
|
|
231
351
|
return complete ? 0 : 1;
|
|
232
352
|
} finally {
|
|
233
353
|
if (cancellationTimer) clearInterval(cancellationTimer);
|
|
234
354
|
dependencies.signal?.removeEventListener("abort", cancel);
|
|
235
355
|
try {
|
|
236
|
-
await runtime
|
|
237
|
-
await
|
|
356
|
+
const results = await Promise.allSettled([...runtime ? [runtime.close()] : [], ...relay ? [relay] : []]);
|
|
357
|
+
while (backgroundTasks.size) await Promise.all(backgroundTasks);
|
|
358
|
+
const failures = [
|
|
359
|
+
.../* @__PURE__ */ new Set([
|
|
360
|
+
...backgroundErrors,
|
|
361
|
+
...results.flatMap((result) => result.status === "rejected" ? [result.reason] : [])
|
|
362
|
+
])
|
|
363
|
+
];
|
|
364
|
+
if (failures.length) throw new AggregateError(failures, "Team background operations failed");
|
|
238
365
|
} finally {
|
|
239
|
-
await Promise.all([workspaces?.close(), artifacts?.close(), ledger.close()]);
|
|
366
|
+
await Promise.all([workspaces?.close(), artifacts?.close(), ledger.close(), executionEnvironments.close()]);
|
|
240
367
|
}
|
|
241
368
|
}
|
|
242
369
|
}
|
|
@@ -250,15 +377,21 @@ function createListTool(workspace) {
|
|
|
250
377
|
return {
|
|
251
378
|
name: "list_files",
|
|
252
379
|
description: "List up to 200 immediate non-symlink entries inside the isolated workspace.",
|
|
253
|
-
inputSchema: {
|
|
380
|
+
inputSchema: {
|
|
381
|
+
type: "object",
|
|
382
|
+
properties: { path: { type: "string", description: "Relative directory path; use . for root" } },
|
|
383
|
+
required: ["path"],
|
|
384
|
+
additionalProperties: false
|
|
385
|
+
},
|
|
254
386
|
parse(input) {
|
|
255
|
-
if (typeof input !== "object" || input === null || !("path" in input) || typeof input.path !== "string")
|
|
387
|
+
if (typeof input !== "object" || input === null || !("path" in input) || typeof input.path !== "string")
|
|
388
|
+
throw new Error("list_files requires a relative path");
|
|
256
389
|
return { path: input.path };
|
|
257
390
|
},
|
|
258
391
|
async execute(input, context) {
|
|
259
392
|
context.signal.throwIfAborted();
|
|
260
393
|
if (isAbsolute(input.path)) throw new Error("Absolute paths are not allowed");
|
|
261
|
-
const target =
|
|
394
|
+
const target = resolve2(workspace, input.path);
|
|
262
395
|
if (!inside(workspace, target)) throw new Error("Path leaves the workspace");
|
|
263
396
|
const parts = relative(workspace, target).split(sep).filter(Boolean);
|
|
264
397
|
let cursor = workspace;
|
|
@@ -269,26 +402,37 @@ function createListTool(workspace) {
|
|
|
269
402
|
const actual = await realpath(target);
|
|
270
403
|
if (!inside(await realpath(workspace), actual)) throw new Error("Path leaves the workspace");
|
|
271
404
|
const entries = (await readdir(actual, { withFileTypes: true })).filter((entry) => !entry.isSymbolicLink()).sort((a, b) => a.name.localeCompare(b.name));
|
|
272
|
-
return {
|
|
405
|
+
return {
|
|
406
|
+
path: input.path,
|
|
407
|
+
entries: entries.slice(0, 200).map((entry) => ({ name: entry.name, type: entry.isDirectory() ? "directory" : "file" })),
|
|
408
|
+
truncated: entries.length > 200
|
|
409
|
+
};
|
|
273
410
|
}
|
|
274
411
|
};
|
|
275
412
|
}
|
|
276
413
|
__name(createListTool, "createListTool");
|
|
277
414
|
function fingerprint(selection) {
|
|
278
|
-
return createHash("sha256").update(
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
415
|
+
return createHash("sha256").update(
|
|
416
|
+
JSON.stringify({
|
|
417
|
+
profile: selection.profile,
|
|
418
|
+
provider: selection.provider,
|
|
419
|
+
adapter: selection.adapter,
|
|
420
|
+
model: selection.model,
|
|
421
|
+
options: selection.options,
|
|
422
|
+
baseURL: selection.providerConfig.baseURL,
|
|
423
|
+
limits: selection.limits
|
|
424
|
+
})
|
|
425
|
+
).digest("hex");
|
|
287
426
|
}
|
|
288
427
|
__name(fingerprint, "fingerprint");
|
|
289
428
|
async function readManifest(path, id) {
|
|
290
|
-
const value = await withFileAccess(
|
|
291
|
-
|
|
429
|
+
const value = await withFileAccess(
|
|
430
|
+
path,
|
|
431
|
+
"shared",
|
|
432
|
+
async () => JSON.parse(await readFile(path, "utf8"))
|
|
433
|
+
);
|
|
434
|
+
if (value.format !== 1 || value.version !== VERSION || value.id !== id || !isAbsolute(value.workspace) || !isAbsolute(value.configPath) || typeof value.model !== "string" || typeof value.prompt !== "string" || !/^[0-9a-f]{64}$/u.test(value.modelFingerprint) || ![value.maxModelCalls, value.maxTotalTokens, value.maxConcurrent].every((n) => Number.isSafeInteger(n) && n > 0))
|
|
435
|
+
throw new Error("Invalid or incompatible team manifest");
|
|
292
436
|
return value;
|
|
293
437
|
}
|
|
294
438
|
__name(readManifest, "readManifest");
|
|
@@ -307,18 +451,17 @@ async function writeDurable(path, value) {
|
|
|
307
451
|
__name(writeDurable, "writeDurable");
|
|
308
452
|
async function writeStatus(directory, snapshot) {
|
|
309
453
|
const path = join(directory, "status.txt");
|
|
310
|
-
await withFileAccess(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
454
|
+
await withFileAccess(
|
|
455
|
+
path,
|
|
456
|
+
"exclusive",
|
|
457
|
+
() => (0, import_write_file_atomic.default)(
|
|
458
|
+
path,
|
|
459
|
+
`Revision ${snapshot.revision}
|
|
315
460
|
${snapshot.tasks.map((task) => `${task.id}: ${task.status}`).join("\n")}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
await rename(temporary, path);
|
|
321
|
-
});
|
|
461
|
+
`,
|
|
462
|
+
{ mode: 384 }
|
|
463
|
+
)
|
|
464
|
+
);
|
|
322
465
|
}
|
|
323
466
|
__name(writeStatus, "writeStatus");
|
|
324
467
|
function inside(root, path) {
|
|
@@ -330,13 +473,10 @@ function terminalSafe(text) {
|
|
|
330
473
|
return text.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/gu, "");
|
|
331
474
|
}
|
|
332
475
|
__name(terminalSafe, "terminalSafe");
|
|
333
|
-
function isMissing(error) {
|
|
334
|
-
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
335
|
-
}
|
|
336
|
-
__name(isMissing, "isMissing");
|
|
337
476
|
|
|
338
477
|
export {
|
|
478
|
+
TeamExecutionEnvironments,
|
|
339
479
|
runMaybeCodeTeamCommand,
|
|
340
480
|
createListTool
|
|
341
481
|
};
|
|
342
|
-
//# sourceMappingURL=chunk-
|
|
482
|
+
//# sourceMappingURL=chunk-SLWLUEHQ.js.map
|