@taptap/cli 2026.8.27
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/.claude-plugin/marketplace.json +20 -0
- package/.claude-plugin/plugin.json +16 -0
- package/CHANGELOG.md +308 -0
- package/LICENSE +21 -0
- package/README.md +301 -0
- package/README.zh.md +295 -0
- package/affordance/README.md +32 -0
- package/affordance/app.md +140 -0
- package/bin/taptap-cli-darwin-amd64 +0 -0
- package/bin/taptap-cli-darwin-arm64 +0 -0
- package/bin/taptap-cli-linux-amd64 +0 -0
- package/bin/taptap-cli-linux-arm64 +0 -0
- package/bin/taptap-cli-linux-riscv64 +0 -0
- package/bin/taptap-cli-windows-amd64.exe +0 -0
- package/bin/taptap-cli-windows-arm64.exe +0 -0
- package/checksums.txt +7 -0
- package/hooks/hooks.json +53 -0
- package/package.json +50 -0
- package/scripts/claude-hooks/dispatch.mjs +563 -0
- package/scripts/claude-hooks/dispatch.test.mjs +362 -0
- package/scripts/install-wizard.js +338 -0
- package/scripts/run.js +121 -0
- package/scripts/skills-source.js +17 -0
- package/skills/index.json +14 -0
- package/skills/taptap-app-edit/SKILL.md +125 -0
- package/skills/taptap-app-edit/references/app-edit-analysis.md +80 -0
- package/skills/taptap-app-edit/references/app-edit-audit-and-history.md +274 -0
- package/skills/taptap-app-edit/references/app-edit-field-map.md +131 -0
- package/skills/taptap-app-edit/references/app-edit-fields-and-packages.md +109 -0
- package/skills/taptap-app-edit/references/app-edit-version-lifecycle.md +72 -0
- package/skills/taptap-app-edit/references/review-risk-checklist.md +128 -0
- package/skills/taptap-asset-library/SKILL.md +117 -0
- package/skills/taptap-asset-library/references/asset-library-ingest.md +99 -0
- package/skills/taptap-asset-library/references/asset-library-search.md +72 -0
- package/skills/taptap-cli/SKILL.md +82 -0
- package/skills/taptap-cli/references/business-routing.md +55 -0
- package/skills/taptap-cli/references/cli-command-patterns.md +166 -0
- package/skills/taptap-cli/references/material-requirements.md +107 -0
- package/skills/taptap-cli/references/official-review-rules-v4.md +287 -0
- package/skills/taptap-cli/references/operation-handbooks.md +35 -0
- package/skills/taptap-cli/references/shared-execution.md +126 -0
- package/skills/taptap-cli/references/sources/operation-handbooks/manifest.json +57 -0
- package/skills/taptap-cli/references/sources/v4/agree.md +408 -0
- package/skills/taptap-cli/references/sources/v4/manifest.json +25 -0
- package/skills/taptap-cli/references/sources/v4/material.md +217 -0
- package/skills/taptap-dashboard-stats/SKILL.md +71 -0
- package/skills/taptap-dashboard-stats/references/dashboard-metrics-cheatsheet.md +79 -0
- package/skills/taptap-identity/SKILL.md +98 -0
- package/skills/taptap-identity/references/identity-behavior-rules.md +115 -0
- package/skills/taptap-materials/SKILL.md +102 -0
- package/skills/taptap-package-management/SKILL.md +120 -0
- package/skills/taptap-package-management/references/package-management-diagnostics.md +65 -0
- package/skills/taptap-package-management/references/package-management-page-paths.md +11 -0
- package/skills/taptap-publish-game/SKILL.md +77 -0
- package/skills/taptap-publish-game/references/publish-game-creation.md +308 -0
- package/skills/taptap-qualification/SKILL.md +85 -0
- package/skills/taptap-qualification/references/qualification-analysis.md +96 -0
- package/skills/taptap-qualification/references/qualification-draft.md +70 -0
- package/skills/taptap-qualification/references/qualification-lifecycle.md +55 -0
- package/skills/taptap-qualification/references/qualification-materials.md +143 -0
- package/skills/taptap-test-plan/SKILL.md +125 -0
- package/skills/taptap-test-plan/references/test-plan-creation.md +103 -0
- package/skills/taptap-test-plan/references/test-plan-faq.md +71 -0
- package/skills/taptap-test-plan/references/test-plan-operations.md +57 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
classifyShellCommand,
|
|
10
|
+
dispatchHook,
|
|
11
|
+
probeSession,
|
|
12
|
+
redactText,
|
|
13
|
+
} from "./dispatch.mjs";
|
|
14
|
+
|
|
15
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const root = resolve(here, "../..");
|
|
17
|
+
const dispatcher = resolve(here, "dispatch.mjs");
|
|
18
|
+
|
|
19
|
+
function preInput(command, toolName = "Bash") {
|
|
20
|
+
return {
|
|
21
|
+
hook_event_name: "PreToolUse",
|
|
22
|
+
tool_name: toolName,
|
|
23
|
+
tool_input: { command },
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
test("hooks config declares the four official events and bounded timeouts", () => {
|
|
28
|
+
const config = JSON.parse(readFileSync(resolve(root, "hooks/hooks.json"), "utf8"));
|
|
29
|
+
assert.deepEqual(Object.keys(config.hooks).sort(), [
|
|
30
|
+
"PostToolUse",
|
|
31
|
+
"PostToolUseFailure",
|
|
32
|
+
"PreToolUse",
|
|
33
|
+
"SessionStart",
|
|
34
|
+
]);
|
|
35
|
+
assert.equal(config.hooks.SessionStart[0].matcher, "startup|resume|clear|compact|fork");
|
|
36
|
+
assert.equal(config.hooks.SessionStart[0].hooks[0].timeout, 5);
|
|
37
|
+
for (const event of ["PreToolUse", "PostToolUse", "PostToolUseFailure"]) {
|
|
38
|
+
assert.equal(config.hooks[event][0].matcher, "Bash|PowerShell");
|
|
39
|
+
assert.equal(config.hooks[event][0].hooks[0].timeout, 2);
|
|
40
|
+
assert.match(config.hooks[event][0].hooks[0].command, /CLAUDE_PLUGIN_ROOT/);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("plugin and npm manifests expose hooks without the invalid cli field", () => {
|
|
45
|
+
const plugin = JSON.parse(readFileSync(resolve(root, ".claude-plugin/plugin.json"), "utf8"));
|
|
46
|
+
const packageJSON = JSON.parse(readFileSync(resolve(root, "package.json"), "utf8"));
|
|
47
|
+
assert.equal(plugin.cli, undefined);
|
|
48
|
+
assert.equal(plugin.hooks, "./hooks/hooks.json");
|
|
49
|
+
assert(packageJSON.files.includes("hooks"));
|
|
50
|
+
assert(packageJSON.files.includes("scripts/claude-hooks"));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("direct-call classifier accepts only a simple bare executable", () => {
|
|
54
|
+
assert.deepEqual(classifyShellCommand("taptap-cli version", "Bash"), {
|
|
55
|
+
kind: "direct",
|
|
56
|
+
executable: "taptap-cli",
|
|
57
|
+
argv: ["version"],
|
|
58
|
+
});
|
|
59
|
+
assert.equal(classifyShellCommand("taptap-cli.exe auth status", "PowerShell").kind, "direct");
|
|
60
|
+
for (const command of [
|
|
61
|
+
"sudo taptap-cli version",
|
|
62
|
+
"/usr/local/bin/taptap-cli version",
|
|
63
|
+
"taptap-cli status | jq .",
|
|
64
|
+
"taptap-cli $(printf status)",
|
|
65
|
+
"taptap-cli status > result.json",
|
|
66
|
+
"bash -c 'taptap-cli status'",
|
|
67
|
+
"& taptap-cli status",
|
|
68
|
+
"taptap-cli {status,version}",
|
|
69
|
+
"taptap-cli status @(Get-Item .)",
|
|
70
|
+
"taptap-cli status @args",
|
|
71
|
+
]) {
|
|
72
|
+
assert.equal(classifyShellCommand(command, "PowerShell").kind, "unknown", command);
|
|
73
|
+
}
|
|
74
|
+
assert.equal(classifyShellCommand("$cli status", "PowerShell").kind, "none");
|
|
75
|
+
assert.equal(classifyShellCommand("git status", "Bash").kind, "none");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("PreToolUse emits no decision for non-TapTap commands", () => {
|
|
79
|
+
assert.deepEqual(dispatchHook(preInput("git status")), {});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("PreToolUse asks for unsupported shell composition", () => {
|
|
83
|
+
const output = dispatchHook(preInput("taptap-cli status | jq ."));
|
|
84
|
+
assert.equal(output.hookSpecificOutput.hookEventName, "PreToolUse");
|
|
85
|
+
assert.equal(output.hookSpecificOutput.permissionDecision, "ask");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("PreToolUse asks when the CLI recognizes a command but rejects its argv", () => {
|
|
89
|
+
const output = dispatchHook(preInput("taptap-cli status --definitely-unknown"), {
|
|
90
|
+
inspectCommand: () => ({
|
|
91
|
+
recognized: true,
|
|
92
|
+
invocation_valid: false,
|
|
93
|
+
canonical_path: "status",
|
|
94
|
+
risk: "read",
|
|
95
|
+
policy_decision: "allow",
|
|
96
|
+
reason_code: "invalid_arguments",
|
|
97
|
+
}),
|
|
98
|
+
log: () => {},
|
|
99
|
+
});
|
|
100
|
+
assert.equal(output.hookSpecificOutput.permissionDecision, "ask");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("PreToolUse allows only inspected read calls allowed by policy", () => {
|
|
104
|
+
const output = dispatchHook(preInput("taptap-cli status"), {
|
|
105
|
+
inspectCommand: () => ({
|
|
106
|
+
recognized: true,
|
|
107
|
+
invocation_valid: true,
|
|
108
|
+
canonical_path: "status",
|
|
109
|
+
risk: "read",
|
|
110
|
+
policy_decision: "allow",
|
|
111
|
+
}),
|
|
112
|
+
log: () => {},
|
|
113
|
+
});
|
|
114
|
+
assert.equal(output.hookSpecificOutput.permissionDecision, "allow");
|
|
115
|
+
assert.match(output.hookSpecificOutput.permissionDecisionReason, /status/);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("PreToolUse asks for writes, local data, and unavailable inspection", () => {
|
|
119
|
+
const write = dispatchHook(preInput("taptap-cli app save-changes --yes"), {
|
|
120
|
+
inspectCommand: () => ({
|
|
121
|
+
recognized: true,
|
|
122
|
+
invocation_valid: true,
|
|
123
|
+
canonical_path: "app/save-changes",
|
|
124
|
+
risk: "write",
|
|
125
|
+
policy_decision: "allow",
|
|
126
|
+
}),
|
|
127
|
+
log: () => {},
|
|
128
|
+
});
|
|
129
|
+
assert.equal(write.hookSpecificOutput.permissionDecision, "ask");
|
|
130
|
+
|
|
131
|
+
const localData = dispatchHook(preInput("taptap-cli status --data @query.json"), {
|
|
132
|
+
inspectCommand: () => ({
|
|
133
|
+
recognized: true,
|
|
134
|
+
invocation_valid: true,
|
|
135
|
+
canonical_path: "status",
|
|
136
|
+
risk: "read",
|
|
137
|
+
policy_decision: "allow",
|
|
138
|
+
}),
|
|
139
|
+
log: () => {},
|
|
140
|
+
});
|
|
141
|
+
assert.equal(localData.hookSpecificOutput.permissionDecision, "ask");
|
|
142
|
+
|
|
143
|
+
for (const command of [
|
|
144
|
+
"taptap-cli status --input ./query.json",
|
|
145
|
+
"taptap-cli status --output=result.json",
|
|
146
|
+
"taptap-cli event consume test.event --app-id 1 --output-dir events",
|
|
147
|
+
"taptap-cli status C:\\temp\\query.json",
|
|
148
|
+
]) {
|
|
149
|
+
const shellTool = command.includes("C:\\") ? "PowerShell" : "Bash";
|
|
150
|
+
const localPath = dispatchHook(preInput(command, shellTool), {
|
|
151
|
+
inspectCommand: () => ({
|
|
152
|
+
recognized: true,
|
|
153
|
+
invocation_valid: true,
|
|
154
|
+
canonical_path: "status",
|
|
155
|
+
risk: "read",
|
|
156
|
+
policy_decision: "allow",
|
|
157
|
+
}),
|
|
158
|
+
log: () => {},
|
|
159
|
+
});
|
|
160
|
+
assert.equal(localPath.hookSpecificOutput.permissionDecision, "ask", command);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const unavailable = dispatchHook(preInput("taptap-cli status"), {
|
|
164
|
+
inspectCommand: () => {
|
|
165
|
+
throw new Error("not installed");
|
|
166
|
+
},
|
|
167
|
+
log: () => {},
|
|
168
|
+
});
|
|
169
|
+
assert.equal(unavailable.hookSpecificOutput.permissionDecision, "ask");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("PreToolUse denies only an explicit CLI policy denial", () => {
|
|
173
|
+
const output = dispatchHook(preInput("taptap-cli app save-changes"), {
|
|
174
|
+
inspectCommand: () => ({
|
|
175
|
+
recognized: true,
|
|
176
|
+
invocation_valid: true,
|
|
177
|
+
canonical_path: "app/save-changes",
|
|
178
|
+
risk: "write",
|
|
179
|
+
policy_decision: "deny",
|
|
180
|
+
reason_code: "write_not_allowed",
|
|
181
|
+
}),
|
|
182
|
+
log: () => {},
|
|
183
|
+
});
|
|
184
|
+
assert.equal(output.hookSpecificOutput.permissionDecision, "deny");
|
|
185
|
+
assert.match(output.hookSpecificOutput.permissionDecisionReason, /write_not_allowed/);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("SessionStart is local, bounded by its caller, and performs no mutation", () => {
|
|
189
|
+
let probes = 0;
|
|
190
|
+
const startup = dispatchHook(
|
|
191
|
+
{ hook_event_name: "SessionStart", source: "startup" },
|
|
192
|
+
{
|
|
193
|
+
probeSession: () => {
|
|
194
|
+
probes += 1;
|
|
195
|
+
return {
|
|
196
|
+
available: true,
|
|
197
|
+
version: "2026.7.22",
|
|
198
|
+
auth: {
|
|
199
|
+
profile: "default",
|
|
200
|
+
credentialSource: "keychain",
|
|
201
|
+
hasAccessToken: true,
|
|
202
|
+
accessTokenExpired: false,
|
|
203
|
+
},
|
|
204
|
+
skills: {
|
|
205
|
+
embedded: { count: 9, content_hash: "sha256:test" },
|
|
206
|
+
global_agent_skills: { status: "sync_recorded", verified: false },
|
|
207
|
+
project_agent_skills: { status: "not_managed" },
|
|
208
|
+
project_plugin: { status: "not_implemented" },
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
);
|
|
214
|
+
assert.equal(probes, 1);
|
|
215
|
+
assert.equal(startup.hookSpecificOutput.hookEventName, "SessionStart");
|
|
216
|
+
assert.match(startup.hookSpecificOutput.additionalContext, /Offline auth/);
|
|
217
|
+
assert.match(startup.hookSpecificOutput.additionalContext, /embedded 9/);
|
|
218
|
+
assert.match(startup.hookSpecificOutput.additionalContext, /No login, update, Skill installation/);
|
|
219
|
+
|
|
220
|
+
const compact = dispatchHook(
|
|
221
|
+
{ hook_event_name: "SessionStart", source: "compact" },
|
|
222
|
+
{
|
|
223
|
+
probeSession: () => {
|
|
224
|
+
throw new Error("compact must not probe");
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
);
|
|
228
|
+
assert.match(compact.hookSpecificOutput.additionalContext, /hooks remain active/);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test("SessionStart probe uses only version and local offline status APIs", () => {
|
|
232
|
+
const calls = [];
|
|
233
|
+
const result = probeSession((args, timeout) => {
|
|
234
|
+
calls.push({ args, timeout });
|
|
235
|
+
if (args[0] === "version") {
|
|
236
|
+
return { version: "2026.7.22" };
|
|
237
|
+
}
|
|
238
|
+
if (args[0] === "auth") {
|
|
239
|
+
return { offline: true, serverChecked: false };
|
|
240
|
+
}
|
|
241
|
+
return { embedded: { count: 1 } };
|
|
242
|
+
});
|
|
243
|
+
assert.equal(result.available, true);
|
|
244
|
+
assert.deepEqual(calls.map(({ args }) => args), [
|
|
245
|
+
["version", "--format", "json"],
|
|
246
|
+
["auth", "status", "--offline", "--json"],
|
|
247
|
+
["skills", "status", "--json"],
|
|
248
|
+
]);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("PostToolUse reports only a complete success envelope", () => {
|
|
252
|
+
const output = dispatchHook(
|
|
253
|
+
{
|
|
254
|
+
hook_event_name: "PostToolUse",
|
|
255
|
+
tool_name: "Bash",
|
|
256
|
+
tool_input: { command: "taptap-cli status" },
|
|
257
|
+
tool_response: { stdout: "{\"ok\":true,\"data\":{\"access_token\":\"secret\"}}" },
|
|
258
|
+
duration_ms: 42,
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
inspectCommand: () => ({ canonical_path: "status" }),
|
|
262
|
+
log: () => {},
|
|
263
|
+
},
|
|
264
|
+
);
|
|
265
|
+
assert.equal(output.hookSpecificOutput.hookEventName, "PostToolUse");
|
|
266
|
+
assert.match(output.hookSpecificOutput.additionalContext, /ok:true/);
|
|
267
|
+
assert.doesNotMatch(output.hookSpecificOutput.additionalContext, /secret/);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("PostToolUseFailure preserves classification and warns before uncertain write retry", () => {
|
|
271
|
+
const accessToken = ["access", "token"].join("_");
|
|
272
|
+
const output = dispatchHook(
|
|
273
|
+
{
|
|
274
|
+
hook_event_name: "PostToolUseFailure",
|
|
275
|
+
tool_name: "PowerShell",
|
|
276
|
+
tool_input: {
|
|
277
|
+
command: "taptap-cli app save-changes --idempotency-key intent-1 --yes",
|
|
278
|
+
},
|
|
279
|
+
error: JSON.stringify({
|
|
280
|
+
ok: false,
|
|
281
|
+
error: {
|
|
282
|
+
type: "invalid_response",
|
|
283
|
+
subtype: "timeout",
|
|
284
|
+
hint: `query resource before retry; ${accessToken}=secret`,
|
|
285
|
+
},
|
|
286
|
+
}),
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
inspectCommand: () => ({
|
|
290
|
+
canonical_path: "app/save-changes",
|
|
291
|
+
risk: "write",
|
|
292
|
+
}),
|
|
293
|
+
log: () => {},
|
|
294
|
+
},
|
|
295
|
+
);
|
|
296
|
+
const context = output.hookSpecificOutput.additionalContext;
|
|
297
|
+
assert.equal(output.hookSpecificOutput.hookEventName, "PostToolUseFailure");
|
|
298
|
+
assert.match(context, /read back/i);
|
|
299
|
+
assert.match(context, /invalid_response\/timeout/);
|
|
300
|
+
assert.doesNotMatch(context, /secret/);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test("PostToolUseFailure parses an exit-code prefix only before a complete envelope", () => {
|
|
304
|
+
const complete = dispatchHook(
|
|
305
|
+
{
|
|
306
|
+
hook_event_name: "PostToolUseFailure",
|
|
307
|
+
tool_name: "Bash",
|
|
308
|
+
tool_input: { command: "taptap-cli app save-changes --yes" },
|
|
309
|
+
error: "Exit code 4\n{\"ok\":false,\"error\":{\"type\":\"validation\",\"subtype\":\"failed_precondition\"}}",
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
inspectCommand: () => ({
|
|
313
|
+
canonical_path: "app/save-changes",
|
|
314
|
+
risk: "write",
|
|
315
|
+
}),
|
|
316
|
+
log: () => {},
|
|
317
|
+
},
|
|
318
|
+
);
|
|
319
|
+
assert.match(complete.hookSpecificOutput.additionalContext, /validation\/failed_precondition/);
|
|
320
|
+
|
|
321
|
+
const partial = dispatchHook(
|
|
322
|
+
{
|
|
323
|
+
hook_event_name: "PostToolUseFailure",
|
|
324
|
+
tool_name: "Bash",
|
|
325
|
+
tool_input: { command: "taptap-cli app save-changes --yes" },
|
|
326
|
+
error: "Exit code 4\nlog line\n{\"ok\":false,\"error\":{\"type\":\"validation\"}}",
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
inspectCommand: () => ({
|
|
330
|
+
canonical_path: "app/save-changes",
|
|
331
|
+
risk: "write",
|
|
332
|
+
}),
|
|
333
|
+
log: () => {},
|
|
334
|
+
},
|
|
335
|
+
);
|
|
336
|
+
assert.match(partial.hookSpecificOutput.additionalContext, /No complete CLI error envelope/);
|
|
337
|
+
assert.doesNotMatch(partial.hookSpecificOutput.additionalContext, /CLI classification/);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test("redaction removes credentials, signed query values, and home paths", () => {
|
|
341
|
+
const accessToken = ["access", "token"].join("_");
|
|
342
|
+
const redacted = redactText(
|
|
343
|
+
[
|
|
344
|
+
`${process.env.HOME}/file ${accessToken}=xyz`,
|
|
345
|
+
"Authorization: AWS4-HMAC-SHA256 Credential=AKIA/20260817/cn/service/aws4_request, SignedHeaders=host, Signature=signed",
|
|
346
|
+
"https://x.test?a=1&X-Amz-Credential=AKIA%2Fscope&X-Amz-Security-Token=session&X-Amz-Signature=signed",
|
|
347
|
+
].join("\n"),
|
|
348
|
+
);
|
|
349
|
+
assert.doesNotMatch(redacted, /AKIA|xyz|session|signed|aws4_request/);
|
|
350
|
+
assert.doesNotMatch(redacted, new RegExp(process.env.HOME.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
|
|
351
|
+
assert.match(redacted, /\[REDACTED\]/);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test("dispatcher process degrades malformed input to one JSON object and exit 0", () => {
|
|
355
|
+
const child = spawnSync(process.execPath, [dispatcher], {
|
|
356
|
+
input: "{\"access_token\":\"super-secret\"",
|
|
357
|
+
encoding: "utf8",
|
|
358
|
+
});
|
|
359
|
+
assert.equal(child.status, 0);
|
|
360
|
+
assert.deepEqual(JSON.parse(child.stdout), {});
|
|
361
|
+
assert.doesNotMatch(child.stderr, /super-secret/);
|
|
362
|
+
});
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright (c) 2026 TapTap
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const { execFileSync, execFile } = require("child_process");
|
|
8
|
+
const { skillsSourceForVersion } = require("./skills-source");
|
|
9
|
+
|
|
10
|
+
// @clack/prompts is ESM-only since v1; load it via dynamic import() so this
|
|
11
|
+
// CommonJS script works on all supported Node versions (require() of an ESM
|
|
12
|
+
// package throws ERR_REQUIRE_ESM before Node 22.12). Assigned in the entry
|
|
13
|
+
// point below before main() runs.
|
|
14
|
+
let p;
|
|
15
|
+
|
|
16
|
+
const PKG = "@taptap/cli";
|
|
17
|
+
const NPM_REGISTRY = "https://registry.npmjs.org/";
|
|
18
|
+
const isWindows = process.platform === "win32";
|
|
19
|
+
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// i18n
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
const messages = {
|
|
25
|
+
zh: {
|
|
26
|
+
setup: "正在设置 TapTap CLI...",
|
|
27
|
+
step1: "正在安装 %s...",
|
|
28
|
+
step1Upgrade: "正在升级 %s (v%s → v%s)...",
|
|
29
|
+
step1Skip: "已安装 (v%s),跳过",
|
|
30
|
+
step1Done: "已全局安装",
|
|
31
|
+
step1Upgraded: "已升级到 v%s",
|
|
32
|
+
step1Fail: "全局安装失败。运行以下命令重试: npm install -g %s",
|
|
33
|
+
step2: "安装 AI Skills",
|
|
34
|
+
step2Skip: "已安装,跳过",
|
|
35
|
+
step2Spinner: "正在安装 Skills...",
|
|
36
|
+
step2Done: "Skills 已安装",
|
|
37
|
+
step2Fail: "Skills 安装失败。运行以下命令重试: npx skills add %s -y -g",
|
|
38
|
+
step3: "授权",
|
|
39
|
+
step3NotFound: "未找到 taptap-cli,跳过授权",
|
|
40
|
+
step3Confirm: "是否允许 AI 访问你的 TapTap 数据,并按你的确认执行操作?",
|
|
41
|
+
step3Skip: "跳过授权。后续运行 taptap-cli auth login 完成授权",
|
|
42
|
+
step3Done: "授权完成",
|
|
43
|
+
step3Fail: "授权失败。运行以下命令重试: taptap-cli auth login",
|
|
44
|
+
done: "安装完成!\n可以和你的 AI 工具(如 Claude Code、Trae等)说:\"TapTap CLI 能帮我做什么?结合我的情况推荐一下从哪里开始\"",
|
|
45
|
+
cancelled: "安装已取消",
|
|
46
|
+
nonTtyHint: "要完成授权,请在终端中运行:\n taptap-cli auth login",
|
|
47
|
+
},
|
|
48
|
+
en: {
|
|
49
|
+
setup: "Setting up TapTap CLI...",
|
|
50
|
+
step1: "Installing %s globally...",
|
|
51
|
+
step1Upgrade: "Upgrading %s (v%s → v%s)...",
|
|
52
|
+
step1Skip: "Already installed (v%s). Skipped",
|
|
53
|
+
step1Done: "Installed globally",
|
|
54
|
+
step1Upgraded: "Upgraded to v%s",
|
|
55
|
+
step1Fail: "Failed to install globally. Run manually: npm install -g %s",
|
|
56
|
+
step2: "Install AI skills",
|
|
57
|
+
step2Skip: "Already installed. Skipped",
|
|
58
|
+
step2Spinner: "Installing skills...",
|
|
59
|
+
step2Done: "Skills installed",
|
|
60
|
+
step2Fail: "Failed to install skills. Run manually: npx skills add %s -y -g",
|
|
61
|
+
step3: "Authorization",
|
|
62
|
+
step3NotFound: "taptap-cli not found. Skipping authorization",
|
|
63
|
+
step3Confirm: "Allow the AI to access your TapTap data and perform operations after your confirmation?",
|
|
64
|
+
step3Skip: "Skipped. Run taptap-cli auth login to authorize later",
|
|
65
|
+
step3Done: "Authorization complete",
|
|
66
|
+
step3Fail: "Failed to authorize. Run taptap-cli auth login to retry",
|
|
67
|
+
done: "You are all set!\nNow try asking your AI tool (Claude Code, Trae, etc.): \"What can TapTap CLI help me with, and where should I start?\"",
|
|
68
|
+
cancelled: "Installation cancelled",
|
|
69
|
+
nonTtyHint: "To authorize later, run:\n taptap-cli auth login",
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// Helpers
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
|
|
77
|
+
function handleCancel(value, msg) {
|
|
78
|
+
if (p.isCancel(value)) {
|
|
79
|
+
p.cancel(msg.cancelled);
|
|
80
|
+
process.exit(0);
|
|
81
|
+
}
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function execCmd(cmd, args, opts) {
|
|
86
|
+
if (isWindows) {
|
|
87
|
+
return execFileSync("cmd.exe", ["/c", cmd, ...args], opts);
|
|
88
|
+
}
|
|
89
|
+
return execFileSync(cmd, args, opts);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function run(cmd, args, opts = {}) {
|
|
93
|
+
execCmd(cmd, args, { stdio: "inherit", ...opts });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function runSilent(cmd, args, opts = {}) {
|
|
97
|
+
return execCmd(cmd, args, {
|
|
98
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
99
|
+
...opts,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function runSilentAsync(cmd, args, opts = {}) {
|
|
104
|
+
const actualCmd = isWindows ? "cmd.exe" : cmd;
|
|
105
|
+
const actualArgs = isWindows ? ["/c", cmd, ...args] : args;
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
execFile(actualCmd, actualArgs, {
|
|
108
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
109
|
+
...opts,
|
|
110
|
+
}, (err, stdout) => {
|
|
111
|
+
if (err) reject(err);
|
|
112
|
+
else resolve(stdout);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function fmt(template, ...values) {
|
|
118
|
+
let i = 0;
|
|
119
|
+
return template.replace(/%s/g, () => values[i++] ?? "");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Resolve the path of globally installed taptap-cli (skip npx temp copies). */
|
|
123
|
+
function whichTapTapCli() {
|
|
124
|
+
try {
|
|
125
|
+
const prefix = execFileSync("npm", ["prefix", "-g"], {
|
|
126
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
127
|
+
}).toString().trim();
|
|
128
|
+
const bin = isWindows
|
|
129
|
+
? path.join(prefix, "taptap-cli.cmd")
|
|
130
|
+
: path.join(prefix, "bin", "taptap-cli");
|
|
131
|
+
if (fs.existsSync(bin)) return bin;
|
|
132
|
+
} catch (_) {
|
|
133
|
+
// fall through
|
|
134
|
+
}
|
|
135
|
+
// Fallback to which/where if npm prefix lookup fails.
|
|
136
|
+
try {
|
|
137
|
+
const cmd = isWindows ? "where" : "which";
|
|
138
|
+
return execFileSync(cmd, ["taptap-cli"], { stdio: ["ignore", "pipe", "pipe"] })
|
|
139
|
+
.toString()
|
|
140
|
+
.split("\n")[0]
|
|
141
|
+
.trim();
|
|
142
|
+
} catch (_) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Get the latest version of @taptap/cli from the registry. Returns version or null. */
|
|
148
|
+
function getLatestVersion() {
|
|
149
|
+
try {
|
|
150
|
+
const out = runSilent("npm", [
|
|
151
|
+
"view", PKG, "version",
|
|
152
|
+
"--registry", NPM_REGISTRY,
|
|
153
|
+
"--@taptap:registry", NPM_REGISTRY,
|
|
154
|
+
], { timeout: 15000 });
|
|
155
|
+
const ver = out.toString().trim();
|
|
156
|
+
return /^\d+\.\d+\.\d+/.test(ver) ? ver : null;
|
|
157
|
+
} catch (_) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Compare two semver strings. Returns true if a < b. */
|
|
163
|
+
function semverLessThan(a, b) {
|
|
164
|
+
const pa = a.replace(/-.*$/, "").split(".").map(Number);
|
|
165
|
+
const pb = b.replace(/-.*$/, "").split(".").map(Number);
|
|
166
|
+
for (let i = 0; i < 3; i++) {
|
|
167
|
+
if ((pa[i] || 0) < (pb[i] || 0)) return true;
|
|
168
|
+
if ((pa[i] || 0) > (pb[i] || 0)) return false;
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Check whether @taptap/cli is truly installed in npm global prefix. Returns version or null. */
|
|
174
|
+
function getGloballyInstalledVersion() {
|
|
175
|
+
try {
|
|
176
|
+
const out = runSilent("npm", ["list", "-g", PKG], { timeout: 15000 });
|
|
177
|
+
const match = out.toString().match(/@(\d+\.\d+\.\d+[^\s]*)/);
|
|
178
|
+
return match ? match[1] : "unknown";
|
|
179
|
+
} catch (_) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Parse --lang from process.argv, returns "zh", "en", or null. */
|
|
185
|
+
function parseLangArg() {
|
|
186
|
+
const args = process.argv.slice(2);
|
|
187
|
+
for (let i = 0; i < args.length; i++) {
|
|
188
|
+
if (args[i] === "--lang" && args[i + 1]) {
|
|
189
|
+
const val = args[i + 1].toLowerCase();
|
|
190
|
+
if (val === "zh" || val === "en") return val;
|
|
191
|
+
}
|
|
192
|
+
if (args[i].startsWith("--lang=")) {
|
|
193
|
+
const val = args[i].split("=")[1].toLowerCase();
|
|
194
|
+
if (val === "zh" || val === "en") return val;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
// Steps
|
|
202
|
+
// ---------------------------------------------------------------------------
|
|
203
|
+
|
|
204
|
+
async function stepSelectLang() {
|
|
205
|
+
const fromArg = parseLangArg();
|
|
206
|
+
if (fromArg) return fromArg;
|
|
207
|
+
|
|
208
|
+
const lang = await p.select({
|
|
209
|
+
message: "请选择语言 / Select language",
|
|
210
|
+
options: [
|
|
211
|
+
{ value: "zh", label: "中文" },
|
|
212
|
+
{ value: "en", label: "English" },
|
|
213
|
+
],
|
|
214
|
+
});
|
|
215
|
+
return handleCancel(lang, messages.zh);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function stepInstallGlobally(msg) {
|
|
219
|
+
const installedVer = getGloballyInstalledVersion();
|
|
220
|
+
const latestVer = getLatestVersion();
|
|
221
|
+
const needsUpgrade = installedVer && latestVer && semverLessThan(installedVer, latestVer);
|
|
222
|
+
|
|
223
|
+
if (installedVer && !needsUpgrade) {
|
|
224
|
+
p.log.info(fmt(msg.step1Skip, installedVer));
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const s = p.spinner();
|
|
229
|
+
if (needsUpgrade) {
|
|
230
|
+
s.start(fmt(msg.step1Upgrade, PKG, installedVer, latestVer));
|
|
231
|
+
} else {
|
|
232
|
+
s.start(fmt(msg.step1, PKG));
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
await runSilentAsync("npm", [
|
|
236
|
+
"install", "-g", PKG,
|
|
237
|
+
"--registry", NPM_REGISTRY,
|
|
238
|
+
"--@taptap:registry", NPM_REGISTRY,
|
|
239
|
+
], { timeout: 120000 });
|
|
240
|
+
s.stop(needsUpgrade ? fmt(msg.step1Upgraded, latestVer) : msg.step1Done);
|
|
241
|
+
return needsUpgrade;
|
|
242
|
+
} catch (_) {
|
|
243
|
+
s.stop(fmt(msg.step1Fail, PKG));
|
|
244
|
+
process.exit(1);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function installOfficialSkills(version, runner = runSilentAsync) {
|
|
249
|
+
const skillsSource = skillsSourceForVersion(version);
|
|
250
|
+
const args = ["-y", "skills", "add", skillsSource, "-y", "-g"];
|
|
251
|
+
try {
|
|
252
|
+
await runner("npx", args, { timeout: 120000 });
|
|
253
|
+
} catch (_) {
|
|
254
|
+
await runner("npx", args, { timeout: 120000 });
|
|
255
|
+
}
|
|
256
|
+
return skillsSource;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function stepInstallSkills(msg) {
|
|
260
|
+
const version = getGloballyInstalledVersion();
|
|
261
|
+
const skillsSource = skillsSourceForVersion(version);
|
|
262
|
+
const s = p.spinner();
|
|
263
|
+
s.start(msg.step2Spinner);
|
|
264
|
+
try {
|
|
265
|
+
await installOfficialSkills(version);
|
|
266
|
+
s.stop(msg.step2Done);
|
|
267
|
+
} catch (_) {
|
|
268
|
+
s.stop(fmt(msg.step2Fail, skillsSource));
|
|
269
|
+
process.exit(1);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
async function stepAuthLogin(msg) {
|
|
274
|
+
const taptapCli = whichTapTapCli();
|
|
275
|
+
if (!taptapCli) {
|
|
276
|
+
p.log.warn(msg.step3NotFound);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const yes = await p.confirm({
|
|
281
|
+
message: msg.step3Confirm,
|
|
282
|
+
});
|
|
283
|
+
if (p.isCancel(yes)) {
|
|
284
|
+
p.cancel(msg.cancelled);
|
|
285
|
+
process.exit(0);
|
|
286
|
+
}
|
|
287
|
+
if (!yes) {
|
|
288
|
+
p.log.info(msg.step3Skip);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
p.log.step(msg.step3);
|
|
293
|
+
try {
|
|
294
|
+
run(taptapCli, ["auth", "login"]);
|
|
295
|
+
p.log.success(msg.step3Done);
|
|
296
|
+
} catch (_) {
|
|
297
|
+
p.log.warn(msg.step3Fail);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// ---------------------------------------------------------------------------
|
|
302
|
+
// Main
|
|
303
|
+
// ---------------------------------------------------------------------------
|
|
304
|
+
|
|
305
|
+
async function main() {
|
|
306
|
+
const isInteractive = !!process.stdin.isTTY;
|
|
307
|
+
const lang = isInteractive ? await stepSelectLang() : (parseLangArg() || "en");
|
|
308
|
+
const msg = messages[lang];
|
|
309
|
+
|
|
310
|
+
if (isInteractive) {
|
|
311
|
+
p.intro(msg.setup);
|
|
312
|
+
await stepInstallGlobally(msg);
|
|
313
|
+
await stepInstallSkills(msg);
|
|
314
|
+
await stepAuthLogin(msg);
|
|
315
|
+
p.outro(msg.done);
|
|
316
|
+
} else {
|
|
317
|
+
console.log(msg.setup);
|
|
318
|
+
await stepInstallGlobally(msg);
|
|
319
|
+
await stepInstallSkills(msg);
|
|
320
|
+
console.log(msg.nonTtyHint);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
async function runWizard() {
|
|
325
|
+
p = await import("@clack/prompts");
|
|
326
|
+
await main();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (require.main === module) {
|
|
330
|
+
runWizard().catch((err) => {
|
|
331
|
+
const msg = "Unexpected error: " + (err.message || err);
|
|
332
|
+
if (p) p.cancel(msg);
|
|
333
|
+
else console.error(msg);
|
|
334
|
+
process.exit(1);
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
module.exports = { installOfficialSkills, runWizard };
|