@team-ai/teamai-cli 0.40.2 → 0.40.4
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/cli.js +70 -36
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -63072,6 +63072,14 @@ async function askViaTty(prompt) {
|
|
|
63072
63072
|
}
|
|
63073
63073
|
async function promptForProjectBinding(workspacePath, projects) {
|
|
63074
63074
|
if (projects.length === 0) return null;
|
|
63075
|
+
if (!isInteractive2()) {
|
|
63076
|
+
log.info("\u53EF\u7528\u9879\u76EE:");
|
|
63077
|
+
projects.forEach((project, index2) => {
|
|
63078
|
+
const desc = project.description ? ` - ${project.description}` : "";
|
|
63079
|
+
log.info(` ${index2 + 1}. ${project.name}${desc} [id=${project.id}]`);
|
|
63080
|
+
});
|
|
63081
|
+
return null;
|
|
63082
|
+
}
|
|
63075
63083
|
log.debug(`local-agent: workspace not bound: ${workspacePath}`);
|
|
63076
63084
|
const answer = await askViaTty("\u662F\u5426\u7ED1\u5B9A\u5230\u4E00\u4E2A\u9879\u76EE\uFF1F[y/N] ");
|
|
63077
63085
|
if (!answer || answer.toLowerCase() !== "y") return null;
|
|
@@ -63149,15 +63157,22 @@ async function bindWorkspaceToProject(workspacePath, projectId) {
|
|
|
63149
63157
|
log.success(`\u5DF2\u5C06\u5DE5\u4F5C\u533A\u7ED1\u5B9A\u5230\u9879\u76EE\uFF1A${project.name} [id=${project.id}]`);
|
|
63150
63158
|
return binding;
|
|
63151
63159
|
}
|
|
63152
|
-
|
|
63153
|
-
|
|
63154
|
-
|
|
63155
|
-
|
|
63156
|
-
|
|
63160
|
+
function hintMarkerPath(prefix, key) {
|
|
63161
|
+
const flat = key.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
63162
|
+
return path76.join(os9.tmpdir(), `${prefix}-${flat}`);
|
|
63163
|
+
}
|
|
63164
|
+
function bindingHintMarkerFresh(marker) {
|
|
63157
63165
|
try {
|
|
63158
|
-
fs35.
|
|
63166
|
+
const stamp = Number(fs35.readFileSync(marker, "utf8"));
|
|
63167
|
+
return Number.isFinite(stamp) && Date.now() - stamp < BINDING_MARKER_TTL_MS;
|
|
63159
63168
|
} catch {
|
|
63169
|
+
return false;
|
|
63160
63170
|
}
|
|
63171
|
+
}
|
|
63172
|
+
async function ensureWorkspaceBinding(config, workspacePath, sessionId, cwd, tool) {
|
|
63173
|
+
if (config.workspaceBindings[workspacePath]?.projectName !== PENDING_BINDING_NAME) return;
|
|
63174
|
+
const hintMarker = hintMarkerPath("teamai-bind-session", sessionId || `ppid-${process.ppid}`);
|
|
63175
|
+
if (bindingHintMarkerFresh(hintMarker)) return;
|
|
63161
63176
|
let projects;
|
|
63162
63177
|
try {
|
|
63163
63178
|
projects = await fetchUserProjects(config, tool);
|
|
@@ -63184,6 +63199,10 @@ async function ensureWorkspaceBinding(config, workspacePath, sessionId, cwd, too
|
|
|
63184
63199
|
additionalContext: context
|
|
63185
63200
|
}
|
|
63186
63201
|
});
|
|
63202
|
+
try {
|
|
63203
|
+
fs35.writeFileSync(hintMarker, String(Date.now()));
|
|
63204
|
+
} catch {
|
|
63205
|
+
}
|
|
63187
63206
|
process.stdout.write(hookOutput + "\n");
|
|
63188
63207
|
}
|
|
63189
63208
|
function isBindPromptEnabled() {
|
|
@@ -63198,13 +63217,8 @@ function isBindPromptTool(tool) {
|
|
|
63198
63217
|
}
|
|
63199
63218
|
async function emitBindingHint(config, workspacePath, sessionId, tool) {
|
|
63200
63219
|
if (config.workspaceBindings[workspacePath]?.projectName !== PENDING_BINDING_NAME) return;
|
|
63201
|
-
const
|
|
63202
|
-
|
|
63203
|
-
if (fs35.existsSync(hintMarker)) return;
|
|
63204
|
-
try {
|
|
63205
|
-
fs35.writeFileSync(hintMarker, "");
|
|
63206
|
-
} catch {
|
|
63207
|
-
}
|
|
63220
|
+
const hintMarker = hintMarkerPath("teamai-bind-hint", sessionId || `ppid-${process.ppid}`);
|
|
63221
|
+
if (bindingHintMarkerFresh(hintMarker)) return;
|
|
63208
63222
|
let projects;
|
|
63209
63223
|
try {
|
|
63210
63224
|
projects = await fetchUserProjects(config, tool);
|
|
@@ -63235,25 +63249,29 @@ async function emitBindingHint(config, workspacePath, sessionId, tool) {
|
|
|
63235
63249
|
additionalContext: context
|
|
63236
63250
|
}
|
|
63237
63251
|
});
|
|
63238
|
-
process.stdout.write(hookOutput + "\n");
|
|
63239
|
-
}
|
|
63240
|
-
async function noticeUnenrolledWorkspace(workspacePath, event) {
|
|
63241
|
-
const markerKey = event?.sessionId || `ppid-${process.ppid}`;
|
|
63242
|
-
const marker = path76.join(os9.tmpdir(), `teamai-unenrolled-${markerKey}`);
|
|
63243
|
-
if (fs35.existsSync(marker)) return;
|
|
63244
63252
|
try {
|
|
63245
|
-
fs35.writeFileSync(
|
|
63253
|
+
fs35.writeFileSync(hintMarker, String(Date.now()));
|
|
63246
63254
|
} catch {
|
|
63247
63255
|
}
|
|
63248
|
-
|
|
63249
|
-
|
|
63250
|
-
|
|
63256
|
+
process.stdout.write(hookOutput + "\n");
|
|
63257
|
+
}
|
|
63258
|
+
function unenrolledNotice(context, workspacePath) {
|
|
63259
|
+
const marker = hintMarkerPath("teamai-unenrolled", context.event?.sessionId || `ppid-${process.ppid}`);
|
|
63260
|
+
if (bindingHintMarkerFresh(marker)) return;
|
|
63261
|
+
const text2 = [
|
|
63262
|
+
`[teamai] This workspace is not enrolled, so teamai reports and syncs nothing here: ${workspacePath}`,
|
|
63263
|
+
"Run `teamai bind-project` once in it to enroll \u2014 bind a ClawPro project, or `--skip` to enroll without one."
|
|
63264
|
+
].join("\n");
|
|
63251
63265
|
const hookOutput = JSON.stringify({
|
|
63252
63266
|
hookSpecificOutput: {
|
|
63253
|
-
hookEventName: event
|
|
63254
|
-
additionalContext:
|
|
63267
|
+
hookEventName: context.event?.type === "prompt_submit" ? "UserPromptSubmit" : "SessionStart",
|
|
63268
|
+
additionalContext: text2
|
|
63255
63269
|
}
|
|
63256
63270
|
});
|
|
63271
|
+
try {
|
|
63272
|
+
fs35.writeFileSync(marker, String(Date.now()));
|
|
63273
|
+
} catch {
|
|
63274
|
+
}
|
|
63257
63275
|
process.stdout.write(hookOutput + "\n");
|
|
63258
63276
|
}
|
|
63259
63277
|
function isEphemeralTaskDir(dir) {
|
|
@@ -65220,8 +65238,8 @@ async function syncLocalAgent(context) {
|
|
|
65220
65238
|
if (!config) return false;
|
|
65221
65239
|
const currentPath = await resolveWorkspacePath(context.cwd);
|
|
65222
65240
|
if (currentPath && !await enrollWorkspace(config, context.cwd, currentPath)) {
|
|
65223
|
-
if (isBindPromptEnabled()) await noticeUnenrolledWorkspace(currentPath, context.event);
|
|
65224
65241
|
log.debug(`[local-agent] workspace not enrolled, skipping: ${currentPath}`);
|
|
65242
|
+
if (isBindPromptEnabled()) unenrolledNotice(context, currentPath);
|
|
65225
65243
|
return false;
|
|
65226
65244
|
}
|
|
65227
65245
|
if (currentPath && isBindPromptEnabled() && isBindPromptTool(context.tool)) {
|
|
@@ -65435,8 +65453,11 @@ async function chooseAgentToken(existing2, agent, current, incoming) {
|
|
|
65435
65453
|
log.info(`Keeping the ${agent} access token already on this machine; the new one is not used.`);
|
|
65436
65454
|
return current;
|
|
65437
65455
|
}
|
|
65456
|
+
function isUserToken(token) {
|
|
65457
|
+
return token.startsWith("hk-");
|
|
65458
|
+
}
|
|
65438
65459
|
function legacyTokenAgent(config) {
|
|
65439
|
-
if (!config.token) return void 0;
|
|
65460
|
+
if (!config.token || isUserToken(config.token)) return void 0;
|
|
65440
65461
|
const agents = new Set(Object.values(config.workspaceBindings).map((binding) => binding.ideType).filter((t2) => Boolean(t2)).map(normalizeAgentType));
|
|
65441
65462
|
return agents.size === 1 ? [...agents][0] : void 0;
|
|
65442
65463
|
}
|
|
@@ -65448,14 +65469,15 @@ async function initLocalAgentHttp(options2) {
|
|
|
65448
65469
|
const existing2 = await loadLocalAgentConfig();
|
|
65449
65470
|
const token = options2.token?.trim() || void 0;
|
|
65450
65471
|
const sameEndpoint = existing2 !== null && normalizeEndpoint(existing2.endpoint) === endpoint;
|
|
65451
|
-
const
|
|
65472
|
+
const namedCount = options2.filterAgents?.length ?? 0;
|
|
65473
|
+
const namedAgent = namedCount === 1 ? normalizeAgentType(options2.filterAgents[0]) : void 0;
|
|
65452
65474
|
const held = sameEndpoint ? Object.keys(existing2?.agentTokens ?? {}) : [];
|
|
65453
|
-
const agent =
|
|
65454
|
-
const perAgent = Boolean(agent && token);
|
|
65475
|
+
const agent = namedAgent ?? (namedCount === 0 && token && !isUserToken(token) && held.length === 1 ? held[0] : void 0);
|
|
65476
|
+
const perAgent = Boolean(agent && token && !isUserToken(token));
|
|
65455
65477
|
if (existing2 && !options2.force && !(perAgent && sameEndpoint)) {
|
|
65456
65478
|
throw new Error("HTTP local agent is already initialized. Re-run with --force to overwrite.");
|
|
65457
65479
|
}
|
|
65458
|
-
if (token && !agent && (
|
|
65480
|
+
if (token && !agent && !isUserToken(token) && (namedCount > 1 || held.length > 1)) {
|
|
65459
65481
|
throw new Error(
|
|
65460
65482
|
`An access token works for one agent only. Re-run with --agent <tool> naming the agent it is for${held.length > 1 ? `; this machine already holds credentials for ${held.join(", ")}` : ""}.`
|
|
65461
65483
|
);
|
|
@@ -65470,6 +65492,10 @@ async function initLocalAgentHttp(options2) {
|
|
|
65470
65492
|
}
|
|
65471
65493
|
agentTokens[agent] = sameEndpoint ? await chooseAgentToken(existing2, agent, current, token) : token;
|
|
65472
65494
|
}
|
|
65495
|
+
if (perAgent && sharedToken && sameEndpoint && sharedToken !== token && await tokenStillWorks(existing2, sharedToken) === false) {
|
|
65496
|
+
log.warn("The shared access token on this machine no longer works, so the agents without a token of their own have none now. Re-run with `--agent <tool>` for each of them to install a new one.");
|
|
65497
|
+
sharedToken = void 0;
|
|
65498
|
+
}
|
|
65473
65499
|
const config = {
|
|
65474
65500
|
endpoint,
|
|
65475
65501
|
token: sharedToken,
|
|
@@ -65739,7 +65765,7 @@ async function bindCurrentProject(options2) {
|
|
|
65739
65765
|
log.info("\u672A\u7ED1\u5B9A\u9879\u76EE\u3002");
|
|
65740
65766
|
}
|
|
65741
65767
|
}
|
|
65742
|
-
var import_fs_extra9, execFileAsync2, LOCAL_AGENT_DIR, CONFIG_FILE, MANIFEST_FILE, MODEL_MANIFEST_FILE, REPORTER_ERROR_LOG, LOCAL_AGENT_FETCH_TIMEOUT_MS, LOCAL_AGENT_HOOK_FETCH_TIMEOUT_MS, activeFetchTimeoutMs, UNIMPLEMENTED_COMMAND_TYPES, IMPLEMENTED_HOOK_COMMAND_TYPES, PENDING_BINDING_NAME, DEFAULT_ROUTES, LOCK_HOLDER_ENV, WORKSPACE_CACHE_GITIGNORE, PLUGIN_PULL_INTERVAL_MS, PLUGIN_FAIL_BACKOFF_MS, ZIP_MAGIC, DEFAULT_MAX_TOKENS, MODEL_KEY_RERUN, TEAMAI_MODEL_GITIGNORE, VALID_MCP_TRANSPORTS;
|
|
65768
|
+
var import_fs_extra9, execFileAsync2, LOCAL_AGENT_DIR, CONFIG_FILE, MANIFEST_FILE, MODEL_MANIFEST_FILE, REPORTER_ERROR_LOG, LOCAL_AGENT_FETCH_TIMEOUT_MS, LOCAL_AGENT_HOOK_FETCH_TIMEOUT_MS, activeFetchTimeoutMs, UNIMPLEMENTED_COMMAND_TYPES, IMPLEMENTED_HOOK_COMMAND_TYPES, PENDING_BINDING_NAME, DEFAULT_ROUTES, LOCK_HOLDER_ENV, WORKSPACE_CACHE_GITIGNORE, PLUGIN_PULL_INTERVAL_MS, PLUGIN_FAIL_BACKOFF_MS, BINDING_MARKER_TTL_MS, ZIP_MAGIC, DEFAULT_MAX_TOKENS, MODEL_KEY_RERUN, TEAMAI_MODEL_GITIGNORE, VALID_MCP_TRANSPORTS;
|
|
65743
65769
|
var init_local_agent = __esm({
|
|
65744
65770
|
"src/local-agent.ts"() {
|
|
65745
65771
|
"use strict";
|
|
@@ -65799,6 +65825,7 @@ var init_local_agent = __esm({
|
|
|
65799
65825
|
WORKSPACE_CACHE_GITIGNORE = ["# teamai local state", "local-agent/", ""].join("\n");
|
|
65800
65826
|
PLUGIN_PULL_INTERVAL_MS = 12 * 60 * 60 * 1e3;
|
|
65801
65827
|
PLUGIN_FAIL_BACKOFF_MS = 60 * 60 * 1e3;
|
|
65828
|
+
BINDING_MARKER_TTL_MS = 10 * 60 * 1e3;
|
|
65802
65829
|
ZIP_MAGIC = Buffer.from([80, 75, 3, 4]);
|
|
65803
65830
|
DEFAULT_MAX_TOKENS = 4096;
|
|
65804
65831
|
MODEL_KEY_RERUN = "apply the model config again";
|
|
@@ -66946,14 +66973,21 @@ async function initHttp(url, options2) {
|
|
|
66946
66973
|
await runInitScript(localConfig2, "preInit", options2.dryRun);
|
|
66947
66974
|
await reconcileHooksForInit(teamConfig, localConfig2, filterAgents2);
|
|
66948
66975
|
const { initLocalAgentHttp: initLocalAgentHttp2 } = await Promise.resolve().then(() => (init_local_agent(), local_agent_exports));
|
|
66976
|
+
let localAgentFailed = false;
|
|
66949
66977
|
try {
|
|
66950
66978
|
await initLocalAgentHttp2({ endpoint: url, token: options2.token, force: options2.force, filterAgents: filterAgents2 });
|
|
66951
66979
|
} catch (e) {
|
|
66952
|
-
|
|
66980
|
+
localAgentFailed = true;
|
|
66981
|
+
process.exitCode = 1;
|
|
66982
|
+
log.error(`Local agent init: ${e.message}`);
|
|
66953
66983
|
}
|
|
66954
66984
|
await runInitScript(localConfig2, "postInit", options2.dryRun, true);
|
|
66955
|
-
|
|
66956
|
-
|
|
66985
|
+
if (localAgentFailed) {
|
|
66986
|
+
log.warn("teamai initialized (HTTP read-only) without the local agent: report/sync keeps the credentials this machine already had.");
|
|
66987
|
+
} else {
|
|
66988
|
+
log.success("teamai initialized (HTTP read-only)!");
|
|
66989
|
+
log.info("Skills/rules will auto-sync on each session start in an enrolled workspace via report/sync. This team is read-only (no push).");
|
|
66990
|
+
}
|
|
66957
66991
|
closePrompt();
|
|
66958
66992
|
}
|
|
66959
66993
|
async function reconcileHooksForInit(teamConfig, localConfig2, filterAgents2) {
|
|
@@ -108256,7 +108290,7 @@ async function sourceAddHttp(endpoint, options2) {
|
|
|
108256
108290
|
const agents = normalizeAgentList2(options2.agent);
|
|
108257
108291
|
await initLocalAgentHttp2({ endpoint: trimmed2, token: options2.token, force: true, filterAgents: agents.length > 0 ? agents : void 0 });
|
|
108258
108292
|
log.success(`HTTP source added (${trimmed2}).`);
|
|
108259
|
-
log.info("It will report/sync on the next AI session (via the hook-dispatch hook already installed).");
|
|
108293
|
+
log.info("It will report/sync on the next AI session in each workspace where `teamai bind-project` ran once (via the hook-dispatch hook already installed).");
|
|
108260
108294
|
}
|
|
108261
108295
|
async function sourceRemoveHttp(options2) {
|
|
108262
108296
|
if (options2.dryRun) {
|