@aiti-ai/aiti-git-review 0.2.11 → 0.2.13
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/client/src/entry.tsx +6 -1
- package/client/src/git-review-app.tsx +1 -1
- package/client/src/review-app.tsx +1 -1
- package/client/src/task-picker.tsx +7 -3
- package/dist/aiti-git-review-client.mjs +866 -151
- package/index.ts +110 -15
- package/lib/ai-commit.test.mjs +91 -5
- package/lib/ai-commit.ts +175 -20
- package/lib/late-result.test.mjs +71 -0
- package/lib/late-result.ts +105 -0
- package/package.json +2 -2
- package/tools/deploy.mjs +5 -7
- package/vite.config.ts +4 -0
- package/check-client.mjs +0 -273
- package/deploy-commit.mjs +0 -52
- package/dev-pack.mjs +0 -259
- package/ext-icons-deploy.mjs +0 -24
- package/icons/eye.svg +0 -1
- package/reconcile-deps.mjs +0 -41
- package/reload-instances.mjs +0 -60
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Late-answer store for AI runs that outlive their deadline.
|
|
3
|
+
*
|
|
4
|
+
* A generation that runs past its deadline keeps running server-side: the caller gets the session
|
|
5
|
+
* id and may pull the answer afterwards instead of losing the work (provider retries alone can take
|
|
6
|
+
* minutes). This store remembers which session ids are still pullable (`track`), holds the final
|
|
7
|
+
* text once the session settles (`settle`), and serves it for `ttlMs` (`get`).
|
|
8
|
+
*
|
|
9
|
+
* Pure bookkeeping (no timers, no network) so it can be unit-tested; the caller owns the clock.
|
|
10
|
+
*/
|
|
11
|
+
export interface LateResultStore {
|
|
12
|
+
/** Mark a session id as pullable (after its caller timed out). */
|
|
13
|
+
track(sessionId: string, now?: number): void;
|
|
14
|
+
isTracked(sessionId: string): boolean;
|
|
15
|
+
/** Cache the settled answer. Returns true when the id was tracked by a timed-out caller. */
|
|
16
|
+
settle(sessionId: string, text: string, now?: number): boolean;
|
|
17
|
+
/** Record that the run failed without an answer (text stays null). */
|
|
18
|
+
fail(sessionId: string, error: string, now?: number): boolean;
|
|
19
|
+
/** Failure reason of a tracked session, or null while running / after success / expired. */
|
|
20
|
+
errorOf(sessionId: string, now?: number): string | null;
|
|
21
|
+
/** Final answer for a tracked session, or null while it is still running / unknown / expired. */
|
|
22
|
+
get(sessionId: string, now?: number): string | null;
|
|
23
|
+
/** Number of live entries (tests/diagnostics). */
|
|
24
|
+
size(now?: number): number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface LateResultStoreOptions {
|
|
28
|
+
/** How long a timed-out session stays pullable (default 10 minutes). */
|
|
29
|
+
ttlMs?: number;
|
|
30
|
+
/** Maximum tracked sessions; the oldest ones are dropped first (default 20). */
|
|
31
|
+
max?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function createLateResultStore(opts: LateResultStoreOptions = {}): LateResultStore {
|
|
35
|
+
const ttlMs = opts.ttlMs && opts.ttlMs > 0 ? opts.ttlMs : 10 * 60_000;
|
|
36
|
+
const max = opts.max && opts.max > 0 ? opts.max : 20;
|
|
37
|
+
const entries = new Map<string, { at: number; text: string | null; error: string | null }>();
|
|
38
|
+
|
|
39
|
+
const prune = (now: number): void => {
|
|
40
|
+
for (const [sid, e] of entries) {
|
|
41
|
+
if (now - e.at > ttlMs) entries.delete(sid);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
track(sessionId, now = Date.now()) {
|
|
47
|
+
const sid = String(sessionId ?? "");
|
|
48
|
+
if (!sid) return;
|
|
49
|
+
prune(now);
|
|
50
|
+
const prev = entries.get(sid);
|
|
51
|
+
entries.set(sid, { at: now, text: prev?.text ?? null, error: prev?.error ?? null });
|
|
52
|
+
while (entries.size > max) {
|
|
53
|
+
const oldest = entries.keys().next();
|
|
54
|
+
if (oldest.done) break;
|
|
55
|
+
entries.delete(oldest.value);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
isTracked(sessionId) {
|
|
59
|
+
const sid = String(sessionId ?? "");
|
|
60
|
+
return !!sid && entries.has(sid);
|
|
61
|
+
},
|
|
62
|
+
settle(sessionId, text, now = Date.now()) {
|
|
63
|
+
const sid = String(sessionId ?? "");
|
|
64
|
+
const e = entries.get(sid);
|
|
65
|
+
if (!e) return false;
|
|
66
|
+
e.text = String(text ?? "");
|
|
67
|
+
e.error = null;
|
|
68
|
+
e.at = now;
|
|
69
|
+
return true;
|
|
70
|
+
},
|
|
71
|
+
fail(sessionId, error, now = Date.now()) {
|
|
72
|
+
const sid = String(sessionId ?? "");
|
|
73
|
+
const e = entries.get(sid);
|
|
74
|
+
if (!e) return false;
|
|
75
|
+
e.text = null;
|
|
76
|
+
e.error = String(error ?? "") || "the run failed without an answer";
|
|
77
|
+
e.at = now;
|
|
78
|
+
return true;
|
|
79
|
+
},
|
|
80
|
+
errorOf(sessionId, now = Date.now()) {
|
|
81
|
+
const sid = String(sessionId ?? "");
|
|
82
|
+
const e = entries.get(sid);
|
|
83
|
+
if (!e) return null;
|
|
84
|
+
if (now - e.at > ttlMs) {
|
|
85
|
+
entries.delete(sid);
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
return e.error;
|
|
89
|
+
},
|
|
90
|
+
get(sessionId, now = Date.now()) {
|
|
91
|
+
const sid = String(sessionId ?? "");
|
|
92
|
+
const e = entries.get(sid);
|
|
93
|
+
if (!e) return null;
|
|
94
|
+
if (now - e.at > ttlMs) {
|
|
95
|
+
entries.delete(sid);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return e.text;
|
|
99
|
+
},
|
|
100
|
+
size(now = Date.now()) {
|
|
101
|
+
prune(now);
|
|
102
|
+
return entries.size;
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiti-ai/aiti-git-review",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Dedicated to reviewing uncommitted changes — Monaco diff workspace (side-by-side/merged/new-only/outline) + line-level annotations (must/suggest/question) + anchor flag-line re-mapping (stays valid while editing mid-review) + summary final-review checklist + AI pre-review (aiti_review_* tools injected only into review sessions, zero tools day-to-day)",
|
|
6
6
|
"displayNameI18n": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@aiti-ai/ext-shared": "^0.1.12"
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
|
-
"contentHash": "
|
|
34
|
+
"contentHash": "d0d87a4ab103f087",
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|
|
37
37
|
"url": "git+https://github.com/aiti-ai/aiti-ai.git",
|
package/tools/deploy.mjs
CHANGED
|
@@ -16,13 +16,12 @@ import { resolve } from "node:path";
|
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
17
|
import { homedir } from "node:os";
|
|
18
18
|
import { execSync } from "node:child_process";
|
|
19
|
-
import { deployCommit } from "
|
|
20
|
-
import {
|
|
21
|
-
import { notifyReconcile } from "../../_shared/reconcile-deps.mjs";
|
|
19
|
+
import { deployCommit } from "@aiti-ai/ext-shared/deploy-commit";
|
|
20
|
+
import { notifyReconcile } from "@aiti-ai/ext-shared/reconcile-deps";
|
|
22
21
|
|
|
23
22
|
// client TS 残留检查(.mjs 里是合法 JS 语法检查不报、运行时必炸;FAIL 即部署失败)
|
|
24
23
|
{
|
|
25
|
-
const { checkClientDir } = await import("
|
|
24
|
+
const { checkClientDir } = await import("@aiti-ai/ext-shared/check-client");
|
|
26
25
|
checkClientDir(fileURLToPath(new URL("../client", import.meta.url)), { log: (m) => console.log("[deploy] " + m) });
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -76,7 +75,6 @@ console.log("[deploy] 完成。生效:POST /api/extensions/reload(或重启
|
|
|
76
75
|
// 提交部署状态到扩展 git 仓库(生产目录是 git 仓库)
|
|
77
76
|
|
|
78
77
|
// 图标文件拷贝(icon: "icons/<name>.svg" → 宿主加载时内嵌;库在 _shared/icons/)
|
|
79
|
-
for (const t of targets) copyIcons(resolve(t, "icons"), ["eye"], { log: (m2) => console.log(m2) });
|
|
80
78
|
|
|
81
79
|
deployCommit({ repo: extRepo, name: "aiti-git-review", paths: ["aiti-git-review"], log: (m) => console.log("[deploy] " + m) });
|
|
82
80
|
|
|
@@ -85,7 +83,7 @@ await notifyReconcile();
|
|
|
85
83
|
|
|
86
84
|
// ── 双实例热重载(basePath 双 env 按机器设值)——允许失败:服务未启动/共享模块缺失仅提示,不影响 deploy 退出码 ──
|
|
87
85
|
try {
|
|
88
|
-
const { reloadInstances } = await import("
|
|
86
|
+
const { reloadInstances } = await import("@aiti-ai/ext-shared/reload-instances");
|
|
89
87
|
await reloadInstances();
|
|
90
88
|
} catch (e) {
|
|
91
89
|
console.log("[deploy] 自动 reload 未执行(" + String((e && e.message) || e) + ")— 需手动 POST /api/extensions/reload");
|
|
@@ -93,7 +91,7 @@ try {
|
|
|
93
91
|
|
|
94
92
|
// ── dev-pack(方案 §3.2:源码+构建工具+AGENTS.md 直达部署目录,AI 可现场直改)——允许失败,不影响 deploy 退出码 ──
|
|
95
93
|
try {
|
|
96
|
-
const { packDevPack } = await import("
|
|
94
|
+
const { packDevPack } = await import("@aiti-ai/ext-shared/dev-pack");
|
|
97
95
|
packDevPack({ extRoot: resolve(import.meta.dirname, ".."), log: (m) => console.log("[deploy] " + m) });
|
|
98
96
|
} catch (e) {
|
|
99
97
|
console.log("[deploy] dev-pack 未执行(" + String((e && e.message) || e) + ")");
|
package/vite.config.ts
CHANGED
|
@@ -14,6 +14,10 @@ export default defineConfig({
|
|
|
14
14
|
esbuild: {
|
|
15
15
|
jsx: "automatic",
|
|
16
16
|
jsxImportSource: "react",
|
|
17
|
+
// Production lib bundle: never let the JSX runtime follow the build shell's NODE_ENV.
|
|
18
|
+
// Vite infers jsxDev from NODE_ENV; a build from a dev-instance shell inherits
|
|
19
|
+
// NODE_ENV=development -> jsxDEV(), but jsx-runtime.ts only exports jsx/jsxs/Fragment.
|
|
20
|
+
jsxDev: false,
|
|
17
21
|
},
|
|
18
22
|
resolve: {
|
|
19
23
|
alias: [
|
package/check-client.mjs
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* check-client —— 扩展 client .mjs/.js 的 TS 残留 tripwire(零依赖,纯 node)。
|
|
3
|
-
*
|
|
4
|
-
* 背景:aiti-plan-review 事故(docs/aiti-ext-client-hardening-plan.md §1)——
|
|
5
|
-
* `useState<any>(null)` 解析为合法 JS 比较表达式 `useState < any > (null)`,
|
|
6
|
-
* node --check / TS 解析器 / babel 全不报错,只有运行时才炸。纯语法检查
|
|
7
|
-
* 原理性无效,只能启发式规则 + 渲染期错误边界兜底。
|
|
8
|
-
*
|
|
9
|
-
* 用法:
|
|
10
|
-
* CLI node check-client.mjs <file|dir>... FAIL → exit 1
|
|
11
|
-
* 自测 node check-client.mjs --selftest fixtures 全过 → exit 0
|
|
12
|
-
* API lintClientSource(src) → violations[] { line, level, rule, text }
|
|
13
|
-
* lintPath(path) → { files, violations }(文件或目录,递归)
|
|
14
|
-
* checkClientDir(dir,{log}) FAIL → throw(deploy 脚本用)
|
|
15
|
-
*
|
|
16
|
-
* 词法:规则匹配前先剥离注释/字符串/模板字面量(${} 插值内代码保留检查)——
|
|
17
|
-
* aiti-editor 的 Monaco TS stub 模板串、JSDoc @return 都是合法内容,不剥全误报。
|
|
18
|
-
* 已知极限:regex 字面量含引号等 lexer 歧义允许漏报(tripwire 定位非编译器)。
|
|
19
|
-
*
|
|
20
|
-
* 豁免:目标行或其上一行含 `check-client:allow` 即跳过该行。
|
|
21
|
-
* 权威源:本文件;aiti-extman 部署副本由其 tools/deploy.mjs 拷贝(改动两处同步)。
|
|
22
|
-
*/
|
|
23
|
-
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
24
|
-
import { join, resolve } from "node:path";
|
|
25
|
-
|
|
26
|
-
// ── 规则(分级)──────────────────────────────────────────────────────────────
|
|
27
|
-
|
|
28
|
-
const RULES = [
|
|
29
|
-
// FAIL:合法 JS 但运行时必炸 / 纯 TS 语法
|
|
30
|
-
{ level: "FAIL", re: /\b(useState|useRef|useMemo|useCallback|useReducer|useImperativeHandle)\s*</, why: "React hook 泛型(运行时必炸)" },
|
|
31
|
-
// 注:含「any/unknown/string」字样的规则用字符串构 RegExp——本文件自身也
|
|
32
|
-
// 会被扫,正则字面量里的 (?:any 会被自己命中(词法器不处理 regex 字面量),
|
|
33
|
-
// 字符串字面量则会被词法遮蔽。
|
|
34
|
-
{ level: "FAIL", re: new RegExp("\\bas\\s+(?:" + "any|unknown|const)\\b"), why: "as 断言" },
|
|
35
|
-
{ level: "FAIL", re: new RegExp(":\\s*(?:" + "any|unknown)\\b"), why: ": any/: unknown 注解" },
|
|
36
|
-
{ level: "FAIL", re: /\b(?:import|export)\s+type\s/, why: "import/export type" },
|
|
37
|
-
{ level: "FAIL", re: /\b(?:interface|enum)\s+[A-Za-z_$]/, why: "interface/enum 声明" },
|
|
38
|
-
// warn:疑似残留,人工确认,不阻断
|
|
39
|
-
{ level: "warn", re: new RegExp(":\\s*(?:" + "string|number|boolean|void)\\b(?!\\s*[._\\w])"), why: "疑似类型注解" },
|
|
40
|
-
{ level: "warn", re: /\bsatisfies\s/, why: "satisfies" },
|
|
41
|
-
{ level: "warn", re: /\b(?:Record|Partial|Readonly|Omit|Pick)\s*</, why: "TS 工具类型" },
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
// ── 词法剥离:注释/字符串/模板字面量 → 空格(保留换行,行号不漂移)─────────
|
|
45
|
-
export function stripLiterals(src) {
|
|
46
|
-
const out = src.split("");
|
|
47
|
-
const n = src.length;
|
|
48
|
-
const mask = (from, to) => {
|
|
49
|
-
for (let k = from; k < to && k < n; k++) if (out[k] !== "\n") out[k] = " ";
|
|
50
|
-
};
|
|
51
|
-
let mode = "code";
|
|
52
|
-
let depth = 0;
|
|
53
|
-
const stack = []; // 模板 ${ 插值进入时的 brace 深度(支持嵌套模板)
|
|
54
|
-
let i = 0;
|
|
55
|
-
while (i < n) {
|
|
56
|
-
const c = src[i];
|
|
57
|
-
const d = i + 1 < n ? src[i + 1] : "";
|
|
58
|
-
if (mode === "code") {
|
|
59
|
-
if (c === "/" && d === "/") {
|
|
60
|
-
const j = src.indexOf("\n", i);
|
|
61
|
-
const end = j === -1 ? n : j;
|
|
62
|
-
mask(i, end);
|
|
63
|
-
i = end;
|
|
64
|
-
} else if (c === "/" && d === "*") {
|
|
65
|
-
const j = src.indexOf("*/", i + 2);
|
|
66
|
-
const end = j === -1 ? n : j + 2;
|
|
67
|
-
mask(i, end);
|
|
68
|
-
i = end;
|
|
69
|
-
} else if (c === "'" || c === '"') {
|
|
70
|
-
let j = i + 1;
|
|
71
|
-
while (j < n && src[j] !== c && src[j] !== "\n") j += src[j] === "\\" ? 2 : 1;
|
|
72
|
-
if (j < n && src[j] === c) {
|
|
73
|
-
mask(i, j + 1);
|
|
74
|
-
i = j + 1;
|
|
75
|
-
} else {
|
|
76
|
-
// 未闭合到行尾 → 可能是 regex 字面量歧义,只遮开引号,按代码继续
|
|
77
|
-
out[i] = " ";
|
|
78
|
-
i++;
|
|
79
|
-
}
|
|
80
|
-
} else if (c === "`") {
|
|
81
|
-
mode = "tpl";
|
|
82
|
-
out[i] = " ";
|
|
83
|
-
i++;
|
|
84
|
-
} else if (c === "{") {
|
|
85
|
-
depth++;
|
|
86
|
-
i++;
|
|
87
|
-
} else if (c === "}") {
|
|
88
|
-
if (stack.length && depth === stack[stack.length - 1]) {
|
|
89
|
-
stack.pop();
|
|
90
|
-
mode = "tpl"; // 插值结束回模板
|
|
91
|
-
out[i] = " ";
|
|
92
|
-
} else {
|
|
93
|
-
depth = Math.max(0, depth - 1);
|
|
94
|
-
}
|
|
95
|
-
i++;
|
|
96
|
-
} else i++;
|
|
97
|
-
} else if (mode === "tpl") {
|
|
98
|
-
if (c === "\\") {
|
|
99
|
-
mask(i, Math.min(i + 2, n));
|
|
100
|
-
i += 2;
|
|
101
|
-
} else if (c === "`") {
|
|
102
|
-
mode = "code";
|
|
103
|
-
out[i] = " ";
|
|
104
|
-
i++;
|
|
105
|
-
} else if (c === "$" && d === "{") {
|
|
106
|
-
stack.push(depth);
|
|
107
|
-
mode = "code";
|
|
108
|
-
mask(i, i + 2);
|
|
109
|
-
i += 2;
|
|
110
|
-
} else {
|
|
111
|
-
if (c !== "\n") out[i] = " ";
|
|
112
|
-
i++;
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
// 不可达:line/block/字符串均在 code 分支内联处理
|
|
116
|
-
i++;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return out.join("");
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// ── 单源检查 ────────────────────────────────────────────────────────────────
|
|
123
|
-
export function lintClientSource(src) {
|
|
124
|
-
const masked = stripLiterals(src);
|
|
125
|
-
const origLines = src.split("\n");
|
|
126
|
-
const maskedLines = masked.split("\n");
|
|
127
|
-
const violations = [];
|
|
128
|
-
for (let i = 0; i < maskedLines.length; i++) {
|
|
129
|
-
const prev = i > 0 ? origLines[i - 1] : "";
|
|
130
|
-
if (origLines[i].includes("check-client:allow") || prev.includes("check-client:allow")) continue;
|
|
131
|
-
for (const { level, re, why } of RULES) {
|
|
132
|
-
if (re.test(maskedLines[i])) {
|
|
133
|
-
violations.push({ line: i + 1, level, rule: why, text: origLines[i].trim().slice(0, 90) });
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return violations;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// ── 文件/目录检查 ───────────────────────────────────────────────────────────
|
|
141
|
-
const SKIP_DIR = new Set(["node_modules", ".git"]);
|
|
142
|
-
/** 超过此体积视为 vendored bundle(如 Monaco ts.worker,合法含 interface 字样),不查。 */
|
|
143
|
-
const MAX_BYTES = 512 * 1024;
|
|
144
|
-
const isClientFile = (name) => /\.(mjs|js|cjs)$/.test(name) && !/\.min\./.test(name) && !/\.test\./.test(name);
|
|
145
|
-
|
|
146
|
-
export function lintPath(p, out = { files: 0, violations: [] }) {
|
|
147
|
-
const st = statSync(p);
|
|
148
|
-
if (st.isDirectory()) {
|
|
149
|
-
for (const name of readdirSync(p)) {
|
|
150
|
-
if (SKIP_DIR.has(name)) continue;
|
|
151
|
-
lintPath(join(p, name), out);
|
|
152
|
-
}
|
|
153
|
-
return out;
|
|
154
|
-
}
|
|
155
|
-
const base = p.split("/").pop();
|
|
156
|
-
if (!isClientFile(base)) return out;
|
|
157
|
-
if (st.size > MAX_BYTES) return out; // vendored bundle 豁免
|
|
158
|
-
out.files++;
|
|
159
|
-
for (const v of lintClientSource(readFileSync(p, "utf8"))) out.violations.push({ file: p, ...v });
|
|
160
|
-
return out;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function formatViolations(violations) {
|
|
164
|
-
return violations
|
|
165
|
-
.map((v) => ` ${v.level} ${v.file}:${v.line} [${v.rule}] ${v.text}`)
|
|
166
|
-
.join("\n");
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** deploy 脚本用:检查目录,FAIL 抛错(消息含违规清单),warn 只打日志不阻断。 */
|
|
170
|
-
export function checkClientDir(dir, { log = console.log } = {}) {
|
|
171
|
-
const { files, violations } = lintPath(resolve(dir));
|
|
172
|
-
const fails = violations.filter((v) => v.level === "FAIL");
|
|
173
|
-
const warns = violations.filter((v) => v.level === "warn");
|
|
174
|
-
if (warns.length) log(`[check-client] ${warns.length} 处疑似 TS 残留(不阻断,建议人工确认):\n${formatViolations(warns)}`);
|
|
175
|
-
if (fails.length) {
|
|
176
|
-
throw new Error(
|
|
177
|
-
`client 检查未通过:${files} 个文件中 ${fails.length} 处 TS 残留(.mjs 里是合法 JS,语法检查不报,运行时必炸)。\n` +
|
|
178
|
-
formatViolations(fails) +
|
|
179
|
-
`\n修复或在该行加注释 // check-client:allow 豁免。详见 docs/aiti-ext-client-hardening-plan.md`,
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
if (files) log(`[check-client] ${files} 个 client 文件检查通过`);
|
|
183
|
-
return { files, fails: fails.length, warns: warns.length };
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* extman 安装用:扫整个扩展目录(含第三方,不遵循 client/ 约定)。
|
|
188
|
-
* 在 SKIP_DIR 之上额外跳过构建产物/vendored 目录(Monaco ts.worker、语言包等
|
|
189
|
-
* 合法包含 TS 字样,词法器对 minified 代码不提供保证);体积上限同上。
|
|
190
|
-
*/
|
|
191
|
-
export function lintExtensionDir(dir) {
|
|
192
|
-
const out = { files: 0, violations: [] };
|
|
193
|
-
const walk = (p) => {
|
|
194
|
-
const st = statSync(p);
|
|
195
|
-
if (st.isDirectory()) {
|
|
196
|
-
for (const name of readdirSync(p)) {
|
|
197
|
-
if (SKIP_DIR.has(name) || VENDORED_DIRS.has(name)) continue;
|
|
198
|
-
walk(join(p, name));
|
|
199
|
-
}
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const base = p.split("/").pop();
|
|
203
|
-
if (!isClientFile(base) || st.size > MAX_BYTES) return;
|
|
204
|
-
out.files++;
|
|
205
|
-
for (const v of lintClientSource(readFileSync(p, "utf8"))) out.violations.push({ file: p, ...v });
|
|
206
|
-
};
|
|
207
|
-
walk(resolve(dir));
|
|
208
|
-
return out;
|
|
209
|
-
}
|
|
210
|
-
const VENDORED_DIRS = new Set(["vendor", "monaco", "dist", "build", "assets", "static", "bundles", "chunks"]);
|
|
211
|
-
|
|
212
|
-
// ── CLI ─────────────────────────────────────────────────────────────────────
|
|
213
|
-
function selftest() {
|
|
214
|
-
const MUST_FAIL = [
|
|
215
|
-
"const [st, setSt] = useState<any>(null);",
|
|
216
|
-
"const r = useRef<number>(null);",
|
|
217
|
-
"const x = v as any;",
|
|
218
|
-
"function f(a: unknown) {}",
|
|
219
|
-
'import type { Foo } from "./x";',
|
|
220
|
-
"interface Foo { a: string }",
|
|
221
|
-
"enum Color { Red }",
|
|
222
|
-
"const y = v as const;",
|
|
223
|
-
];
|
|
224
|
-
const MUST_WARN = [
|
|
225
|
-
"const opts = { mode: string };",
|
|
226
|
-
"x satisfies Y;",
|
|
227
|
-
"const m: Record<string, any> = {};",
|
|
228
|
-
];
|
|
229
|
-
const MUST_PASS = [
|
|
230
|
-
'const REACT_TYPE_STUB = `\ndeclare module "react" {\n export function useState<T>(init: T): [T];\n export const Fragment: any;\n}\n`;',
|
|
231
|
-
"/** @return {{chars1: string, chars2: string}} */",
|
|
232
|
-
"const [s] = useState(null);",
|
|
233
|
-
"useState<any>(null); // check-client:allow",
|
|
234
|
-
"// check-client:allow\nuseState<never>(0);",
|
|
235
|
-
"const cmp = a < b && c > (d);",
|
|
236
|
-
"if (a // 注释里 as any 不算\n ) run();",
|
|
237
|
-
];
|
|
238
|
-
let bad = 0;
|
|
239
|
-
const check = (src, expect, desc) => {
|
|
240
|
-
const v = lintClientSource(src);
|
|
241
|
-
const fails = v.filter((x) => x.level === "FAIL");
|
|
242
|
-
const ok = expect === "FAIL" ? fails.length > 0 : expect === "PASS" ? v.length === 0 : v.length > 0 && fails.length === 0;
|
|
243
|
-
if (!ok) {
|
|
244
|
-
bad++;
|
|
245
|
-
console.log(`SELFTEST FAIL [${desc}] 期望 ${expect},实际 ${JSON.stringify(v)}`);
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
MUST_FAIL.forEach((s) => check(s, "FAIL", s.slice(0, 40)));
|
|
249
|
-
MUST_WARN.forEach((s) => check(s, "WARN", s.slice(0, 40)));
|
|
250
|
-
MUST_PASS.forEach((s) => check(s, "PASS", s.replace(/\n/g, "⏎").slice(0, 40)));
|
|
251
|
-
if (bad) {
|
|
252
|
-
console.log(`selftest: ${bad} 处未过`);
|
|
253
|
-
process.exit(1);
|
|
254
|
-
}
|
|
255
|
-
console.log("selftest: 全部通过(8 FAIL / 3 WARN / 7 PASS)");
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (process.argv[1] && resolve(process.argv[1]) === resolve(import.meta.filename)) {
|
|
259
|
-
if (process.argv.includes("--selftest")) {
|
|
260
|
-
selftest();
|
|
261
|
-
} else if (process.argv.length > 2) {
|
|
262
|
-
const all = { files: 0, violations: [] };
|
|
263
|
-
for (const p of process.argv.slice(2)) lintPath(resolve(p), all);
|
|
264
|
-
const fails = all.violations.filter((v) => v.level === "FAIL");
|
|
265
|
-
const warns = all.violations.filter((v) => v.level === "warn");
|
|
266
|
-
if (all.violations.length) console.log(formatViolations(all.violations));
|
|
267
|
-
console.log(`\n${all.files} 个文件:FAIL=${fails.length} warn=${warns.length}`);
|
|
268
|
-
process.exit(fails.length ? 1 : 0);
|
|
269
|
-
} else {
|
|
270
|
-
console.log("用法:node check-client.mjs <file|dir>... | --selftest");
|
|
271
|
-
process.exit(2);
|
|
272
|
-
}
|
|
273
|
-
}
|
package/deploy-commit.mjs
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* deploy 脚本共享「部署状态 commit」助手(pi-web-ext 各扩展 tools/deploy.mjs 统一用)。
|
|
3
|
-
*
|
|
4
|
-
* 背景(2026-08-30 排障,session 0cc6ad47 op264):重复部署同内容时
|
|
5
|
-
* `git add -A && git commit` 以 "nothing to commit" exit 1,而 stdio:"ignore" 吞掉
|
|
6
|
-
* stderr,输出「提交失败(忽略):Command failed: …」假报警(msg-smart 实证);
|
|
7
|
-
* 另有 --allow-empty 族每次部署都造空 commit 噪音。本助手统一三态语义:
|
|
8
|
-
* committed → 有暂存变更,已提交
|
|
9
|
-
* clean → 无变更,跳过(不算失败)
|
|
10
|
-
* failed → git 真失败(带 stderr 首行,不阻断部署——部署本体永远优先)
|
|
11
|
-
*
|
|
12
|
-
* 用法:
|
|
13
|
-
* import { deployCommit } from "../../_shared/deploy-commit.mjs";
|
|
14
|
-
* deployCommit({ repo: extRepo, name: "aiti-msg-smart", paths: ["aiti-msg-smart"],
|
|
15
|
-
* log: (m) => console.log("[deploy] " + m) });
|
|
16
|
-
*
|
|
17
|
-
* 红线:本助手永不 throw、不触碰部署产物路径之外的任何东西;只对 <repo> 做
|
|
18
|
-
* add/diff/commit(默认 --no-verify,extRepo 无 hooks,防未来误挂)。
|
|
19
|
-
*/
|
|
20
|
-
import { execFileSync } from "node:child_process";
|
|
21
|
-
|
|
22
|
-
export function deployCommit({ repo, name, paths = null, extraMsg = "", ident = false, log = console.log }) {
|
|
23
|
-
const git = (args) =>
|
|
24
|
-
execFileSync("git", args, { cwd: repo, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
25
|
-
const firstLine = (s) => String(s || "").trim().split("\n")[0];
|
|
26
|
-
try {
|
|
27
|
-
// 暂存:默认只收本扩展子目录(与 add <ext> 行为对齐;避免把别的扩展的
|
|
28
|
-
// 未提交改动卷进本扩展的部署 commit);paths=null 时退回 add -A 全仓。
|
|
29
|
-
git(["add", ...(paths && paths.length ? ["--", ...paths] : ["-A"])]);
|
|
30
|
-
let dirty;
|
|
31
|
-
try {
|
|
32
|
-
git(["diff", "--cached", "--quiet"]);
|
|
33
|
-
dirty = false; // exit 0 = 暂存区与 HEAD 一致
|
|
34
|
-
} catch (e) {
|
|
35
|
-
if (e.status !== 1) throw e; // 1 = 有变更;其他才是真错误
|
|
36
|
-
dirty = true;
|
|
37
|
-
}
|
|
38
|
-
if (!dirty) {
|
|
39
|
-
log("扩展仓库无变化(跳过提交)");
|
|
40
|
-
return { status: "clean" };
|
|
41
|
-
}
|
|
42
|
-
const stamp = new Date().toISOString().replace("T", " ").slice(0, 19);
|
|
43
|
-
const msg = `[deploy] ${name} · ${stamp}${extraMsg ? " · " + extraMsg : ""}`;
|
|
44
|
-
git([...(ident ? ["-c", "user.name=deploy", "-c", "user.email=deploy@local"] : []), "commit", "--no-verify", "-m", msg]);
|
|
45
|
-
log("扩展仓库已提交:" + msg);
|
|
46
|
-
return { status: "committed", msg };
|
|
47
|
-
} catch (e) {
|
|
48
|
-
const reason = firstLine(e.stderr) || firstLine(e.message) || "git error";
|
|
49
|
-
log("提交失败(忽略,不影响部署):" + reason);
|
|
50
|
-
return { status: "failed", reason };
|
|
51
|
-
}
|
|
52
|
-
}
|