@adhdev/mesh-shared 1.0.82-rc.33 → 1.0.82-rc.35

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/index.mjs CHANGED
@@ -773,6 +773,7 @@ var CANONICAL_MESH_TOOL_NAMES = [
773
773
  "mesh_list_pending_approvals",
774
774
  "mesh_create",
775
775
  "mesh_add_node",
776
+ "mesh_reattach_source_parent",
776
777
  "mesh_attach_remote",
777
778
  "mesh_clone_node",
778
779
  "mesh_remove_node",
@@ -796,7 +797,9 @@ var CANONICAL_MESH_TOOL_NAMES = [
796
797
  "mesh_node_slots",
797
798
  "driver_list",
798
799
  "driver_describe",
799
- "artifact_list"
800
+ "artifact_list",
801
+ "artifact_read",
802
+ "artifact_register"
800
803
  ];
801
804
  var CANONICAL_MESH_TOOL_COUNT = CANONICAL_MESH_TOOL_NAMES.length;
802
805
  var RETIRED_MESH_TOOLS = {
@@ -1106,9 +1109,15 @@ var DAEMON_STATUS_EVENT_NAMES = [
1106
1109
  "agent:waiting_choice",
1107
1110
  "agent:generating_completed",
1108
1111
  "agent:stopped",
1109
- "monitor:no_progress"
1112
+ "monitor:no_progress",
1113
+ // An owner decision (structured missions) needs the owner. Server-bound for the push only;
1114
+ // the dashboard learns about decisions over P2P (`mission_decisions_list`).
1115
+ "agent:decision_needed"
1110
1116
  ];
1111
1117
  var isDaemonStatusEventName = makeTypeGuard(DAEMON_STATUS_EVENT_NAMES);
1118
+ var DECISION_PUSH_QUESTION_MAX = 80;
1119
+ var DECISION_PUSH_OPTION_LABEL_MAX = 24;
1120
+ var DECISION_PUSH_OPTIONS_MAX = 3;
1112
1121
  var RELEASE_CHANNELS = ["stable", "preview"];
1113
1122
  var NPM_UPDATE_TAGS = ["latest", "next"];
1114
1123
  var VERSION_UPDATE_REASONS = ["force_update_below", "major_minor_mismatch", "patch_mismatch", "daemon_ahead"];
@@ -1682,7 +1691,18 @@ var WORKER_TOOLS = [
1682
1691
  "driver_list",
1683
1692
  "driver_describe",
1684
1693
  "driver_invoke",
1685
- "artifact_register"
1694
+ "driver_scaffold",
1695
+ "driver_validate",
1696
+ "driver_export",
1697
+ "driver_install",
1698
+ "artifact_register",
1699
+ "artifact_list",
1700
+ "artifact_read",
1701
+ // Contract versioning (Cut A): exact pinned-unit reads (E2), the explicit
1702
+ // read claim (C1) and the authoritative head/notice pull.
1703
+ "contract_read",
1704
+ "contract_observe",
1705
+ "contract_current"
1686
1706
  ];
1687
1707
  var WORKER_TOOL_SET = new Set(WORKER_TOOLS);
1688
1708
  function isWorkerTool(value) {
@@ -1783,7 +1803,11 @@ var ASSISTANT_TOOLS = [
1783
1803
  "launch_defaults",
1784
1804
  "launch_defaults_set",
1785
1805
  "driver_list",
1786
- "driver_describe"
1806
+ "driver_describe",
1807
+ "artifact_list",
1808
+ "artifact_read",
1809
+ "decision_answer",
1810
+ "decision_request"
1787
1811
  ];
1788
1812
  var ASSISTANT_TOOL_SET = new Set(ASSISTANT_TOOLS);
1789
1813
  function isAssistantTool(value) {
@@ -1811,6 +1835,12 @@ var ASSISTANT_VERB = {
1811
1835
  projectNote: "assistant_project_note",
1812
1836
  launchDefaults: "assistant_launch_defaults",
1813
1837
  launchDefaultsSet: "assistant_launch_defaults_set",
1838
+ artifactList: "assistant_artifact_list",
1839
+ artifactRead: "assistant_artifact_read",
1840
+ /** Owner-decision inbox (structured-missions design 2026-10-28 §6.3): the owner's words recorded as answers. */
1841
+ decisionAnswer: "assistant_decision_answer",
1842
+ /** Register a plain-text question a coordinator put to the owner as a decision item (§5.2). */
1843
+ decisionRequest: "assistant_decision_request",
1814
1844
  // assistant-side daemon verbs without a tool of the same name
1815
1845
  launch: "launch_assistant",
1816
1846
  pendingRelays: "assistant_pending_relays",
@@ -1840,9 +1870,13 @@ var ASSISTANT_TOOL_VERBS = {
1840
1870
  skill_manage: ASSISTANT_VERB.skillManage,
1841
1871
  project_note: ASSISTANT_VERB.projectNote,
1842
1872
  launch_defaults: ASSISTANT_VERB.launchDefaults,
1843
- launch_defaults_set: ASSISTANT_VERB.launchDefaultsSet
1873
+ launch_defaults_set: ASSISTANT_VERB.launchDefaultsSet,
1874
+ artifact_list: ASSISTANT_VERB.artifactList,
1875
+ artifact_read: ASSISTANT_VERB.artifactRead,
1876
+ decision_answer: ASSISTANT_VERB.decisionAnswer,
1877
+ decision_request: ASSISTANT_VERB.decisionRequest
1844
1878
  };
1845
- var ASSISTANT_WRITE_TOOLS = ["project_watch", "assistant_action", "memory", "skill_manage", "project_note", "project_send", "project_add", "project_attach_remote", "launch_defaults_set"];
1879
+ var ASSISTANT_WRITE_TOOLS = ["project_watch", "assistant_action", "memory", "skill_manage", "project_note", "project_send", "project_add", "project_attach_remote", "launch_defaults_set", "decision_answer", "decision_request"];
1846
1880
  var ASSISTANT_OWNER_VERBS = [
1847
1881
  ASSISTANT_VERB.executionSettings,
1848
1882
  ASSISTANT_VERB.stagedResolve,
@@ -1863,11 +1897,22 @@ var ASSISTANT_REMOTE_PROJECT_COMMAND = "assistant_remote_project";
1863
1897
  var ASSISTANT_REMOTE_PROJECT_CATALOG_COMMAND = "assistant_remote_project_catalog";
1864
1898
  var ASSISTANT_REMOTE_PROJECT_ACCESS_COMMAND = "assistant_remote_project_access";
1865
1899
  var ASSISTANT_REMOTE_FOLLOW_COMMAND = "assistant_remote_follow";
1866
- var ASSISTANT_FOLLOWER_ALLOWED_OPS = ["status", "read", "poll", "report", "send"];
1900
+ var ASSISTANT_FOLLOWER_ALLOWED_OPS = ["status", "read", "poll", "report", "send", "artifact_list", "artifact_read", "decision_list", "decision_answer", "decision_request"];
1867
1901
  var ASSISTANT_FOLLOWER_ALLOWED_OP_SET = new Set(ASSISTANT_FOLLOWER_ALLOWED_OPS);
1868
1902
  function isAssistantFollowerAllowedOp(value) {
1869
1903
  return typeof value === "string" && ASSISTANT_FOLLOWER_ALLOWED_OP_SET.has(value);
1870
1904
  }
1905
+ var DECISION_OP_IMPLIED_BY = {
1906
+ decision_list: "status",
1907
+ decision_answer: "send",
1908
+ decision_request: "send"
1909
+ };
1910
+ function followerOpPermitted(op, allowedOps) {
1911
+ if (!isAssistantFollowerAllowedOp(op)) return false;
1912
+ if (allowedOps.includes(op)) return true;
1913
+ const implied = DECISION_OP_IMPLIED_BY[op];
1914
+ return implied !== void 0 && allowedOps.includes(implied);
1915
+ }
1871
1916
  function followedRemoteProjectKey(hostDaemonId, meshId) {
1872
1917
  const canonHost = canonicalDaemonId(hostDaemonId) ?? hostDaemonId.trim();
1873
1918
  return `${canonHost}::${meshId.trim()}`;
@@ -2766,8 +2811,23 @@ function isMissionBriefWire(value) {
2766
2811
  }
2767
2812
  return true;
2768
2813
  }
2814
+ var STRUCTURED_MISSION_KEYS = ["summary", "outcome", "outcomeReason", "version", "carryOver", "openItems"];
2815
+ function isOpenItemCountsWire(value) {
2816
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["remaining", "live_check", "decision", "evidence"])) return false;
2817
+ return ["remaining", "live_check", "decision", "evidence"].every((k) => isNonNegativeInt(value[k]));
2818
+ }
2819
+ function isStructuredMissionFields(value) {
2820
+ for (const k of ["summary", "outcome", "outcomeReason"]) {
2821
+ if (value[k] !== void 0 && typeof value[k] !== "string") return false;
2822
+ }
2823
+ if (value.version !== void 0 && !isNonNegativeInt(value.version)) return false;
2824
+ if (value.carryOver !== void 0 && typeof value.carryOver !== "boolean") return false;
2825
+ if (value.openItems !== void 0 && !isOpenItemCountsWire(value.openItems)) return false;
2826
+ return true;
2827
+ }
2769
2828
  function isMeshMissionRecordWire(value) {
2770
- if (!isRecord(value) || !hasOnlyKeys2(value, ["id", "meshId", "title", "goal", "status", "brief"])) return false;
2829
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["id", "meshId", "title", "goal", "status", "brief", ...STRUCTURED_MISSION_KEYS])) return false;
2830
+ if (!isStructuredMissionFields(value)) return false;
2771
2831
  if (!isEvidenceIdentifier(value.id) || !isEvidenceIdentifier(value.meshId)) return false;
2772
2832
  if (typeof value.title !== "string" || typeof value.goal !== "string") return false;
2773
2833
  if (!isMeshMissionStatusValue(value.status)) return false;
@@ -2775,11 +2835,22 @@ function isMeshMissionRecordWire(value) {
2775
2835
  return true;
2776
2836
  }
2777
2837
  function isMissionUpsertRequest(value) {
2778
- if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "id", "title", "goal", "status", "brief"])) return false;
2838
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "id", "title", "goal", "status", "brief", "structured", "summary", "outcome", "outcomeReason", "carryOverTo", "toCarryOver", "itemsAdd", "itemsUpdate"])) return false;
2779
2839
  if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2780
