jitda-agent 0.1.0 → 0.1.1
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/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/dist/server.mjs +74 -4
- package/package.json +1 -1
package/dist/server.mjs
CHANGED
|
@@ -37400,6 +37400,7 @@ function workspaceFromResponse(body) {
|
|
|
37400
37400
|
workspace_id: String(doc?.data?.id ?? ""),
|
|
37401
37401
|
token: doc?.data?.attributes?.token ?? null,
|
|
37402
37402
|
profile_name: profile?.attributes?.name ?? null,
|
|
37403
|
+
profile_id: profile?.id ? String(profile.id) : null,
|
|
37403
37404
|
hackathon_id: hackathon?.id ?? null,
|
|
37404
37405
|
hackathon_name: hackathon?.attributes?.name ?? null,
|
|
37405
37406
|
team_name: team && !team.attributes?.is_personal ? team.attributes?.name ?? null : null
|
|
@@ -37608,6 +37609,50 @@ function publish(file2, entries) {
|
|
|
37608
37609
|
fs6.writeFileSync(tmp, toLines(entries));
|
|
37609
37610
|
fs6.renameSync(tmp, file2);
|
|
37610
37611
|
}
|
|
37612
|
+
function readDestinationMeta(dir) {
|
|
37613
|
+
try {
|
|
37614
|
+
return JSON.parse(fs6.readFileSync(path5.join(dir, "destination.json"), "utf8"));
|
|
37615
|
+
} catch {
|
|
37616
|
+
return null;
|
|
37617
|
+
}
|
|
37618
|
+
}
|
|
37619
|
+
function writeDestinationMeta(fp, dest, meta3) {
|
|
37620
|
+
const dir = outboxDir(fp, dest);
|
|
37621
|
+
const current = readDestinationMeta(dir);
|
|
37622
|
+
if (current && (current.profile_id || !meta3.profile_id)) return;
|
|
37623
|
+
fs6.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
37624
|
+
const file2 = path5.join(dir, "destination.json");
|
|
37625
|
+
const tmp = `${file2}.${process.pid}-${crypto4.randomBytes(4).toString("hex")}.tmp`;
|
|
37626
|
+
fs6.writeFileSync(tmp, JSON.stringify(meta3));
|
|
37627
|
+
fs6.renameSync(tmp, file2);
|
|
37628
|
+
}
|
|
37629
|
+
function adoptPending(fp, dest, match) {
|
|
37630
|
+
const root = path5.join(folderDir(fp), "outbox");
|
|
37631
|
+
let moved = 0;
|
|
37632
|
+
for (const other of listDir(root)) {
|
|
37633
|
+
if (other === dest) continue;
|
|
37634
|
+
const dir = path5.join(root, other);
|
|
37635
|
+
const meta3 = readDestinationMeta(dir);
|
|
37636
|
+
if (!meta3 || !match(meta3)) continue;
|
|
37637
|
+
for (const name of listDir(dir)) {
|
|
37638
|
+
const isSending = name.endsWith(".sending");
|
|
37639
|
+
if (!name.endsWith(".jsonl") && !isSending) continue;
|
|
37640
|
+
const file2 = path5.join(dir, name);
|
|
37641
|
+
try {
|
|
37642
|
+
if (isSending && Date.now() - fs6.statSync(file2).mtimeMs < STALE_SENDING_MS) continue;
|
|
37643
|
+
const original = isSending ? `${name.split(".jsonl.")[0]}.jsonl` : name;
|
|
37644
|
+
const count = countEntries(file2);
|
|
37645
|
+
fs6.mkdirSync(outboxDir(fp, dest), { recursive: true, mode: 448 });
|
|
37646
|
+
let target = path5.join(outboxDir(fp, dest), original);
|
|
37647
|
+
if (fs6.existsSync(target)) target = target.replace(/\.jsonl$/, `-${crypto4.randomBytes(4).toString("hex")}.jsonl`);
|
|
37648
|
+
fs6.renameSync(file2, target);
|
|
37649
|
+
moved += count;
|
|
37650
|
+
} catch {
|
|
37651
|
+
}
|
|
37652
|
+
}
|
|
37653
|
+
}
|
|
37654
|
+
return moved;
|
|
37655
|
+
}
|
|
37611
37656
|
function appendOutbox(fp, dest, entries) {
|
|
37612
37657
|
if (!entries.length) return;
|
|
37613
37658
|
const name = `${Date.now().toString().padStart(15, "0")}-${process.pid}-${crypto4.randomBytes(4).toString("hex")}.jsonl`;
|
|
@@ -37831,10 +37876,10 @@ var Recorder = class {
|
|
|
37831
37876
|
return { status: "login_required", message, notice: late2 ?? message };
|
|
37832
37877
|
}
|
|
37833
37878
|
if (!outcome.done) this.scheduleDrain(fp, agent, input2.session_id);
|
|
37834
|
-
if (input2.hook_event_name === "SessionEnd") {
|
|
37835
|
-
await Promise.race([this.
|
|
37879
|
+
if (input2.hook_event_name === "SessionEnd" || input2.hook_event_name === "Stop") {
|
|
37880
|
+
await Promise.race([this.flushFinal(fp), sleep(FINAL_FLUSH_MS)]);
|
|
37836
37881
|
} else {
|
|
37837
|
-
this.scheduleFlush(fp,
|
|
37882
|
+
this.scheduleFlush(fp, 1e3);
|
|
37838
37883
|
}
|
|
37839
37884
|
return late2 ? { status: "queued", queued: outcome.queued, notice: late2 } : { status: "queued", queued: outcome.queued };
|
|
37840
37885
|
}
|
|
@@ -37856,9 +37901,11 @@ var Recorder = class {
|
|
|
37856
37901
|
if (hook) events.push(hook);
|
|
37857
37902
|
if (events.length) {
|
|
37858
37903
|
const session = { external_session_id: state.session_id, started_at: state.started_at, cwd: state.cwd };
|
|
37904
|
+
const dest = destinationKey(credential);
|
|
37905
|
+
writeDestinationMeta(fp, dest, { api_url: credential.api_url, hackathon_id: credential.hackathon_id, profile_id: credential.profile_id ?? null });
|
|
37859
37906
|
appendOutbox(
|
|
37860
37907
|
fp,
|
|
37861
|
-
|
|
37908
|
+
dest,
|
|
37862
37909
|
events.map((event) => ({ agent: state.agent, session, event: { ...event, seq: ++state.seq } }))
|
|
37863
37910
|
);
|
|
37864
37911
|
}
|
|
@@ -37945,6 +37992,27 @@ var Recorder = class {
|
|
|
37945
37992
|
}, delayMs);
|
|
37946
37993
|
runtime.timer.unref();
|
|
37947
37994
|
}
|
|
37995
|
+
/**
|
|
37996
|
+
* 턴 끝에 쓰는 전송. 이미 다른 전송이 돌고 있으면 flush() 는 그 전송(방금 쌓은 이벤트가 빠진)을 돌려주므로,
|
|
37997
|
+
* 끝난 뒤 남은 것이 있으면 다시 보낸다. 실패·인증 문제·다른 프로세스가 보내는 중이면 멈춘다.
|
|
37998
|
+
*/
|
|
37999
|
+
async flushFinal(fp) {
|
|
38000
|
+
for (let i = 0; i < 3; i++) {
|
|
38001
|
+
const result = await this.flush(fp);
|
|
38002
|
+
if (!result || result.retryable || result.unauthorized || result.busy || !result.remaining) return;
|
|
38003
|
+
}
|
|
38004
|
+
}
|
|
38005
|
+
/** 같은 사람·해커톤·서버의 이전 등록에 남은 기록을 지금 목적지로 옮긴다. 옮긴 수를 돌려준다. */
|
|
38006
|
+
adoptForCredential(fp, credential) {
|
|
38007
|
+
const adopted = adoptPending(
|
|
38008
|
+
fp,
|
|
38009
|
+
destinationKey(credential),
|
|
38010
|
+
(meta3) => meta3.api_url === credential.api_url && meta3.hackathon_id === credential.hackathon_id && !!meta3.profile_id && meta3.profile_id === credential.profile_id
|
|
38011
|
+
);
|
|
38012
|
+
if (adopted) process.stderr.write(`[jitda] \uC774\uC804 \uB4F1\uB85D\uC5D0 \uB0A8\uC740 \uAE30\uB85D ${adopted}\uAC74\uC744 \uC774\uC5B4\uBC1B\uC74C
|
|
38013
|
+
`);
|
|
38014
|
+
return adopted;
|
|
38015
|
+
}
|
|
37948
38016
|
/** 쌓인 이벤트를 보낸다. 같은 폴더에 대해 동시에 한 번만 돈다. */
|
|
37949
38017
|
flush(fp) {
|
|
37950
38018
|
const runtime = this.runtime(fp);
|
|
@@ -37955,6 +38023,7 @@ var Recorder = class {
|
|
|
37955
38023
|
runtime.flushing = (async () => {
|
|
37956
38024
|
const credential = credentialFor(fp);
|
|
37957
38025
|
if (!credential) return null;
|
|
38026
|
+
this.adoptForCredential(fp, credential);
|
|
37958
38027
|
const result = await flushOutbox(fp, destinationKey(credential), this.apiFor(credential), credential.token);
|
|
37959
38028
|
if (result.sent || result.dropped || result.error) runtime.last = { ...result, at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
37960
38029
|
if (result.unauthorized) {
|
|
@@ -38120,6 +38189,7 @@ var Recorder = class {
|
|
|
38120
38189
|
hackathon_name: info.hackathon_name,
|
|
38121
38190
|
profile_name: info.profile_name,
|
|
38122
38191
|
team_name: info.team_name,
|
|
38192
|
+
profile_id: info.profile_id,
|
|
38123
38193
|
root,
|
|
38124
38194
|
api_url: this.api.baseUrl,
|
|
38125
38195
|
saved_at: (/* @__PURE__ */ new Date()).toISOString()
|