@team-ai/teamai-cli 0.40.9 → 0.50.0
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/CHANGELOG.md +167 -11
- package/README.ja.md +32 -29
- package/README.ko.md +32 -29
- package/README.md +32 -29
- package/README.th.md +32 -29
- package/README.zh-CN.md +32 -29
- package/agents/README.md +68 -0
- package/agents/README.zh-CN.md +68 -0
- package/agents/teamai-recall.md +10 -9
- package/dist/cli.js +210551 -136899
- package/dist/index.js +291 -0
- package/dist/runtime-paseo.js +27562 -0
- package/dist/runtime-sandbox.js +94740 -0
- package/dist/runtime-t3.js +41891 -0
- package/drivers/teamai-claude.yaml +6 -0
- package/drivers/teamai-codex.yaml +6 -0
- package/drivers/teamai-local.yaml +5 -0
- package/drivers/teamai-opencode.yaml +6 -0
- package/drivers/teamai-paseo.yaml +6 -0
- package/drivers/teamai-sandbox.yaml +7 -0
- package/drivers/teamai-t3.yaml +8 -0
- package/hooks/teamai-env-hint/HOOK.yaml +1 -0
- package/hooks/teamai-env-hint/README.md +80 -0
- package/hooks/teamai-env-hint/README.zh-CN.md +80 -0
- package/hooks/teamai-env-hint/exec.md +1 -0
- package/hooks/teamai-env-hint/secrets-rule.md +1 -0
- package/hooks/teamai-env-hint/secrets.md +1 -0
- package/hooks/teamai-env-hint/variables.md +1 -0
- package/hooks/teamai-friction-reminder/HOOK.yaml +1 -0
- package/hooks/teamai-friction-reminder/README.md +117 -0
- package/hooks/teamai-friction-reminder/README.zh-CN.md +117 -0
- package/hooks/teamai-friction-reminder/action-gap.md +1 -0
- package/hooks/teamai-friction-reminder/action-gap.zh.md +1 -0
- package/hooks/teamai-friction-reminder/action-share-learnings.md +1 -0
- package/hooks/teamai-friction-reminder/action-share-learnings.zh.md +1 -0
- package/hooks/teamai-friction-reminder/action.md +1 -0
- package/hooks/teamai-friction-reminder/action.zh.md +1 -0
- package/hooks/teamai-friction-reminder/gap-reasons.md +1 -0
- package/hooks/teamai-friction-reminder/gap-reasons.zh.md +1 -0
- package/hooks/teamai-friction-reminder/gap.md +1 -0
- package/hooks/teamai-friction-reminder/gap.zh.md +1 -0
- package/hooks/teamai-friction-reminder/params.yaml +12 -0
- package/hooks/teamai-friction-reminder/problem-reasons.md +1 -0
- package/hooks/teamai-friction-reminder/problem-reasons.zh.md +1 -0
- package/hooks/teamai-friction-reminder/problem.md +1 -0
- package/hooks/teamai-friction-reminder/problem.zh.md +1 -0
- package/hooks/teamai-friction-reminder/reason-correction.md +1 -0
- package/hooks/teamai-friction-reminder/reason-correction.zh.md +1 -0
- package/hooks/teamai-friction-reminder/reason-interrupt.md +1 -0
- package/hooks/teamai-friction-reminder/reason-interrupt.zh.md +1 -0
- package/hooks/teamai-friction-reminder/reason-tool-error.md +1 -0
- package/hooks/teamai-friction-reminder/reason-tool-error.zh.md +1 -0
- package/hooks/teamai-friction-reminder/reason-tool-reject.md +1 -0
- package/hooks/teamai-friction-reminder/reason-tool-reject.zh.md +1 -0
- package/hooks/teamai-friction-reminder/task.md +1 -0
- package/hooks/teamai-friction-reminder/task.zh.md +1 -0
- package/hooks/teamai-mr-hint/HOOK.yaml +1 -0
- package/hooks/teamai-mr-hint/README.md +81 -0
- package/hooks/teamai-mr-hint/README.zh-CN.md +81 -0
- package/hooks/teamai-mr-hint/offer-command.en.md +7 -0
- package/hooks/teamai-mr-hint/offer-command.md +10 -0
- package/hooks/teamai-mr-hint/offer-workflow.en.md +7 -0
- package/hooks/teamai-mr-hint/offer-workflow.md +10 -0
- package/hooks/teamai-mr-hint/params.yaml +2 -0
- package/hooks/teamai-package-hint/HOOK.yaml +1 -0
- package/hooks/teamai-package-hint/README.md +64 -0
- package/hooks/teamai-package-hint/README.zh-CN.md +64 -0
- package/hooks/teamai-package-hint/message.md +3 -0
- package/hooks/teamai-todowrite-hint/HOOK.yaml +1 -0
- package/hooks/teamai-todowrite-hint/README.md +68 -0
- package/hooks/teamai-todowrite-hint/README.zh-CN.md +68 -0
- package/hooks/teamai-todowrite-hint/message.en.md +6 -0
- package/hooks/teamai-todowrite-hint/message.md +9 -0
- package/package.json +41 -14
- package/rules/teamai-recall/README.md +78 -0
- package/rules/teamai-recall/README.zh-CN.md +78 -0
- package/rules/teamai-recall/RULE.en.md +36 -0
- package/rules/teamai-recall/RULE.md +43 -0
- package/rules/teamai-recall/block-direct.md +27 -0
- package/rules/teamai-recall/block.en.md +42 -0
- package/rules/teamai-recall/block.md +44 -0
- package/runtimes/teamai-paseo.yaml +5 -0
- package/runtimes/teamai-sandbox.yaml +3 -0
- package/runtimes/teamai-t3.yaml +5 -0
- package/sandboxes/teamai-bwrap.yaml +2 -0
- package/sandboxes/teamai-default.yaml +4 -0
- package/sandboxes/teamai-docker.yaml +5 -0
- package/sandboxes/teamai-podman.yaml +4 -0
- package/sandboxes/teamai-sbx.yaml +4 -0
- package/sandboxes/teamai-seatbelt.yaml +2 -0
- package/sandboxes/teamai-vercel.yaml +4 -0
- package/scorers/README.md +103 -0
- package/scorers/README.zh-CN.md +103 -0
- package/scorers/teamai-adoption.md +11 -0
- package/scorers/teamai-correctness.md +17 -0
- package/scorers/teamai-routing.md +11 -0
- package/skill-data/core/SKILL.md +4 -3
- package/skill-data/core/references/commands.md +300 -67
- package/skill-data/core/references/contribute-member.md +4 -4
- package/skill-data/core/references/troubleshooting.md +128 -18
- package/skill-data/setup/references/join-member.md +13 -9
- package/skill-data/setup/references/manage-admin.md +41 -17
- package/skill-data/setup/references/setup-admin.md +2 -2
- package/skill-data/setup/references/uninstall.md +30 -9
- package/skill-data/share/SKILL.md +17 -12
- package/skill-data/share/references/doc-template.md +3 -4
- package/skill-data/wiki/SKILL.md +1 -1
- package/skill-data/wiki/references/agents/graph-rag-agent.md +5 -1
- package/skill-data/workflow/SKILL.md +39 -16
- package/skill-data/workflow/references/fleet.md +13 -0
- package/skill-data/workflow/references/judging.md +17 -10
- package/skill-data/workflow/references/places.md +64 -7
- package/skill-data/workflow/references/sandbox.md +3 -3
- package/skill-data/workflow/references/session-hosts.md +27 -0
- package/skill-data/workflow-local/SKILL.md +4 -3
- package/skill-data/workflow-local/references/ci.md +1 -1
- package/skills/teamai/SKILL.md +4 -3
- package/workflows/README.md +103 -0
- package/workflows/README.zh-CN.md +103 -0
- package/workflows/teamai-benchmark.yaml +78 -0
- package/workflows/teamai-ci-extract-mr.yaml +66 -0
- package/workflows/teamai-codebase-deep-enrich/README.md +123 -0
- package/workflows/teamai-codebase-deep-enrich/README.zh-CN.md +123 -0
- package/workflows/teamai-codebase-deep-enrich/WORKFLOW.yaml +119 -0
- package/workflows/teamai-codebase-deep-enrich/architecture.md +30 -0
- package/workflows/teamai-codebase-deep-enrich/component.md +30 -0
- package/workflows/teamai-codebase-deep-enrich/params.yaml +1 -0
- package/workflows/teamai-codebase-deep-enrich/scenarios.md +32 -0
- package/workflows/teamai-codebase-enrich.yaml +98 -0
- package/workflows/teamai-draft-learning-updates/README.md +116 -0
- package/workflows/teamai-draft-learning-updates/README.zh-CN.md +116 -0
- package/workflows/teamai-draft-learning-updates/WORKFLOW.yaml +61 -0
- package/workflows/teamai-draft-learning-updates/params.yaml +4 -0
- package/workflows/teamai-finished-sessions/README.md +101 -0
- package/workflows/teamai-finished-sessions/README.zh-CN.md +101 -0
- package/workflows/teamai-finished-sessions/WORKFLOW.yaml +43 -0
- package/workflows/teamai-finished-sessions/params.yaml +1 -0
- package/workflows/teamai-import-from-iwiki.yaml +90 -0
- package/workflows/teamai-import-from-mr/README.md +104 -0
- package/workflows/teamai-import-from-mr/README.zh-CN.md +104 -0
- package/workflows/teamai-import-from-mr/WORKFLOW.yaml +94 -0
- package/workflows/teamai-import-from-mr/draft.en.md +48 -0
- package/workflows/teamai-import-from-mr/draft.zh.md +48 -0
- package/workflows/teamai-import-from-repo/README.md +106 -0
- package/workflows/teamai-import-from-repo/README.zh-CN.md +106 -0
- package/workflows/teamai-import-from-repo/WORKFLOW.yaml +109 -0
- package/workflows/teamai-import-from-repo/narrative.md +83 -0
- package/workflows/teamai-import-learnings.yaml +83 -0
- package/workflows/teamai-import-rules.yaml +34 -0
- package/workflows/teamai-new-scorer.yaml +54 -0
- package/workflows/teamai-promote-learning/README.md +122 -0
- package/workflows/teamai-promote-learning/README.zh-CN.md +122 -0
- package/workflows/teamai-promote-learning/WORKFLOW.yaml +102 -0
- package/workflows/teamai-promote-learning/params.yaml +4 -0
- package/workflows/teamai-score.yaml +121 -0
- package/workflows/teamai-self-improvement.yaml +37 -0
- package/workflows/teamai-session-to-task.yaml +69 -0
- package/workflows/teamai-sessions-to-tasks.yaml +62 -0
- package/workflows/teamai-share-learnings-from-sessions.yaml +36 -0
- package/workflows/teamai-share-learnings.yaml +25 -0
- package/workflows/teamai-share-session.yaml +21 -0
- package/workflows/teamai-try-scorer.yaml +32 -0
- package/skill-data/workflow/references/hosts.md +0 -27
package/dist/index.js
CHANGED
|
@@ -4,6 +4,297 @@ const require = __teamaiCreateRequire(import.meta.url);
|
|
|
4
4
|
|
|
5
5
|
// src/bin.ts
|
|
6
6
|
import module from "module";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
8
|
+
|
|
9
|
+
// src/hook-fast-path.ts
|
|
10
|
+
import { spawn } from "child_process";
|
|
11
|
+
import fs2 from "fs";
|
|
12
|
+
import os2 from "os";
|
|
13
|
+
import path3 from "path";
|
|
14
|
+
|
|
15
|
+
// packages/shared/src/debug-log.ts
|
|
16
|
+
import fs from "fs";
|
|
17
|
+
import path2 from "path";
|
|
18
|
+
|
|
19
|
+
// packages/shared/src/home.ts
|
|
20
|
+
import os from "os";
|
|
21
|
+
import path from "path";
|
|
22
|
+
function normalizeHomePath(home) {
|
|
23
|
+
if (process.platform !== "win32") return home;
|
|
24
|
+
const match = /^\/(?:cygdrive\/)?([a-zA-Z])(?:\/(.*))?$/.exec(home);
|
|
25
|
+
if (!match) return home;
|
|
26
|
+
const rest = (match[2] ?? "").replace(/\//g, "\\");
|
|
27
|
+
return `${match[1].toUpperCase()}:${rest ? `\\${rest}` : "\\"}`;
|
|
28
|
+
}
|
|
29
|
+
function getUserHome() {
|
|
30
|
+
return installHome ?? memberHome();
|
|
31
|
+
}
|
|
32
|
+
var installHome;
|
|
33
|
+
function memberHome() {
|
|
34
|
+
const home = process.env.HOME?.trim() || process.env.USERPROFILE?.trim() || os.homedir();
|
|
35
|
+
if (!home) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"Unable to determine the user home directory: none of HOME, USERPROFILE, or os.homedir() is available. Set HOME explicitly before running teamai."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return normalizeHomePath(home);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// packages/shared/src/debug-log.ts
|
|
44
|
+
var MAX_LOG_BYTES = 5 * 1024 * 1024;
|
|
45
|
+
var _logFilePath = null;
|
|
46
|
+
var _dirEnsured = false;
|
|
47
|
+
function defaultLogFilePath() {
|
|
48
|
+
return path2.join(getUserHome(), ".teamai", "debug.log");
|
|
49
|
+
}
|
|
50
|
+
var _dirExistedAtStart = fs.existsSync(path2.dirname(defaultLogFilePath()));
|
|
51
|
+
var _writing = false;
|
|
52
|
+
function getLogFilePath() {
|
|
53
|
+
if (!_logFilePath) {
|
|
54
|
+
_logFilePath = defaultLogFilePath();
|
|
55
|
+
}
|
|
56
|
+
return _logFilePath;
|
|
57
|
+
}
|
|
58
|
+
function ensureLogDir() {
|
|
59
|
+
if (_dirEnsured) return;
|
|
60
|
+
const dir = path2.dirname(getLogFilePath());
|
|
61
|
+
if (_dirExistedAtStart && !fs.existsSync(dir)) {
|
|
62
|
+
_dirEnsured = true;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
_dirEnsured = true;
|
|
70
|
+
}
|
|
71
|
+
function maybeRotate() {
|
|
72
|
+
try {
|
|
73
|
+
const stat = fs.statSync(getLogFilePath());
|
|
74
|
+
if (stat.size >= MAX_LOG_BYTES) {
|
|
75
|
+
fs.renameSync(getLogFilePath(), getLogFilePath() + ".1");
|
|
76
|
+
}
|
|
77
|
+
} catch {
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function writeToFile(level, msg) {
|
|
81
|
+
if (_writing) return;
|
|
82
|
+
_writing = true;
|
|
83
|
+
try {
|
|
84
|
+
ensureLogDir();
|
|
85
|
+
maybeRotate();
|
|
86
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
87
|
+
const line = `${ts} [${level}] ${msg}
|
|
88
|
+
`;
|
|
89
|
+
fs.appendFileSync(getLogFilePath(), line, "utf-8");
|
|
90
|
+
} catch {
|
|
91
|
+
} finally {
|
|
92
|
+
_writing = false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/utils/hook-stdin.ts
|
|
97
|
+
var STDIN_READ_TIMEOUT_MS = 1e3;
|
|
98
|
+
async function readStdin(stream = process.stdin, timeoutMs = STDIN_READ_TIMEOUT_MS) {
|
|
99
|
+
if (stream.isTTY) return "";
|
|
100
|
+
const chunks = [];
|
|
101
|
+
const readAll = (async () => {
|
|
102
|
+
for await (const chunk of stream) {
|
|
103
|
+
chunks.push(chunk);
|
|
104
|
+
}
|
|
105
|
+
})();
|
|
106
|
+
void readAll.catch(() => {
|
|
107
|
+
});
|
|
108
|
+
let timer;
|
|
109
|
+
let timedOut = false;
|
|
110
|
+
const deadline = new Promise((resolve) => {
|
|
111
|
+
timer = setTimeout(() => {
|
|
112
|
+
timedOut = true;
|
|
113
|
+
resolve();
|
|
114
|
+
}, timeoutMs);
|
|
115
|
+
timer.unref();
|
|
116
|
+
});
|
|
117
|
+
try {
|
|
118
|
+
await Promise.race([readAll, deadline]);
|
|
119
|
+
} finally {
|
|
120
|
+
if (timer) clearTimeout(timer);
|
|
121
|
+
}
|
|
122
|
+
if (timedOut && !stream.destroyed) stream.destroy();
|
|
123
|
+
return Buffer.concat(chunks).toString("utf-8");
|
|
124
|
+
}
|
|
125
|
+
function handOffHookStdin(raw) {
|
|
126
|
+
globalThis.teamaiHandedOffHookStdin = raw;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/hook-fast-path.ts
|
|
130
|
+
var LAUNCHED_BY_ENV = "TEAMAI_LAUNCHED_BY";
|
|
131
|
+
var ATTEMPT_ENV = "TEAMAI_WORKFLOW_ATTEMPT";
|
|
132
|
+
var FOREGROUND_PAYLOAD_KEYS = ["teamai_run", "teamai_launch"];
|
|
133
|
+
var HTTP_ENDPOINT_ENVS = ["TEAMAI_HTTP_ENDPOINT", "TEAMAI_ENDPOINT", "TEAMAI_API_BASE_URL"];
|
|
134
|
+
var LOGIN_DEFERRED_ENV = "TEAMAI_HOOK_LOGIN";
|
|
135
|
+
var LOGIN_SHELL_ARGS = ["-lc", 'exec teamai "$@"', "teamai"];
|
|
136
|
+
var PIPED_PAYLOAD_MAX_BYTES = 16 * 1024;
|
|
137
|
+
var FULL_DISPATCH_TOOLS = /* @__PURE__ */ new Set(["copilot", "agy", "git"]);
|
|
138
|
+
var SESSION_ID_FIELDS = ["session_id", "sessionId", "conversation_id"];
|
|
139
|
+
var FAST_EVENTS = ["post-tool-use", "prompt-submit"];
|
|
140
|
+
function argvVerdict(argv, env, platform) {
|
|
141
|
+
if (platform === "win32") return { kind: "full" };
|
|
142
|
+
const [command, event, toolFlag, tool, matcherFlag, matcher, ...rest] = argv;
|
|
143
|
+
const fastEvent = FAST_EVENTS.find((candidate) => candidate === event);
|
|
144
|
+
if (command !== "hook-dispatch" || !fastEvent || toolFlag !== "--tool" || !tool || rest.length > 0) return { kind: "full" };
|
|
145
|
+
if (matcherFlag !== void 0 && (fastEvent !== "post-tool-use" || matcherFlag !== "--matcher" || !matcher)) return { kind: "full" };
|
|
146
|
+
const launcher = env[LAUNCHED_BY_ENV];
|
|
147
|
+
if (launcher && launcher !== "workflow") return { kind: "skip" };
|
|
148
|
+
if (env[ATTEMPT_ENV] || FULL_DISPATCH_TOOLS.has(tool) || matcher === "TodoWrite") return { kind: "full" };
|
|
149
|
+
if (tool === "claude" && (env.CURSOR_VERSION?.trim() || env.COPILOT_PROJECT_DIR?.trim() || env.GROK_HOOK_EVENT?.trim())) return { kind: "full" };
|
|
150
|
+
if (tool === "cursor" && env.GROK_HOOK_EVENT?.trim()) return { kind: "full" };
|
|
151
|
+
return { kind: "payload", hook: { event: fastEvent, tool, matcher: matcher ?? "*" } };
|
|
152
|
+
}
|
|
153
|
+
function childPayload(raw) {
|
|
154
|
+
const fields = jsonObjectFields(raw);
|
|
155
|
+
const sessionId = fields && SESSION_ID_FIELDS.map((field) => fields.get(field)).find(isNonEmptyString);
|
|
156
|
+
if (!fields || !sessionId || fields.get("tool_name") === "TodoWrite") return null;
|
|
157
|
+
if (!FOREGROUND_PAYLOAD_KEYS.some((key) => fields.has(key))) return { payload: raw, sessionId };
|
|
158
|
+
for (const key of FOREGROUND_PAYLOAD_KEYS) fields.delete(key);
|
|
159
|
+
return { payload: JSON.stringify(Object.fromEntries(fields)), sessionId };
|
|
160
|
+
}
|
|
161
|
+
function jsonObjectFields(raw) {
|
|
162
|
+
let payload;
|
|
163
|
+
try {
|
|
164
|
+
payload = JSON.parse(raw);
|
|
165
|
+
} catch {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
return payload instanceof Object && !Array.isArray(payload) ? new Map(Object.entries(payload)) : null;
|
|
169
|
+
}
|
|
170
|
+
function isNonEmptyString(value) {
|
|
171
|
+
return typeof value === "string" && value !== "";
|
|
172
|
+
}
|
|
173
|
+
function isHttpEnrolled(env) {
|
|
174
|
+
const teamaiHome = path3.join(getUserHome(), ".teamai");
|
|
175
|
+
const stored = readTextFile(path3.join(teamaiHome, "local-agent", "config.json"));
|
|
176
|
+
if (stored !== null) return jsonObjectFields(stored)?.get("disabled") !== true;
|
|
177
|
+
const memberConfig = readTextFile(path3.join(teamaiHome, "config.yaml")) ?? "";
|
|
178
|
+
return /\bkind:\s*['"]?http\b/.test(memberConfig) || HTTP_ENDPOINT_ENVS.some((name) => !!env[name]);
|
|
179
|
+
}
|
|
180
|
+
function promptAnswersInForeground(sessionId, env) {
|
|
181
|
+
const teamaiHome = path3.join(getUserHome(), ".teamai");
|
|
182
|
+
const file = sessionId.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
183
|
+
return fs2.existsSync(path3.join(teamaiHome, "package-hints", `${file}.pending.json`)) || fs2.existsSync(path3.join(sessionStateDir(), `${file}.mr-hint.pending.json`)) || (readTextFile(path3.join(sessionStateDir(), `${file}.json`)) ?? "").includes('"pendingHint"') || isHttpEnrolled(env);
|
|
184
|
+
}
|
|
185
|
+
function sessionStateDir() {
|
|
186
|
+
return path3.join(getUserHome(), ".teamai", "sessions");
|
|
187
|
+
}
|
|
188
|
+
function readTextFile(file) {
|
|
189
|
+
let fd;
|
|
190
|
+
try {
|
|
191
|
+
fd = fs2.openSync(file, process.platform === "win32" ? fs2.constants.O_RDONLY : fs2.constants.O_RDONLY | fs2.constants.O_NONBLOCK);
|
|
192
|
+
} catch {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
return fs2.fstatSync(fd).isFile() ? fs2.readFileSync(fd, "utf8") : null;
|
|
197
|
+
} catch {
|
|
198
|
+
return null;
|
|
199
|
+
} finally {
|
|
200
|
+
fs2.closeSync(fd);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async function runHookFastPath(argv, options) {
|
|
204
|
+
const verdict = argvVerdict(argv, options.env, options.platform);
|
|
205
|
+
if (verdict.kind !== "payload") return verdict.kind === "skip" ? "done" : "full";
|
|
206
|
+
const raw = await readStdin(options.stdin());
|
|
207
|
+
const { event, tool, matcher } = verdict.hook;
|
|
208
|
+
const child = childPayload(raw);
|
|
209
|
+
if (child === null || event === "prompt-submit" && promptAnswersInForeground(child.sessionId, options.env)) {
|
|
210
|
+
handOffHookStdin(raw);
|
|
211
|
+
return "full";
|
|
212
|
+
}
|
|
213
|
+
await spawnBackgroundChild(process.execPath, [options.entry, "hook-dispatch", event, "--tool", tool, "--bg-only", ...matcher === "*" ? [] : ["--matcher", matcher]], child.payload);
|
|
214
|
+
writeToFile("DEBUG", `[hook-dispatch] ${event}/${tool} fast path`);
|
|
215
|
+
return "done";
|
|
216
|
+
}
|
|
217
|
+
async function runLoginDeferredHook(argv, options) {
|
|
218
|
+
if (options.env[LOGIN_DEFERRED_ENV] !== "deferred" || argv[0] !== "hook-dispatch") return null;
|
|
219
|
+
const env = hostEnvironment(options.env);
|
|
220
|
+
const verdict = argvVerdict(argv, env, options.platform);
|
|
221
|
+
if (verdict.kind === "skip") return 0;
|
|
222
|
+
if (verdict.kind === "full") return runThroughLoginShell({ argv, env, stdin: null });
|
|
223
|
+
const raw = await readStdin(options.stdin());
|
|
224
|
+
const { event, tool, matcher } = verdict.hook;
|
|
225
|
+
const child = childPayload(raw);
|
|
226
|
+
if (child === null || event === "prompt-submit" && (promptAnswersInForeground(child.sessionId, env) || !loginSawNoEnrolment(child.sessionId, raw))) {
|
|
227
|
+
return runThroughLoginShell({ argv, env, stdin: raw });
|
|
228
|
+
}
|
|
229
|
+
const payloadFile = Buffer.byteLength(child.payload) > PIPED_PAYLOAD_MAX_BYTES ? writePayloadFile(child.payload) : null;
|
|
230
|
+
const started = await spawnBackgroundChild(
|
|
231
|
+
"bash",
|
|
232
|
+
[...LOGIN_SHELL_ARGS, "hook-dispatch", event, "--tool", tool, "--bg-only", ...matcher === "*" ? [] : ["--matcher", matcher], ...payloadFile === null ? [] : ["--stdin-file", payloadFile]],
|
|
233
|
+
payloadFile === null ? child.payload : "",
|
|
234
|
+
env
|
|
235
|
+
);
|
|
236
|
+
if (!started && payloadFile !== null) fs2.rmSync(payloadFile, { force: true });
|
|
237
|
+
writeToFile("DEBUG", `[hook-dispatch] ${event}/${tool} fast path`);
|
|
238
|
+
return 0;
|
|
239
|
+
}
|
|
240
|
+
function loginEnrolmentFile(sessionId) {
|
|
241
|
+
return path3.join(sessionStateDir(), `${sessionId.replace(/[^a-zA-Z0-9._-]/g, "_")}.http-enrolment.json`);
|
|
242
|
+
}
|
|
243
|
+
function loginSawNoEnrolment(sessionId, raw) {
|
|
244
|
+
const recorded = jsonObjectFields(readTextFile(loginEnrolmentFile(sessionId)) ?? "");
|
|
245
|
+
return recorded !== null && recorded.get("enrolled") === false && recorded.get("cwd") === jsonObjectFields(raw)?.get("cwd");
|
|
246
|
+
}
|
|
247
|
+
function hostEnvironment(env) {
|
|
248
|
+
const { [LOGIN_DEFERRED_ENV]: _marker, ...host } = env;
|
|
249
|
+
return host;
|
|
250
|
+
}
|
|
251
|
+
function runThroughLoginShell({ argv, env, stdin }) {
|
|
252
|
+
return new Promise((resolve) => {
|
|
253
|
+
const child = spawn("bash", [...LOGIN_SHELL_ARGS, ...argv], { env, stdio: [stdin === null ? "inherit" : "pipe", "inherit", "inherit"] });
|
|
254
|
+
child.on("error", () => resolve(127));
|
|
255
|
+
child.on("exit", (code) => resolve(code ?? 1));
|
|
256
|
+
child.stdin?.on("error", () => {
|
|
257
|
+
});
|
|
258
|
+
child.stdin?.end(stdin ?? "");
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function writePayloadFile(payload) {
|
|
262
|
+
const file = path3.join(os2.tmpdir(), `teamai-hook-${process.pid}-${Date.now()}.json`);
|
|
263
|
+
try {
|
|
264
|
+
fs2.writeFileSync(file, payload, { encoding: "utf8", mode: 384 });
|
|
265
|
+
return file;
|
|
266
|
+
} catch {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async function spawnBackgroundChild(command, args, stdin, env) {
|
|
271
|
+
try {
|
|
272
|
+
const child = spawn(command, args, { detached: true, stdio: ["pipe", "ignore", "ignore"], env });
|
|
273
|
+
const started = new Promise((resolve) => {
|
|
274
|
+
child.once("spawn", () => resolve(true));
|
|
275
|
+
child.on("error", () => resolve(false));
|
|
276
|
+
});
|
|
277
|
+
await new Promise((resolve) => {
|
|
278
|
+
child.stdin.on("error", () => resolve());
|
|
279
|
+
child.stdin.end(stdin, () => resolve());
|
|
280
|
+
});
|
|
281
|
+
child.unref();
|
|
282
|
+
return await started;
|
|
283
|
+
} catch {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/bin.ts
|
|
289
|
+
var deferred = await runLoginDeferredHook(process.argv.slice(2), { env: process.env, platform: process.platform, stdin: () => process.stdin });
|
|
290
|
+
if (deferred !== null) process.exit(deferred);
|
|
291
|
+
var hook = await runHookFastPath(process.argv.slice(2), {
|
|
292
|
+
env: process.env,
|
|
293
|
+
platform: process.platform,
|
|
294
|
+
stdin: () => process.stdin,
|
|
295
|
+
entry: fileURLToPath(import.meta.url)
|
|
296
|
+
});
|
|
297
|
+
if (hook === "done") process.exit(0);
|
|
7
298
|
module.enableCompileCache?.();
|
|
8
299
|
await import(new URL("./cli.js", import.meta.url).href);
|
|
9
300
|
//# sourceMappingURL=index.js.map
|