2840
  if (!isEvidenceIdentifier(value.meshId)) return false;
2781
2841
  if (value.id !== void 0 && !isEvidenceIdentifier(value.id)) return false;
2782
- if (typeof value.title !== "string" || value.title.trim().length === 0) return false;
2842
+ if (typeof value.title !== "string") return false;
2843
+ if (value.title.trim().length === 0 && value.toCarryOver !== true && value.id === void 0) return false;
2844
+ if (value.structured !== void 0 && typeof value.structured !== "boolean") return false;
2845
+ if (value.toCarryOver !== void 0 && typeof value.toCarryOver !== "boolean") return false;
2846
+ for (const k of ["summary", "outcome", "outcomeReason"]) {
2847
+ if (value[k] !== void 0 && typeof value[k] !== "string") return false;
2848
+ }
2849
+ if (value.carryOverTo !== void 0 && !isEvidenceIdentifier(value.carryOverTo)) return false;
2850
+ for (const k of ["itemsAdd", "itemsUpdate"]) {
2851
+ const list = value[k];
2852
+ if (list !== void 0 && (!Array.isArray(list) || list.length > 500 || !list.every(isRecord))) return false;
2853
+ }
2783
2854
  if (value.goal !== void 0 && typeof value.goal !== "string") return false;
2784
2855
  if (value.status !== void 0 && !isMeshMissionStatusValue(value.status)) return false;
