@fantasticit/sumi 0.14.16 → 0.14.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +0 -0
- package/dist/codex-trust.d.ts +4 -1
- package/dist/codex-trust.js +17 -2
- package/dist/codex-trust.js.map +1 -1
- package/dist/codex-user-hook.cjs +1 -1
- package/dist/mcp-hosts.d.ts +25 -0
- package/dist/mcp-hosts.js +82 -0
- package/dist/mcp-hosts.js.map +1 -0
- package/dist/trace.d.ts +16 -0
- package/dist/trace.js +30 -0
- package/dist/trace.js.map +1 -0
- package/node_modules/@sumi/create/dist/bin.d.ts +2 -0
- package/node_modules/@sumi/create/dist/bin.js +52 -0
- package/node_modules/@sumi/create/dist/bin.js.map +1 -0
- package/node_modules/@sumi/create/package.json +2 -2
- package/node_modules/@sumi/kernel/package.json +2 -2
- package/node_modules/@sumi/plugin-sdk/package.json +1 -1
- package/node_modules/@sumi/plugins-core/dist/tool-batches.d.ts +11 -0
- package/node_modules/@sumi/plugins-core/dist/tool-batches.js +41 -0
- package/node_modules/@sumi/plugins-core/dist/tool-batches.js.map +1 -0
- package/node_modules/@sumi/plugins-core/package.json +3 -3
- package/node_modules/@sumi/plugins-governance/dist/boundary-answer-page.d.ts +3 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-answer-page.js +76 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-answer-page.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-browser.d.ts +6 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-browser.js +128 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-browser.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-form.d.ts +18 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-form.js +97 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-form.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-mcp.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-mcp.js +231 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-mcp.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/approve.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/approve.js +29 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/approve.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/protected-after-shell.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/protected-after-shell.js +20 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/protected-after-shell.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/unlock.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/unlock.js +23 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/unlock.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/hooks.d.ts +2 -0
- package/node_modules/@sumi/plugins-governance/dist/hooks.js +4 -0
- package/node_modules/@sumi/plugins-governance/dist/hooks.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/protected-shell.d.ts +12 -0
- package/node_modules/@sumi/plugins-governance/dist/protected-shell.js +152 -0
- package/node_modules/@sumi/plugins-governance/dist/protected-shell.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/package.json +4 -4
- package/node_modules/@sumi/plugins-openspec/package.json +6 -6
- package/node_modules/@sumi/plugins-precedent/dist/commands/session-start-context.d.ts +1 -0
- package/node_modules/@sumi/plugins-precedent/dist/commands/session-start-context.js +6 -0
- package/node_modules/@sumi/plugins-precedent/dist/commands/session-start-context.js.map +1 -0
- package/node_modules/@sumi/plugins-precedent/package.json +3 -3
- package/node_modules/@sumi/plugins-review/dist/claude-review-agent.js +3 -1
- package/node_modules/@sumi/plugins-review/dist/claude-review-agent.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/commands/submit.js +5 -2
- package/node_modules/@sumi/plugins-review/dist/commands/submit.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/model-execution.d.ts +15 -1
- package/node_modules/@sumi/plugins-review/dist/model-execution.js +26 -18
- package/node_modules/@sumi/plugins-review/dist/model-execution.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/model-independence.js +3 -2
- package/node_modules/@sumi/plugins-review/dist/model-independence.js.map +1 -1
- package/node_modules/@sumi/plugins-review/package.json +6 -6
- package/package.json +10 -10
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { boundaryAnswer, cancelBoundaryAnswer, submitBoundaryAnswer } from './boundary.js';
|
|
4
|
+
import { boundaryAnswerPage, boundaryForm } from './boundary-answer-page.js';
|
|
5
|
+
import { openPage } from './view-page.js';
|
|
6
|
+
const browserTransport = String.raw `
|
|
7
|
+
status.textContent = '';
|
|
8
|
+
async function submit(action, answers) {
|
|
9
|
+
const response = await fetch(location.pathname, {
|
|
10
|
+
method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({action, answers})
|
|
11
|
+
});
|
|
12
|
+
const result = await response.json();
|
|
13
|
+
if (!response.ok) throw new Error(result.error);
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
async function notifyHost() {}
|
|
17
|
+
function done(state) {
|
|
18
|
+
form.hidden = true;
|
|
19
|
+
status.textContent = (state === 'confirmed' ? '已保存' : '已取消') + ',可关闭此页';
|
|
20
|
+
status.focus();
|
|
21
|
+
// 只有脚本打开的页签允许关闭;失败时保留上面的提示
|
|
22
|
+
try { window.close(); } catch {}
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
async function readSubmission(request) {
|
|
26
|
+
const chunks = [];
|
|
27
|
+
let size = 0;
|
|
28
|
+
for await (const chunk of request) {
|
|
29
|
+
size += chunk.length;
|
|
30
|
+
if (size > 128 * 1024)
|
|
31
|
+
throw new Error('提交内容超过限制');
|
|
32
|
+
chunks.push(chunk);
|
|
33
|
+
}
|
|
34
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
35
|
+
}
|
|
36
|
+
export async function waitForBoundaryAnswer(root, session, id, options) {
|
|
37
|
+
const nonce = randomBytes(24).toString('base64');
|
|
38
|
+
const path = `/boundary/${randomBytes(24).toString('hex')}`;
|
|
39
|
+
const page = boundaryAnswerPage(boundaryForm(boundaryAnswer(root, session, id)), browserTransport, nonce);
|
|
40
|
+
let origin = '';
|
|
41
|
+
let finish;
|
|
42
|
+
let completed = false;
|
|
43
|
+
const result = new Promise((resolve) => {
|
|
44
|
+
finish = resolve;
|
|
45
|
+
});
|
|
46
|
+
const server = createServer({ requestTimeout: 15_000 }, (req, res) => {
|
|
47
|
+
void handle(req, res).catch((error) => {
|
|
48
|
+
reply(res, 400, { error: error instanceof Error ? error.message : '提交失败' });
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
function reply(res, code, payload) {
|
|
52
|
+
res.writeHead(code, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store' });
|
|
53
|
+
res.end(JSON.stringify(payload));
|
|
54
|
+
}
|
|
55
|
+
async function handle(req, res) {
|
|
56
|
+
if (`http://${req.headers.host}` !== origin || req.url !== path || completed) {
|
|
57
|
+
reply(res, 404, { error: '页面已失效' });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (req.method === 'GET') {
|
|
61
|
+
res.writeHead(200, {
|
|
62
|
+
'Content-Type': 'text/html; charset=utf-8',
|
|
63
|
+
'Content-Security-Policy': `default-src 'none'; style-src 'unsafe-inline'; script-src 'nonce-${nonce}'; connect-src 'self'; frame-ancestors 'none'; base-uri 'none'`,
|
|
64
|
+
'Cache-Control': 'no-store',
|
|
65
|
+
'Referrer-Policy': 'no-referrer',
|
|
66
|
+
});
|
|
67
|
+
res.end(page);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (req.method !== 'POST' || req.headers.origin !== origin || req.headers['content-type'] !== 'application/json') {
|
|
71
|
+
reply(res, 403, { error: '拒绝来自其他页面的提交' });
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const { action, answers } = await readSubmission(req);
|
|
75
|
+
if (options.signal.aborted || completed)
|
|
76
|
+
throw new Error('页面已失效');
|
|
77
|
+
if (action !== 'cancel' && action !== 'confirm' && action !== 'defaults')
|
|
78
|
+
throw new Error('未知操作');
|
|
79
|
+
const receipt = action === 'cancel' ? undefined : submitBoundaryAnswer(root, session, id, action === 'defaults' ? {} : answers);
|
|
80
|
+
if (!receipt)
|
|
81
|
+
cancelBoundaryAnswer(root, session, id);
|
|
82
|
+
completed = true;
|
|
83
|
+
res.once('finish', () => finish(receipt));
|
|
84
|
+
res.once('close', () => finish(receipt));
|
|
85
|
+
reply(res, 200, { status: receipt?.status ?? 'cancelled' });
|
|
86
|
+
}
|
|
87
|
+
const abort = () => finish();
|
|
88
|
+
options.signal.addEventListener('abort', abort, { once: true });
|
|
89
|
+
if (options.signal.aborted)
|
|
90
|
+
abort();
|
|
91
|
+
try {
|
|
92
|
+
await new Promise((resolve, reject) => {
|
|
93
|
+
server.once('error', reject);
|
|
94
|
+
server.listen(0, '127.0.0.1', resolve);
|
|
95
|
+
});
|
|
96
|
+
if (options.signal.aborted)
|
|
97
|
+
return undefined;
|
|
98
|
+
const address = server.address();
|
|
99
|
+
if (!address || typeof address === 'string')
|
|
100
|
+
throw new Error('无法确定本地确认页地址');
|
|
101
|
+
origin = `http://127.0.0.1:${address.port}`;
|
|
102
|
+
const url = origin + path;
|
|
103
|
+
options.output(url);
|
|
104
|
+
if (options.open !== false) {
|
|
105
|
+
try {
|
|
106
|
+
openPage(url);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
/* 终端已显示备用地址。 */
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return await result;
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
options.signal.removeEventListener('abort', abort);
|
|
116
|
+
server.close();
|
|
117
|
+
server.closeAllConnections();
|
|
118
|
+
if (!completed) {
|
|
119
|
+
try {
|
|
120
|
+
cancelBoundaryAnswer(root, session, id);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
/* 提案可能已被替换或手工确认。 */
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=boundary-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundary-browser.js","sourceRoot":"","sources":["../src/boundary-browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAA6C,MAAM,WAAW,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,oBAAoB,EAAuB,MAAM,eAAe,CAAC;AAChH,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;CAkBlC,CAAC;AAEF,KAAK,UAAU,cAAc,CAAC,OAAwB;IACpD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAClC,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC;QACrB,IAAI,IAAI,GAAG,GAAG,GAAG,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;QACnD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,CAAC,KAAK,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,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QAC5E,MAAM,GAAG,oBAAoB,OAAO,CAAC,IAAI,EAAE,CAAC;QAC5C,MAAM,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC;QAC1B,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACpB,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YAC3B,IAAI,CAAC;gBACH,QAAQ,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC;YAAC,MAAM,CAAC;gBACP,gBAAgB;YAClB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,MAAM,CAAC;IACtB,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACnD,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,mBAAmB,EAAE,CAAC;QAC7B,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,IAAI,CAAC;gBACH,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;YAC1C,CAAC;YAAC,MAAM,CAAC;gBACP,oBAAoB;YACtB,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type BoundaryRow } from './boundary.js';
|
|
2
|
+
export interface BoundaryAnswerRow {
|
|
3
|
+
section: string;
|
|
4
|
+
text: string;
|
|
5
|
+
answer: string;
|
|
6
|
+
decision: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 把页面上的选择写成 `sumi boundary confirm` 可解析的五节答复。
|
|
10
|
+
* 页面脚本直接嵌入本函数源码,函数体只能使用浏览器与 Node 都有的内置能力。
|
|
11
|
+
*/
|
|
12
|
+
export declare function boundaryAnswer(rows: BoundaryAnswerRow[]): string;
|
|
13
|
+
export declare const BOUNDARY_FORM_STYLE = "\n.boundary fieldset{margin:0 0 14px;padding:14px 16px;border:1px solid var(--line);border-radius:10px;background:var(--surface)}\n.boundary fieldset.decide{border-left:4px solid var(--warn)}.boundary fieldset.changed{border-left-color:var(--accent);background:var(--soft)}\n.boundary legend{float:left;width:100%;padding:0;font-weight:650}.boundary legend+label{clear:both}.boundary .tag{margin-left:8px;padding:1px 8px;border-radius:999px;background:var(--warn-soft);color:var(--warn);font-size:12px;font-weight:600}\n.boundary label{display:flex;gap:8px;align-items:flex-start;margin-top:8px;cursor:pointer}.boundary input[type=radio]{margin-top:7px}\n.boundary textarea{width:100%;min-height:54px;margin-top:6px;padding:8px 10px;border:1px solid var(--line);border-radius:8px;font:inherit;background:var(--bg);color:var(--ink)}\n.boundary .answer{margin-top:24px;padding:14px 16px;border:1px solid var(--line);border-radius:10px;background:var(--surface)}\n.boundary .answer textarea{min-height:160px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px}\n.boundary .bar button.primary{background:var(--accent);border-color:var(--accent);color:var(--surface)}";
|
|
14
|
+
/** 可交互的确认表单:每条可按建议或改写,下方实时生成五节答复供复制回对话。 */
|
|
15
|
+
export declare function boundaryForm(rows: BoundaryRow[]): {
|
|
16
|
+
html: string;
|
|
17
|
+
script: string;
|
|
18
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { escapeHtml } from '@sumi/plugin-sdk';
|
|
2
|
+
import { BOUNDARY_HEADINGS } from './boundary.js';
|
|
3
|
+
/**
|
|
4
|
+
* 把页面上的选择写成 `sumi boundary confirm` 可解析的五节答复。
|
|
5
|
+
* 页面脚本直接嵌入本函数源码,函数体只能使用浏览器与 Node 都有的内置能力。
|
|
6
|
+
*/
|
|
7
|
+
export function boundaryAnswer(rows) {
|
|
8
|
+
const sections = [];
|
|
9
|
+
const lines = {};
|
|
10
|
+
for (const row of rows) {
|
|
11
|
+
if (!lines[row.section]) {
|
|
12
|
+
sections.push(row.section);
|
|
13
|
+
lines[row.section] = [];
|
|
14
|
+
}
|
|
15
|
+
// 答案以分号或换行结束解析,自填内容中的这些字符改成逗号和空格
|
|
16
|
+
const answer = row.answer.replace(/[;;]/g, ',').replace(/\s+/g, ' ').trim();
|
|
17
|
+
lines[row.section].push(`- ${row.text} 建议默认:${answer};需拍板:${row.decision ? '是' : '否'}。`);
|
|
18
|
+
}
|
|
19
|
+
return `${sections.map((section) => `### ${section}\n\n${lines[section].join('\n')}`).join('\n\n')}\n`;
|
|
20
|
+
}
|
|
21
|
+
const SCRIPT = `${boundaryAnswer.toString()}
|
|
22
|
+
const form = document.getElementById('boundary-form');
|
|
23
|
+
const output = document.getElementById('boundary-answer');
|
|
24
|
+
const status = document.getElementById('boundary-status');
|
|
25
|
+
const fields = Array.from(form.querySelectorAll('fieldset[data-section]'));
|
|
26
|
+
function render() {
|
|
27
|
+
let changed = 0;
|
|
28
|
+
const rows = fields.map((field) => {
|
|
29
|
+
const custom = field.querySelector('textarea').value.trim();
|
|
30
|
+
const own = field.querySelector('input[value="custom"]').checked && custom !== '';
|
|
31
|
+
if (own) changed++;
|
|
32
|
+
field.classList.toggle('changed', own);
|
|
33
|
+
return { section: field.dataset.section, text: field.dataset.text, answer: own ? custom : field.dataset.suggested, decision: field.dataset.decision === '是' };
|
|
34
|
+
});
|
|
35
|
+
output.value = '边界确认答复:\\n\\n' + boundaryAnswer(rows);
|
|
36
|
+
status.textContent = changed ? '已修改 ' + changed + ' 条,其余按建议' : '全部按建议';
|
|
37
|
+
}
|
|
38
|
+
form.addEventListener('input', (event) => {
|
|
39
|
+
if (event.target.tagName === 'TEXTAREA') event.target.closest('fieldset').querySelector('input[value="custom"]').checked = true;
|
|
40
|
+
render();
|
|
41
|
+
});
|
|
42
|
+
document.getElementById('boundary-reset').addEventListener('click', () => {
|
|
43
|
+
for (const field of fields) field.querySelector('input[value="suggested"]').checked = true;
|
|
44
|
+
render();
|
|
45
|
+
});
|
|
46
|
+
document.getElementById('boundary-copy').addEventListener('click', async () => {
|
|
47
|
+
try {
|
|
48
|
+
await navigator.clipboard.writeText(output.value);
|
|
49
|
+
} catch {
|
|
50
|
+
output.select();
|
|
51
|
+
document.execCommand('copy');
|
|
52
|
+
}
|
|
53
|
+
status.textContent = '已复制,粘贴到对话中即可';
|
|
54
|
+
});
|
|
55
|
+
render();
|
|
56
|
+
`;
|
|
57
|
+
export const BOUNDARY_FORM_STYLE = `
|
|
58
|
+
.boundary fieldset{margin:0 0 14px;padding:14px 16px;border:1px solid var(--line);border-radius:10px;background:var(--surface)}
|
|
59
|
+
.boundary fieldset.decide{border-left:4px solid var(--warn)}.boundary fieldset.changed{border-left-color:var(--accent);background:var(--soft)}
|
|
60
|
+
.boundary legend{float:left;width:100%;padding:0;font-weight:650}.boundary legend+label{clear:both}.boundary .tag{margin-left:8px;padding:1px 8px;border-radius:999px;background:var(--warn-soft);color:var(--warn);font-size:12px;font-weight:600}
|
|
61
|
+
.boundary label{display:flex;gap:8px;align-items:flex-start;margin-top:8px;cursor:pointer}.boundary input[type=radio]{margin-top:7px}
|
|
62
|
+
.boundary textarea{width:100%;min-height:54px;margin-top:6px;padding:8px 10px;border:1px solid var(--line);border-radius:8px;font:inherit;background:var(--bg);color:var(--ink)}
|
|
63
|
+
.boundary .answer{margin-top:24px;padding:14px 16px;border:1px solid var(--line);border-radius:10px;background:var(--surface)}
|
|
64
|
+
.boundary .answer textarea{min-height:160px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px}
|
|
65
|
+
.boundary .bar button.primary{background:var(--accent);border-color:var(--accent);color:var(--surface)}`;
|
|
66
|
+
function field(row, index) {
|
|
67
|
+
const attr = escapeHtml;
|
|
68
|
+
const name = `row-${index}`;
|
|
69
|
+
return [
|
|
70
|
+
`<fieldset class="${row.decision ? 'decide' : ''}" data-section="${attr(row.section)}" data-text="${attr(row.text)}" data-suggested="${attr(row.suggested)}" data-decision="${row.decision ? '是' : '否'}">`,
|
|
71
|
+
`<legend>${attr(row.text)}${row.decision ? '<span class="tag">需要你拍板</span>' : ''}</legend>`,
|
|
72
|
+
`<label><input type="radio" name="${name}" value="suggested" checked><span>按建议:${attr(row.suggested)}</span></label>`,
|
|
73
|
+
`<label><input type="radio" name="${name}" value="custom"><span>改为:</span></label>`,
|
|
74
|
+
`<textarea aria-label="${attr(row.text)} 的修改" placeholder="写下你的答案"></textarea>`,
|
|
75
|
+
'</fieldset>',
|
|
76
|
+
].join('\n');
|
|
77
|
+
}
|
|
78
|
+
/** 可交互的确认表单:每条可按建议或改写,下方实时生成五节答复供复制回对话。 */
|
|
79
|
+
export function boundaryForm(rows) {
|
|
80
|
+
let index = 0;
|
|
81
|
+
const sections = BOUNDARY_HEADINGS.map((section) => {
|
|
82
|
+
const own = rows.filter((row) => row.section === section);
|
|
83
|
+
return `<h2>${escapeHtml(section)}</h2>\n${own.map((row) => field(row, index++)).join('\n')}`;
|
|
84
|
+
});
|
|
85
|
+
const html = [
|
|
86
|
+
'<form id="boundary-form" class="boundary">',
|
|
87
|
+
'<p>逐条选择“按建议”或写下你的答案;黄色标记的条目需要你拍板。完成后复制下方答复,粘贴到对话中。</p>',
|
|
88
|
+
...sections,
|
|
89
|
+
'<div class="answer">',
|
|
90
|
+
'<div class="bar"><button type="button" id="boundary-copy" class="primary">复制答复</button><button type="button" id="boundary-reset">全部按建议</button><span id="boundary-status" role="status"></span></div>',
|
|
91
|
+
'<textarea id="boundary-answer" aria-label="边界确认答复" readonly></textarea>',
|
|
92
|
+
'</div>',
|
|
93
|
+
'</form>',
|
|
94
|
+
].join('\n');
|
|
95
|
+
return { html, script: SCRIPT };
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=boundary-form.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundary-form.js","sourceRoot":"","sources":["../src/boundary-form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAi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M,IAAI,GAAG;QACX,4CAA4C;QAC5C,wDAAwD;QACxD,GAAG,QAAQ;QACX,sBAAsB;QACtB,uMAAuM;QACvM,yEAAyE;QACzE,QAAQ;QACR,SAAS;KACV,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACb,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function serveBoundaryMcp(root: string): Promise<void>;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline';
|
|
2
|
+
import { waitForBoundaryAnswer } from './boundary-browser.js';
|
|
3
|
+
import { desktopAvailable } from './view-page.js';
|
|
4
|
+
import { boundaryAnswer, boundaryReceipt, cancelBoundaryAnswer, submitBoundaryAnswer } from './boundary.js';
|
|
5
|
+
import { boundaryAnswerPage, boundaryForm } from './boundary-answer-page.js';
|
|
6
|
+
const URI = 'ui://sumi/boundary-answer.html';
|
|
7
|
+
const MIME = 'text/html;profile=mcp-app';
|
|
8
|
+
const properties = { session: { type: 'string' }, id: { type: 'string' } };
|
|
9
|
+
const inputSchema = { type: 'object', properties, required: ['session', 'id'], additionalProperties: false };
|
|
10
|
+
const tools = [
|
|
11
|
+
{
|
|
12
|
+
name: 'show_boundary',
|
|
13
|
+
description: '在当前桌面会话展示 Sumi 边界表单。传入 boundary propose --no-open 返回的会话和提案 ID,展示后等待用户在表单里确认;宿主不能内嵌表单时改为打开浏览器页面并等待回传。',
|
|
14
|
+
inputSchema,
|
|
15
|
+
annotations: { readOnlyHint: true },
|
|
16
|
+
_meta: { ui: { resourceUri: URI } },
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'read_boundary_answer',
|
|
20
|
+
description: '按会话和提案 ID 读取 Sumi 已保存的确认结果。收到表单提交回执后调用此工具,再按答案继续。',
|
|
21
|
+
inputSchema,
|
|
22
|
+
annotations: { readOnlyHint: true },
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'submit_boundary_answer',
|
|
26
|
+
description: '表单按钮提交或取消当前边界提案。',
|
|
27
|
+
inputSchema: {
|
|
28
|
+
...inputSchema,
|
|
29
|
+
properties: { ...properties, action: { enum: ['confirm', 'defaults', 'cancel'] }, answers: { type: 'object' } },
|
|
30
|
+
required: [...inputSchema.required, 'action', 'answers'],
|
|
31
|
+
},
|
|
32
|
+
_meta: { ui: { visibility: ['app'] } },
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
const mcpTransport = String.raw `
|
|
36
|
+
let proposal;
|
|
37
|
+
let cursor = 0;
|
|
38
|
+
let ready = false;
|
|
39
|
+
const pending = new Map();
|
|
40
|
+
const rpc = (method, params, id) => parent.postMessage({
|
|
41
|
+
jsonrpc: '2.0', method, params, ...(id === undefined ? {} : { id })
|
|
42
|
+
}, '*');
|
|
43
|
+
function call(method, params) {
|
|
44
|
+
const id = ++cursor;
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
const timeout = setTimeout(() => {
|
|
47
|
+
pending.delete(id);
|
|
48
|
+
reject(new Error('宿主响应超时。'));
|
|
49
|
+
}, 15000);
|
|
50
|
+
pending.set(id, (message) => {
|
|
51
|
+
clearTimeout(timeout);
|
|
52
|
+
if (message.error) reject(new Error(message.error.message));
|
|
53
|
+
else resolve(message.result);
|
|
54
|
+
});
|
|
55
|
+
rpc(method, params, id);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
addEventListener('message', ({ source, data }) => {
|
|
59
|
+
if (source !== parent || data?.jsonrpc !== '2.0') return;
|
|
60
|
+
if (data.method === 'ui/notifications/tool-result') {
|
|
61
|
+
const result = data.params?.structuredContent;
|
|
62
|
+
if (!result || typeof result.html !== 'string') return;
|
|
63
|
+
proposal = {session: result.session, id: result.id};
|
|
64
|
+
document.querySelector('#questions').innerHTML = result.html;
|
|
65
|
+
status.textContent = '';
|
|
66
|
+
fields.disabled = false;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const callback = pending.get(data.id);
|
|
70
|
+
if (callback) {
|
|
71
|
+
pending.delete(data.id);
|
|
72
|
+
callback(data);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
async function submit(action, answers) {
|
|
76
|
+
const result = await call('tools/call', {
|
|
77
|
+
name: 'submit_boundary_answer', arguments: {...proposal, action, answers}
|
|
78
|
+
});
|
|
79
|
+
if (result?.isError || !result?.structuredContent) throw new Error(result?.content?.[0]?.text || '提交失败。');
|
|
80
|
+
return result.structuredContent;
|
|
81
|
+
}
|
|
82
|
+
async function notifyHost(receipt) {
|
|
83
|
+
const text = receipt.status === 'confirmed'
|
|
84
|
+
? '我已提交 Sumi 边界确认。请读取刚才表单对应的已保存答案,并按答案继续当前任务。提案 ID ' + proposal.id
|
|
85
|
+
: '我已取消 Sumi 边界表单。请回到会话内确认边界。';
|
|
86
|
+
const response = await call('ui/message', {role: 'user', content: [{type: 'text', text}]});
|
|
87
|
+
if (response?.isError) throw new Error('宿主拒绝自动回传');
|
|
88
|
+
}
|
|
89
|
+
// 提交后收起为一行回执;高度变化由下面的观察器通知宿主
|
|
90
|
+
function done(state, note) {
|
|
91
|
+
const time = new Date().toLocaleTimeString('zh-CN', {hour12: false, hour: '2-digit', minute: '2-digit'});
|
|
92
|
+
const line = document.createElement('p');
|
|
93
|
+
line.id = 'status';
|
|
94
|
+
line.setAttribute('role', 'status');
|
|
95
|
+
line.textContent = (state === 'confirmed' ? '已确认' : '已取消') + '(' + time + ')' + note;
|
|
96
|
+
document.querySelector('main').replaceChildren(line);
|
|
97
|
+
}
|
|
98
|
+
new ResizeObserver(() => {
|
|
99
|
+
if (ready) rpc('ui/notifications/size-changed', {height: Math.ceil(document.body.getBoundingClientRect().height)});
|
|
100
|
+
}).observe(document.body);
|
|
101
|
+
call('ui/initialize', {appInfo: {name: 'sumi-boundary', version: '1.0.0'}, appCapabilities: {}, protocolVersion: '2026-01-26'})
|
|
102
|
+
.then(() => {
|
|
103
|
+
ready = true;
|
|
104
|
+
rpc('ui/notifications/initialized', {});
|
|
105
|
+
rpc('ui/notifications/size-changed', {height: Math.ceil(document.body.getBoundingClientRect().height)});
|
|
106
|
+
})
|
|
107
|
+
.catch(error => {status.textContent = error.message;});
|
|
108
|
+
`;
|
|
109
|
+
function toolResult(text, structuredContent) {
|
|
110
|
+
return { content: [{ type: 'text', text }], ...(structuredContent ? { structuredContent } : {}) };
|
|
111
|
+
}
|
|
112
|
+
/** 等待浏览器答复页回传的最长时间,与 `boundary propose --wait` 一致。 */
|
|
113
|
+
const BROWSER_WAIT_MS = 5 * 60_000;
|
|
114
|
+
/** 客户端按 MCP Apps 规范在 initialize 的 capabilities.extensions 中声明能渲染 `text/html;profile=mcp-app`。 */
|
|
115
|
+
function supportsMcpApps(params) {
|
|
116
|
+
const capabilities = params.capabilities;
|
|
117
|
+
const mimeTypes = capabilities?.extensions?.['io.modelcontextprotocol/ui']?.mimeTypes;
|
|
118
|
+
return Array.isArray(mimeTypes) && mimeTypes.includes(MIME);
|
|
119
|
+
}
|
|
120
|
+
/** 宿主不能内嵌表单:打开浏览器答复页并在工具调用内等待回传。 */
|
|
121
|
+
async function showInBrowser(root, session, id, signal) {
|
|
122
|
+
const fallback = '请在会话内用问答确认边界,或重新发起提案。';
|
|
123
|
+
if (!desktopAvailable())
|
|
124
|
+
return toolResult(`当前环境无法打开答复页。${fallback}已确认后调用 read_boundary_answer 读取答案。`);
|
|
125
|
+
const timer = AbortSignal.timeout(BROWSER_WAIT_MS);
|
|
126
|
+
let url = '';
|
|
127
|
+
try {
|
|
128
|
+
const record = await waitForBoundaryAnswer(root, session, id, {
|
|
129
|
+
signal: AbortSignal.any([signal, timer]),
|
|
130
|
+
output: (address) => (url = address),
|
|
131
|
+
});
|
|
132
|
+
if (record)
|
|
133
|
+
return toolResult(boundaryReceipt(record), { status: record.status, id });
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
return toolResult(`无法使用浏览器答复页:${error.message}。${fallback}`);
|
|
137
|
+
}
|
|
138
|
+
return toolResult(`浏览器答复页已取消或超时(${url}),提案已取消。${fallback}`);
|
|
139
|
+
}
|
|
140
|
+
async function callTool(root, name, args, apps, signal) {
|
|
141
|
+
const { session, id } = args;
|
|
142
|
+
if (typeof session !== 'string' || !session || session.length > 407 || typeof id !== 'string' || !id) {
|
|
143
|
+
throw new Error('需要当前会话和边界提案 ID');
|
|
144
|
+
}
|
|
145
|
+
if (name === 'submit_boundary_answer') {
|
|
146
|
+
if (args.action === 'cancel') {
|
|
147
|
+
cancelBoundaryAnswer(root, session, id);
|
|
148
|
+
return toolResult('已取消', { status: 'cancelled' });
|
|
149
|
+
}
|
|
150
|
+
if (args.action !== 'confirm' && args.action !== 'defaults')
|
|
151
|
+
throw new Error('未知操作');
|
|
152
|
+
const receipt = submitBoundaryAnswer(root, session, id, args.action === 'defaults' ? {} : args.answers);
|
|
153
|
+
return toolResult(boundaryReceipt(receipt), { status: receipt.status, id });
|
|
154
|
+
}
|
|
155
|
+
const record = boundaryAnswer(root, session, id);
|
|
156
|
+
if (name === 'read_boundary_answer') {
|
|
157
|
+
if (record.status !== 'confirmed')
|
|
158
|
+
return toolResult('当前提案尚未确认');
|
|
159
|
+
return toolResult(boundaryReceipt(record), { status: record.status, id });
|
|
160
|
+
}
|
|
161
|
+
if (name !== 'show_boundary')
|
|
162
|
+
throw new Error('未知工具');
|
|
163
|
+
if (record.status !== 'proposed')
|
|
164
|
+
throw new Error('边界提案已经结束');
|
|
165
|
+
if (!apps)
|
|
166
|
+
return showInBrowser(root, session, id, signal);
|
|
167
|
+
return toolResult('边界表单已交给宿主展示。若宿主没有显示表单,请用会话内问答确认。收到提交回执后调用 read_boundary_answer。', {
|
|
168
|
+
html: boundaryForm(record),
|
|
169
|
+
session,
|
|
170
|
+
id,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
export async function serveBoundaryMcp(root) {
|
|
174
|
+
let apps = false;
|
|
175
|
+
const shutdown = new AbortController();
|
|
176
|
+
async function route(method, params) {
|
|
177
|
+
switch (method) {
|
|
178
|
+
case 'initialize':
|
|
179
|
+
apps = supportsMcpApps(params);
|
|
180
|
+
return {
|
|
181
|
+
protocolVersion: params.protocolVersion === '2025-06-18' ? '2025-06-18' : '2025-11-25',
|
|
182
|
+
capabilities: { tools: {}, resources: {}, extensions: { 'io.modelcontextprotocol/ui': { mimeTypes: [MIME] } } },
|
|
183
|
+
serverInfo: { name: 'sumi-boundary', version: '1.0.0' },
|
|
184
|
+
};
|
|
185
|
+
case 'ping':
|
|
186
|
+
return {};
|
|
187
|
+
case 'tools/list':
|
|
188
|
+
return { tools };
|
|
189
|
+
case 'resources/list':
|
|
190
|
+
return { resources: [{ uri: URI, name: 'Sumi 边界确认', mimeType: MIME }] };
|
|
191
|
+
case 'resources/templates/list':
|
|
192
|
+
return { resourceTemplates: [] };
|
|
193
|
+
case 'resources/read':
|
|
194
|
+
if (params.uri !== URI)
|
|
195
|
+
throw new Error('未知资源');
|
|
196
|
+
return { contents: [{ uri: URI, mimeType: MIME, text: boundaryAnswerPage('', mcpTransport) }] };
|
|
197
|
+
case 'tools/call':
|
|
198
|
+
try {
|
|
199
|
+
return await callTool(root, params.name, (params.arguments ?? {}), apps, shutdown.signal);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
return { ...toolResult(error instanceof Error ? error.message : '工具调用失败'), isError: true };
|
|
203
|
+
}
|
|
204
|
+
default:
|
|
205
|
+
throw new Error('未知 MCP 方法');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// 浏览器等待期间仍要响应其他请求,逐条并发处理;输入关闭后中止等待并等已发出的请求收尾
|
|
209
|
+
const inflight = new Set();
|
|
210
|
+
async function handle(line) {
|
|
211
|
+
let id = null;
|
|
212
|
+
try {
|
|
213
|
+
const message = JSON.parse(line);
|
|
214
|
+
if (message.id === undefined)
|
|
215
|
+
return;
|
|
216
|
+
id = message.id;
|
|
217
|
+
const result = await route(message.method, message.params ?? {});
|
|
218
|
+
process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', id, result })}\n`);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', id, error: { code: -32603, message: error.message } })}\n`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for await (const line of createInterface({ input: process.stdin, crlfDelay: Infinity })) {
|
|
225
|
+
const task = handle(line).finally(() => inflight.delete(task));
|
|
226
|
+
inflight.add(task);
|
|
227
|
+
}
|
|
228
|
+
shutdown.abort();
|
|
229
|
+
await Promise.all(inflight);
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=boundary-mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundary-mcp.js","sourceRoot":"","sources":["../src/boundary-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC5G,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE7E,MAAM,GAAG,GAAG,gCAAgC,CAAC;AAC7C,MAAM,IAAI,GAAG,2BAA2B,CAAC;AACzC,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC;AAC3E,MAAM,WAAW,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;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+1,29 @@
|
|
|
1
|
+
import { guardCommandArgs } from '@sumi/plugin-sdk';
|
|
2
|
+
import { confirmOnTty, readRequest, recordApproval } from '../state.js';
|
|
3
|
+
/** sumi approve <请求 id>:展示待确认请求的内容与语义变化,在控制终端上输入短码后记录确认。 */
|
|
4
|
+
const root = process.env.SUMI_ROOT ?? process.cwd();
|
|
5
|
+
guardCommandArgs(process.argv.slice(2), { usage: '用法:sumi approve <请求 id>' });
|
|
6
|
+
const id = process.argv[2];
|
|
7
|
+
if (!id) {
|
|
8
|
+
process.stderr.write('用法:sumi approve <请求 id>\n');
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
const request = readRequest(root, id);
|
|
12
|
+
if (!request) {
|
|
13
|
+
process.stderr.write(`没有待确认的请求 ${id}\n`);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const ok = await confirmOnTty([`待确认(${request.kind}):`, ...request.summary.map((s) => ` - ${s}`)]);
|
|
18
|
+
if (!ok) {
|
|
19
|
+
process.stderr.write('短码不匹配,未记录确认\n');
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
recordApproval(root, request);
|
|
23
|
+
process.stdout.write(`已确认 ${id}\n`);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
process.stderr.write(`${error.message}\n`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=approve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approve.js","sourceRoot":"","sources":["../../src/commands/approve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAExE,4DAA4D;AAC5D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,OAAO,C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,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { protectedChangeMessage, protectedShellChanges } from '../protected-shell.js';
|
|
3
|
+
/**
|
|
4
|
+
* 编辑后 hook:核对本次 Bash 命令是否在没有编辑窗口时改动了受保护文件。
|
|
5
|
+
* 发现时以退出码 2 结束,AI 工具把 stderr 作为反馈交给代理。
|
|
6
|
+
*/
|
|
7
|
+
const root = process.env.SUMI_ROOT ?? process.cwd();
|
|
8
|
+
let raw = '';
|
|
9
|
+
try {
|
|
10
|
+
raw = readFileSync(0, 'utf8');
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
raw = '';
|
|
14
|
+
}
|
|
15
|
+
const changes = protectedShellChanges(root, raw);
|
|
16
|
+
if (changes.length) {
|
|
17
|
+
process.stderr.write(`${protectedChangeMessage(changes)}\n`);
|
|
18
|
+
process.exitCode = 2;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=protected-after-shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protected-after-shell.js","sourceRoot":"","sources":["../../src/commands/protected-after-shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEtF;;;GAGG;AACH,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;AACpD,IAAI,GAAG,GAAG,EAAE,CAAC;AACb,IAAI,CAAC;IACH,GAAG,GAAG,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC;AAAC,MAAM,CAAC;IACP,GAAG,GAAG,EAAE,CAAC;AACX,CAAC;AACD,MAAM,OAAO,GAAG,qBAAqB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACjD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,sBAAsB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { guardCommandArgs } from '@sumi/plugin-sdk';
|
|
2
|
+
import { confirmOnTty, writeUnlock } from '../state.js';
|
|
3
|
+
/** sumi unlock [--minutes N]:由人开启一个限时窗口,期间允许 AI 编辑受保护路径(推送前仍需确认)。 */
|
|
4
|
+
const root = process.env.SUMI_ROOT ?? process.cwd();
|
|
5
|
+
guardCommandArgs(process.argv.slice(2), { usage: '用法:sumi unlock [--minutes N]', options: ['minutes'] });
|
|
6
|
+
const i = process.argv.indexOf('--minutes');
|
|
7
|
+
const minutes = i >= 0 ? Number(process.argv[i + 1]) : 30;
|
|
8
|
+
if (!Number.isFinite(minutes) || minutes <= 0) {
|
|
9
|
+
process.stderr.write('用法:sumi unlock [--minutes N]\n');
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
if (!(await confirmOnTty([`开启 ${minutes} 分钟的 control 编辑窗口,期间 AI 可以编辑受保护路径。`]))) {
|
|
14
|
+
process.stderr.write('短码不匹配,未开启\n');
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
process.stdout.write(`编辑窗口开启至 ${writeUnlock(root, minutes)}\n`);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
process.stderr.write(`${error.message}\n`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=unlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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