shipgate-cli 0.0.0-stage → 0.2.2

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.
Files changed (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +261 -2
  3. package/agents/context-builder.md +158 -0
  4. package/agents/debug-executor.md +234 -0
  5. package/assets/gates/classifier.js +245 -0
  6. package/assets/gates/dsh/index.js +767 -0
  7. package/assets/gates/dsh/policy.json +93 -0
  8. package/assets/gates/index.js +3 -0
  9. package/assets/gates/pi/index.js +1131 -0
  10. package/assets/gates/pi/policy.json +93 -0
  11. package/assets/gates/policy.js +4267 -0
  12. package/assets/gates/profiles/ai4s-dry-lab.json +64 -0
  13. package/assets/gates/profiles/ai4s-quant.json +36 -0
  14. package/assets/pi-extensions/auto-continue.ts +176 -0
  15. package/assets/pi-extensions/goal-mode.ts +313 -0
  16. package/bin/shipgate.mjs +9 -0
  17. package/commands/ai-spec.md +9 -0
  18. package/commands/api-first.md +33 -0
  19. package/commands/code-review.md +7 -0
  20. package/commands/codebase-context.md +19 -0
  21. package/commands/debug-ui.md +147 -0
  22. package/commands/debug.md +101 -0
  23. package/commands/dev-env-scan.md +18 -0
  24. package/commands/dev-host-init.md +28 -0
  25. package/commands/discover-skill-opportunities.md +33 -0
  26. package/commands/fork-sync.md +17 -0
  27. package/commands/gh-actions.md +26 -0
  28. package/commands/goal-driven-development.md +7 -0
  29. package/commands/intent-grill.md +7 -0
  30. package/commands/iteration-manager.md +7 -0
  31. package/commands/loop-engineer.md +21 -0
  32. package/commands/nodejs-npm-auto-release.md +12 -0
  33. package/commands/prd.md +7 -0
  34. package/commands/project-health-audit.md +7 -0
  35. package/commands/ralph-yolo.md +346 -0
  36. package/commands/ralph.md +226 -0
  37. package/commands/security-audit.md +7 -0
  38. package/commands/ux-experience-audit.md +133 -0
  39. package/docs/ARCHITECTURE.md +63 -0
  40. package/docs/GATES.md +106 -0
  41. package/docs/HARNESS.md +257 -0
  42. package/package.json +48 -4
  43. package/references/ADR-FORMAT.md +67 -0
  44. package/references/CONTEXT-FORMAT.md +62 -0
  45. package/references/mcp-config-template.json +54 -0
  46. package/scripts/fix-skill-frontmatter.mjs +66 -0
  47. package/scripts/migrate-skillpack.mjs +257 -0
  48. package/skills/ai-spec/SKILL.md +90 -0
  49. package/skills/api-first-modular/SKILL.md +411 -0
  50. package/skills/code-debugger/SKILL.md +379 -0
  51. package/skills/code-review/SKILL.md +62 -0
  52. package/skills/codebase-context/SKILL.md +139 -0
  53. package/skills/debug-ui/SKILL.md +220 -0
  54. package/skills/dev-env-scan/SKILL.md +147 -0
  55. package/skills/dev-host-init/SKILL.md +198 -0
  56. package/skills/dev-host-init/scripts/fill-placeholders.py +226 -0
  57. package/skills/dev-host-init/scripts/host-scan.ps1 +159 -0
  58. package/skills/dev-host-init/scripts/host-scan.sh +201 -0
  59. package/skills/dev-host-init/scripts/render-now.py +488 -0
  60. package/skills/dev-host-init/scripts/tools-catalog.py +229 -0
  61. package/skills/dev-host-init/templates/graph-first-gate.ts +291 -0
  62. package/skills/dev-host-init/templates/host-injection.template.md +725 -0
  63. package/skills/discover-skill-opportunities/SKILL.md +145 -0
  64. package/skills/discover-skill-opportunities/references/accounting-finance-ops.md +24 -0
  65. package/skills/discover-skill-opportunities/references/business-consulting.md +24 -0
  66. package/skills/discover-skill-opportunities/references/evidence-and-privacy.md +39 -0
  67. package/skills/discover-skill-opportunities/references/finance-investment.md +24 -0
  68. package/skills/discover-skill-opportunities/references/legal-and-compliance.md +24 -0
  69. package/skills/discover-skill-opportunities/references/output-contract.md +75 -0
  70. package/skills/discover-skill-opportunities/references/product-and-operations.md +24 -0
  71. package/skills/discover-skill-opportunities/references/quant-trading.md +24 -0
  72. package/skills/discover-skill-opportunities/references/scientific-research.md +24 -0
  73. package/skills/discover-skill-opportunities/references/scoring-rubric.md +45 -0
  74. package/skills/discover-skill-opportunities/references/session-skill-review.md +78 -0
  75. package/skills/discover-skill-opportunities/references/software-development.md +24 -0
  76. package/skills/fork-sync/SKILL.md +86 -0
  77. package/skills/gh-actions-architect/SKILL.md +395 -0
  78. package/skills/goal-driven-development/SKILL.md +132 -0
  79. package/skills/intent-grill/SKILL.md +46 -0
  80. package/skills/iteration-manager/SKILL.md +53 -0
  81. package/skills/loop-engineer/SKILL.md +108 -0
  82. package/skills/nodejs-npm-auto-release/SKILL.md +141 -0
  83. package/skills/prd/SKILL.md +63 -0
  84. package/skills/project-health-audit/SKILL.md +64 -0
  85. package/skills/ralph/SKILL.md +329 -0
  86. package/skills/ralph-yolo/SKILL.md +623 -0
  87. package/skills/security-audit/SKILL.md +114 -0
  88. package/skills/security-audit/references/audit-checklist.md +135 -0
  89. package/skills/security-audit/references/evidence-conventions.md +54 -0
  90. package/skills/security-audit/references/findings-schema.md +37 -0
  91. package/skills/security-audit/references/stack-signatures.md +66 -0
  92. package/skills/shipgate/SKILL.md +40 -0
  93. package/skills/shipgate-install/SKILL.md +87 -0
  94. package/skills/shipgate-quality/SKILL.md +80 -0
  95. package/skills/shipgate-security/SKILL.md +97 -0
  96. package/skills/shipgate-spec/SKILL.md +67 -0
  97. package/skills/ux-experience-audit/SKILL.md +202 -0
  98. package/src/cli.mjs +118 -0
  99. package/src/commands/ask.mjs +82 -0
  100. package/src/commands/deploy.mjs +587 -0
  101. package/src/commands/gates.mjs +83 -0
  102. package/src/commands/policy.mjs +116 -0
  103. package/src/gates/quality.mjs +123 -0
  104. package/src/gates/security.mjs +92 -0
  105. package/src/gates/ship.mjs +74 -0
  106. package/src/gates/spec.mjs +88 -0
  107. package/src/harness/index.mjs +203 -0
  108. package/src/inject/render.mjs +75 -0
  109. package/src/lib/cfg.mjs +66 -0
  110. package/src/lib/duration.mjs +41 -0
  111. package/src/lib/engines.mjs +182 -0
  112. package/src/lib/exec.mjs +80 -0
  113. package/src/lib/fsx.mjs +119 -0
  114. package/src/lib/gate.mjs +329 -0
  115. package/src/lib/log.mjs +31 -0
  116. package/src/lib/skills.mjs +347 -0
  117. package/src/lib/state.mjs +50 -0
  118. package/src/lib/update.mjs +67 -0
  119. package/src/version.mjs +14 -0
  120. package/templates/agents-snippet.md +82 -0
  121. package/templates/dev-profile.schema.json +119 -0
  122. package/templates/prd.json.example +64 -0
  123. package/templates/rule.json.example +28 -0
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "ai4s-dry-lab",
3
+ "version": 1,
4
+ "description": "计算生物学干实验:scRNA-seq / 空间转录组 / 跨物种比较。域检查守三件事——跑之前有 Worklog、脚本自己留日志、结果目录有说明文件。",
5
+ "reminder": "[AI4S 域已启用 · 干实验]\n本轮额外硬约束:\n① 跑分析脚本前先把本轮计划写进 docs/WORKLOG.md(目标/输入数据/关键参数/预期产出/回退),30 分钟内没更新会被拦。\n② .R/.r/.py 脚本要自己写日志(R: sink / Sys.time;Py: logging / FileHandler),跑完要留下同名 .log。\n③ 本轮动过的 results/ 或 figures/ 子目录,各放一个 README_ 开头的说明(这个目录是什么、用哪个脚本跑的、关键参数)。\n④ 文献引用写 PMID,但本阶段不做硬校验,自己核对真伪。\n⑤ .ipynb / .Rmd 不要求额外 .log:执行后的笔记本与渲染产物本身就是留痕。\n判错域只会少一层规矩,不会阻塞你干活。",
6
+ "fingerprints": [
7
+ ["docs/STATE.md", "docs/WORKLOG.md"],
8
+ ["docs/WORKLOG.md", "docs/CONTEXT.md"],
9
+ [".ai4s/state.json"]
10
+ ],
11
+ "keywords": {
12
+ "min_hits": 2,
13
+ "strong": [
14
+ "单细胞",
15
+ "scrna",
16
+ "scrna-seq",
17
+ "sc-rna",
18
+ "空间转录组",
19
+ "spatial transcriptomics",
20
+ "seurat",
21
+ "cellranger",
22
+ "cell ranger",
23
+ "scanpy",
24
+ "anndata",
25
+ "细胞注释",
26
+ "细胞通讯",
27
+ "cell communication",
28
+ "cellchat",
29
+ "差异表达",
30
+ "deg",
31
+ "gsea",
32
+ "拟时序",
33
+ "轨迹分析",
34
+ "pseudotime",
35
+ "umap",
36
+ "harmony",
37
+ "干实验",
38
+ "dry-lab",
39
+ "ai4s-dry-lab",
40
+ "生信分析",
41
+ "bioinformatics"
42
+ ],
43
+ "weak": [
44
+ "细胞",
45
+ "基因",
46
+ "表达量",
47
+ "测序",
48
+ "聚类",
49
+ "降维",
50
+ "批次效应",
51
+ "marker",
52
+ "富集"
53
+ ]
54
+ },
55
+ "checks": ["ai4s-worklog-before-run", "ai4s-script-log-source"],
56
+ "config": {
57
+ "worklog_path": "docs/WORKLOG.md",
58
+ "worklog_ttl_ms": 1800000,
59
+ "result_dirs": ["results", "figures"],
60
+ "readme_prefix": "README_",
61
+ "script_extensions": [".R", ".Rmd", ".r", ".py", ".ipynb"],
62
+ "log_required_extensions": [".R", ".r", ".py"]
63
+ }
64
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "ai4s-quant",
3
+ "version": 1,
4
+ "description": "量化研究(占位骨架)。本阶段只做识别:能被判成该域、不误伤、不与干实验规则混用;域检查留待下一 CHG(因子 IC / 回测日志 / 数据快照)。",
5
+ "fingerprints": [
6
+ ["docs/STRATEGY.md", "docs/BACKTEST.md"],
7
+ ["docs/STRATEGY.md", "strategies/"]
8
+ ],
9
+ "keywords": {
10
+ "min_hits": 2,
11
+ "strong": [
12
+ "回测",
13
+ "backtest",
14
+ "多因子",
15
+ "因子挖掘",
16
+ "因子库",
17
+ "alpha",
18
+ "ic 分析",
19
+ "ic分析",
20
+ "夏普",
21
+ "sharpe",
22
+ "最大回撤",
23
+ "drawdown",
24
+ "策略池",
25
+ "仓位管理",
26
+ "止损",
27
+ "walk-forward",
28
+ "gridsearch",
29
+ "quant",
30
+ "量化策略"
31
+ ],
32
+ "weak": ["股票", "收益率", "行情", "组合", "净值", "调仓"]
33
+ },
34
+ "checks": [],
35
+ "config": {}
36
+ }
@@ -0,0 +1,176 @@
1
+ /**
2
+ * auto-continue —— pi 长任务续跑扩展(**无轮次上限**)。
3
+ *
4
+ * 背景:pi 每一轮回复结束都会把控制权交回用户 —— 这是对话协议的边界,不是配置项。
5
+ * 但扩展的 `turn_end` 边界可以追加一条输入并请求继续,这是唯一的合法入口。
6
+ *
7
+ * 实现要点(踩过的坑):
8
+ * ❌ 不要在 turn_end 里调 `pi.sendUserMessage()`:此时 agent 仍在处理中,
9
+ * 会抛 "Agent is already processing. Specify streamingBehavior ..."。
10
+ * ✅ 正确做法:返回 `{ continue: true, entries: [{ type: "custom_message", ... }] }`,
11
+ * 由 boundary 机制在本轮结束后把这条输入并入下一轮。
12
+ *
13
+ * 停机条件(只有三个,**没有轮数上限**):
14
+ * 1. `/auto off`;
15
+ * 2. 目标文件出现 `state: DONE`;
16
+ * 3. 助手输出 `<promise>COMPLETE</promise>`。
17
+ *
18
+ * `remaining` 只是可选配额:-1 = 不限额(默认),正数 = 最多再续跑 N 轮,0 = 已停。
19
+ */
20
+
21
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
22
+ import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
23
+ import { join } from "node:path";
24
+
25
+ const STATE_REL = ".pi/auto-continue.json";
26
+ const TASKS_DIR = "tasks";
27
+
28
+ interface AutoState {
29
+ enabled: boolean;
30
+ /** -1 = 无限;正数 = 剩余轮数;0 = 已停 */
31
+ remaining: number;
32
+ prompt: string;
33
+ }
34
+
35
+ const DEFAULT_STATE: AutoState = {
36
+ enabled: false,
37
+ remaining: -1,
38
+ prompt:
39
+ "继续执行当前任务的下一个未完成步骤。" +
40
+ "先查看仓库里的进度记录(如 tasks/、TODO、CHANGELOG 或上一轮的交付说明)确认做到哪一步," +
41
+ "然后直接实现、验证并提交。全部完成时输出 <promise>COMPLETE</promise>。" +
42
+ "不要问我问题,不要停在中途汇报。",
43
+ };
44
+
45
+ function readState(): AutoState {
46
+ const path = join(process.cwd(), STATE_REL);
47
+ if (!existsSync(path)) return { ...DEFAULT_STATE };
48
+ try {
49
+ const raw = JSON.parse(readFileSync(path, "utf8")) as Partial<AutoState>;
50
+ return { ...DEFAULT_STATE, ...raw };
51
+ } catch {
52
+ return { ...DEFAULT_STATE };
53
+ }
54
+ }
55
+
56
+ function writeState(state: AutoState): void {
57
+ writeFileSync(join(process.cwd(), STATE_REL), JSON.stringify(state, null, 2) + "\n", "utf8");
58
+ }
59
+
60
+ function goalDone(): boolean {
61
+ try {
62
+ const dir = join(process.cwd(), TASKS_DIR);
63
+ if (!existsSync(dir)) return false;
64
+ for (const name of readdirSync(dir)) {
65
+ const f = join(dir, name, "goal-state.yaml");
66
+ if (!existsSync(f)) continue;
67
+ if (/^state:\s*DONE\b/m.test(readFileSync(f, "utf8"))) return true;
68
+ }
69
+ } catch {
70
+ /* 读不到就当作未完成 */
71
+ }
72
+ return false;
73
+ }
74
+
75
+ function textOf(message: unknown): string {
76
+ const content = (message as { content?: unknown })?.content;
77
+ if (typeof content === "string") return content;
78
+ if (Array.isArray(content)) {
79
+ return content
80
+ .filter((c): c is { type: "text"; text: string } => (c as { type?: string })?.type === "text")
81
+ .map((c) => c.text)
82
+ .join("\n");
83
+ }
84
+ return "";
85
+ }
86
+
87
+ export default function (pi: ExtensionAPI) {
88
+ pi.on("turn_end", async (event, ctx) => {
89
+ if ((event.message as { role?: string } | undefined)?.role !== "assistant") return;
90
+
91
+ const state = readState();
92
+ if (!state.enabled) return;
93
+
94
+ if (state.remaining === 0) {
95
+ state.enabled = false;
96
+ writeState(state);
97
+ if (ctx.hasUI) ctx.ui.setStatus("auto-continue", "已停(配额用尽)");
98
+ return;
99
+ }
100
+ if (goalDone()) {
101
+ state.enabled = false;
102
+ writeState(state);
103
+ if (ctx.hasUI) ctx.ui.setStatus("auto-continue", "已完成");
104
+ return;
105
+ }
106
+ if (textOf(event.message).includes("<promise>COMPLETE</promise>")) {
107
+ state.enabled = false;
108
+ writeState(state);
109
+ if (ctx.hasUI) ctx.ui.setStatus("auto-continue", "已完成");
110
+ return;
111
+ }
112
+
113
+ if (state.remaining > 0) {
114
+ state.remaining -= 1;
115
+ writeState(state);
116
+ }
117
+ if (ctx.hasUI) {
118
+ const left = state.remaining < 0 ? "∞" : String(state.remaining);
119
+ ctx.ui.setStatus("auto-continue", `续跑中 · 剩 ${left}`);
120
+ }
121
+
122
+ return {
123
+ continue: true,
124
+ entries: [
125
+ {
126
+ type: "custom_message" as const,
127
+ customType: "auto-continue",
128
+ content: state.prompt,
129
+ display: false,
130
+ },
131
+ ],
132
+ };
133
+ });
134
+
135
+ pi.registerCommand("auto", {
136
+ description: "自动续跑:/auto on [轮数|-1] | /auto off | /auto status",
137
+ handler: async (args, ctx) => {
138
+ const state = readState();
139
+ const [sub, n] = (args ?? "").trim().split(/\s+/);
140
+ if (sub === "off") {
141
+ state.enabled = false;
142
+ state.remaining = 0;
143
+ writeState(state);
144
+ ctx.ui.notify("auto-continue 已关闭", "info");
145
+ return;
146
+ }
147
+ if (sub === "on") {
148
+ const turns = n === undefined ? -1 : Number(n);
149
+ state.enabled = true;
150
+ state.remaining = Number.isFinite(turns) ? turns : -1;
151
+ writeState(state);
152
+ ctx.ui.notify(
153
+ state.remaining < 0
154
+ ? "auto-continue 已开启(不限轮数)"
155
+ : `auto-continue 已开启,剩 ${state.remaining} 轮`,
156
+ "info",
157
+ );
158
+ return;
159
+ }
160
+ if (sub === "set") {
161
+ const turns = Number(n);
162
+ state.remaining = Number.isFinite(turns) ? turns : -1;
163
+ state.enabled = state.remaining !== 0;
164
+ writeState(state);
165
+ ctx.ui.notify(`auto-continue remaining=${state.remaining}`, "info");
166
+ return;
167
+ }
168
+ ctx.ui.notify(
169
+ `auto-continue: ${state.enabled ? "on" : "off"} · remaining=${
170
+ state.remaining < 0 ? "∞" : state.remaining
171
+ }`,
172
+ "info",
173
+ );
174
+ },
175
+ });
176
+ }
@@ -0,0 +1,313 @@
1
+ /**
2
+ * goal-mode —— pi 长任务「目标驱动」扩展(带预算与空转保护)。
3
+ *
4
+ * 与同目录 `auto-continue.ts` 的关系:
5
+ * - auto-continue:`turn_end` 边界,**无轮数上限**,靠 `state: DONE` 或
6
+ * `<promise>COMPLETE</promise>` 停机。适合你已经把目标写进 tasks/ 的里程碑流程。
7
+ * - goal-mode:`agent_before_settle` 边界,**带预算**(默认 400 轮 / 12 小时)
8
+ * 和**空转检测**(连续 3 轮没有任何工具调用就停),并由模型显式调用
9
+ * `goal_complete` 工具宣告完成。适合"给一句话目标,让它自己跑到完"。
10
+ *
11
+ * **二选一,不要同时开启。** 两个扩展默认都是关闭状态;同时 `/auto on` 和
12
+ * `/goal ...` 会让两条续跑逻辑叠加,行为不可预测。
13
+ *
14
+ * 状态文件:`<项目>/.pi/goal-state.json`(运行时产物,建议 gitignore)。
15
+ *
16
+ * 依赖说明:`typebox` 由 pi 运行时提供(pi 自身依赖),本仓库不新增依赖;
17
+ * 与 `auto-continue.ts` 只 import `@earendil-works/pi-coding-agent` 同理。
18
+ */
19
+
20
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
21
+ import { Type } from "typebox";
22
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
23
+ import { dirname, join } from "node:path";
24
+
25
+ const STATE_REL = ".pi/goal-state.json";
26
+ /** 连续多少轮「零工具调用」判定为空转 */
27
+ const MAX_IDLE_STREAK = 3;
28
+ /** 两次 settle 间隔小于此值视为同一次收工的重复触发 */
29
+ const SETTLE_DEBOUNCE_MS = 800;
30
+
31
+ type GoalStatus = "idle" | "running" | "done" | "stopped";
32
+
33
+ interface GoalState {
34
+ active: boolean;
35
+ status: GoalStatus;
36
+ prompt: string;
37
+ iteration: number;
38
+ maxIterations: number;
39
+ startedAt: number;
40
+ maxHours: number;
41
+ idleStreak: number;
42
+ toolsThisRound: number;
43
+ lastSettleAt: number;
44
+ stopReason?: string;
45
+ }
46
+
47
+ function freshState(): GoalState {
48
+ return {
49
+ active: false,
50
+ status: "idle",
51
+ prompt: "",
52
+ iteration: 0,
53
+ maxIterations: 400,
54
+ startedAt: 0,
55
+ maxHours: 12,
56
+ idleStreak: 0,
57
+ toolsThisRound: 0,
58
+ lastSettleAt: 0,
59
+ };
60
+ }
61
+
62
+ function statePath(): string {
63
+ return join(process.cwd(), STATE_REL);
64
+ }
65
+
66
+ function loadState(): GoalState {
67
+ try {
68
+ const raw = readFileSync(statePath(), "utf8");
69
+ return { ...freshState(), ...(JSON.parse(raw) as Partial<GoalState>) };
70
+ } catch {
71
+ return freshState();
72
+ }
73
+ }
74
+
75
+ function saveState(state: GoalState): void {
76
+ try {
77
+ const file = statePath();
78
+ mkdirSync(dirname(file), { recursive: true });
79
+ writeFileSync(file, JSON.stringify(state, null, 2) + "\n", "utf8");
80
+ } catch {
81
+ /* 只读目录等场景下降级为内存态,不影响本轮续跑 */
82
+ }
83
+ }
84
+
85
+ function fmtDuration(ms: number): string {
86
+ const totalMin = Math.max(0, Math.floor(ms / 60_000));
87
+ const h = Math.floor(totalMin / 60);
88
+ const m = totalMin % 60;
89
+ return h > 0 ? `${h}h${m}m` : `${m}m`;
90
+ }
91
+
92
+ export default function goalModeExtension(pi: ExtensionAPI) {
93
+ let state = loadState();
94
+ // 上一次进程留下的 active 状态不自动接管,避免意外续跑;等用户 /goal 再决定
95
+ if (state.active) {
96
+ state = {
97
+ ...state,
98
+ active: false,
99
+ status: "stopped",
100
+ stopReason: "进程重启,状态已暂停(用 /goal 查看)",
101
+ };
102
+ saveState(state);
103
+ }
104
+
105
+ const remainingIterations = () => state.maxIterations - state.iteration;
106
+ const deadline = () => state.startedAt + state.maxHours * 3_600_000;
107
+
108
+ const stop = (reason: string) => {
109
+ state.active = false;
110
+ state.status = "stopped";
111
+ state.stopReason = reason;
112
+ saveState(state);
113
+ };
114
+
115
+ const complete = (reason: string) => {
116
+ state.active = false;
117
+ state.status = "done";
118
+ state.stopReason = reason;
119
+ saveState(state);
120
+ };
121
+
122
+ // 让模型能显式宣告「真的做完了」,比文本标记可靠
123
+ pi.registerTool({
124
+ name: "goal_complete",
125
+ label: "Goal Complete",
126
+ description:
127
+ "Call this ONLY when the entire active goal is finished AND verified. Do not call it to report partial progress, a plan, or a blocker.",
128
+ promptSnippet: "Mark the active goal loop as fully complete (goal mode only).",
129
+ parameters: Type.Object({
130
+ summary: Type.String({
131
+ description: "Final summary: what was delivered, what was verified, and any residual risk.",
132
+ }),
133
+ }),
134
+ async execute(_toolCallId, params) {
135
+ complete(params.summary);
136
+ return {
137
+ content: [
138
+ {
139
+ type: "text" as const,
140
+ text: `Goal loop marked complete. Relay the final report to the user now. Summary recorded: ${params.summary}`,
141
+ },
142
+ ],
143
+ details: { goalStatus: "done" },
144
+ };
145
+ },
146
+ });
147
+
148
+ // 统计本轮工具调用,用于空转检测
149
+ pi.on("tool_execution_end", () => {
150
+ state.toolsThisRound += 1;
151
+ });
152
+
153
+ // 核心:收工前拦一道,没完成就继续
154
+ pi.on("agent_before_settle", async (event) => {
155
+ if (!state.active) return;
156
+
157
+ // 用户按 Esc / Ctrl-C 中止:尊重用户,绝不自动续跑
158
+ if (event.outcome === "aborted") {
159
+ stop("用户手动中止");
160
+ return;
161
+ }
162
+
163
+ const now = Date.now();
164
+ if (now - state.lastSettleAt < SETTLE_DEBOUNCE_MS) return;
165
+ state.lastSettleAt = now;
166
+
167
+ if (state.iteration >= state.maxIterations) {
168
+ stop(`达到最大续跑轮数 ${state.maxIterations}`);
169
+ return;
170
+ }
171
+ if (now >= deadline()) {
172
+ stop(`达到最长运行时长 ${state.maxHours} 小时`);
173
+ return;
174
+ }
175
+
176
+ // 空转检测:连续多轮一个工具都没调,说明模型在空谈或卡死
177
+ if (state.toolsThisRound === 0) state.idleStreak += 1;
178
+ else state.idleStreak = 0;
179
+ if (state.idleStreak >= MAX_IDLE_STREAK) {
180
+ stop(`连续 ${MAX_IDLE_STREAK} 轮没有执行任何工具,判定为空转`);
181
+ return;
182
+ }
183
+
184
+ state.iteration += 1;
185
+ state.toolsThisRound = 0;
186
+ saveState(state);
187
+
188
+ const elapsed = fmtDuration(now - state.startedAt);
189
+ const content = [
190
+ `[GOAL MODE · 第 ${state.iteration}/${state.maxIterations} 轮 · 已跑 ${elapsed}]`,
191
+ ``,
192
+ `目标:${state.prompt}`,
193
+ ``,
194
+ `继续执行,不要停。硬性要求:`,
195
+ `1. 不要复述计划、不要询问确认、不要输出「我将要 / 接下来准备 / 是否需要我」。`,
196
+ `2. 这一轮必须至少调用一次工具,实际推进任务。`,
197
+ `3. 一部分做完就接着做下一部分,直到目标全部达成且自检通过。`,
198
+ `4. 只有全部完成时才调用 goal_complete 工具,然后给出最终报告。`,
199
+ `5. 如果遇到真实阻塞(缺凭据、外部服务故障),把阻塞点写清楚并在报告里说明,不要假装完成。`,
200
+ ``,
201
+ `剩余预算:${remainingIterations()} 轮 / 约 ${fmtDuration(Math.max(0, deadline() - now))}。`,
202
+ ].join("\n");
203
+
204
+ return {
205
+ entries: [
206
+ ...event.entries,
207
+ {
208
+ type: "custom_message" as const,
209
+ customType: "goal-mode-continue",
210
+ content,
211
+ display: false,
212
+ },
213
+ ],
214
+ continue: true,
215
+ };
216
+ });
217
+
218
+ // 全部收工后再通知,避免中止/重试时误报
219
+ pi.on("agent_settled", async (_event, ctx) => {
220
+ if (state.status === "done") {
221
+ ctx.ui.notify(`目标已完成:${state.stopReason ?? "无摘要"}`, "info");
222
+ } else if (state.status === "stopped") {
223
+ ctx.ui.notify(`目标循环已停止:${state.stopReason ?? "未知原因"}`, "warning");
224
+ }
225
+ });
226
+
227
+ pi.registerCommand("goal", {
228
+ description:
229
+ "目标模式:持续驱动任务直到完成。用法 /goal <任务> | /goal | /goal done | /goal stop | /goal max <n> | /goal hours <n>",
230
+ getArgumentCompletions: (prefix) => {
231
+ const subs = ["done", "stop", "max", "hours", "status"];
232
+ const hits = subs.filter((s) => s.startsWith(prefix.trim()));
233
+ return hits.length > 0 ? hits.map((s) => ({ value: s, label: s })) : null;
234
+ },
235
+ handler: async (args, ctx) => {
236
+ const input = (args ?? "").trim();
237
+ const [head, ...rest] = input.split(/\s+/);
238
+ const tail = rest.join(" ").trim();
239
+
240
+ if (!input || head === "status") {
241
+ if (!state.active && state.status === "idle") {
242
+ ctx.ui.notify("目标模式未启动。用 /goal <任务描述> 开始。", "info");
243
+ return;
244
+ }
245
+ const lines = [
246
+ `状态:${state.status}${state.active ? "(运行中)" : ""}`,
247
+ state.prompt ? `目标:${state.prompt}` : "",
248
+ `轮次:${state.iteration}/${state.maxIterations}`,
249
+ state.startedAt
250
+ ? `已运行:${fmtDuration(Date.now() - state.startedAt)} / 上限 ${state.maxHours}h`
251
+ : "",
252
+ state.stopReason ? `最近原因:${state.stopReason}` : "",
253
+ ].filter(Boolean);
254
+ ctx.ui.notify(lines.join("\n"), "info");
255
+ return;
256
+ }
257
+
258
+ if (head === "done") {
259
+ complete(tail || "用户手动标记完成");
260
+ ctx.ui.notify("已标记目标完成,停止续跑。", "info");
261
+ return;
262
+ }
263
+
264
+ if (head === "stop" || head === "pause") {
265
+ stop(tail || "用户手动停止");
266
+ ctx.ui.notify("已停止目标循环(任务可稍后用 /goal 重新启动)。", "warning");
267
+ return;
268
+ }
269
+
270
+ if (head === "max") {
271
+ const n = Number.parseInt(tail, 10);
272
+ if (!Number.isFinite(n) || n < 1) {
273
+ ctx.ui.notify("用法:/goal max <正整数>", "warning");
274
+ return;
275
+ }
276
+ state.maxIterations = n;
277
+ saveState(state);
278
+ ctx.ui.notify(`最大续跑轮数已设为 ${n}`, "info");
279
+ return;
280
+ }
281
+
282
+ if (head === "hours") {
283
+ const n = Number.parseFloat(tail);
284
+ if (!Number.isFinite(n) || n <= 0) {
285
+ ctx.ui.notify("用法:/goal hours <小时数>", "warning");
286
+ return;
287
+ }
288
+ state.maxHours = n;
289
+ saveState(state);
290
+ ctx.ui.notify(`最长运行时长已设为 ${n} 小时`, "info");
291
+ return;
292
+ }
293
+
294
+ // 其余一律当作任务描述,启动目标模式
295
+ const prompt = input;
296
+ state = { ...freshState(), active: true, status: "running", prompt, startedAt: Date.now() };
297
+ saveState(state);
298
+
299
+ ctx.ui.notify(`目标模式启动:${prompt}`, "info");
300
+ await pi.sendUserMessage(
301
+ [
302
+ `[GOAL MODE 启动] 目标:${prompt}`,
303
+ ``,
304
+ `从现在开始持续执行,直到目标完成。规则:`,
305
+ `- 不要输出计划后就停下,也不要询问确认;每一步直接调用工具去做。`,
306
+ `- 每轮结束前检查:目标是否真的全部达成?没达成就继续下一项。`,
307
+ `- 全部达成并验证后,调用 goal_complete 工具,然后给出最终报告。`,
308
+ ].join("\n"),
309
+ { deliverAs: "followUp" },
310
+ );
311
+ },
312
+ });
313
+ }
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { main } from '../src/cli.mjs';
3
+
4
+ main(process.argv.slice(2)).then((code) => {
5
+ process.exitCode = code ?? 0;
6
+ }).catch((error) => {
7
+ console.error(`shipgate: ${error.message}`);
8
+ process.exitCode = 2;
9
+ });
@@ -0,0 +1,9 @@
1
+ ---
2
+ description: 主调度并生成版本化工程 SPEC、追踪矩阵和 goal 执行合同
3
+ ---
4
+
5
+ # /ai-spec
6
+
7
+ 读取 skill `ai-spec` 并处理 `$ARGUMENTS`。
8
+
9
+ 需求不完整时路由到 intent/health/PRD;仅在 PRD 已批准后生成 SPEC。SPEC 获得明确批准后,默认交给 `goal-driven-development`,不要直接进入 Ralph。不得自动批准 SPEC、commit 或 push。
@@ -0,0 +1,33 @@
1
+ ---
2
+ description: 激活 API-First 模块化开发框架 — 后端封装为独立API包,前端只调API,跨层任务自动分解
3
+ ---
4
+
5
+ 你现在激活了 **API-First 模块化开发框架**。
6
+
7
+ 请先阅读 skill `api-first-modular` 获取完整的方法论和工作流程。
8
+
9
+ ## 快速指引
10
+
11
+ 根据用户的需求类型,按以下方式工作:
12
+
13
+ ### 1. 纯后端开发
14
+ 走后端 API 包 5 步闭环:**开发 → Checkfix → 封装 → API端点 → API文档**
15
+
16
+ ### 2. 纯前端开发
17
+ 确认 API 文档已就绪,然后依据文档实现页面和 API 调用。如果 API 文档缺失,先要求补全。
18
+
19
+ ### 3. 跨层开发/调试(最常见)
20
+ 执行「跨层任务自动分解协议」:
21
+ 1. **层级识别** — 判断涉及哪些层(后端/前端/中间层)
22
+ 2. **API边界拆分** — 按 API 包粒度拆为有序子任务
23
+ 3. **严格按序执行** — 后端先行 → API文档 → 前端消费 → 集成验证
24
+
25
+ ### 4. Debug 任务
26
+ 执行「Debug 边界规则」:
27
+ 1. **先判断问题归属层** — 后端API包内部?前端?中间层?契约不一致?
28
+ 2. **只在对应层内定位和修复**
29
+ 3. **禁止跨层"绕过"修复**
30
+
31
+ ## 用户需求
32
+
33
+ $ARGUMENTS
@@ -0,0 +1,7 @@
1
+ ---
2
+ description: 对照批准 SPEC、验收条件与工程质量门执行证据化代码审查
3
+ ---
4
+
5
+ # /code-review
6
+
7
+ 读取 skill `code-review` 并审查 `$ARGUMENTS` 指定的 workspace、commit 或 PR。保留所有 finding;Critical/High 阻断,输出 `PASS`、`PASS_WITH_DEBT` 或 `FAIL`。
@@ -0,0 +1,19 @@
1
+ ---
2
+ description: 代码库知识图谱查询 — 推荐 GitNexus MCP,支持影响分析/调用链/依赖图/重命名安全检查
3
+ ---
4
+
5
+ 查询代码库的架构信息:影响分析、调用链追踪、依赖关系、重命名安全性。优先使用 GitNexus MCP/CLI(如已配置),否则降级为内建静态分析。首次调用时若无 GitNexus 会主动推荐配置。
6
+
7
+ $ARGUMENTS
8
+
9
+ ## 关联 Skill(网络调度协议)
10
+
11
+ | 用户意图关键词 | 路由目标 | 说明 |
12
+ |---------------|---------|------|
13
+ | 代码图谱 / impact / 依赖分析 / call chain / 架构理解 / 重构影响 | → 本命令 | 知识图谱查询 |
14
+
15
+ | 关系 | Skill | 场景 |
16
+ |------|-------|------|
17
+ | 被调用 | ai-spec | 架构理解辅助决策 |
18
+ | 被调用 | code-debugger | 调试前建立上下文 |
19
+ | 被调用 | code-review | 审查影响范围 |