2785
2856
  if (value.brief !== void 0 && value.brief !== null && !isMissionBriefWire(value.brief)) return false;
@@ -2789,7 +2860,7 @@ function decodeMissionUpsertRequest(value) {
2789
2860
  return isMissionUpsertRequest(value) ? value : null;
2790
2861
  }
2791
2862
  function isMissionUpsertResponse(value) {
2792
- return isRecord(value) && hasOnlyKeys2(value, ["mission"]) && isMeshMissionRecordWire(value.mission);
2863
+ return isRecord(value) && hasOnlyKeys2(value, ["mission", "result"]) && isMeshMissionRecordWire(value.mission) && (value.result === void 0 || isRecord(value.result));
2793
2864
  }
2794
2865
  function decodeMissionUpsertResponse(value) {
2795
2866
  return isMissionUpsertResponse(value) ? value : null;
@@ -2815,7 +2886,10 @@ function decodeMissionQueryResponse(value) {
2815
2886
  return isMissionQueryResponse(value) ? value : null;
2816
2887
  }
2817
2888
  function isMissionListQueryRequest(value) {
2818
- if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "statuses", "verbose", "withStats", "limit", "historyIdLimit", "meshStatusView"])) return false;
2889
+ if (!isRecord(value) || !hasOnlyKeys2(value, ["v", "meshId", "statuses", "verbose", "withStats", "limit", "historyIdLimit", "meshStatusView", "structured", "items", "history"])) return false;
2890
+ for (const k of ["structured", "items", "history"]) {
2891
+ if (value[k] !== void 0 && typeof value[k] !== "boolean") return false;
2892
+ }
2819
2893
  if (value.meshStatusView !== void 0 && value.meshStatusView !== "compact" && value.meshStatusView !== "verbose") return false;
2820
2894
  if (value.v !== TURN_IPC_PROTOCOL_VERSION) return false;
2821
2895
  if (!isEvidenceIdentifier(value.meshId)) return false;
