happy-imou-cloud 2.1.1 → 2.1.2
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/bin/happy-cloud.mjs +21 -21
- package/compat/acp-sdk-schema/index.js +27 -27
- package/compat/acp-sdk-schema/types.gen.js +2 -2
- package/compat/acp-sdk-schema/zod.gen.js +1553 -1553
- package/compat/ink-build/components/Cursor.d.ts +83 -83
- package/compat/ink-build/components/Cursor.js +52 -52
- package/compat/ink-build/components/CursorContext.d.ts +11 -11
- package/compat/ink-build/components/CursorContext.js +7 -7
- package/compat/ink-build/components/ErrorBoundary.d.ts +18 -18
- package/compat/ink-build/components/ErrorBoundary.js +22 -22
- package/compat/ink-build/hooks/use-cursor.d.ts +12 -12
- package/compat/ink-build/hooks/use-cursor.js +28 -28
- package/dist/{BaseReasoningProcessor-Dn9FxfxU.mjs → BaseReasoningProcessor-BaOWkVcu.mjs} +3 -3
- package/dist/{BaseReasoningProcessor-CBMK-8Gi.cjs → BaseReasoningProcessor-CzvqwxuY.cjs} +3 -3
- package/dist/ProviderSelectionHandler-Q8pl7e-d.mjs +261 -0
- package/dist/ProviderSelectionHandler-wwbfeK_s.cjs +265 -0
- package/dist/{api-DBy5lPZw.mjs → api-Cxifhw5r.mjs} +3 -3
- package/dist/{api-DId_j3C2.cjs → api-DZimmN4C.cjs} +2 -2
- package/dist/{command-CeaBwYCW.mjs → command-B6LM3Nml.mjs} +3 -3
- package/dist/{command-DwfUpmId.cjs → command-RcCJI1jl.cjs} +3 -3
- package/dist/{index-CuuYSKiv.cjs → index-Cuvs0lFS.cjs} +168 -75
- package/dist/{index-66vjECEd.mjs → index-Des7I5WX.mjs} +165 -72
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +3 -3
- package/dist/lib.cjs +1 -1
- package/dist/lib.d.cts +36 -36
- package/dist/lib.d.mts +36 -36
- package/dist/lib.mjs +1 -1
- package/dist/{persistence-BOWh1NER.mjs → persistence-6d4U4Sh8.mjs} +1 -1
- package/dist/{persistence-Dzr6sFwD.cjs → persistence-C8-MtdQK.cjs} +1 -1
- package/dist/{registerKillSessionHandler-D4_wpN18.mjs → registerKillSessionHandler-BFBkz_XT.mjs} +417 -5
- package/dist/{registerKillSessionHandler-Dg_iRBPm.cjs → registerKillSessionHandler-BapPCRmp.cjs} +419 -4
- package/dist/{runClaude-B74dHAnQ.mjs → runClaude-CPV5Uap2.mjs} +34 -5
- package/dist/{runClaude-oIFzkfuU.cjs → runClaude-DVnqKa1q.cjs} +37 -8
- package/dist/{runCodex-D_9CuL6M.cjs → runCodex-Bzsp8gFO.cjs} +29 -21
- package/dist/{runCodex-mLHjsgVj.mjs → runCodex-CwtLSTMJ.mjs} +26 -18
- package/dist/{runGemini-CcWGezMt.cjs → runGemini-6Dwyk_Km.cjs} +267 -82
- package/dist/{runGemini-BMiho2ab.mjs → runGemini-Bmoxehlh.mjs} +267 -82
- package/package.json +9 -9
- package/scripts/build.mjs +68 -68
- package/scripts/ensureAcpSdkCompat.mjs +170 -172
- package/scripts/release-smoke.mjs +38 -35
- package/dist/ProviderSelectionHandler-BuXk-8ji.cjs +0 -680
- package/dist/ProviderSelectionHandler-CMaQThYO.mjs +0 -673
package/dist/{registerKillSessionHandler-D4_wpN18.mjs → registerKillSessionHandler-BFBkz_XT.mjs}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { i as initialMachineMetadata, e as projectPath, R as RuntimeShell, h as resolveCanonicalToolNameV2, f as formatDisplayMessage } from './index-
|
|
2
|
-
import { readSettings } from './persistence-
|
|
1
|
+
import { i as initialMachineMetadata, e as projectPath, R as RuntimeShell, h as resolveCanonicalToolNameV2, f as formatDisplayMessage } from './index-Des7I5WX.mjs';
|
|
2
|
+
import { readSettings } from './persistence-6d4U4Sh8.mjs';
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import { resolve } from 'node:path';
|
|
5
|
-
import { c as configuration, p as packageJson, l as logger } from './api-
|
|
5
|
+
import { c as configuration, p as packageJson, H as HAPPY_ORG_TURN_REPORT_TAG, d as HAPPY_ORG_SUMMARY_MAX_LENGTH, f as HAPPY_ORG_REPEAT_THRESHOLD, l as logger } from './api-Cxifhw5r.mjs';
|
|
6
6
|
import { randomUUID } from 'node:crypto';
|
|
7
7
|
import { createHash } from 'crypto';
|
|
8
8
|
import 'axios';
|
|
@@ -300,7 +300,7 @@ function createAbortError() {
|
|
|
300
300
|
error.name = "AbortError";
|
|
301
301
|
return error;
|
|
302
302
|
}
|
|
303
|
-
async function waitForResponseCompleteWithAbort(backend, signal, timeoutMs =
|
|
303
|
+
async function waitForResponseCompleteWithAbort(backend, signal, timeoutMs = 10 * 6e4) {
|
|
304
304
|
if (!backend.waitForResponseComplete) {
|
|
305
305
|
return;
|
|
306
306
|
}
|
|
@@ -354,6 +354,418 @@ async function syncControlledByUserState(sessionClient, controlledByUser) {
|
|
|
354
354
|
});
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
+
function normalizeOptionalText(value) {
|
|
358
|
+
if (typeof value !== "string") {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
const trimmed = value.trim();
|
|
362
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
363
|
+
}
|
|
364
|
+
function normalizeSummaryText(value) {
|
|
365
|
+
const normalized = normalizeOptionalText(value);
|
|
366
|
+
return normalized ? normalized.replace(/\s+/g, " ").slice(0, HAPPY_ORG_SUMMARY_MAX_LENGTH) : null;
|
|
367
|
+
}
|
|
368
|
+
function cloneHappyOrgMetadata(happyOrg) {
|
|
369
|
+
return {
|
|
370
|
+
taskContext: happyOrg?.taskContext ? { ...happyOrg.taskContext } : void 0,
|
|
371
|
+
runtime: happyOrg?.runtime ? { ...happyOrg.runtime } : void 0,
|
|
372
|
+
activeOwner: happyOrg?.activeOwner ? { ...happyOrg.activeOwner } : null,
|
|
373
|
+
repeat: happyOrg?.repeat ? {
|
|
374
|
+
threshold: happyOrg.repeat.threshold,
|
|
375
|
+
fingerprints: Object.fromEntries(
|
|
376
|
+
Object.entries(happyOrg.repeat.fingerprints ?? {}).map(([fingerprint, entry]) => [
|
|
377
|
+
fingerprint,
|
|
378
|
+
{ ...entry }
|
|
379
|
+
])
|
|
380
|
+
)
|
|
381
|
+
} : void 0,
|
|
382
|
+
lastTurnReport: happyOrg?.lastTurnReport ? { ...happyOrg.lastTurnReport } : void 0
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
function normalizeHappyOrgMetadata(metadata) {
|
|
386
|
+
const happyOrg = cloneHappyOrgMetadata(metadata?.happyOrg);
|
|
387
|
+
return {
|
|
388
|
+
...happyOrg,
|
|
389
|
+
runtime: happyOrg.runtime ?? {
|
|
390
|
+
status: "active",
|
|
391
|
+
reason: null
|
|
392
|
+
},
|
|
393
|
+
repeat: happyOrg.repeat ?? {
|
|
394
|
+
threshold: HAPPY_ORG_REPEAT_THRESHOLD,
|
|
395
|
+
fingerprints: {}
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
function withHappyOrgMetadata(metadata, happyOrg) {
|
|
400
|
+
return {
|
|
401
|
+
...metadata,
|
|
402
|
+
happyOrg
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function resetHappyOrgRuntimeForTask(taskContext) {
|
|
406
|
+
return {
|
|
407
|
+
taskContext,
|
|
408
|
+
runtime: {
|
|
409
|
+
status: "active",
|
|
410
|
+
reason: null
|
|
411
|
+
},
|
|
412
|
+
activeOwner: null,
|
|
413
|
+
repeat: {
|
|
414
|
+
threshold: HAPPY_ORG_REPEAT_THRESHOLD,
|
|
415
|
+
fingerprints: {}
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
function buildTerminatedStatusMessage(taskId) {
|
|
420
|
+
return `Task ${taskId} is terminated. Reopen it with new context, a new decision, or a new resource before continuing.`;
|
|
421
|
+
}
|
|
422
|
+
function buildMemberBusyStatusMessage(memberAgentId, activeTaskId, nextTaskId) {
|
|
423
|
+
return `Member ${memberAgentId} is already busy with active task ${activeTaskId}. Reject task ${nextTaskId} without continuing token usage.`;
|
|
424
|
+
}
|
|
425
|
+
function buildOwnerConflictStatusMessage(taskId, ownerAgentId) {
|
|
426
|
+
return `Task ${taskId} is already active under owner ${ownerAgentId}. This turn must exit without continuing token usage.`;
|
|
427
|
+
}
|
|
428
|
+
function inferDraftTurnStatus(draft) {
|
|
429
|
+
if (draft?.turnStatus === "turn_update" || draft?.turnStatus === "task_complete") {
|
|
430
|
+
return draft.turnStatus;
|
|
431
|
+
}
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
function inferInterventionType(draft) {
|
|
435
|
+
if (draft?.interventionType === "none" || draft?.interventionType === "review_needed" || draft?.interventionType === "blocker" || draft?.interventionType === "decision_needed") {
|
|
436
|
+
return draft.interventionType;
|
|
437
|
+
}
|
|
438
|
+
if (normalizeOptionalText(draft?.decisionNeeded)) {
|
|
439
|
+
return "decision_needed";
|
|
440
|
+
}
|
|
441
|
+
if (normalizeOptionalText(draft?.blockerCode)) {
|
|
442
|
+
return "blocker";
|
|
443
|
+
}
|
|
444
|
+
return "none";
|
|
445
|
+
}
|
|
446
|
+
function buildFallbackSummary(text, turnStatus) {
|
|
447
|
+
const trimmed = text.trim();
|
|
448
|
+
if (trimmed) {
|
|
449
|
+
return trimmed.replace(/\s+/g, " ").slice(0, HAPPY_ORG_SUMMARY_MAX_LENGTH);
|
|
450
|
+
}
|
|
451
|
+
return turnStatus === "turn_aborted" ? "Turn aborted before completion." : "Turn completed without a textual summary.";
|
|
452
|
+
}
|
|
453
|
+
function normalizeTurnReportDraft(draft) {
|
|
454
|
+
return {
|
|
455
|
+
turnStatus: inferDraftTurnStatus(draft),
|
|
456
|
+
summary: normalizeSummaryText(draft?.summary),
|
|
457
|
+
interventionType: inferInterventionType(draft),
|
|
458
|
+
blockerCode: normalizeOptionalText(draft?.blockerCode),
|
|
459
|
+
decisionNeeded: normalizeOptionalText(draft?.decisionNeeded),
|
|
460
|
+
targetArtifact: normalizeOptionalText(draft?.targetArtifact)
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function stripCodeFence(text) {
|
|
464
|
+
return text.replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/i, "").trim();
|
|
465
|
+
}
|
|
466
|
+
function extractTaggedTurnReport(text) {
|
|
467
|
+
const matcher = new RegExp(
|
|
468
|
+
`<${HAPPY_ORG_TURN_REPORT_TAG}>\\s*([\\s\\S]*?)\\s*</${HAPPY_ORG_TURN_REPORT_TAG}>`,
|
|
469
|
+
"gi"
|
|
470
|
+
);
|
|
471
|
+
let lastMatch = null;
|
|
472
|
+
for (let match = matcher.exec(text); match; match = matcher.exec(text)) {
|
|
473
|
+
lastMatch = match;
|
|
474
|
+
}
|
|
475
|
+
if (!lastMatch) {
|
|
476
|
+
return {
|
|
477
|
+
cleanedText: text.trim(),
|
|
478
|
+
draft: null
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
const rawBlock = stripCodeFence(lastMatch[1] ?? "");
|
|
482
|
+
let draft = null;
|
|
483
|
+
try {
|
|
484
|
+
const parsed = JSON.parse(rawBlock);
|
|
485
|
+
draft = {
|
|
486
|
+
turnStatus: normalizeOptionalText(parsed.turnStatus),
|
|
487
|
+
summary: normalizeSummaryText(parsed.summary),
|
|
488
|
+
interventionType: normalizeOptionalText(parsed.interventionType),
|
|
489
|
+
blockerCode: normalizeOptionalText(parsed.blockerCode),
|
|
490
|
+
decisionNeeded: normalizeOptionalText(parsed.decisionNeeded),
|
|
491
|
+
targetArtifact: normalizeOptionalText(parsed.targetArtifact)
|
|
492
|
+
};
|
|
493
|
+
} catch {
|
|
494
|
+
draft = null;
|
|
495
|
+
}
|
|
496
|
+
const cleanedText = `${text.slice(0, lastMatch.index)}${text.slice(lastMatch.index + lastMatch[0].length)}`.replace(/\n{3,}/g, "\n\n").trim();
|
|
497
|
+
return {
|
|
498
|
+
cleanedText,
|
|
499
|
+
draft
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
function buildRepeatFingerprint(context, blockerCode, targetArtifact) {
|
|
503
|
+
if (!blockerCode) {
|
|
504
|
+
return null;
|
|
505
|
+
}
|
|
506
|
+
return [
|
|
507
|
+
context.taskId,
|
|
508
|
+
context.memberAgentId,
|
|
509
|
+
blockerCode,
|
|
510
|
+
targetArtifact ?? ""
|
|
511
|
+
].join("::");
|
|
512
|
+
}
|
|
513
|
+
function resolveReportedTurnStatus(transportTurnStatus, draft) {
|
|
514
|
+
if (transportTurnStatus === "turn_aborted") {
|
|
515
|
+
return "turn_aborted";
|
|
516
|
+
}
|
|
517
|
+
return draft.turnStatus === "task_complete" ? "task_complete" : "turn_update";
|
|
518
|
+
}
|
|
519
|
+
function buildRuntimeStateAfterTurn(report) {
|
|
520
|
+
if (report.turnStatus === "task_complete") {
|
|
521
|
+
return {
|
|
522
|
+
status: "waiting_close",
|
|
523
|
+
reason: "awaiting_ceo_close"
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
switch (report.interventionType) {
|
|
527
|
+
case "decision_needed":
|
|
528
|
+
return {
|
|
529
|
+
status: "waiting_decision",
|
|
530
|
+
reason: "awaiting_user_decision"
|
|
531
|
+
};
|
|
532
|
+
case "review_needed":
|
|
533
|
+
return {
|
|
534
|
+
status: "waiting_review",
|
|
535
|
+
reason: "awaiting_ceo_review"
|
|
536
|
+
};
|
|
537
|
+
case "blocker":
|
|
538
|
+
return {
|
|
539
|
+
status: "waiting_review",
|
|
540
|
+
reason: "awaiting_ceo_context"
|
|
541
|
+
};
|
|
542
|
+
default:
|
|
543
|
+
return {
|
|
544
|
+
status: "active",
|
|
545
|
+
reason: null
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
function buildHappyOrgTurnPrompt(prompt, turn) {
|
|
550
|
+
const reopenLines = turn.reopenContext ? [
|
|
551
|
+
"",
|
|
552
|
+
"This task was explicitly reopened for this turn with the following new inputs:",
|
|
553
|
+
turn.reopenContext.newContext ? `- newContext: ${turn.reopenContext.newContext}` : null,
|
|
554
|
+
turn.reopenContext.newDecision ? `- newDecision: ${turn.reopenContext.newDecision}` : null,
|
|
555
|
+
turn.reopenContext.newResource ? `- newResource: ${turn.reopenContext.newResource}` : null
|
|
556
|
+
].filter(Boolean) : [];
|
|
557
|
+
const header = [
|
|
558
|
+
"[HAPPY_ORG_TASK_CONTEXT]",
|
|
559
|
+
`taskId=${turn.context.taskId}`,
|
|
560
|
+
`organizationId=${turn.context.organizationId}`,
|
|
561
|
+
`memberAgentId=${turn.context.memberAgentId}`,
|
|
562
|
+
`supervisorAgentId=${turn.context.supervisorAgentId}`,
|
|
563
|
+
"Stay on this exact task for the whole turn.",
|
|
564
|
+
"End your response with exactly one raw JSON block inside these tags and do not wrap it in a markdown code fence:",
|
|
565
|
+
`<${HAPPY_ORG_TURN_REPORT_TAG}>{"turnStatus":"turn_update","summary":"short task-board summary","interventionType":"none","blockerCode":null,"decisionNeeded":null,"targetArtifact":null}</${HAPPY_ORG_TURN_REPORT_TAG}>`,
|
|
566
|
+
"Allowed turnStatus values in the JSON block: turn_update, task_complete.",
|
|
567
|
+
"Allowed interventionType values: none, review_needed, blocker, decision_needed.",
|
|
568
|
+
"Use turnStatus=task_complete only when you believe the assigned task is finished and ready for CEO acceptance.",
|
|
569
|
+
"If turnStatus=task_complete, the task will wait for CEO close; do not treat it as automatically closed.",
|
|
570
|
+
"If turnStatus=task_complete, interventionType must be review_needed.",
|
|
571
|
+
`summary must fit on a one-line CEO card or task-board card: short, actionable, no long process logs, max ${HAPPY_ORG_SUMMARY_MAX_LENGTH} characters.`,
|
|
572
|
+
"Use blocker only for problems the organization may still solve internally.",
|
|
573
|
+
"Use decision_needed only when a CEO or user decision is required.",
|
|
574
|
+
"Use review_needed when supervisor review is needed but the work is not blocked.",
|
|
575
|
+
...reopenLines,
|
|
576
|
+
"[/HAPPY_ORG_TASK_CONTEXT]",
|
|
577
|
+
"",
|
|
578
|
+
prompt
|
|
579
|
+
];
|
|
580
|
+
return header.join("\n");
|
|
581
|
+
}
|
|
582
|
+
function resolveHappyOrgQueuedTurn(opts) {
|
|
583
|
+
const metadata = opts.metadata ?? null;
|
|
584
|
+
if (!metadata) {
|
|
585
|
+
return {
|
|
586
|
+
nextMetadata: null,
|
|
587
|
+
queuedTurn: null,
|
|
588
|
+
blocked: false
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
const currentHappyOrg = normalizeHappyOrgMetadata(metadata);
|
|
592
|
+
let nextHappyOrg = cloneHappyOrgMetadata(currentHappyOrg);
|
|
593
|
+
const messageHappyOrg = opts.message.meta?.happyOrg;
|
|
594
|
+
const now = opts.now?.() ?? Date.now();
|
|
595
|
+
const createRunId = opts.createRunId ?? ((taskContext2, currentNow) => `${taskContext2.taskId}:${taskContext2.memberAgentId}:${currentNow}`);
|
|
596
|
+
if (messageHappyOrg?.taskContext) {
|
|
597
|
+
const currentTaskId = currentHappyOrg.taskContext?.taskId ?? null;
|
|
598
|
+
if (currentTaskId !== messageHappyOrg.taskContext.taskId) {
|
|
599
|
+
if (currentHappyOrg.taskContext && currentHappyOrg.runtime?.status === "active") {
|
|
600
|
+
return {
|
|
601
|
+
nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
|
|
602
|
+
queuedTurn: null,
|
|
603
|
+
blocked: true,
|
|
604
|
+
statusMessage: buildMemberBusyStatusMessage(
|
|
605
|
+
currentHappyOrg.taskContext.memberAgentId,
|
|
606
|
+
currentHappyOrg.taskContext.taskId,
|
|
607
|
+
messageHappyOrg.taskContext.taskId
|
|
608
|
+
)
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
nextHappyOrg = resetHappyOrgRuntimeForTask(messageHappyOrg.taskContext);
|
|
612
|
+
} else {
|
|
613
|
+
nextHappyOrg.taskContext = { ...messageHappyOrg.taskContext };
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
const taskContext = nextHappyOrg.taskContext ?? null;
|
|
617
|
+
if (!taskContext) {
|
|
618
|
+
return {
|
|
619
|
+
nextMetadata: metadata,
|
|
620
|
+
queuedTurn: null,
|
|
621
|
+
blocked: false
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
const control = messageHappyOrg?.control;
|
|
625
|
+
if (control?.action === "terminate") {
|
|
626
|
+
nextHappyOrg.runtime = {
|
|
627
|
+
status: "terminated",
|
|
628
|
+
reason: normalizeOptionalText(control.reason) ?? "terminated_by_supervisor",
|
|
629
|
+
terminatedAt: now
|
|
630
|
+
};
|
|
631
|
+
nextHappyOrg.activeOwner = null;
|
|
632
|
+
return {
|
|
633
|
+
nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
|
|
634
|
+
queuedTurn: null,
|
|
635
|
+
blocked: true,
|
|
636
|
+
statusMessage: buildTerminatedStatusMessage(taskContext.taskId)
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
const hasReopenInputs = Boolean(
|
|
640
|
+
normalizeOptionalText(control?.newContext) || normalizeOptionalText(control?.newDecision) || normalizeOptionalText(control?.newResource)
|
|
641
|
+
);
|
|
642
|
+
if (nextHappyOrg.runtime?.status === "terminated") {
|
|
643
|
+
if (control?.action !== "reopen") {
|
|
644
|
+
return {
|
|
645
|
+
nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
|
|
646
|
+
queuedTurn: null,
|
|
647
|
+
blocked: true,
|
|
648
|
+
statusMessage: buildTerminatedStatusMessage(taskContext.taskId)
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
if (!hasReopenInputs) {
|
|
652
|
+
return {
|
|
653
|
+
nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
|
|
654
|
+
queuedTurn: null,
|
|
655
|
+
blocked: true,
|
|
656
|
+
statusMessage: `Task ${taskContext.taskId} can only reopen with new context, a new decision, or a new resource.`
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
const reopenContext = control?.action === "reopen" && hasReopenInputs ? {
|
|
661
|
+
newContext: normalizeOptionalText(control.newContext),
|
|
662
|
+
newDecision: normalizeOptionalText(control.newDecision),
|
|
663
|
+
newResource: normalizeOptionalText(control.newResource)
|
|
664
|
+
} : void 0;
|
|
665
|
+
if (reopenContext) {
|
|
666
|
+
nextHappyOrg.runtime = {
|
|
667
|
+
status: "active",
|
|
668
|
+
reason: null,
|
|
669
|
+
reopenedAt: now
|
|
670
|
+
};
|
|
671
|
+
} else if (!nextHappyOrg.runtime || nextHappyOrg.runtime.status !== "active") {
|
|
672
|
+
nextHappyOrg.runtime = {
|
|
673
|
+
status: "active",
|
|
674
|
+
reason: null
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
if (!nextHappyOrg.activeOwner) {
|
|
678
|
+
nextHappyOrg.activeOwner = {
|
|
679
|
+
ownerAgentId: taskContext.memberAgentId,
|
|
680
|
+
ownerRunId: createRunId(taskContext, now),
|
|
681
|
+
claimedAt: now
|
|
682
|
+
};
|
|
683
|
+
} else if (nextHappyOrg.activeOwner.ownerAgentId !== taskContext.memberAgentId) {
|
|
684
|
+
return {
|
|
685
|
+
nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
|
|
686
|
+
queuedTurn: null,
|
|
687
|
+
blocked: true,
|
|
688
|
+
statusMessage: buildOwnerConflictStatusMessage(
|
|
689
|
+
taskContext.taskId,
|
|
690
|
+
nextHappyOrg.activeOwner.ownerAgentId
|
|
691
|
+
)
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
return {
|
|
695
|
+
nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
|
|
696
|
+
queuedTurn: {
|
|
697
|
+
context: taskContext,
|
|
698
|
+
...reopenContext ? { reopenContext } : {}
|
|
699
|
+
},
|
|
700
|
+
blocked: false
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
function finalizeHappyOrgTurn(opts) {
|
|
704
|
+
const metadata = opts.metadata ?? null;
|
|
705
|
+
const queuedTurn = opts.queuedTurn ?? null;
|
|
706
|
+
const { cleanedText, draft } = extractTaggedTurnReport(opts.responseText);
|
|
707
|
+
if (!metadata || !queuedTurn) {
|
|
708
|
+
return {
|
|
709
|
+
cleanedText,
|
|
710
|
+
report: null,
|
|
711
|
+
nextMetadata: metadata
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
const now = opts.now?.() ?? Date.now();
|
|
715
|
+
const normalizedDraft = normalizeTurnReportDraft(draft);
|
|
716
|
+
const reportTurnStatus = resolveReportedTurnStatus(opts.turnStatus, normalizedDraft);
|
|
717
|
+
const report = {
|
|
718
|
+
...queuedTurn.context,
|
|
719
|
+
turnStatus: reportTurnStatus,
|
|
720
|
+
interventionType: reportTurnStatus === "task_complete" ? "review_needed" : normalizedDraft.interventionType ?? "none",
|
|
721
|
+
summary: normalizedDraft.summary ?? buildFallbackSummary(cleanedText, reportTurnStatus),
|
|
722
|
+
blockerCode: normalizedDraft.blockerCode ?? null,
|
|
723
|
+
decisionNeeded: normalizedDraft.decisionNeeded ?? null,
|
|
724
|
+
targetArtifact: normalizedDraft.targetArtifact ?? null,
|
|
725
|
+
repeatFingerprint: buildRepeatFingerprint(
|
|
726
|
+
queuedTurn.context,
|
|
727
|
+
normalizedDraft.blockerCode ?? null,
|
|
728
|
+
normalizedDraft.targetArtifact ?? null
|
|
729
|
+
)
|
|
730
|
+
};
|
|
731
|
+
const nextHappyOrg = normalizeHappyOrgMetadata(metadata);
|
|
732
|
+
nextHappyOrg.taskContext = { ...queuedTurn.context };
|
|
733
|
+
nextHappyOrg.lastTurnReport = report;
|
|
734
|
+
nextHappyOrg.activeOwner = null;
|
|
735
|
+
nextHappyOrg.repeat = nextHappyOrg.repeat ?? {
|
|
736
|
+
threshold: HAPPY_ORG_REPEAT_THRESHOLD,
|
|
737
|
+
fingerprints: {}
|
|
738
|
+
};
|
|
739
|
+
let terminateMessage;
|
|
740
|
+
if (report.repeatFingerprint) {
|
|
741
|
+
const currentEntry = nextHappyOrg.repeat.fingerprints[report.repeatFingerprint] ?? {
|
|
742
|
+
count: 0};
|
|
743
|
+
const nextCount = currentEntry.count + 1;
|
|
744
|
+
nextHappyOrg.repeat.fingerprints[report.repeatFingerprint] = {
|
|
745
|
+
count: nextCount,
|
|
746
|
+
lastSeenAt: now
|
|
747
|
+
};
|
|
748
|
+
if (nextCount >= nextHappyOrg.repeat.threshold) {
|
|
749
|
+
nextHappyOrg.runtime = {
|
|
750
|
+
status: "terminated",
|
|
751
|
+
reason: `repeat_fingerprint:${report.repeatFingerprint}`,
|
|
752
|
+
terminatedAt: now
|
|
753
|
+
};
|
|
754
|
+
terminateMessage = `Task ${queuedTurn.context.taskId} hit repeat threshold for ${report.repeatFingerprint} and is now terminated until reopen.`;
|
|
755
|
+
} else if (!nextHappyOrg.runtime || nextHappyOrg.runtime.status !== "terminated") {
|
|
756
|
+
nextHappyOrg.runtime = buildRuntimeStateAfterTurn(report);
|
|
757
|
+
}
|
|
758
|
+
} else if (!nextHappyOrg.runtime || nextHappyOrg.runtime.status !== "terminated") {
|
|
759
|
+
nextHappyOrg.runtime = buildRuntimeStateAfterTurn(report);
|
|
760
|
+
}
|
|
761
|
+
return {
|
|
762
|
+
cleanedText,
|
|
763
|
+
report,
|
|
764
|
+
nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
|
|
765
|
+
terminateMessage
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
|
|
357
769
|
const DEFAULT_MAX_MESSAGES = 200;
|
|
358
770
|
const DEFAULT_MAX_CHARACTERS = 1e5;
|
|
359
771
|
const DEFAULT_MAX_MESSAGE_CHARACTERS = 8e3;
|
|
@@ -1179,4 +1591,4 @@ function registerKillSessionHandler(rpcHandlerManager, killThisHappy) {
|
|
|
1179
1591
|
});
|
|
1180
1592
|
}
|
|
1181
1593
|
|
|
1182
|
-
export { BasePermissionHandler as B, ConversationHistory$1 as C, INTERACTION_SUPERSEDED_ERROR as I, MissingMachineIdError as M, INTERACTION_TIMED_OUT_ERROR as a, MessageQueue2 as b, createSessionMetadata as c,
|
|
1594
|
+
export { BasePermissionHandler as B, ConversationHistory$1 as C, INTERACTION_SUPERSEDED_ERROR as I, MissingMachineIdError as M, INTERACTION_TIMED_OUT_ERROR as a, MessageQueue2 as b, createSessionMetadata as c, registerKillSessionHandler as d, ensureManagedProviderMachine as e, MessageBuffer as f, getPendingInteractionTimeoutMs as g, hashObject as h, buildHappyOrgTurnPrompt as i, finalizeHappyOrgTurn as j, closeProviderSession as k, launchRuntimeHandleWithFactoryResult as l, inferToolResultError as m, forwardAgentMessageToProviderSession as n, resolveHappyOrgQueuedTurn as r, syncControlledByUserState as s, waitForResponseCompleteWithAbort as w };
|