aai-lark-bridge 0.2.53 → 0.2.55
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 +172 -22
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Command } from "commander";
|
|
|
4
4
|
// package.json
|
|
5
5
|
var package_default = {
|
|
6
6
|
name: "aai-lark-bridge",
|
|
7
|
-
version: "0.2.
|
|
7
|
+
version: "0.2.55",
|
|
8
8
|
description: "Lark AI Native Bridge - Lark\u57FA\u7840\u8BBE\u65BD\u5C42\u548CCLI\u96C6\u6210",
|
|
9
9
|
type: "module",
|
|
10
10
|
main: "./dist/index.js",
|
|
@@ -717,9 +717,9 @@ function normalizeLarkCli(input, agentKind) {
|
|
|
717
717
|
function normalizeClaudeSeat(input, agentKind) {
|
|
718
718
|
if (!input || typeof input !== "object" || Array.isArray(input)) return void 0;
|
|
719
719
|
const raw = input;
|
|
720
|
-
const mode = raw.mode === "list" || raw.mode === "all" ? raw.mode : "off";
|
|
720
|
+
const mode = raw.mode === "list" || raw.mode === "all" || raw.mode === "agent" ? raw.mode : "off";
|
|
721
721
|
const list = Array.isArray(raw.list) ? raw.list.filter((x) => typeof x === "string" && /^ou_[A-Za-z0-9_-]{1,100}$/.test(x)) : [];
|
|
722
|
-
if (mode === "off") return { mode, list, gatewayUrl: String(raw.gatewayUrl ?? ""), tokenCommand: String(raw.tokenCommand ?? "") };
|
|
722
|
+
if (mode === "off" || mode === "agent") return { mode, list, gatewayUrl: String(raw.gatewayUrl ?? ""), tokenCommand: String(raw.tokenCommand ?? "") };
|
|
723
723
|
if (agentKind !== "claude") throw new Error("larkCli.claudeSeat \u53EA\u652F\u6301 claude profile");
|
|
724
724
|
if (typeof raw.gatewayUrl !== "string" || !/^https?:\/\/[^\s]+$/.test(raw.gatewayUrl)) throw new Error("larkCli.claudeSeat.gatewayUrl \u8981\u662F http(s) \u5730\u5740");
|
|
725
725
|
if (typeof raw.tokenCommand !== "string" || !raw.tokenCommand.trim()) throw new Error("larkCli.claudeSeat.tokenCommand \u4E0D\u80FD\u4E3A\u7A7A");
|
|
@@ -7108,7 +7108,7 @@ import { randomBytes as randomBytes5 } from "crypto";
|
|
|
7108
7108
|
// src/bridge/user-gateway/claude-seat.ts
|
|
7109
7109
|
import { spawn } from "child_process";
|
|
7110
7110
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
7111
|
-
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "fs";
|
|
7111
|
+
import { existsSync as existsSync6, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
7112
7112
|
import { mkdir as mkdir13, mkdtemp, rm as rm11 } from "fs/promises";
|
|
7113
7113
|
import { tmpdir as tmpdir4 } from "os";
|
|
7114
7114
|
import { join as join19 } from "path";
|
|
@@ -7133,6 +7133,40 @@ function readCredentials(dir) {
|
|
|
7133
7133
|
return void 0;
|
|
7134
7134
|
}
|
|
7135
7135
|
}
|
|
7136
|
+
function forceExpire(dir, nowMs) {
|
|
7137
|
+
const f = join19(dir, ".credentials.json");
|
|
7138
|
+
const noop2 = () => {
|
|
7139
|
+
};
|
|
7140
|
+
let raw;
|
|
7141
|
+
let j;
|
|
7142
|
+
try {
|
|
7143
|
+
raw = readFileSync3(f, "utf8");
|
|
7144
|
+
j = JSON.parse(raw);
|
|
7145
|
+
} catch {
|
|
7146
|
+
return noop2;
|
|
7147
|
+
}
|
|
7148
|
+
const o = j.claudeAiOauth;
|
|
7149
|
+
if (!o || typeof o.expiresAt !== "number" || o.expiresAt <= nowMs) return noop2;
|
|
7150
|
+
const original = o.expiresAt;
|
|
7151
|
+
const forced = nowMs - 1e3;
|
|
7152
|
+
try {
|
|
7153
|
+
o.expiresAt = forced;
|
|
7154
|
+
writeFileSync3(f, JSON.stringify(j), { mode: 384 });
|
|
7155
|
+
} catch {
|
|
7156
|
+
return noop2;
|
|
7157
|
+
}
|
|
7158
|
+
return () => {
|
|
7159
|
+
try {
|
|
7160
|
+
const cur = JSON.parse(readFileSync3(f, "utf8"));
|
|
7161
|
+
const c = cur.claudeAiOauth;
|
|
7162
|
+
if (c && c.expiresAt === forced) {
|
|
7163
|
+
c.expiresAt = original;
|
|
7164
|
+
writeFileSync3(f, JSON.stringify(cur), { mode: 384 });
|
|
7165
|
+
}
|
|
7166
|
+
} catch {
|
|
7167
|
+
}
|
|
7168
|
+
};
|
|
7169
|
+
}
|
|
7136
7170
|
function covers(sw, openId) {
|
|
7137
7171
|
return sw.mode === "all" || sw.mode === "list" && sw.list.includes(openId);
|
|
7138
7172
|
}
|
|
@@ -7248,7 +7282,9 @@ function createClaudeSeat(opts) {
|
|
|
7248
7282
|
const recent = now() - (refreshedAt.get(openId) ?? -Infinity) < REFRESH_COOLDOWN_MS && c.expiresAt - now() >= MIN_AFTER_REFRESH_MS;
|
|
7249
7283
|
if (c.expiresAt - now() < MIN_TOKEN_LEFT_MS && !recent) {
|
|
7250
7284
|
const attempt = async (n) => {
|
|
7285
|
+
const restore = forceExpire(dir, now());
|
|
7251
7286
|
const r = normalizeRefresh(await opts.cli.refresh(dir).catch((err) => ({ ok: false, spawnError: scrubOutput(String(err)) })));
|
|
7287
|
+
restore();
|
|
7252
7288
|
const cur = readCredentials(dir);
|
|
7253
7289
|
const left = cur ? cur.expiresAt - now() : 0;
|
|
7254
7290
|
const good = r.ok && !!cur && left >= MIN_AFTER_REFRESH_MS;
|
|
@@ -7348,7 +7384,7 @@ function createClaudeSeat(opts) {
|
|
|
7348
7384
|
}
|
|
7349
7385
|
function seatFromEnv(env) {
|
|
7350
7386
|
const raw = (env.SDLC_CLAUDE_SEAT ?? "off").trim();
|
|
7351
|
-
const mode = raw === "list" || raw === "all" ? raw : "off";
|
|
7387
|
+
const mode = raw === "list" || raw === "all" || raw === "agent" ? raw : "off";
|
|
7352
7388
|
const list = (env.SDLC_CLAUDE_SEAT_LIST ?? "").split(",").map((s) => s.trim()).filter((s) => /^ou_[A-Za-z0-9_-]{1,100}$/.test(s));
|
|
7353
7389
|
return { mode, list };
|
|
7354
7390
|
}
|
|
@@ -7655,6 +7691,9 @@ function seatCovers(cfg, senderId) {
|
|
|
7655
7691
|
if (!cfg || !senderId) return false;
|
|
7656
7692
|
return cfg.mode === "all" || cfg.mode === "list" && cfg.list.includes(senderId);
|
|
7657
7693
|
}
|
|
7694
|
+
function isAgentSeat(cfg) {
|
|
7695
|
+
return cfg?.mode === "agent";
|
|
7696
|
+
}
|
|
7658
7697
|
function isClaudeLogout(text) {
|
|
7659
7698
|
return text.trim() === LOGOUT_TEXT;
|
|
7660
7699
|
}
|
|
@@ -7738,6 +7777,106 @@ async function submitClaudeLogin(cfg, sub, deps = {}) {
|
|
|
7738
7777
|
}
|
|
7739
7778
|
}
|
|
7740
7779
|
|
|
7780
|
+
// src/bridge/bot/claude-quota.ts
|
|
7781
|
+
var TZ_OFFSET_MS = 7 * 60 * 6e4;
|
|
7782
|
+
var DAY_MS = 24 * 60 * 6e4;
|
|
7783
|
+
var QUOTA_FALLBACK_MS = 30 * 6e4;
|
|
7784
|
+
var WEEKDAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
7785
|
+
var MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
7786
|
+
var CN_WEEKDAYS = ["\u5468\u65E5", "\u5468\u4E00", "\u5468\u4E8C", "\u5468\u4E09", "\u5468\u56DB", "\u5468\u4E94", "\u5468\u516D"];
|
|
7787
|
+
var HIT_RE = /hit your (?:[A-Za-z0-9.+-]+ )*limit\b([^\n]*)/i;
|
|
7788
|
+
var TIME_RE = /^(\d{1,2})(?::(\d{2}))?\s*(am|pm)?\b/i;
|
|
7789
|
+
function detectQuota(text, now = /* @__PURE__ */ new Date()) {
|
|
7790
|
+
const m = HIT_RE.exec(text);
|
|
7791
|
+
if (!m) return void 0;
|
|
7792
|
+
const rest = m[1] ?? "";
|
|
7793
|
+
const r = /\bresets\s+(.+)$/i.exec(rest);
|
|
7794
|
+
const at = r ? parseReset(r[1].trim(), now.getTime()) : void 0;
|
|
7795
|
+
return at === void 0 ? { resumeAt: new Date(now.getTime() + QUOTA_FALLBACK_MS), fallback: true } : { resumeAt: new Date(at), fallback: false };
|
|
7796
|
+
}
|
|
7797
|
+
function parseReset(raw, nowMs) {
|
|
7798
|
+
let s = raw;
|
|
7799
|
+
let weekday;
|
|
7800
|
+
let monthDay;
|
|
7801
|
+
const wd = /^([A-Za-z]{3})[a-z]*\.?,?\s+/.exec(s);
|
|
7802
|
+
if (wd) {
|
|
7803
|
+
const key = wd[1].toLowerCase();
|
|
7804
|
+
const w = WEEKDAYS.indexOf(key);
|
|
7805
|
+
const mo = MONTHS.indexOf(key);
|
|
7806
|
+
if (w >= 0) {
|
|
7807
|
+
weekday = w;
|
|
7808
|
+
s = s.slice(wd[0].length);
|
|
7809
|
+
} else if (mo >= 0) {
|
|
7810
|
+
const d = /^(\d{1,2}),?\s+/.exec(s.slice(wd[0].length));
|
|
7811
|
+
if (!d) return void 0;
|
|
7812
|
+
monthDay = { month: mo, day: Number(d[1]) };
|
|
7813
|
+
s = s.slice(wd[0].length + d[0].length);
|
|
7814
|
+
} else {
|
|
7815
|
+
return void 0;
|
|
7816
|
+
}
|
|
7817
|
+
}
|
|
7818
|
+
const t = TIME_RE.exec(s);
|
|
7819
|
+
if (!t) return void 0;
|
|
7820
|
+
let hour = Number(t[1]);
|
|
7821
|
+
const minute = t[2] === void 0 ? 0 : Number(t[2]);
|
|
7822
|
+
const ampm = t[3]?.toLowerCase();
|
|
7823
|
+
if (!ampm && t[2] === void 0) return void 0;
|
|
7824
|
+
if (minute > 59) return void 0;
|
|
7825
|
+
if (ampm) {
|
|
7826
|
+
if (hour < 1 || hour > 12) return void 0;
|
|
7827
|
+
hour = hour % 12 + (ampm === "pm" ? 12 : 0);
|
|
7828
|
+
} else if (hour > 23) {
|
|
7829
|
+
return void 0;
|
|
7830
|
+
}
|
|
7831
|
+
const local = new Date(nowMs + TZ_OFFSET_MS);
|
|
7832
|
+
const localMidnight = Date.UTC(local.getUTCFullYear(), local.getUTCMonth(), local.getUTCDate());
|
|
7833
|
+
const clock = (hour * 60 + minute) * 6e4;
|
|
7834
|
+
const nowLocal = nowMs + TZ_OFFSET_MS;
|
|
7835
|
+
let atLocal;
|
|
7836
|
+
if (monthDay) {
|
|
7837
|
+
atLocal = Date.UTC(local.getUTCFullYear(), monthDay.month, monthDay.day) + clock;
|
|
7838
|
+
if (atLocal <= nowLocal) atLocal = Date.UTC(local.getUTCFullYear() + 1, monthDay.month, monthDay.day) + clock;
|
|
7839
|
+
} else if (weekday !== void 0) {
|
|
7840
|
+
const diff = (weekday - local.getUTCDay() + 7) % 7;
|
|
7841
|
+
atLocal = localMidnight + diff * DAY_MS + clock;
|
|
7842
|
+
if (atLocal <= nowLocal) atLocal += 7 * DAY_MS;
|
|
7843
|
+
} else {
|
|
7844
|
+
atLocal = localMidnight + clock;
|
|
7845
|
+
if (atLocal <= nowLocal) atLocal += DAY_MS;
|
|
7846
|
+
}
|
|
7847
|
+
return atLocal - TZ_OFFSET_MS;
|
|
7848
|
+
}
|
|
7849
|
+
function formatResume(at) {
|
|
7850
|
+
const local = new Date(at.getTime() + TZ_OFFSET_MS);
|
|
7851
|
+
const hh = String(local.getUTCHours()).padStart(2, "0");
|
|
7852
|
+
const mm = String(local.getUTCMinutes()).padStart(2, "0");
|
|
7853
|
+
return `${CN_WEEKDAYS[local.getUTCDay()]} ${hh}:${mm}`;
|
|
7854
|
+
}
|
|
7855
|
+
function quotaReply(at) {
|
|
7856
|
+
return `Claude \u989D\u5EA6\u7528\u5B8C\uFF0C\u7EA6 ${formatResume(at)} \u6062\u590D\uFF0C\u5230\u65F6\u518D\u95EE\u6211`;
|
|
7857
|
+
}
|
|
7858
|
+
var PROXY_DOWN_EXIT = 76;
|
|
7859
|
+
var PROXY_DOWN_REPLY = "Claude \u6682\u65F6\u8FDE\u4E0D\u4E0A\uFF0C\u5DF2\u901A\u77E5\u7EF4\u62A4\u4EBA";
|
|
7860
|
+
function isProxyDownExit(errorMsg) {
|
|
7861
|
+
return !!errorMsg && new RegExp(`^claude exited with code ${PROXY_DOWN_EXIT}\\b`).test(errorMsg);
|
|
7862
|
+
}
|
|
7863
|
+
function agentSeatNotice(state, now = /* @__PURE__ */ new Date()) {
|
|
7864
|
+
if (state.terminal === "error") {
|
|
7865
|
+
if (isProxyDownExit(state.errorMsg)) return PROXY_DOWN_REPLY;
|
|
7866
|
+
const hit = detectQuota([state.errorMsg ?? "", state.finalText ?? ""].join("\n"), now);
|
|
7867
|
+
return hit ? quotaReply(hit.resumeAt) : void 0;
|
|
7868
|
+
}
|
|
7869
|
+
if (state.terminal === "done" && state.finalText && state.finalText.trim().length <= 300) {
|
|
7870
|
+
const hit = detectQuota(state.finalText, now);
|
|
7871
|
+
return hit ? quotaReply(hit.resumeAt) : void 0;
|
|
7872
|
+
}
|
|
7873
|
+
return void 0;
|
|
7874
|
+
}
|
|
7875
|
+
function withNotice(state, text) {
|
|
7876
|
+
const { errorMsg: _e, apiError: _a, authError: _u, budgetHit: _b, budgetUsd: _bu, ...rest } = state;
|
|
7877
|
+
return { ...rest, terminal: "done", footer: null, finalText: text, blocks: [{ kind: "text", content: text, streaming: false }] };
|
|
7878
|
+
}
|
|
7879
|
+
|
|
7741
7880
|
// src/bridge/bot/channel.ts
|
|
7742
7881
|
import { dirname as dirname19, join as join30 } from "path";
|
|
7743
7882
|
|
|
@@ -7819,7 +7958,7 @@ function modelLabel(agentKind, value) {
|
|
|
7819
7958
|
// src/bridge/bot/router.ts
|
|
7820
7959
|
import { spawn as spawn2 } from "child_process";
|
|
7821
7960
|
import { randomBytes as randomBytes6 } from "crypto";
|
|
7822
|
-
import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as
|
|
7961
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
7823
7962
|
import { isAbsolute as isAbsolute2, join as join20 } from "path";
|
|
7824
7963
|
var SAFE = /^[A-Za-z0-9_.:@+-]{1,200}$/;
|
|
7825
7964
|
var ROUTER_TIMEOUT_MS = 6e4;
|
|
@@ -7934,7 +8073,7 @@ function writePending(workspace, pending) {
|
|
|
7934
8073
|
const dir = join20(stateDir(workspace), "route-pending");
|
|
7935
8074
|
mkdirSync3(dir, { recursive: true, mode: 448 });
|
|
7936
8075
|
const f = join20(dir, `${pending.nonce}.json`);
|
|
7937
|
-
|
|
8076
|
+
writeFileSync4(`${f}.new`, JSON.stringify(pending), { mode: 384 });
|
|
7938
8077
|
renameSync2(`${f}.new`, f);
|
|
7939
8078
|
return true;
|
|
7940
8079
|
}
|
|
@@ -8013,7 +8152,7 @@ import {
|
|
|
8013
8152
|
rmSync as rmSync2,
|
|
8014
8153
|
statSync,
|
|
8015
8154
|
unlinkSync as unlinkSync2,
|
|
8016
|
-
writeFileSync as
|
|
8155
|
+
writeFileSync as writeFileSync5
|
|
8017
8156
|
} from "fs";
|
|
8018
8157
|
import { basename as basename5, dirname as dirname14, isAbsolute as isAbsolute3, join as join21, sep as sep2 } from "path";
|
|
8019
8158
|
var BINDING_VERSION = 1;
|
|
@@ -8132,7 +8271,7 @@ function registerDispatchRoot(dir, rootMessageId, chatId, now = /* @__PURE__ */
|
|
|
8132
8271
|
const file = join21(folder, `${rootMessageId}.json`);
|
|
8133
8272
|
if (existsSync8(file)) return;
|
|
8134
8273
|
const tmp = `${file}.${randomBytes7(4).toString("hex")}.tmp`;
|
|
8135
|
-
|
|
8274
|
+
writeFileSync5(tmp, `${JSON.stringify({ chat_id: chatId, at: now.toISOString() })}
|
|
8136
8275
|
`);
|
|
8137
8276
|
renameSync3(tmp, file);
|
|
8138
8277
|
pruneDispatchRoots(folder, now);
|
|
@@ -8211,7 +8350,7 @@ function switchToTask(rawConfig, chatId, senderOpenId, taskId, { messageId = nul
|
|
|
8211
8350
|
if (from) queue.unshift(from);
|
|
8212
8351
|
const next = { ...doc, active: item, queue, updated_at: now.toISOString() };
|
|
8213
8352
|
const tmp = `${file}.new-${process.pid}`;
|
|
8214
|
-
|
|
8353
|
+
writeFileSync5(tmp, JSON.stringify(next, null, 2), { mode: 384 });
|
|
8215
8354
|
renameSync3(tmp, file);
|
|
8216
8355
|
return { from: from?.task_id ?? null, to: taskId };
|
|
8217
8356
|
});
|
|
@@ -8222,7 +8361,7 @@ function switchToTask(rawConfig, chatId, senderOpenId, taskId, { messageId = nul
|
|
|
8222
8361
|
const eventsDir = join21(cfg.dir, "events");
|
|
8223
8362
|
mkdirSync4(eventsDir, { recursive: true });
|
|
8224
8363
|
const tmp = join21(eventsDir, `.${randomBytes7(6).toString("hex")}.tmp`);
|
|
8225
|
-
|
|
8364
|
+
writeFileSync5(tmp, JSON.stringify(event));
|
|
8226
8365
|
renameSync3(tmp, join21(eventsDir, `switch-${now.getTime()}-${randomBytes7(4).toString("hex")}.json`));
|
|
8227
8366
|
eventWritten = true;
|
|
8228
8367
|
} catch {
|
|
@@ -8265,7 +8404,7 @@ function writeBudgetHitEvent(dir, event) {
|
|
|
8265
8404
|
return false;
|
|
8266
8405
|
}
|
|
8267
8406
|
const tmp = join21(eventsDir, `.${randomBytes7(6).toString("hex")}.tmp`);
|
|
8268
|
-
|
|
8407
|
+
writeFileSync5(tmp, JSON.stringify(event));
|
|
8269
8408
|
try {
|
|
8270
8409
|
linkSync(tmp, file);
|
|
8271
8410
|
return true;
|
|
@@ -8320,7 +8459,7 @@ function dropTaskEvent(workspace, taskId, event, route3) {
|
|
|
8320
8459
|
const key = createHash2("sha256").update(`${taskId}\0${event.id}`).digest("hex").slice(0, 32);
|
|
8321
8460
|
const target = join21(inbox, `${key}.json`);
|
|
8322
8461
|
const tmp = `${target}.new-${process.pid}`;
|
|
8323
|
-
|
|
8462
|
+
writeFileSync5(tmp, JSON.stringify({ task_id: taskId, event, ...route3 ? { route: route3 } : {} }), { mode: 384 });
|
|
8324
8463
|
renameSync3(tmp, target);
|
|
8325
8464
|
return true;
|
|
8326
8465
|
}
|
|
@@ -8365,7 +8504,7 @@ function taskRunHooks(input) {
|
|
|
8365
8504
|
|
|
8366
8505
|
// src/bridge/binding/awaiting.ts
|
|
8367
8506
|
import { createHash as createHash3 } from "crypto";
|
|
8368
|
-
import { existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync6, renameSync as renameSync4, rmSync as rmSync3, writeFileSync as
|
|
8507
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync6, renameSync as renameSync4, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "fs";
|
|
8369
8508
|
import { join as join22 } from "path";
|
|
8370
8509
|
var AWAITING_TTL_MS = 24 * 36e5;
|
|
8371
8510
|
var DECISION_SHOW_MAX = 200;
|
|
@@ -8400,7 +8539,7 @@ function submitDecision(dir, handoffDir, a, msg) {
|
|
|
8400
8539
|
const file = join22(handoffDir, name);
|
|
8401
8540
|
if (!existsSync9(file)) {
|
|
8402
8541
|
const tmp = join22(handoffDir, `.${name}.${process.pid}.tmp`);
|
|
8403
|
-
|
|
8542
|
+
writeFileSync6(
|
|
8404
8543
|
tmp,
|
|
8405
8544
|
JSON.stringify({
|
|
8406
8545
|
event_id: "",
|
|
@@ -13043,7 +13182,7 @@ async function lookupMessageRoot(channel, messageId) {
|
|
|
13043
13182
|
|
|
13044
13183
|
// src/bridge/card/handoff.ts
|
|
13045
13184
|
import { createHash as createHash5 } from "crypto";
|
|
13046
|
-
import { existsSync as existsSync10, mkdirSync as mkdirSync6, renameSync as renameSync5, writeFileSync as
|
|
13185
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync6, renameSync as renameSync5, writeFileSync as writeFileSync7 } from "fs";
|
|
13047
13186
|
import { isAbsolute as isAbsolute5, join as join25 } from "path";
|
|
13048
13187
|
function handoffDirs(raw) {
|
|
13049
13188
|
if (!raw || typeof raw !== "object") return {};
|
|
@@ -13072,7 +13211,7 @@ function tryHandoff(evt, dirs) {
|
|
|
13072
13211
|
const file = join25(dir, name);
|
|
13073
13212
|
if (existsSync10(file)) return true;
|
|
13074
13213
|
const tmp = join25(dir, `.${name}.${process.pid}.tmp`);
|
|
13075
|
-
|
|
13214
|
+
writeFileSync7(
|
|
13076
13215
|
tmp,
|
|
13077
13216
|
JSON.stringify({
|
|
13078
13217
|
event_id: eventId,
|
|
@@ -14864,7 +15003,7 @@ function preview(text) {
|
|
|
14864
15003
|
|
|
14865
15004
|
// src/bridge/bot/doc-confirmation.ts
|
|
14866
15005
|
import { createHash as createHash8 } from "crypto";
|
|
14867
|
-
import { mkdirSync as mkdirSync7, realpathSync as realpathSync2, renameSync as renameSync6, writeFileSync as
|
|
15006
|
+
import { mkdirSync as mkdirSync7, realpathSync as realpathSync2, renameSync as renameSync6, writeFileSync as writeFileSync8 } from "fs";
|
|
14868
15007
|
import { isAbsolute as isAbsolute6, join as join27, sep as sep3 } from "path";
|
|
14869
15008
|
import { spawn as spawn3 } from "child_process";
|
|
14870
15009
|
var waking = /* @__PURE__ */ new Set();
|
|
@@ -14884,7 +15023,7 @@ function enqueueDocConfirmation(workspace, event, { selfReply = false } = {}) {
|
|
|
14884
15023
|
const key = createHash8("sha256").update(JSON.stringify([hint.file_token, hint.comment_id, hint.reply_id])).digest("hex");
|
|
14885
15024
|
const target = join27(inbox, key + ".json");
|
|
14886
15025
|
const tmp = target + `.new-${process.pid}`;
|
|
14887
|
-
|
|
15026
|
+
writeFileSync8(tmp, JSON.stringify(hint), { mode: 384 });
|
|
14888
15027
|
renameSync6(tmp, target);
|
|
14889
15028
|
if (!waking.has(root)) {
|
|
14890
15029
|
waking.add(root);
|
|
@@ -17276,6 +17415,7 @@ async function runAgentBatchInner(deps) {
|
|
|
17276
17415
|
...threadId && !workerScope ? { threadId } : {}
|
|
17277
17416
|
};
|
|
17278
17417
|
const capability = controls.profileConfig.agentKind === "codex" ? codexCapability(controls.profileConfig) : claudeCapability(controls.profileConfig);
|
|
17418
|
+
const agentSeat = controls.profileConfig.agentKind === "claude" && isAgentSeat(controls.profileConfig.larkCli.claudeSeat);
|
|
17279
17419
|
const flow = await startRunFlow({
|
|
17280
17420
|
scopeId: scope,
|
|
17281
17421
|
scope: scopeContext,
|
|
@@ -17302,7 +17442,7 @@ async function runAgentBatchInner(deps) {
|
|
|
17302
17442
|
now: Date.now(),
|
|
17303
17443
|
stopGraceMs: getAgentStopGraceMs(controls.cfg),
|
|
17304
17444
|
...binding && taskPlan?.ok ? { task: { binding, maxBudgetUsd: taskPlan.maxBudgetUsd } } : {},
|
|
17305
|
-
...deps.userRead?.extraEnv || deps.claudeEnv || firstMsg.chatType === "p2p" ? { extraEnv: { ...deps.claudeEnv, ...deps.userRead?.extraEnv, ...firstMsg.chatType === "p2p" ? { SDLC_DM_CHAT: chatId } : {}, ...firstMsg.chatType === "p2p" && scope === chatId ? { SDLC_DM_MSG: lastMsg.messageId } : {} } } : {},
|
|
17445
|
+
...deps.userRead?.extraEnv || deps.claudeEnv || firstMsg.chatType === "p2p" || agentSeat ? { extraEnv: { ...deps.claudeEnv, ...deps.userRead?.extraEnv, ...firstMsg.chatType === "p2p" ? { SDLC_DM_CHAT: chatId } : {}, ...firstMsg.chatType === "p2p" && scope === chatId ? { SDLC_DM_MSG: lastMsg.messageId } : {}, ...agentSeat ? { SDLC_USAGE_SCENE: firstMsg.chatType === "p2p" ? "dm" : "group" } : {} } } : {},
|
|
17306
17446
|
observability: {
|
|
17307
17447
|
profile: controls.profile,
|
|
17308
17448
|
agent: capability.agentId,
|
|
@@ -17399,6 +17539,14 @@ async function runAgentBatchInner(deps) {
|
|
|
17399
17539
|
recordSession.costDelta = (total) => runSessionId ? sessionCatalog.recordCost({ scopeId: scope, agentId: "claude", cwdRealpath: runCwd, policyFingerprint: flow.policy.policyFingerprint, sessionId: runSessionId }, total) : total;
|
|
17400
17540
|
}
|
|
17401
17541
|
const startState = binding ? { ...initialState, task: { footer: taskFooterLine(binding) } } : initialState;
|
|
17542
|
+
if (agentSeat) {
|
|
17543
|
+
recordSession.onTerminal = (state) => {
|
|
17544
|
+
const notice = agentSeatNotice(state);
|
|
17545
|
+
if (!notice) return state;
|
|
17546
|
+
log.info("agent", "seat-notice", { scope, terminal: state.terminal, notice });
|
|
17547
|
+
return withNotice(state, notice);
|
|
17548
|
+
};
|
|
17549
|
+
}
|
|
17402
17550
|
if (binding) {
|
|
17403
17551
|
const hooks = taskRunHooks({
|
|
17404
17552
|
binding,
|
|
@@ -17999,6 +18147,7 @@ async function processAgentStream(handle2, events, scope, idleTimeoutMs, recordS
|
|
|
17999
18147
|
if (state.budgetHit && !state.task?.budgetNote && recordSession.onBudgetHit) {
|
|
18000
18148
|
state = recordSession.onBudgetHit(state);
|
|
18001
18149
|
}
|
|
18150
|
+
if (state.terminal !== "running" && recordSession.onTerminal) state = recordSession.onTerminal(state);
|
|
18002
18151
|
if (state.footer !== prevFooter || state.terminal !== prevTerminal) {
|
|
18003
18152
|
log.info("card", "transition", { footer: state.footer, terminal: state.terminal });
|
|
18004
18153
|
}
|
|
@@ -18016,6 +18165,7 @@ async function processAgentStream(handle2, events, scope, idleTimeoutMs, recordS
|
|
|
18016
18165
|
} else {
|
|
18017
18166
|
state = finalizeIfRunning(state);
|
|
18018
18167
|
}
|
|
18168
|
+
if (recordSession.onTerminal) state = recordSession.onTerminal(state);
|
|
18019
18169
|
}
|
|
18020
18170
|
log.info("card", "final", { scope, terminal: state.terminal, interrupted: handle2.interrupted });
|
|
18021
18171
|
reportMetric("run_e2e_ms", Date.now() - runStart2, { terminal: state.terminal });
|
|
@@ -20544,7 +20694,7 @@ function toResult(r) {
|
|
|
20544
20694
|
|
|
20545
20695
|
// src/bridge/user-gateway/gateway.ts
|
|
20546
20696
|
import { createHash as createHash9, randomBytes as randomBytes11 } from "crypto";
|
|
20547
|
-
import { existsSync as existsSync12, readFileSync as readFileSync9, renameSync as renameSync7, rmSync as rmSync5, writeFileSync as
|
|
20697
|
+
import { existsSync as existsSync12, readFileSync as readFileSync9, renameSync as renameSync7, rmSync as rmSync5, writeFileSync as writeFileSync9 } from "fs";
|
|
20548
20698
|
import { mkdir as mkdir19, readdir as readdir6, readFile as readFileFs, rm as rm14, stat as stat8, writeFile as writeFile9 } from "fs/promises";
|
|
20549
20699
|
import { join as join31 } from "path";
|
|
20550
20700
|
|
|
@@ -21362,7 +21512,7 @@ function createGateway(opts) {
|
|
|
21362
21512
|
function saveProofState() {
|
|
21363
21513
|
const tmp = `${holdsFile}.${process.pid}.tmp`;
|
|
21364
21514
|
try {
|
|
21365
|
-
|
|
21515
|
+
writeFileSync9(tmp, JSON.stringify({ holds: Object.fromEntries(holds), used: Object.fromEntries(used) }), { mode: 384 });
|
|
21366
21516
|
renameSync7(tmp, holdsFile);
|
|
21367
21517
|
} catch (err) {
|
|
21368
21518
|
log.warn("user-gateway", "proof-state.write-failed", { detail: String(err) });
|