@fantasticit/sumi 0.14.5 → 0.14.6
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/agent-hooks.js +15 -2
- package/dist/agent-hooks.js.map +1 -1
- package/dist/agents.js +14 -9
- package/dist/agents.js.map +1 -1
- package/dist/cli.js +20 -3
- package/dist/cli.js.map +1 -1
- package/dist/codex-trust.d.ts +8 -0
- package/dist/codex-trust.js +27 -0
- package/dist/codex-trust.js.map +1 -0
- package/dist/codex-user-hook-entry.d.ts +1 -0
- package/dist/codex-user-hook-entry.js +134 -0
- package/dist/codex-user-hook-entry.js.map +1 -0
- package/dist/codex-user-hook.cjs +137 -0
- package/dist/codex-user-hook.d.ts +2 -0
- package/dist/codex-user-hook.js +85 -0
- package/dist/codex-user-hook.js.map +1 -0
- package/dist/context.d.ts +3 -1
- package/dist/context.js +16 -16
- package/dist/context.js.map +1 -1
- package/dist/doctor-wiring.d.ts +1 -6
- package/dist/doctor-wiring.js +4 -25
- package/dist/doctor-wiring.js.map +1 -1
- package/dist/hub/board.d.ts +85 -0
- package/dist/hub/board.js +261 -0
- package/dist/hub/board.js.map +1 -0
- package/dist/hub/commands.d.ts +13 -0
- package/dist/hub/commands.js +86 -0
- package/dist/hub/commands.js.map +1 -0
- package/dist/hub/pages.d.ts +2 -0
- package/dist/hub/pages.js +136 -0
- package/dist/hub/pages.js.map +1 -0
- package/dist/hub/server.d.ts +23 -0
- package/dist/hub/server.js +128 -0
- package/dist/hub/server.js.map +1 -0
- package/dist/hub/snapshot.d.ts +48 -0
- package/dist/hub/snapshot.js +132 -0
- package/dist/hub/snapshot.js.map +1 -0
- package/dist/hub/start.d.ts +13 -0
- package/dist/hub/start.js +59 -0
- package/dist/hub/start.js.map +1 -0
- package/dist/hub/state.d.ts +49 -0
- package/dist/hub/state.js +144 -0
- package/dist/hub/state.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/instructions.js +1 -1
- package/dist/run-stats.d.ts +20 -0
- package/dist/run-stats.js +58 -6
- package/dist/run-stats.js.map +1 -1
- package/dist/task.js +8 -2
- package/dist/task.js.map +1 -1
- package/node_modules/@sumi/create/package.json +2 -2
- package/node_modules/@sumi/create/template/control/flows/check.flow.yaml +3 -0
- package/node_modules/@sumi/create/template/control/rules/development.md +1 -1
- package/node_modules/@sumi/kernel/dist/brief.d.ts +2 -0
- package/node_modules/@sumi/kernel/dist/brief.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/engine.js +1 -0
- package/node_modules/@sumi/kernel/dist/engine.js.map +1 -1
- package/node_modules/@sumi/kernel/dist/runner.js +1 -1
- package/node_modules/@sumi/kernel/dist/runner.js.map +1 -1
- package/node_modules/@sumi/kernel/package.json +2 -2
- package/node_modules/@sumi/plugin-sdk/dist/context-delivery.d.ts +11 -6
- package/node_modules/@sumi/plugin-sdk/dist/context-delivery.js +35 -3
- package/node_modules/@sumi/plugin-sdk/dist/context-delivery.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/edit-paths.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/edit-paths.js +29 -23
- package/node_modules/@sumi/plugin-sdk/dist/edit-paths.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/env.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/env.js +7 -0
- package/node_modules/@sumi/plugin-sdk/dist/env.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/git.d.ts +8 -0
- package/node_modules/@sumi/plugin-sdk/dist/git.js +38 -0
- package/node_modules/@sumi/plugin-sdk/dist/git.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/hub.d.ts +31 -0
- package/node_modules/@sumi/plugin-sdk/dist/hub.js +32 -0
- package/node_modules/@sumi/plugin-sdk/dist/hub.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/import-graph.d.ts +22 -0
- package/node_modules/@sumi/plugin-sdk/dist/import-graph.js +118 -0
- package/node_modules/@sumi/plugin-sdk/dist/import-graph.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.js +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/permissions.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/permissions.js +12 -1
- package/node_modules/@sumi/plugin-sdk/dist/permissions.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/session-context.d.ts +2 -2
- package/node_modules/@sumi/plugin-sdk/dist/session-context.js +10 -7
- package/node_modules/@sumi/plugin-sdk/dist/session-context.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/session-env.d.ts +2 -0
- package/node_modules/@sumi/plugin-sdk/dist/session-env.js +3 -0
- package/node_modules/@sumi/plugin-sdk/dist/session-env.js.map +1 -0
- package/node_modules/@sumi/plugin-sdk/dist/shell.d.ts +11 -5
- package/node_modules/@sumi/plugin-sdk/dist/shell.js +132 -23
- package/node_modules/@sumi/plugin-sdk/dist/shell.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/package.json +1 -1
- package/node_modules/@sumi/plugins-core/dist/agent-rules.js +20 -5
- package/node_modules/@sumi/plugins-core/dist/agent-rules.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/change-impact.js +1 -13
- package/node_modules/@sumi/plugins-core/dist/change-impact.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/commands/agent-rules-subagent-context.d.ts +1 -0
- package/node_modules/@sumi/plugins-core/dist/commands/agent-rules-subagent-context.js +10 -0
- package/node_modules/@sumi/plugins-core/dist/commands/agent-rules-subagent-context.js.map +1 -0
- package/node_modules/@sumi/plugins-core/dist/plugins/test-affected.js +26 -7
- package/node_modules/@sumi/plugins-core/dist/plugins/test-affected.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/test-scope.d.ts +3 -1
- package/node_modules/@sumi/plugins-core/dist/test-scope.js +14 -3
- package/node_modules/@sumi/plugins-core/dist/test-scope.js.map +1 -1
- package/node_modules/@sumi/plugins-core/dist/vitest-runner.js +16 -0
- package/node_modules/@sumi/plugins-core/dist/vitest-runner.js.map +1 -1
- package/node_modules/@sumi/plugins-core/instructions/bugfix.md +1 -1
- package/node_modules/@sumi/plugins-core/instructions/feature.md +1 -1
- package/node_modules/@sumi/plugins-core/package.json +2 -2
- package/node_modules/@sumi/plugins-core/sumi-plugins.yaml +6 -0
- 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 +121 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-browser.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 +179 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary-mcp.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary.d.ts +10 -0
- package/node_modules/@sumi/plugins-governance/dist/boundary.js +135 -29
- package/node_modules/@sumi/plugins-governance/dist/boundary.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/branch-scope.d.ts +9 -0
- package/node_modules/@sumi/plugins-governance/dist/branch-scope.js +64 -0
- package/node_modules/@sumi/plugins-governance/dist/branch-scope.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/checkout.d.ts +2 -0
- package/node_modules/@sumi/plugins-governance/dist/checkout.js +13 -3
- package/node_modules/@sumi/plugins-governance/dist/checkout.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary.js +59 -9
- package/node_modules/@sumi/plugins-governance/dist/commands/boundary.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/gate.js +16 -11
- package/node_modules/@sumi/plugins-governance/dist/commands/gate.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/hub-snapshot.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/hub-snapshot.js +4 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/hub-snapshot.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/commands/pr-report.js +3 -1
- package/node_modules/@sumi/plugins-governance/dist/commands/pr-report.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.d.ts +2 -1
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.js +11 -2
- package/node_modules/@sumi/plugins-governance/dist/gate-cache.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/guard.js +147 -19
- package/node_modules/@sumi/plugins-governance/dist/guard.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.d.ts +3 -0
- package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.js +40 -0
- package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.js.map +1 -0
- package/node_modules/@sumi/plugins-governance/dist/index.d.ts +3 -1
- package/node_modules/@sumi/plugins-governance/dist/index.js +3 -1
- package/node_modules/@sumi/plugins-governance/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-base.js +21 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-base.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-compose.js +4 -2
- package/node_modules/@sumi/plugins-governance/dist/pr-report-compose.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-markers.d.ts +2 -0
- package/node_modules/@sumi/plugins-governance/dist/pr-report-markers.js +2 -0
- package/node_modules/@sumi/plugins-governance/dist/pr-report-markers.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/pr-report-sections.js +34 -4
- package/node_modules/@sumi/plugins-governance/dist/pr-report-sections.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/preflight.d.ts +1 -0
- package/node_modules/@sumi/plugins-governance/dist/preflight.js +2 -2
- package/node_modules/@sumi/plugins-governance/dist/preflight.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/instructions/boundary.md +18 -2
- package/node_modules/@sumi/plugins-governance/package.json +4 -4
- package/node_modules/@sumi/plugins-governance/sumi-plugins.yaml +6 -0
- package/node_modules/@sumi/plugins-openspec/dist/commands/hub-snapshot.d.ts +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/commands/hub-snapshot.js +4 -0
- package/node_modules/@sumi/plugins-openspec/dist/commands/hub-snapshot.js.map +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/hub-snapshot.d.ts +4 -0
- package/node_modules/@sumi/plugins-openspec/dist/hub-snapshot.js +34 -0
- package/node_modules/@sumi/plugins-openspec/dist/hub-snapshot.js.map +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/index.d.ts +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/index.js +1 -0
- package/node_modules/@sumi/plugins-openspec/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugins-openspec/dist/plugins/impact-consistency.js +2 -0
- package/node_modules/@sumi/plugins-openspec/dist/plugins/impact-consistency.js.map +1 -1
- package/node_modules/@sumi/plugins-openspec/package.json +6 -6
- package/node_modules/@sumi/plugins-openspec/sumi-plugins.yaml +4 -0
- package/node_modules/@sumi/plugins-precedent/dist/after-edit-context.js +10 -11
- package/node_modules/@sumi/plugins-precedent/dist/after-edit-context.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/candidates.d.ts +9 -3
- package/node_modules/@sumi/plugins-precedent/dist/candidates.js +12 -6
- package/node_modules/@sumi/plugins-precedent/dist/candidates.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/commands/promote.js +20 -5
- package/node_modules/@sumi/plugins-precedent/dist/commands/promote.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/context-output.d.ts +15 -8
- package/node_modules/@sumi/plugins-precedent/dist/context-output.js +93 -34
- package/node_modules/@sumi/plugins-precedent/dist/context-output.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/context-provider.js +7 -3
- package/node_modules/@sumi/plugins-precedent/dist/context-provider.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/impact-state.d.ts +2 -1
- package/node_modules/@sumi/plugins-precedent/dist/impact-state.js +5 -4
- package/node_modules/@sumi/plugins-precedent/dist/impact-state.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/impact.d.ts +7 -6
- package/node_modules/@sumi/plugins-precedent/dist/impact.js +33 -29
- package/node_modules/@sumi/plugins-precedent/dist/impact.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/matching.d.ts +12 -0
- package/node_modules/@sumi/plugins-precedent/dist/matching.js +90 -0
- package/node_modules/@sumi/plugins-precedent/dist/matching.js.map +1 -0
- package/node_modules/@sumi/plugins-precedent/dist/plugins/harvest.js +44 -13
- package/node_modules/@sumi/plugins-precedent/dist/plugins/harvest.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/plugins/impact.js +15 -10
- package/node_modules/@sumi/plugins-precedent/dist/plugins/impact.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/plugins/planner.js +47 -6
- package/node_modules/@sumi/plugins-precedent/dist/plugins/planner.js.map +1 -1
- package/node_modules/@sumi/plugins-precedent/dist/review-candidates.d.ts +3 -0
- package/node_modules/@sumi/plugins-precedent/dist/review-candidates.js +40 -0
- package/node_modules/@sumi/plugins-precedent/dist/review-candidates.js.map +1 -0
- package/node_modules/@sumi/plugins-precedent/package.json +3 -3
- package/node_modules/@sumi/plugins-review/dist/command-input.d.ts +1 -1
- package/node_modules/@sumi/plugins-review/dist/command-input.js +4 -4
- package/node_modules/@sumi/plugins-review/dist/command-input.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/commands/stats.js +3 -3
- package/node_modules/@sumi/plugins-review/dist/commands/stats.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/commands/submit.js +6 -0
- package/node_modules/@sumi/plugins-review/dist/commands/submit.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/convergence.d.ts +7 -2
- package/node_modules/@sumi/plugins-review/dist/convergence.js +43 -5
- package/node_modules/@sumi/plugins-review/dist/convergence.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/dispatch.js +2 -0
- package/node_modules/@sumi/plugins-review/dist/dispatch.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/plugins/independent-recheck.js +1 -1
- package/node_modules/@sumi/plugins-review/dist/plugins/independent-recheck.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/precedent-context.d.ts +7 -0
- package/node_modules/@sumi/plugins-review/dist/precedent-context.js +28 -0
- package/node_modules/@sumi/plugins-review/dist/precedent-context.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/preflight.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/preflight.js +15 -5
- package/node_modules/@sumi/plugins-review/dist/preflight.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/report.d.ts +9 -0
- package/node_modules/@sumi/plugins-review/dist/report.js +28 -7
- package/node_modules/@sumi/plugins-review/dist/report.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/resolved-blockers.d.ts +9 -0
- package/node_modules/@sumi/plugins-review/dist/resolved-blockers.js +50 -0
- package/node_modules/@sumi/plugins-review/dist/resolved-blockers.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/review-scope.d.ts +1 -3
- package/node_modules/@sumi/plugins-review/dist/review-scope.js +1 -24
- package/node_modules/@sumi/plugins-review/dist/review-scope.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/review-slices.js +1 -0
- package/node_modules/@sumi/plugins-review/dist/review-slices.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/review.d.ts +47 -8
- package/node_modules/@sumi/plugins-review/dist/review.js +215 -34
- package/node_modules/@sumi/plugins-review/dist/review.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/rubric-check.js +71 -32
- package/node_modules/@sumi/plugins-review/dist/rubric-check.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/stats.d.ts +1 -0
- package/node_modules/@sumi/plugins-review/dist/stats.js +11 -15
- package/node_modules/@sumi/plugins-review/dist/stats.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/submission.js +24 -8
- package/node_modules/@sumi/plugins-review/dist/submission.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/submit-files.d.ts +3 -0
- package/node_modules/@sumi/plugins-review/dist/submit-files.js +55 -0
- package/node_modules/@sumi/plugins-review/dist/submit-files.js.map +1 -0
- package/node_modules/@sumi/plugins-review/dist/validation-receipt.js +4 -2
- package/node_modules/@sumi/plugins-review/dist/validation-receipt.js.map +1 -1
- package/node_modules/@sumi/plugins-review/package.json +6 -6
- package/package.json +10 -10
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import { loadConfig, loadRegistry, readRecords, resolveArgv } from '@sumi/kernel';
|
|
3
|
+
import { HUB_SNAPSHOT_CAPABILITY, cleanEnv, parseHubContributions, projectWorktrees, spawnCommandSync, withoutSessionEnv, } from '@sumi/plugin-sdk';
|
|
4
|
+
import { sessionReader } from '../visualize-sessions.js';
|
|
5
|
+
export const SNAPSHOT_SCHEMA = 1;
|
|
6
|
+
const RECENT_RUNS = 5;
|
|
7
|
+
const SESSION_WINDOW_MS = 7 * 24 * 3600_000;
|
|
8
|
+
const MAX_SESSIONS = 50;
|
|
9
|
+
const CONTRIBUTION_TIMEOUT_MS = 10_000;
|
|
10
|
+
function git(cwd, args) {
|
|
11
|
+
const result = spawnCommandSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true });
|
|
12
|
+
return { ok: result.status === 0, out: typeof result.stdout === 'string' ? result.stdout.trim() : '' };
|
|
13
|
+
}
|
|
14
|
+
/** 默认分支名:先看 origin/HEAD,再看本地的 main 与 master;都没有时为 null。 */
|
|
15
|
+
function defaultBranch(root) {
|
|
16
|
+
const remote = git(root, ['symbolic-ref', '--short', 'refs/remotes/origin/HEAD']);
|
|
17
|
+
if (remote.ok && remote.out.startsWith('origin/'))
|
|
18
|
+
return remote.out.slice('origin/'.length);
|
|
19
|
+
return ['main', 'master'].find((name) => git(root, ['rev-parse', '--verify', '-q', `refs/heads/${name}`]).ok) ?? null;
|
|
20
|
+
}
|
|
21
|
+
/** 分支提交已被默认分支包含,且不是同一个提交(刚从默认分支切出的分支不算已合并)。 */
|
|
22
|
+
function isMerged(checkout, base) {
|
|
23
|
+
if (!base)
|
|
24
|
+
return false;
|
|
25
|
+
const head = git(checkout, ['rev-parse', 'HEAD']);
|
|
26
|
+
if (!head.ok)
|
|
27
|
+
return false;
|
|
28
|
+
return [`origin/${base}`, base].some((ref) => {
|
|
29
|
+
const tip = git(checkout, ['rev-parse', '--verify', '-q', ref]);
|
|
30
|
+
return tip.ok && tip.out !== head.out && git(checkout, ['merge-base', '--is-ancestor', head.out, ref]).ok;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function addContribution(table, key, next) {
|
|
34
|
+
const current = table.get(key) ?? {};
|
|
35
|
+
const awaiting = [current.awaiting, next.awaiting].filter(Boolean).join(';');
|
|
36
|
+
const progress = [...(current.progress ?? []), ...(next.progress ?? [])];
|
|
37
|
+
table.set(key, { ...(awaiting ? { awaiting } : {}), ...(progress.length ? { progress } : {}) });
|
|
38
|
+
}
|
|
39
|
+
/** 调用各插件以 `hub.snapshot` 能力声明的命令并合并结果;某个命令失败只丢弃它的贡献。 */
|
|
40
|
+
function contributions(root, input, diagnostics) {
|
|
41
|
+
const merged = { checkouts: new Map(), sessions: new Map() };
|
|
42
|
+
let registry;
|
|
43
|
+
try {
|
|
44
|
+
registry = loadRegistry(root, loadConfig(root));
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
diagnostics.push(`无法加载项目插件:${error.message}`);
|
|
48
|
+
return merged;
|
|
49
|
+
}
|
|
50
|
+
for (const command of registry.commands.values()) {
|
|
51
|
+
if (command.capability !== HUB_SNAPSHOT_CAPABILITY)
|
|
52
|
+
continue;
|
|
53
|
+
const [bin, ...argv] = resolveArgv(command.argv, command.dir);
|
|
54
|
+
const child = spawnCommandSync(bin, argv, {
|
|
55
|
+
cwd: root,
|
|
56
|
+
input: JSON.stringify(input),
|
|
57
|
+
encoding: 'utf8',
|
|
58
|
+
windowsHide: true,
|
|
59
|
+
timeout: CONTRIBUTION_TIMEOUT_MS,
|
|
60
|
+
env: { ...cleanEnv(withoutSessionEnv()), SUMI_ROOT: root },
|
|
61
|
+
});
|
|
62
|
+
const parsed = child.status === 0 && !child.error ? parseHubContributions(child.stdout) : null;
|
|
63
|
+
if (!parsed) {
|
|
64
|
+
diagnostics.push(`快照贡献命令 ${command.name} 失败`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
for (const [key, value] of Object.entries(parsed.checkouts))
|
|
68
|
+
addContribution(merged.checkouts, key, value);
|
|
69
|
+
for (const [key, value] of Object.entries(parsed.sessions))
|
|
70
|
+
addContribution(merged.sessions, key, value);
|
|
71
|
+
}
|
|
72
|
+
return merged;
|
|
73
|
+
}
|
|
74
|
+
/** 项目自己的只读快照:检出与分支、最近运行、会话列表及插件贡献。不修改任何项目数据。 */
|
|
75
|
+
export function buildSnapshot(root, now = Date.now()) {
|
|
76
|
+
const diagnostics = [];
|
|
77
|
+
const base = defaultBranch(root);
|
|
78
|
+
const trees = projectWorktrees(root);
|
|
79
|
+
const checkouts = (trees.length ? trees : [root]).map((path) => {
|
|
80
|
+
const branch = git(path, ['symbolic-ref', '--short', '-q', 'HEAD']);
|
|
81
|
+
const name = branch.ok && branch.out ? branch.out : null;
|
|
82
|
+
return {
|
|
83
|
+
path,
|
|
84
|
+
branch: name,
|
|
85
|
+
isDefault: name !== null && name === base,
|
|
86
|
+
merged: name !== null && name !== base && isMerged(path, base),
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
const sessions = sessionReader(root)
|
|
90
|
+
.list()
|
|
91
|
+
.filter((session) => session.updatedAt !== null && now - Date.parse(session.updatedAt) <= SESSION_WINDOW_MS)
|
|
92
|
+
.slice(0, MAX_SESSIONS);
|
|
93
|
+
const extra = contributions(root, {
|
|
94
|
+
repoRoot: root,
|
|
95
|
+
checkouts: checkouts.map(({ path, branch }) => ({ path, branch })),
|
|
96
|
+
sessions: sessions.map(({ id, session }) => ({ id, session })),
|
|
97
|
+
}, diagnostics);
|
|
98
|
+
return {
|
|
99
|
+
schemaVersion: SNAPSHOT_SCHEMA,
|
|
100
|
+
name: basename(root),
|
|
101
|
+
root,
|
|
102
|
+
checkouts: checkouts.map((checkout) => ({
|
|
103
|
+
...checkout,
|
|
104
|
+
runs: readRecords(checkout.path)
|
|
105
|
+
.slice(-RECENT_RUNS)
|
|
106
|
+
.reverse()
|
|
107
|
+
.map((record) => ({
|
|
108
|
+
runId: record.runId,
|
|
109
|
+
flow: record.flow,
|
|
110
|
+
conclusion: record.conclusion,
|
|
111
|
+
partial: record.partial === true,
|
|
112
|
+
startedAt: record.startedAt,
|
|
113
|
+
finishedAt: record.finishedAt ?? null,
|
|
114
|
+
})),
|
|
115
|
+
contribution: extra.checkouts.get(checkout.path) ?? {},
|
|
116
|
+
})),
|
|
117
|
+
sessions: sessions.map((session) => {
|
|
118
|
+
const awaiting = extra.sessions.get(session.id)?.awaiting;
|
|
119
|
+
return awaiting ? { ...session, awaiting } : session;
|
|
120
|
+
}),
|
|
121
|
+
diagnostics,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** 会话明细:直接复用单项目页的账本读取。 */
|
|
125
|
+
export function sessionDetail(root, id, view) {
|
|
126
|
+
const reader = sessionReader(root);
|
|
127
|
+
return {
|
|
128
|
+
schemaVersion: SNAPSHOT_SCHEMA,
|
|
129
|
+
...(view.confirmations ? { confirmations: reader.confirmations(id) } : { events: reader.events(id, view.after) }),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../src/hub/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EACL,uBAAuB,EACvB,QAAQ,EACR,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,GAGlB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAuB,MAAM,0BAA0B,CAAC;AAE9E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AACjC,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC;AAC5C,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAgCvC,SAAS,GAAG,CAAC,GAAW,EAAE,IAAc;IACtC,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IAChI,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,GAAG,EAAE,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACzG,CAAC;AAED,2DAA2D;AAC3D,SAAS,aAAa,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C,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACvD,CAAC,CAAC;QACF,WAAW;KACZ,CAAC;AACJ,CAAC;AAED,0BAA0B;AAC1B,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,EAAU,EAAE,IAA+C;IACrG,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,OAAO;QACL,aAAa,EAAE,eAAe;QAC9B,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;KAClH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface StartOptions {
|
|
2
|
+
/** 健康探测的超时上限(毫秒)。 */
|
|
3
|
+
probeMs?: number;
|
|
4
|
+
/** 拉起后台 hub;默认以分离的子进程运行当前 CLI 的 `hub serve`。 */
|
|
5
|
+
spawnHub?: () => void;
|
|
6
|
+
}
|
|
7
|
+
/** 记录最近一次 hub 相关的失败,供 `sumi hub status` 查看;不进入会话输出。 */
|
|
8
|
+
export declare function recordHubDiagnostic(message: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* 会话开始:登记当前项目并确保 hub 在运行,返回要送达的一行提示(无事可告知时为 null)。
|
|
11
|
+
* 任何失败只记录诊断;探测有超时上限,拉起不等待。`SUMI_HUB=off` 时跳过。
|
|
12
|
+
*/
|
|
13
|
+
export declare function hubSessionStart(root: string, options?: StartOptions): Promise<string | null>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { chmodSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { cleanEnv, withoutSessionEnv } from '@sumi/plugin-sdk';
|
|
4
|
+
import { hubFiles, probeHub, registerProject } from './state.js';
|
|
5
|
+
/** 记录最近一次 hub 相关的失败,供 `sumi hub status` 查看;不进入会话输出。 */
|
|
6
|
+
export function recordHubDiagnostic(message) {
|
|
7
|
+
try {
|
|
8
|
+
const { home, diagnostic } = hubFiles();
|
|
9
|
+
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
10
|
+
writeFileSync(diagnostic, `${new Date().toISOString()} ${message}\n`, { mode: 0o600 });
|
|
11
|
+
chmodSync(diagnostic, 0o600);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
/* 诊断写不出去也不影响会话 */
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** 分离的后台进程:不继承标准流,Windows 不弹窗,父进程不等待。 */
|
|
18
|
+
function spawnDetachedHub() {
|
|
19
|
+
const entry = process.env.SUMI_BIN ?? process.argv[1];
|
|
20
|
+
if (!entry)
|
|
21
|
+
throw new Error('找不到 sumi 入口');
|
|
22
|
+
const { home } = hubFiles();
|
|
23
|
+
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
24
|
+
const child = spawn(process.execPath, [entry, 'hub', 'serve'], {
|
|
25
|
+
cwd: home,
|
|
26
|
+
detached: true,
|
|
27
|
+
stdio: 'ignore',
|
|
28
|
+
windowsHide: true,
|
|
29
|
+
env: cleanEnv(withoutSessionEnv()),
|
|
30
|
+
});
|
|
31
|
+
child.on('error', (error) => recordHubDiagnostic(`拉起 hub 失败:${error.message}`));
|
|
32
|
+
child.unref();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 会话开始:登记当前项目并确保 hub 在运行,返回要送达的一行提示(无事可告知时为 null)。
|
|
36
|
+
* 任何失败只记录诊断;探测有超时上限,拉起不等待。`SUMI_HUB=off` 时跳过。
|
|
37
|
+
*/
|
|
38
|
+
export async function hubSessionStart(root, options = {}) {
|
|
39
|
+
if (process.env.SUMI_HUB === 'off')
|
|
40
|
+
return null;
|
|
41
|
+
try {
|
|
42
|
+
registerProject(root);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
recordHubDiagnostic(`hub 登记失败:${error.message}`);
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const running = await probeHub(options.probeMs ?? 300);
|
|
49
|
+
if (running)
|
|
50
|
+
return `Sumi hub:${running.url}(本机所有项目的看板与会话,只读)`;
|
|
51
|
+
(options.spawnHub ?? spawnDetachedHub)();
|
|
52
|
+
return 'Sumi hub 正在后台启动,地址见 `sumi hub status`';
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
recordHubDiagnostic(`hub 探测或拉起失败:${error.message}`);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=start.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/hub/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AASjE,uDAAuD;AACvD,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,QAAQ,EAAE,CAAC;QACxC,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAClD,aAAa,CAAC,UAAU,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,OAAO,IAAI,EAAE,EAAE,IAAI,EAAE,KA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YAAa,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,IAAI,GAAG,CAAC,CAAC;QACvD,IAAI,OAAO;YAAE,OAAO,YAAY,OAAO,CAAC,GAAG,mBAAmB,CAAC;QAC/D,CAAC,OAAO,CAAC,QAAQ,IAAI,gBAAgB,CAAC,EAAE,CAAC;QACzC,OAAO,uCAAuC,CAAC;IACjD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,mBAAmB,CAAC,eAAgB,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** hub 的首选端口;被占用时顺延。 */
|
|
2
|
+
export declare const HUB_PORT = 4801;
|
|
3
|
+
export interface RegisteredProject {
|
|
4
|
+
path: string;
|
|
5
|
+
registeredAt: number;
|
|
6
|
+
lastSeenAt: number;
|
|
7
|
+
}
|
|
8
|
+
export interface HubState {
|
|
9
|
+
pid: number;
|
|
10
|
+
port: number;
|
|
11
|
+
startedAt: number;
|
|
12
|
+
lastActivityAt: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function hubFiles(): {
|
|
15
|
+
home: string;
|
|
16
|
+
projects: string;
|
|
17
|
+
projectsLock: string;
|
|
18
|
+
state: string;
|
|
19
|
+
lock: string;
|
|
20
|
+
diagnostic: string;
|
|
21
|
+
};
|
|
22
|
+
/** 该项目所属仓库的主工作区:worktree 里的会话与主工作区登记为同一项。 */
|
|
23
|
+
export declare function mainWorktree(root: string): string;
|
|
24
|
+
/** 读取登记表;缺失或损坏时为空表。 */
|
|
25
|
+
export declare function readProjects(): RegisteredProject[];
|
|
26
|
+
/**
|
|
27
|
+
* 登记项目(只有会话开始 hook 调用)。目录锁内“读、合并、原子写”,同时开始的会话不会互相覆盖;
|
|
28
|
+
* 锁在 500 毫秒内拿不到时抛错,本次登记放弃,由下次会话开始重试。
|
|
29
|
+
*/
|
|
30
|
+
export declare function registerProject(root: string, now?: number): string;
|
|
31
|
+
export declare function pidAlive(pid: number): boolean;
|
|
32
|
+
export declare function readHubState(): HubState | null;
|
|
33
|
+
export declare function writeHubState(state: HubState): void;
|
|
34
|
+
/**
|
|
35
|
+
* 单实例锁:以 `wx` 创建、内容是进程号,hub 持有至退出。持有者进程已不存在时接管;
|
|
36
|
+
* 内容不是进程号(刚创建尚未写入,或被改坏)时保守地当作被持有,由 `sumi hub stop` 兜底清理。
|
|
37
|
+
*/
|
|
38
|
+
export declare function acquireHubLock(): boolean;
|
|
39
|
+
/** 删除状态文件与锁;`owner` 给出时只在文件属于该进程时删除。 */
|
|
40
|
+
export declare function releaseHubFiles(owner?: number): void;
|
|
41
|
+
/** hub 的健康响应标识;探测靠它确认端口上的确是本机 hub。 */
|
|
42
|
+
export declare const HEALTH: {
|
|
43
|
+
readonly hub: "sumi";
|
|
44
|
+
};
|
|
45
|
+
/** 探测运行中的 hub:状态文件、进程存活与端口健康检查都通过才算运行。 */
|
|
46
|
+
export declare function probeHub(timeoutMs: number): Promise<{
|
|
47
|
+
url: string;
|
|
48
|
+
state: HubState;
|
|
49
|
+
} | null>;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { spawnCommandSync, userStateHome, withFileLock, writeFileAtomic } from '@sumi/plugin-sdk';
|
|
4
|
+
/** hub 的首选端口;被占用时顺延。 */
|
|
5
|
+
export const HUB_PORT = 4801;
|
|
6
|
+
export function hubFiles() {
|
|
7
|
+
const home = userStateHome();
|
|
8
|
+
return {
|
|
9
|
+
home,
|
|
10
|
+
projects: join(home, 'projects.json'),
|
|
11
|
+
projectsLock: join(home, 'projects.lock'),
|
|
12
|
+
state: join(home, 'hub.json'),
|
|
13
|
+
lock: join(home, 'hub.lock'),
|
|
14
|
+
diagnostic: join(home, 'hub-diagnostic.log'),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function ensureHome() {
|
|
18
|
+
const { home } = hubFiles();
|
|
19
|
+
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
20
|
+
chmodSync(home, 0o700);
|
|
21
|
+
return home;
|
|
22
|
+
}
|
|
23
|
+
/** 该项目所属仓库的主工作区:worktree 里的会话与主工作区登记为同一项。 */
|
|
24
|
+
export function mainWorktree(root) {
|
|
25
|
+
const real = realpathSync(root);
|
|
26
|
+
const listed = spawnCommandSync('git', ['worktree', 'list', '--porcelain'], {
|
|
27
|
+
cwd: real,
|
|
28
|
+
encoding: 'utf8',
|
|
29
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
30
|
+
windowsHide: true,
|
|
31
|
+
});
|
|
32
|
+
const first = listed.status === 0 && typeof listed.stdout === 'string' ? /^worktree (.+)$/m.exec(listed.stdout)?.[1] : undefined;
|
|
33
|
+
try {
|
|
34
|
+
return first && existsSync(first) ? realpathSync(first) : real;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return real;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const isEntry = (value) => {
|
|
41
|
+
const entry = value;
|
|
42
|
+
return !!entry && typeof entry.path === 'string' && Number.isFinite(entry.registeredAt) && Number.isFinite(entry.lastSeenAt);
|
|
43
|
+
};
|
|
44
|
+
/** 读取登记表;缺失或损坏时为空表。 */
|
|
45
|
+
export function readProjects() {
|
|
46
|
+
try {
|
|
47
|
+
const value = JSON.parse(readFileSync(hubFiles().projects, 'utf8'));
|
|
48
|
+
return Array.isArray(value.projects) ? value.projects.filter(isEntry) : [];
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 登记项目(只有会话开始 hook 调用)。目录锁内“读、合并、原子写”,同时开始的会话不会互相覆盖;
|
|
56
|
+
* 锁在 500 毫秒内拿不到时抛错,本次登记放弃,由下次会话开始重试。
|
|
57
|
+
*/
|
|
58
|
+
export function registerProject(root, now = Date.now()) {
|
|
59
|
+
const path = mainWorktree(root);
|
|
60
|
+
const files = hubFiles();
|
|
61
|
+
ensureHome();
|
|
62
|
+
withFileLock(files.projectsLock, () => {
|
|
63
|
+
const projects = readProjects();
|
|
64
|
+
const existing = projects.find((entry) => entry.path === path);
|
|
65
|
+
if (existing)
|
|
66
|
+
existing.lastSeenAt = now;
|
|
67
|
+
else
|
|
68
|
+
projects.push({ path, registeredAt: now, lastSeenAt: now });
|
|
69
|
+
writeFileAtomic(files.projects, JSON.stringify({ projects }, null, 2), { mode: 0o600 });
|
|
70
|
+
}, { required: true });
|
|
71
|
+
return path;
|
|
72
|
+
}
|
|
73
|
+
export function pidAlive(pid) {
|
|
74
|
+
try {
|
|
75
|
+
process.kill(pid, 0);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return error.code === 'EPERM';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function readHubState() {
|
|
83
|
+
try {
|
|
84
|
+
const state = JSON.parse(readFileSync(hubFiles().state, 'utf8'));
|
|
85
|
+
return [state.pid, state.port, state.startedAt, state.lastActivityAt].every((value) => Number.isFinite(value))
|
|
86
|
+
? state
|
|
87
|
+
: null;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function writeHubState(state) {
|
|
94
|
+
ensureHome();
|
|
95
|
+
writeFileAtomic(hubFiles().state, JSON.stringify(state), { mode: 0o600 });
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 单实例锁:以 `wx` 创建、内容是进程号,hub 持有至退出。持有者进程已不存在时接管;
|
|
99
|
+
* 内容不是进程号(刚创建尚未写入,或被改坏)时保守地当作被持有,由 `sumi hub stop` 兜底清理。
|
|
100
|
+
*/
|
|
101
|
+
export function acquireHubLock() {
|
|
102
|
+
const { lock } = hubFiles();
|
|
103
|
+
ensureHome();
|
|
104
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
105
|
+
try {
|
|
106
|
+
writeFileSync(lock, String(process.pid), { flag: 'wx', mode: 0o600 });
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (error.code !== 'EEXIST')
|
|
111
|
+
throw error;
|
|
112
|
+
const owner = Number(readFileSync(lock, 'utf8'));
|
|
113
|
+
if (!Number.isSafeInteger(owner) || owner <= 0 || pidAlive(owner))
|
|
114
|
+
return false;
|
|
115
|
+
rmSync(lock, { force: true });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
/** 删除状态文件与锁;`owner` 给出时只在文件属于该进程时删除。 */
|
|
121
|
+
export function releaseHubFiles(owner) {
|
|
122
|
+
const files = hubFiles();
|
|
123
|
+
if (owner !== undefined && readHubState()?.pid !== owner)
|
|
124
|
+
return;
|
|
125
|
+
rmSync(files.state, { force: true });
|
|
126
|
+
rmSync(files.lock, { force: true });
|
|
127
|
+
}
|
|
128
|
+
/** hub 的健康响应标识;探测靠它确认端口上的确是本机 hub。 */
|
|
129
|
+
export const HEALTH = { hub: 'sumi' };
|
|
130
|
+
/** 探测运行中的 hub:状态文件、进程存活与端口健康检查都通过才算运行。 */
|
|
131
|
+
export async function probeHub(timeoutMs) {
|
|
132
|
+
const state = readHubState();
|
|
133
|
+
if (!state || !pidAlive(state.pid))
|
|
134
|
+
return null;
|
|
135
|
+
try {
|
|
136
|
+
const response = await fetch(`http://127.0.0.1:${state.port}/api/health`, { signal: AbortSignal.timeout(timeoutMs) });
|
|
137
|
+
const body = (await response.json());
|
|
138
|
+
return response.ok && body.hub === HEALTH.hub && body.pid === state.pid ? { url: `http://127.0.0.1:${state.port}`, state } : null;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/hub/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC9G,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAElG,wBAAwB;AACxB,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC;AAe7B,MAAM,UAAU,QAAQ;IACtB,MAAM,IAAI,GAAG,aAAa,EAAE,CAAC;IAC7B,OAAO;QACL,IAAI;QACJ,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC;QACrC,YAAY,EAAE,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC;QACzC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC;QAC7B,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC;QAC5B,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,oBAAoB,CAAC;KAC7C,CAAC;AACJ,CAAC;AAED,SAAS,UAAU;IACjB,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,EAAE,CAAC;IAC5B,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAClD,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,YAAY,CAAC,IA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C,CAAC;QACtH,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAqC,CAAC;QACzE,OAAO,QAAQ,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,KAAK,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,oBAAoB,KAAK,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACpI,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,OAAO,UAAU,CAAC;AAClB,OAAO,kBAAkB,CAAC;AAC1B,OAAO,aAAa,CAAC;AACrB,OAAO,mBAAmB,CAAC;AAC3B,OAAO,wBAAwB,CAAC;AAChC,OAAO,cAAc,CAAC;AACtB,OAAO,WAAW,CAAC;AACnB,OAAO,gBAAgB,CAAC;AACxB,OAAO,aAAa,CAAC;AACrB,OAAO,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,OAAO,UAAU,CAAC;AAClB,OAAO,kBAAkB,CAAC;AAC1B,OAAO,aAAa,CAAC;AACrB,OAAO,mBAAmB,CAAC;AAC3B,OAAO,wBAAwB,CAAC;AAChC,OAAO,cAAc,CAAC;AACtB,OAAO,WAAW,CAAC;AACnB,OAAO,gBAAgB,CAAC;AACxB,OAAO,mBAAmB,CAAC;AAC3B,OAAO,aAAa,CAAC;AACrB,OAAO,gBAAgB,CAAC;AACxB,OAAO,sBAAsB,CAAC"}
|
package/dist/instructions.js
CHANGED
|
@@ -37,7 +37,7 @@ ${Object.entries(ctx.zones).length
|
|
|
37
37
|
## 步骤
|
|
38
38
|
|
|
39
39
|
1. **识别任务**:运行 \`sumi task "<任务意图>"\`(缺陷加 \`--bug\`,新能力加 \`--feature\`)。阅读目录,自行选择相关 ID,运行 \`sumi task --select <id,...>\`;不得把目录描述当作约束原文。
|
|
40
|
-
需求开发、缺陷修复前 MUST
|
|
40
|
+
需求开发、缺陷修复前 MUST 先与用户确认边界:套用项目常设边界,按五节起草,每条给建议默认答案与需拍板标记,按 \`sumi instructions boundary\` 选择 Codex 表单、CLI 浏览器或宿主手工问答;已有明确确认直接记录。非交互按保守默认 \`confirm --unconfirmed\` 后继续,不新增审批;纯格式或文档用 \`boundary skip --reason\`。
|
|
41
41
|
2. **明确范围并查约束**:列出要新增或修改的文件路径(可以是尚不存在的文件、目录或 glob),运行 \`sumi context <路径...>\`。命令自动按宿主环境绑定会话;调用方缺少独立身份环境时,在首次查询前显式传入 \`--session <会话 ID>\`。范围变化时重查。
|
|
42
42
|
- 默认摘要列出条目 ID 和规则位置;需要完整约束时用 \`--full\` 或 \`task --full --select <ID>\`,也可打开给出的文件与行号。
|
|
43
43
|
- 通用条目适用于所有改动,按需读取原文。
|
package/dist/run-stats.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type Conclusion } from '@sumi/kernel';
|
|
2
|
+
import { type StepState } from '@sumi/plugin-sdk';
|
|
1
3
|
interface Distribution {
|
|
2
4
|
p50: number;
|
|
3
5
|
p90: number;
|
|
@@ -7,6 +9,21 @@ export interface GroupStats {
|
|
|
7
9
|
flow: string;
|
|
8
10
|
tier: string;
|
|
9
11
|
runs: number;
|
|
12
|
+
/** 完整且有结论的运行;比例分母为这些结论的总数。 */
|
|
13
|
+
conclusions: Record<Conclusion, number>;
|
|
14
|
+
passRate: number | null;
|
|
15
|
+
partialRuns: number;
|
|
16
|
+
missingConclusion: number;
|
|
17
|
+
reasons: {
|
|
18
|
+
state: Conclusion;
|
|
19
|
+
label: string;
|
|
20
|
+
runs: number;
|
|
21
|
+
rate: number | null;
|
|
22
|
+
steps: {
|
|
23
|
+
id: string;
|
|
24
|
+
runs: number;
|
|
25
|
+
}[];
|
|
26
|
+
}[];
|
|
10
27
|
/** 步骤耗时之和(毫秒),不含复用的步骤。 */
|
|
11
28
|
stepSum: Distribution;
|
|
12
29
|
/** 墙钟耗时(毫秒);没有结束时间的旧记录不计入,全部缺失时为 null。 */
|
|
@@ -24,10 +41,13 @@ export interface StatsRecord {
|
|
|
24
41
|
tier: string;
|
|
25
42
|
startedAt: string;
|
|
26
43
|
finishedAt?: string;
|
|
44
|
+
conclusion?: Conclusion;
|
|
45
|
+
partial?: boolean;
|
|
27
46
|
steps: {
|
|
28
47
|
id: string;
|
|
29
48
|
durationMs?: number;
|
|
30
49
|
reusedFrom?: string;
|
|
50
|
+
state?: StepState;
|
|
31
51
|
}[];
|
|
32
52
|
}
|
|
33
53
|
export interface RunStats {
|
package/dist/run-stats.js
CHANGED
|
@@ -14,23 +14,37 @@ const isTime = (v) => typeof v === 'string' && Number.isFinite(Date.parse(v));
|
|
|
14
14
|
const optional = (v, check) => v === undefined || check(v);
|
|
15
15
|
const isDuration = (v) => typeof v === 'number' && Number.isFinite(v) && v >= 0;
|
|
16
16
|
const isString = (v) => typeof v === 'string';
|
|
17
|
+
const isConclusion = (v) => ['pass', 'fail', 'blocked', 'pending'].includes(v);
|
|
18
|
+
const isStepState = (v) => isConclusion(v) || v === 'skipped' || v === 'not-applicable';
|
|
19
|
+
const isBoolean = (v) => typeof v === 'boolean';
|
|
17
20
|
/** 把一份 result.json 解析为统计记录;任一用到的字段不合法时返回 null,整条记录不参与统计。 */
|
|
18
21
|
export function parseStatsRecord(value) {
|
|
19
22
|
if (!isObject(value) || !isString(value.flow) || !isString(value.tier) || !isTime(value.startedAt))
|
|
20
23
|
return null;
|
|
21
24
|
if (!optional(value.finishedAt, isTime) || !Array.isArray(value.steps))
|
|
22
25
|
return null;
|
|
26
|
+
if (!optional(value.conclusion, isConclusion) || !optional(value.partial, isBoolean))
|
|
27
|
+
return null;
|
|
23
28
|
const steps = [];
|
|
24
29
|
for (const step of value.steps) {
|
|
25
30
|
if (!isObject(step) || !isString(step.id) || !optional(step.durationMs, isDuration) || !optional(step.reusedFrom, isString))
|
|
26
31
|
return null;
|
|
27
|
-
|
|
32
|
+
if (!optional(step.state, isStepState))
|
|
33
|
+
return null;
|
|
34
|
+
steps.push({
|
|
35
|
+
id: step.id,
|
|
36
|
+
durationMs: step.durationMs,
|
|
37
|
+
reusedFrom: step.reusedFrom,
|
|
38
|
+
state: step.state,
|
|
39
|
+
});
|
|
28
40
|
}
|
|
29
41
|
return {
|
|
30
42
|
flow: value.flow,
|
|
31
43
|
tier: value.tier,
|
|
32
44
|
startedAt: value.startedAt,
|
|
33
45
|
...(value.finishedAt === undefined ? {} : { finishedAt: value.finishedAt }),
|
|
46
|
+
conclusion: value.conclusion,
|
|
47
|
+
partial: value.partial,
|
|
34
48
|
steps,
|
|
35
49
|
};
|
|
36
50
|
}
|
|
@@ -61,13 +75,14 @@ export function readRunRecords(root) {
|
|
|
61
75
|
}
|
|
62
76
|
export function runStats(records, options = {}) {
|
|
63
77
|
const groups = new Map();
|
|
64
|
-
|
|
78
|
+
const filtered = records.filter((record) => {
|
|
65
79
|
if (options.flow && record.flow !== options.flow)
|
|
66
|
-
|
|
80
|
+
return false;
|
|
67
81
|
if (options.tier && record.tier !== options.tier)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
82
|
+
return false;
|
|
83
|
+
return !options.since || Date.parse(record.startedAt) >= options.since.getTime();
|
|
84
|
+
});
|
|
85
|
+
for (const record of filtered) {
|
|
71
86
|
const key = `${record.flow}\0${record.tier}`;
|
|
72
87
|
groups.set(key, [...(groups.get(key) ?? []), record]);
|
|
73
88
|
}
|
|
@@ -86,10 +101,35 @@ export function runStats(records, options = {}) {
|
|
|
86
101
|
.map(([id, values]) => ({ id, totalMs: values.reduce((a, b) => a + b, 0), runs: values.length, p50: distribution(values).p50 }))
|
|
87
102
|
.sort((a, b) => b.totalMs - a.totalMs || a.id.localeCompare(b.id))
|
|
88
103
|
.slice(0, options.top ?? 5);
|
|
104
|
+
const complete = group.filter((record) => !record.partial && record.conclusion !== undefined);
|
|
105
|
+
const conclusions = { pass: 0, fail: 0, blocked: 0, pending: 0 };
|
|
106
|
+
for (const record of complete)
|
|
107
|
+
conclusions[record.conclusion]++;
|
|
108
|
+
const reasons = ['fail', 'blocked', 'pending'].map((state) => {
|
|
109
|
+
const counts = new Map();
|
|
110
|
+
for (const record of complete.filter((record) => record.conclusion === state))
|
|
111
|
+
for (const step of record.steps.filter((step) => step.state === state))
|
|
112
|
+
counts.set(step.id, (counts.get(step.id) ?? 0) + 1);
|
|
113
|
+
return {
|
|
114
|
+
state,
|
|
115
|
+
label: { fail: '检查发现', blocked: '受阻', pending: '等待评审或记录' }[state],
|
|
116
|
+
runs: conclusions[state],
|
|
117
|
+
rate: complete.length ? conclusions[state] / complete.length : null,
|
|
118
|
+
steps: [...counts]
|
|
119
|
+
.map(([id, runs]) => ({ id, runs }))
|
|
120
|
+
.sort((a, b) => b.runs - a.runs || a.id.localeCompare(b.id))
|
|
121
|
+
.slice(0, options.top ?? 5),
|
|
122
|
+
};
|
|
123
|
+
});
|
|
89
124
|
return {
|
|
90
125
|
flow: group[0].flow,
|
|
91
126
|
tier: group[0].tier,
|
|
92
127
|
runs: group.length,
|
|
128
|
+
conclusions,
|
|
129
|
+
passRate: complete.length ? conclusions.pass / complete.length : null,
|
|
130
|
+
partialRuns: group.filter((record) => record.partial).length,
|
|
131
|
+
missingConclusion: group.filter((record) => !record.partial && record.conclusion === undefined).length,
|
|
132
|
+
reasons,
|
|
93
133
|
stepSum: distribution(group.map((r) => executed(r).reduce((sum, s) => sum + s.durationMs, 0))),
|
|
94
134
|
wall: walls.length ? distribution(walls) : null,
|
|
95
135
|
slowest,
|
|
@@ -99,12 +139,24 @@ export function runStats(records, options = {}) {
|
|
|
99
139
|
}
|
|
100
140
|
const seconds = (ms) => `${(ms / 1000).toFixed(ms < 10_000 ? 1 : 0)} s`;
|
|
101
141
|
const triple = (d) => `P50 ${seconds(d.p50)} P90 ${seconds(d.p90)} max ${seconds(d.max)}`;
|
|
142
|
+
const percentage = (rate) => `${(rate * 100).toFixed(1)}%`;
|
|
102
143
|
export function renderRunStats(stats) {
|
|
103
144
|
const lines = [];
|
|
104
145
|
for (const g of stats.groups) {
|
|
105
146
|
lines.push(`${g.flow} / ${g.tier}:${g.runs} 次运行`);
|
|
106
147
|
lines.push(` 步骤耗时之和 ${triple(g.stepSum)}`);
|
|
107
148
|
lines.push(` 墙钟 ${g.wall ? triple(g.wall) : '无结束时间记录'}`);
|
|
149
|
+
const c = g.conclusions;
|
|
150
|
+
if (g.passRate !== null) {
|
|
151
|
+
lines.push(` 整体结论 通过 ${c.pass} 次,不通过 ${c.fail} 次,受阻 ${c.blocked} 次,等待中 ${c.pending} 次`);
|
|
152
|
+
lines.push(` 通过率 ${percentage(g.passRate)}`);
|
|
153
|
+
}
|
|
154
|
+
lines.push(` 部分运行 ${g.partialRuns} 次,缺少整体结论 ${g.missingConclusion} 次(均不计入通过率)`);
|
|
155
|
+
for (const reason of g.reasons.filter((reason) => reason.runs > 0)) {
|
|
156
|
+
lines.push(` ${reason.label} ${reason.runs} 次(${percentage(reason.rate)})`);
|
|
157
|
+
for (const step of reason.steps)
|
|
158
|
+
lines.push(` ${step.id} ${step.runs} 次`);
|
|
159
|
+
}
|
|
108
160
|
if (g.slowest.length) {
|
|
109
161
|
lines.push(' 累计耗时最长的步骤:');
|
|
110
162
|
for (const s of g.slowest)
|