@@ -2857,7 +2931,7 @@ function isMissionListSummaryWire(value) {
2857
2931
  const hasGoal = "goal" in value;
2858
2932
  const hasPreview = "goalPreview" in value && "goalTruncated" in value;
2859
2933
  if (hasGoal === hasPreview) return false;
2860
- const baseKeys = ["id", "meshId", "title", "status", "tasks", "stats", "brief", "createdAt", "updatedAt", "closeCandidateEmittedAt"];
2934
+ const baseKeys = ["id", "meshId", "title", "status", "tasks", "stats", "brief", "createdAt", "updatedAt", "closeCandidateEmittedAt", ...STRUCTURED_MISSION_KEYS, "items", "history"];
2861
2935
  const allowed = hasGoal ? [...baseKeys, "goal"] : [...baseKeys, "goalPreview", "goalTruncated"];
2862
2936
  if (!hasOnlyKeys2(value, allowed)) return false;
2863
2937
  if (!isEvidenceIdentifier(value.id) || !isEvidenceIdentifier(value.meshId)) return false;
@@ -2871,6 +2945,10 @@ function isMissionListSummaryWire(value) {
2871
2945
  if (value.createdAt !== void 0 && typeof value.createdAt !== "string") return false;
2872
2946
  if (value.updatedAt !== void 0 && typeof value.updatedAt !== "string") return false;
2873
2947
  if (value.closeCandidateEmittedAt !== void 0 && value.closeCandidateEmittedAt !== null && typeof value.closeCandidateEmittedAt !== "string") return false;
2948
+ if (!isStructuredMissionFields(value)) return false;
2949
+ for (const k of ["items", "history"]) {
2950
+ if (value[k] !== void 0 && (!Array.isArray(value[k]) || !value[k].every(isRecord))) return false;
2951
+ }
2874
2952
  return true;
2875
2953
  }
2876
2954
  function isMeshMissionHistoryFoldWire(value) {
@@ -3393,6 +3471,282 @@ function touchedFilesOutsideOwnership(touched, owned) {
3393
3471
  return { undeclaredTouched, unusedDeclarations };
3394
3472
  }
3395
3473
 
3474
+ // src/mission-items.ts
3475
+ var MISSION_ITEM_KINDS = ["remaining", "live_check", "decision", "evidence"];
3476
+ var MISSION_ITEM_STATES = ["open", "done", "dropped", "moved", "answered", "expired", "withdrawn", "superseded"];
3477
+ var COORDINATOR_SETTABLE_ITEM_STATES = {
3478
+ remaining: ["open", "done", "dropped"],
3479
+ live_check: ["open", "done", "dropped"],
3480
+ evidence: ["open", "done", "dropped"],
3481
+ decision: ["open", "withdrawn", "superseded"]
3482
+ };
3483
+ var MISSION_OUTCOMES = ["merged", "verified_live", "superseded", "not_needed", "owner_abandoned", "unspecified"];
3484
+ function isMissionOutcome(value) {
3485
+ return typeof value === "string" && MISSION_OUTCOMES.includes(value);
3486
+ }
3487
+ var MISSION_REF_KINDS = ["commit", "branch", "pr", "task", "artifact", "mission", "url"];
3488
+ var MISSION_LIMITS = {
3489
+ summary: 300,
3490
+ outcomeReason: 500,
3491
+ itemText: 300,
3492
+ machine: 80,
3493
+ refs: 8,
3494
+ refValue: 300,
3495
+ refRepo: 120,
3496
+ refNote: 200,
3497
+ dedupeKey: 400,
3498
+ question: 300,
3499
+ context: 600,
3500
+ options: 5,
3501
+ optionLabel: 60,
3502
+ optionDetail: 200,
3503
+ /** Open items per mission before the oldest `remaining` fold into a "N more" summary item. */
3504
+ openItemsPerMission: 200,
3505
+ /** One event payload (serialized). */
3506
+ eventPayloadBytes: 16 * 1024,
3507
+ /** items_add / items_update entries honoured per call (extra entries are reported, not applied). */
3508
+ itemsPerCall: 50
3509
+ };
3510
+ var MISSION_DECISION_OPTION_IDS = ["a", "b", "c", "d", "e"];
3511
+ var MISSION_DECISION_URGENCIES = ["normal", "blocking"];
3512
+ var MISSION_DECISION_ON_DUE = ["remind", "apply_recommended"];
3513
+ function truncateMissionText(value, max) {
3514
+ if (value.length <= max) return value;
3515
+ return `${value.slice(0, max - 1).trimEnd()}\u2026`;
3516
+ }
3517
+ function str(value) {
3518
+ return typeof value === "string" ? value.trim() : "";
3519
+ }
3520
+ function collapse(value) {
3521
+ return value.replace(/\s+/g, " ").trim();
3522
+ }
3523
+ function normalizeMissionSummary(value) {
3524
+ if (typeof value !== "string") return null;
3525
+ const text = collapse(value);
3526
+ return { value: truncateMissionText(text, MISSION_LIMITS.summary), truncated: text.length > MISSION_LIMITS.summary };
3527
+ }
3528
+ function normalizeOutcomeReason(value) {
3529
+ if (typeof value !== "string") return null;
3530
+ const text = value.trim();
3531
+ return { value: truncateMissionText(text, MISSION_LIMITS.outcomeReason), truncated: text.length > MISSION_LIMITS.outcomeReason };
3532
+ }
3533
+ function normalizeMissionRefs(value) {
3534
+ if (!Array.isArray(value)) return { refs: [], truncated: false };
3535
+ const refs = [];
3536
+ let truncated = false;
3537
+ for (const raw of value) {
3538
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
3539
+ const r = raw;
3540
+ const kind = str(r.kind);
3541
+ const refValue = str(r.value);
3542
+ if (!MISSION_REF_KINDS.includes(kind) || !refValue) continue;
3543
+ if (refs.length >= MISSION_LIMITS.refs) {
3544
+ truncated = true;
3545
+ break;
3546
+ }
3547
+ const repo = str(r.repo);
3548
+ const note = str(r.note);
3549
+ refs.push({
3550
+ kind,
3551
+ ...repo ? { repo: truncateMissionText(repo, MISSION_LIMITS.refRepo) } : {},
3552
+ value: truncateMissionText(refValue, MISSION_LIMITS.refValue),
3553
+ ...note ? { note: truncateMissionText(note, MISSION_LIMITS.refNote) } : {}
3554
+ });
3555
+ }
3556
+ return { refs, truncated };
3557
+ }
3558
+ function normalizeOptions(value, truncated) {
3559
+ if (!Array.isArray(value)) return [];
3560
+ const out = [];
3561
+ for (const raw of value) {
3562
+ if (typeof raw === "string" && raw.trim()) {
3563
+ if (out.length >= MISSION_LIMITS.options) {
3564
+ truncated.push("options");
3565
+ break;
3566
+ }
3567
+ out.push({ id: MISSION_DECISION_OPTION_IDS[out.length], label: truncateMissionText(raw.trim(), MISSION_LIMITS.optionLabel) });
3568
+ continue;
3569
+ }
3570
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) continue;
3571
+ const o = raw;
3572
+ const label = collapse(str(o.label));
3573
+ if (!label) continue;
3574
+ if (out.length >= MISSION_LIMITS.options) {
3575
+ truncated.push("options");
3576
+ break;
3577
+ }
3578
+ const detail = str(o.detail);
3579
+ out.push({
3580
+ id: MISSION_DECISION_OPTION_IDS[out.length],
3581
+ label: truncateMissionText(label, MISSION_LIMITS.optionLabel),
3582
+ ...detail ? { detail: truncateMissionText(detail, MISSION_LIMITS.optionDetail) } : {}
3583
+ });
3584
+ }
3585
+ return out;
3586
+ }
3587
+ function normalizeDueAt(value) {
3588
+ if (typeof value !== "string" || !value.trim()) return void 0;
3589
+ const ms2 = Date.parse(value);
3590
+ return Number.isNaN(ms2) ? void 0 : new Date(ms2).toISOString();
3591
+ }
3592
+ function normalizeDecisionInput(raw, truncated) {
3593
+ const questionSource = collapse(str(raw.question) || str(raw.text));
3594
+ if (!questionSource) return null;
3595
+ if (questionSource.length > MISSION_LIMITS.question) truncated.push("question");
3596
+ const question = truncateMissionText(questionSource, MISSION_LIMITS.question);
3597
+ const contextSource = str(raw.context);
3598
+ if (contextSource.length > MISSION_LIMITS.context) truncated.push("context");
3599
+ const options = normalizeOptions(raw.options, truncated);
3600
+ const recommendedRaw = str(raw.recommended);
3601
+ const recommended = recommendedRaw && options.some((o) => o.id === recommendedRaw) ? recommendedRaw : options.find((o) => recommendedRaw && o.label.toLowerCase() === recommendedRaw.toLowerCase())?.id;
3602
+ const dueAt = normalizeDueAt(raw.dueAt ?? raw.due_at);
3603
+ const onDueRaw = str(raw.onDue ?? raw.on_due);
3604
+ const urgencyRaw = str(raw.urgency);
3605
+ const allowFreeTextRaw = raw.allowFreeText ?? raw.allow_free_text;
3606
+ return {
3607
+ question,
3608
+ ...contextSource ? { context: truncateMissionText(contextSource, MISSION_LIMITS.context) } : {},
3609
+ options,
3610
+ ...recommended ? { recommended } : {},
3611
+ allowFreeText: typeof allowFreeTextRaw === "boolean" ? allowFreeTextRaw : true,
3612
+ ...dueAt ? { dueAt } : {},
3613
+ // apply_recommended without a recommended option has nothing to apply — fall back to remind.
3614
+ onDue: onDueRaw === "apply_recommended" && recommended ? "apply_recommended" : "remind",
3615
+ urgency: urgencyRaw === "blocking" ? "blocking" : "normal"
3616
+ };
3617
+ }
3618
+ function normalizeForDedupe(text) {
3619
+ return collapse(text).toLowerCase().replace(/[\s.!?。]+$/u, "");
3620
+ }
3621
+ function deriveItemDedupeKey(kind, parts) {
3622
+ const explicit = str(parts.explicit);
3623
+ if (explicit) return truncateMissionText(`k:${explicit}`, MISSION_LIMITS.dedupeKey);
3624
+ if (kind === "decision") return truncateMissionText(`decision:${normalizeForDedupe(parts.question ?? parts.text ?? "")}`, MISSION_LIMITS.dedupeKey);
3625
+ if (kind === "evidence") {
3626
+ const ref2 = parts.refs?.[0];
3627
+ if (ref2) return truncateMissionText(`evidence:${ref2.kind}:${ref2.repo ?? ""}:${ref2.value}`, MISSION_LIMITS.dedupeKey);
3628
+ }
3629
+ const machine = parts.machine ? `@${normalizeForDedupe(parts.machine)}` : "";
3630
+ return truncateMissionText(`${kind}${machine}:${normalizeForDedupe(parts.text ?? "")}`, MISSION_LIMITS.dedupeKey);
3631
+ }
3632
+ function normalizeMissionItemInput(raw) {
3633
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { error: "item must be an object" };
3634
+ const r = raw;
3635
+ const kind = str(r.kind) || "remaining";
3636
+ if (!MISSION_ITEM_KINDS.includes(kind)) {
3637
+ return { error: `invalid kind '${kind}' (valid: ${MISSION_ITEM_KINDS.join(", ")})` };
3638
+ }
3639
+ const truncated = [];
3640
+ const { refs, truncated: refsTruncated } = normalizeMissionRefs(r.refs);
3641
+ if (refsTruncated) truncated.push("refs");
3642
+ const machineRaw = collapse(str(r.machine));
3643
+ const machine = machineRaw ? truncateMissionText(machineRaw, MISSION_LIMITS.machine) : void 0;
3644
+ const explicitKey = str(r.dedupe_key ?? r.dedupeKey);
3645
+ if (kind === "decision") {
3646
+ const decisionRaw = r.decision && typeof r.decision === "object" && !Array.isArray(r.decision) ? r.decision : r;
3647
+ const decision = normalizeDecisionInput({ ...decisionRaw, question: decisionRaw.question ?? r.question ?? r.text }, truncated);
3648
+ if (!decision) return { error: "decision item needs a question" };
3649
+ return {
3650
+ item: {
3651
+ kind,
3652
+ text: decision.question,
3653
+ ...machine ? { machine } : {},
3654
+ refs,
3655
+ decision,
3656
+ dedupeKey: deriveItemDedupeKey("decision", { question: decision.question, explicit: explicitKey }),
3657
+ truncated
3658
+ }
3659
+ };
3660
+ }
3661
+ const textSource = collapse(str(r.text));
3662
+ if (!textSource && !(kind === "evidence" && refs.length > 0)) return { error: `${kind} item needs text` };
3663
+ if (textSource.length > MISSION_LIMITS.itemText) truncated.push("text");
3664
+ const text = truncateMissionText(textSource || `${refs[0].kind}: ${refs[0].value}`, MISSION_LIMITS.itemText);
3665
+ return {
3666
+ item: {
3667
+ kind,
3668
+ text,
3669
+ ...machine ? { machine } : {},
3670
+ refs,
3671
+ dedupeKey: deriveItemDedupeKey(kind, { text, machine, refs, explicit: explicitKey }),
3672
+ truncated
3673
+ }
3674
+ };
3675
+ }
3676
+ function normalizeMissionItemUpdate(raw) {
3677
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { error: "update must be an object" };
3678
+ const r = raw;
3679
+ const id2 = str(r.id ?? r.item_id ?? r.itemId);
3680
+ if (!id2) return { error: "update needs an item id" };
3681
+ const truncated = [];
3682
+ const update = { id: id2 };
3683
+ if (r.state !== void 0) {
3684
+ const state = str(r.state);
3685
+ if (!MISSION_ITEM_STATES.includes(state)) return { error: `invalid state '${state}'` };
3686
+ update.state = state;
3687
+ }
3688
+ if (typeof r.text === "string") {
3689
+ const text = collapse(r.text);
3690
+ if (text.length > MISSION_LIMITS.itemText) truncated.push("text");
3691
+ if (text) update.text = truncateMissionText(text, MISSION_LIMITS.itemText);
3692
+ }
3693
+ if (r.machine === null) update.machine = null;
3694
+ else if (typeof r.machine === "string") {
3695
+ const machine = collapse(r.machine);
3696
+ update.machine = machine ? truncateMissionText(machine, MISSION_LIMITS.machine) : null;
3697
+ }
3698
+ if (r.refs !== void 0) {
3699
+ const { refs, truncated: t } = normalizeMissionRefs(r.refs);
3700
+ if (t) truncated.push("refs");
3701
+ update.refs = refs;
3702
+ }
3703
+ return { update, truncated };
3704
+ }
3705
+ function boundEventPayload(payload) {
3706
+ let json = JSON.stringify(payload);
3707
+ if (json.length <= MISSION_LIMITS.eventPayloadBytes) return json;
3708
+ const shrunk = {};
3709
+ for (const [k, v] of Object.entries(payload)) {
3710
+ shrunk[k] = typeof v === "string" && v.length > 4e3 ? `${v.slice(0, 4e3)}\u2026` : v;
3711
+ }
3712
+ shrunk.payloadTruncated = true;
3713
+ json = JSON.stringify(shrunk);
3714
+ if (json.length <= MISSION_LIMITS.eventPayloadBytes) return json;
3715
+ return JSON.stringify({ payloadTruncated: true, keys: Object.keys(payload).slice(0, 20) });
3716
+ }
3717
+ var CARRY_OVER_MISSION_TITLE = "Carry-over \u2014 open items from closed missions";
3718
+ var LEGACY_CARRY_OVER_MISSION_TITLE = "\uC774\uC6D4 \u2014 \uB2EB\uD78C \uBBF8\uC158\uC5D0\uC11C \uB118\uC5B4\uC628 \uD56D\uBAA9";
3719
+ var CARRY_OVER_MISSION_GOAL = "Open items carried over from closed missions, and decisions requested without a mission. Managed automatically \u2014 do not close.";
3720
+ function isCarryOverMissionRecord(m) {
3721
+ return !!m && (m.isCarryOver === true || isCarryOverMissionTitle(m.title));
3722
+ }
3723
+ function isCarryOverMissionTitle(title) {
3724
+ if (typeof title !== "string") return false;
3725
+ const t = title.trim();
3726
+ return t === CARRY_OVER_MISSION_TITLE || t === LEGACY_CARRY_OVER_MISSION_TITLE;
3727
+ }
3728
+ var OWNER_ABANDON_CONFIRM_KEY_PREFIX = "owner-abandon-confirm:";
3729
+ var OWNER_ABANDON_CONFIRM_QUESTION = "The coordinator closed this as 'owner abandoned' \u2014 correct?";
3730
+ var OWNER_ABANDON_CONFIRM_OPTIONS = ["Correct", "Reopen"];
3731
+ var WORKER_DECISIONS_NEEDED_MAX = 3;
3732
+ var WORKER_COMMITS_MAX = 20;
3733
+ var SHA_RE = /^[0-9a-f]{7,64}$/i;
3734
+ function normalizeReportCommits(value) {
3735
+ if (!Array.isArray(value)) return null;
3736
+ const out = [];
3737
+ for (const v of value) {
3738
+ if (typeof v !== "string") return null;
3739
+ const sha = v.trim();
3740
+ if (!SHA_RE.test(sha)) return null;
3741
+ if (!out.includes(sha.toLowerCase())) out.push(sha.toLowerCase());
3742
+ }
3743
+ return out;
3744
+ }
3745
+
3746
+ // src/decision-push-relay.ts
3747
+ var DECISION_PUSH_RELAY_COMMAND = "mission_decision_push_relay_answer";
3748
+ var DECISION_PUSH_RELAY_SOURCE = "push_relay";
3749
+
3396
3750
  // src/keyed-doc-delta.ts
3397
3751
  function sig(value) {
3398
3752
  if (value === void 0) return void 0;
@@ -3755,6 +4109,86 @@ function isProviderQuestionBinding(value) {
3755
4109
  if (["sessionId", "generation", "threadId", "turnId", "itemId"].some((key) => typeof b[key] !== "string" || !b[key].trim())) return false;
3756
4110
  return b.transport === "codex_async" ? b.requestId === void 0 : typeof b.requestId === "string" && !!b.requestId.trim() || typeof b.requestId === "number" && Number.isFinite(b.requestId);
3757
4111
  }
4112
+
4113
+ // src/relay-reprobe.ts
4114
+ var RELAY_REPROBE_BASE_DELAY_MS = 6e4;
4115
+ var RELAY_REPROBE_MAX_DELAY_MS = 5 * 6e4;
4116
+ var RELAY_REPROBE_JITTER_RATIO = 0.2;
4117
+ function computeRelayReprobeDelay(failures, random, timing = {}) {
4118
+ const base = timing.baseDelayMs ?? RELAY_REPROBE_BASE_DELAY_MS;
4119
+ const max = timing.maxDelayMs ?? RELAY_REPROBE_MAX_DELAY_MS;
4120
+ const jitter = timing.jitterRatio ?? RELAY_REPROBE_JITTER_RATIO;
4121
+ const grown = Math.min(max, base * 2 ** Math.max(0, failures));
4122
+ const factor = 1 + jitter * (Math.min(1, Math.max(0, random())) * 2 - 1);
4123
+ return Math.round(grown * factor);
4124
+ }
4125
+ var RelayReprobeScheduler = class {
4126
+ constructor(options) {
4127
+ this.options = options;
4128
+ }
4129
+ handle = null;
4130
+ running = false;
4131
+ inFlight = false;
4132
+ failureCount = 0;
4133
+ generation = 0;
4134
+ get isRunning() {
4135
+ return this.running;
4136
+ }
4137
+ get failures() {
4138
+ return this.failureCount;
4139
+ }
4140
+ get probing() {
4141
+ return this.inFlight;
4142
+ }
4143
+ /** Begin probing (idempotent). Call when a connection is selected as relay. */
4144
+ start() {
4145
+ if (this.running) return;
4146
+ this.running = true;
4147
+ this.failureCount = 0;
4148
+ this.generation++;
4149
+ this.schedule();
4150
+ }
4151
+ /** Stop for good (direct path found, connection closed, auth epoch changed). */
4152
+ stop() {
4153
+ this.running = false;
4154
+ this.generation++;
4155
+ if (this.handle !== null) {
4156
+ this.options.clearTimer(this.handle);
4157
+ this.handle = null;
4158
+ }
4159
+ }
4160
+ schedule() {
4161
+ if (!this.running) return;
4162
+ const generation = this.generation;
4163
+ const delay = computeRelayReprobeDelay(this.failureCount, this.options.random, this.options);
4164
+ this.handle = this.options.setTimer(() => {
4165
+ this.handle = null;
4166
+ void this.tick(generation);
4167
+ }, delay);
4168
+ }
4169
+ async tick(generation) {
4170
+ if (!this.running || generation !== this.generation) return;
4171
+ if (this.inFlight || !this.options.shouldProbe()) {
4172
+ this.schedule();
4173
+ return;
4174
+ }
4175
+ this.inFlight = true;
4176
+ let outcome;
4177
+ try {
4178
+ outcome = await this.options.probe();
4179
+ } catch {
4180
+ outcome = "failed";
4181
+ }
4182
+ this.inFlight = false;
4183
+ if (!this.running || generation !== this.generation) return;
4184
+ if (outcome === "direct") {
4185
+ this.stop();
4186
+ return;
4187
+ }
4188
+ if (outcome !== "skipped") this.failureCount++;
4189
+ this.schedule();
4190
+ }
4191
+ };
3758
4192
  export {
3759
4193
  ASSISTANT_ACCOUNT_SLOT,
3760
4194
  ASSISTANT_FOLLOWER_ALLOWED_OPS,
@@ -3774,12 +4208,15 @@ export {
3774
4208
  CANCEL_REASONS,
3775
4209
  CANONICAL_MESH_TOOL_COUNT,
3776
4210
  CANONICAL_MESH_TOOL_NAMES,
4211
+ CARRY_OVER_MISSION_GOAL,
4212
+ CARRY_OVER_MISSION_TITLE,
3777
4213
  CLAUDE_TUI_REVIEW_PAGE_NOT_FOCUSED_PREFIX,
3778
4214
  CLAUDE_TUI_REVIEW_UNCONFIRMED_PREFIX,
3779
4215
  CLI_SLOT_RECIPES,
3780
4216
  COMMIT_STRENGTHS,
3781
4217
  CONSUME_PROFILES,
3782
4218
  COORDINATOR_ACK_OUTCOMES,
4219
+ COORDINATOR_SETTABLE_ITEM_STATES,
3783
4220
  DAEMON_METADATA_DOC_SPEC,
3784
4221
  DAEMON_P2P_SIGNAL_TYPES,
3785
4222
  DAEMON_STATUS_EVENT_NAMES,
@@ -3792,6 +4229,11 @@ export {
3792
4229
  DASHBOARD_TO_DAEMON_P2P_TYPES,
3793
4230
  DASHBOARD_TO_USER_SESSION_TYPES,
3794
4231
  DASHBOARD_WIRE_VERSION,
4232
+ DECISION_PUSH_OPTIONS_MAX,
4233
+ DECISION_PUSH_OPTION_LABEL_MAX,
4234
+ DECISION_PUSH_QUESTION_MAX,
4235
+ DECISION_PUSH_RELAY_COMMAND,
4236
+ DECISION_PUSH_RELAY_SOURCE,
3795
4237
  DEFAULT_DIFFICULTY_BRAINS,
3796
4238
  DELIVERY_OUTCOMES,
3797
4239
  DELIVERY_VIAS,
@@ -3803,6 +4245,7 @@ export {
3803
4245
  LAUNCH_DEFAULT_ERROR_CODES,
3804
4246
  LAUNCH_DEFAULT_ROLES,
3805
4247
  LAUNCH_DEFAULT_SOURCES,
4248
+ LEGACY_CARRY_OVER_MISSION_TITLE,
3806
4249
  LIVENESS_RESULTS,
3807
4250
  MAX_MESH_RECORD_STRING,
3808
4251
  MAX_OWNED_PATHS,
@@ -3828,6 +4271,14 @@ export {
3828
4271
  MESH_TOPIC_ENTRY_KINDS,
3829
4272
  MESH_TOPIC_PROTOCOL_VERSION,
3830
4273
  MISSION_BRIEF_RENDER_MAX_CHARS,
4274
+ MISSION_DECISION_ON_DUE,
4275
+ MISSION_DECISION_OPTION_IDS,
4276
+ MISSION_DECISION_URGENCIES,
4277
+ MISSION_ITEM_KINDS,
4278
+ MISSION_ITEM_STATES,
4279
+ MISSION_LIMITS,
4280
+ MISSION_OUTCOMES,
4281
+ MISSION_REF_KINDS,
3831
4282
  MODEL_AXIS_SOURCES,
3832
4283
  MODEL_SELECTION_HISTORY_LIMIT,
3833
4284
  MeshChunkAssembler,
@@ -3841,6 +4292,9 @@ export {
3841
4292
  OPERATOR_STATUS_REASON_VALUES,
3842
4293
  OPERATOR_STATUS_VALUES,
3843
4294
  OUTBOUND_MESSAGE_ORIGINS,
4295
+ OWNER_ABANDON_CONFIRM_KEY_PREFIX,
4296
+ OWNER_ABANDON_CONFIRM_OPTIONS,
4297
+ OWNER_ABANDON_CONFIRM_QUESTION,
3844
4298
  P2P_SIGNAL_TYPES,
3845
4299
  PROVIDER_FAILURES,
3846
4300
  QUOTA_BACKFILL_HORIZON_MS,
@@ -3848,9 +4302,13 @@ export {
3848
4302
  QUOTA_SUPPORTED_PROVIDERS,
3849
4303
  RECENT_SESSION_BUCKETS,
3850
4304
  RECLAIMING_SEND_REFUSALS,
4305
+ RELAY_REPROBE_BASE_DELAY_MS,
4306
+ RELAY_REPROBE_JITTER_RATIO,
4307
+ RELAY_REPROBE_MAX_DELAY_MS,
3851
4308
  RELEASE_CHANNELS,
3852
4309
  REMOVED_MESH_TOOLS,
3853
4310
  RETIRED_MESH_TOOLS,
4311
+ RelayReprobeScheduler,
3854
4312
  SEND_POLICY_MODES,
3855
4313
  SEND_REFUSAL_REASONS,
3856
4314
  SERVER_STATUS_EVENT_NAMES,
@@ -3888,6 +4346,8 @@ export {
3888
4346
  VERSION_UPDATE_REASONS,
3889
4347
  VIEWER_TO_SHARED_SESSION_TYPES,
3890
4348
  WORKER_BRANCH_STATES,
4349
+ WORKER_COMMITS_MAX,
4350
+ WORKER_DECISIONS_NEEDED_MAX,
3891
4351
  WORKER_PROTOCOL_FOOTER_MARKER,
3892
4352
  WORKER_REPORT_OUTCOMES,
3893
4353
  WORKER_REPORT_SUMMARY_MAX_CHARS,
@@ -3895,11 +4355,13 @@ export {
3895
4355
  appendWorkerProtocolFooter,
3896
4356
  argsCarryStatusProbeMarker,
3897
4357
  assessQuotaFreshness,
4358
+ boundEventPayload,
3898
4359
  buildSlotProposal,
3899
4360
  canonicalDaemonId,
3900
4361
  classifySessionStatus,
3901
4362
  compareDashboardWireVersion,
3902
4363
  compareSemver,
4364
+ computeRelayReprobeDelay,
3903
4365
  daemonIdsEquivalent,
3904
4366
  decodeActiveWorkQueryRequest,
3905
4367
  decodeActiveWorkQueryResponse,
@@ -3963,6 +4425,7 @@ export {
3963
4425
  decodeUserSessionToDashboard,
3964
4426
  decodeViewerToSharedSession,
3965
4427
  defaultProviderPriorityFromNodeFacts,
4428
+ deriveItemDedupeKey,
3966
4429
  deriveProviderPriorityFromSlots,
3967
4430
  deriveSlotsFromLegacy,
3968
4431
  describeModelSelection,
@@ -3974,6 +4437,7 @@ export {
3974
4437
  findOwnershipConflicts,
3975
4438
  foldKeyedDoc,
3976
4439
  followedRemoteProjectKey,
4440
+ followerOpPermitted,
3977
4441
  formatQuotaAccount,
3978
4442
  hasGitStatusEvidence,
3979
4443
  hasWorkerProtocolFooter,
@@ -3983,6 +4447,8 @@ export {
3983
4447
  isAssistantTool,
3984
4448
  isBlockedStatus,
3985
4449
  isBusyStatus,
4450
+ isCarryOverMissionRecord,
4451
+ isCarryOverMissionTitle,
3986
4452
  isChunkType,
3987
4453
  isCommitStrength,
3988
4454
  isDaemonDirectCommandType,
@@ -4015,6 +4481,7 @@ export {
4015
4481
  isMeshTerminalTaskStatus,
4016
4482
  isMeshTopicEntry,
4017
4483
  isMessageId,
4484
+ isMissionOutcome,
4018
4485
  isMissionUpsertResponse,
4019
4486
  isModelAxisSource,
4020
4487
  isNativeMarkerRef,
@@ -4065,16 +4532,24 @@ export {
4065
4532
  minutesUntilQuotaCheck,
4066
4533
  normalizeAuthOkLimits,
4067
4534
  normalizeBrainSlot,
4535
+ normalizeDecisionInput,
4068
4536
  normalizeDifficultyBrainMap,
4537
+ normalizeForDedupe,
4069
4538
  normalizeGitStatus,
4070
4539
  normalizeMeshNodeFacts,
4071
4540
  normalizeMeshNodeId,
4072
4541
  normalizeMeshSessionRecord,
4073
4542
  normalizeMeshWorkspaceForCompare,
4074
4543
  normalizeMissionBrief,
4544
+ normalizeMissionItemInput,
4545
+ normalizeMissionItemUpdate,
4546
+ normalizeMissionRefs,
4547
+ normalizeMissionSummary,
4075
4548
  normalizeNodeCapabilitySlot,
4076
4549
  normalizeNodeCapabilitySlots,
4550
+ normalizeOutcomeReason,
4077
4551
  normalizeOwnedPaths,
4552
+ normalizeReportCommits,
4078
4553
  normalizeSessionStatus,
4079
4554
  normalizeThinkingLevel,
4080
4555
  orderProvidersByBuiltinPreference,
@@ -4114,6 +4589,7 @@ export {
4114
4589
  summarizeGitShape,
4115
4590
  supportsQuota,
4116
4591
  touchedFilesOutsideOwnership,
4592
+ truncateMissionText,
4117
4593
  unwrapPastedContent,
4118
4594
  withStatusProbeMarker
4119
4595
  };