@quantiya/codevibe-claude-plugin 2.0.24 → 2.0.26

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.
Files changed (27) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/dist/server.js +7 -7
  3. package/node_modules/@quantiya/codevibe-core/dist/e1/__tests__/prompt-publication.test.d.ts +1 -0
  4. package/node_modules/@quantiya/codevibe-core/dist/e1/index.d.ts +1 -0
  5. package/node_modules/@quantiya/codevibe-core/dist/e1/prompt-publication.d.ts +14 -0
  6. package/node_modules/@quantiya/codevibe-core/dist/index.d.ts +3 -2
  7. package/node_modules/@quantiya/codevibe-core/dist/index.js +621 -430
  8. package/node_modules/@quantiya/codevibe-core/dist/orchestration-shell/audit-browser.d.ts +42 -2
  9. package/node_modules/@quantiya/codevibe-core/dist/orchestration-shell/audit-runner.d.ts +13 -1
  10. package/node_modules/@quantiya/codevibe-core/dist/orchestration-shell/cli.d.ts +8 -0
  11. package/node_modules/@quantiya/codevibe-core/dist/orchestration-shell/cli.js +649 -87
  12. package/node_modules/@quantiya/codevibe-core/dist/orchestration-shell/flag-command.d.ts +4 -1
  13. package/node_modules/@quantiya/codevibe-core/dist/orchestration-shell/index.d.ts +16 -2
  14. package/node_modules/@quantiya/codevibe-core/dist/orchestration-shell/types.d.ts +2 -0
  15. package/node_modules/@quantiya/codevibe-core/dist/tool-activity/types.d.ts +32 -32
  16. package/node_modules/@quantiya/codevibe-core/package.json +1 -1
  17. package/node_modules/fs-ext/build/Makefile +347 -0
  18. package/node_modules/fs-ext/build/Release/.deps/Release/fs_ext.node.d +1 -0
  19. package/node_modules/fs-ext/build/Release/.deps/Release/obj.target/fs_ext/fs-ext.o.d +165 -0
  20. package/node_modules/fs-ext/build/Release/fs_ext.node +0 -0
  21. package/node_modules/fs-ext/build/Release/obj.target/fs_ext/fs-ext.o +0 -0
  22. package/node_modules/fs-ext/build/binding.Makefile +6 -0
  23. package/node_modules/fs-ext/build/config.gypi +503 -0
  24. package/node_modules/fs-ext/build/fs_ext.target.mk +183 -0
  25. package/node_modules/fs-ext/build/gyp-mac-tool +768 -0
  26. package/node_modules/keytar/build/Release/keytar.node +0 -0
  27. package/package.json +2 -2
@@ -7703,7 +7703,7 @@ CodeVibe \u2014 choose mode (${tier} tier):
7703
7703
  }
7704
7704
 
7705
7705
  // src/orchestration-shell/index.ts
7706
- var React20 = __toESM(require("react")), path64 = __toESM(require("path")), os35 = __toESM(require("os")), import_promises2 = require("node:fs/promises"), import_node_async_hooks = require("node:async_hooks"), import_uuid11 = require("uuid");
7706
+ var React20 = __toESM(require("react")), path64 = __toESM(require("path")), os35 = __toESM(require("os")), import_promises2 = require("node:fs/promises"), import_node_fs26 = require("node:fs"), import_node_async_hooks = require("node:async_hooks"), import_uuid11 = require("uuid");
7707
7707
  init_logger2();
7708
7708
 
7709
7709
  // src/track-presentation.ts
@@ -24763,43 +24763,312 @@ function buildReviewerVerdictModel(payload) {
24763
24763
  let provenance = parts.length > 0 ? parts.join(" \xB7 ") : null, reasoning = asString(verdict.reasoning), sugRaw = verdict.suggested_changes ?? verdict.suggestedChanges, suggestedChanges = Array.isArray(sugRaw) ? sugRaw.filter((s) => typeof s == "string") : [];
24764
24764
  return { decisionLabel, provenance, reasoning, suggestedChanges };
24765
24765
  }
24766
+ function extractEffectivePayload(payload) {
24767
+ let rec = asRecord2(payload);
24768
+ if (!rec) return { dict: {}, hasSpec: !1 };
24769
+ let spec = asRecord2(rec.spec);
24770
+ if (spec && typeof rec.kind == "string") {
24771
+ let extra = {};
24772
+ for (let [k, v] of Object.entries(rec))
24773
+ k !== "kind" && k !== "spec" && (extra[k] = v);
24774
+ return { dict: { ...extra, ...spec }, hasSpec: !0 };
24775
+ }
24776
+ return { dict: rec, hasSpec: !1 };
24777
+ }
24766
24778
  function buildTaskAuthorizedModel(payload) {
24767
- let spec = asRecord2(payload.spec);
24768
- return spec ? {
24769
- authorizedAction: asString(spec.authorized_action),
24779
+ let spec = asRecord2(payload.spec) ?? payload, authorizedAction = asString(spec.authorized_action);
24780
+ return authorizedAction ? {
24781
+ authorizedAction,
24770
24782
  authorityScope: asString(spec.authority_scope),
24771
24783
  authorityExpiresAt: asString(spec.authority_expires_at),
24772
24784
  approvalEventId: asString(spec.approval_event_id)
24773
24785
  } : null;
24774
24786
  }
24787
+ var decisionLabelMap = {
24788
+ ...decisionCopy,
24789
+ APPROVE: "Approved",
24790
+ REJECT: "Rejected",
24791
+ REVISE: "Requested changes",
24792
+ ESCALATE: "Escalated",
24793
+ approve: "Approved",
24794
+ proceed: "Approved",
24795
+ consensus_approve: "Consensus approve",
24796
+ reject: "Rejected",
24797
+ revise: "Requested changes",
24798
+ auto_revise: "Auto-revise",
24799
+ escalate: "Escalated",
24800
+ pass: "Pass",
24801
+ fail: "Fail",
24802
+ accept: "Accept",
24803
+ accept_with_notes: "Accept with notes",
24804
+ reject_with_notes: "Reject with notes",
24805
+ reject_restart: "Reject and restart",
24806
+ abort_task: "Abort task"
24807
+ };
24808
+ function formatDecisionValue(raw) {
24809
+ if (typeof raw == "string")
24810
+ return decisionLabelMap[raw] ?? decisionCopy[raw] ?? raw;
24811
+ if (typeof raw == "number" || typeof raw == "boolean")
24812
+ return String(raw);
24813
+ if (asRecord2(raw)) {
24814
+ let rawKind = asRecord2(raw).kind;
24815
+ if (typeof rawKind == "string")
24816
+ return decisionLabelMap[rawKind] ?? decisionCopy[rawKind] ?? rawKind;
24817
+ if (typeof rawKind == "number" || typeof rawKind == "boolean")
24818
+ return String(rawKind);
24819
+ }
24820
+ return null;
24821
+ }
24822
+ function appendString(rows, dict, keys, label, consumed) {
24823
+ for (let k of keys) {
24824
+ let v = dict[k];
24825
+ if (typeof v == "string" && v.trim().length > 0) {
24826
+ rows.push({ label, value: v.trim() }), consumed && consumed.add(k);
24827
+ return;
24828
+ }
24829
+ }
24830
+ }
24831
+ function appendScalar(rows, dict, keys, label, consumed) {
24832
+ for (let k of keys) {
24833
+ let v = dict[k];
24834
+ if (typeof v == "string" && v.trim().length > 0) {
24835
+ rows.push({ label, value: v.trim() }), consumed && consumed.add(k);
24836
+ return;
24837
+ }
24838
+ if (typeof v == "number" && Number.isFinite(v)) {
24839
+ rows.push({ label, value: String(v) }), consumed && consumed.add(k);
24840
+ return;
24841
+ }
24842
+ }
24843
+ }
24844
+ function appendInt(rows, dict, keys, label, consumed) {
24845
+ for (let k of keys) {
24846
+ let v = dict[k];
24847
+ if (typeof v == "number" && Number.isFinite(v)) {
24848
+ rows.push({ label, value: String(v) }), consumed && consumed.add(k);
24849
+ return;
24850
+ }
24851
+ }
24852
+ }
24853
+ function appendStringList(rows, dict, keys, label, consumed) {
24854
+ for (let k of keys) {
24855
+ let v = dict[k];
24856
+ if (Array.isArray(v)) {
24857
+ if (v.length === 0) {
24858
+ rows.push({ label, value: "(none)" }), consumed && consumed.add(k);
24859
+ return;
24860
+ }
24861
+ if (v.every((item) => typeof item == "string")) {
24862
+ let items = v.map((item) => item.trim()).filter((s) => s.length > 0);
24863
+ rows.push({ label, value: items.length > 0 ? items.join(", ") : "(none)" }), consumed && consumed.add(k);
24864
+ return;
24865
+ }
24866
+ return;
24867
+ }
24868
+ }
24869
+ }
24870
+ function humanize(key) {
24871
+ let spaced = key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").trim();
24872
+ return spaced.length === 0 ? key : spaced.charAt(0).toUpperCase() + spaced.slice(1);
24873
+ }
24874
+ function buildCompactVerdictRows(payload, ctx) {
24875
+ let rows = [], { consumed } = ctx;
24876
+ appendScalar(rows, payload, ["seat_id", "seatId", "exhausted_seat_id"], "Seat", consumed), appendString(rows, payload, ["new_seat_id", "newSeatId"], "New seat", consumed), appendString(rows, payload, ["role"], "Role", consumed), appendString(rows, payload, ["agent_kind", "reviewer_agent", "reviewerAgent"], "Reviewer", consumed);
24877
+ let decisionKey = ["decision", "verdict", "seat_state"].find(
24878
+ (k) => payload[k] !== void 0
24879
+ );
24880
+ if (decisionKey) {
24881
+ let decisionRaw = payload[decisionKey], label = formatDecisionValue(decisionRaw), decisionRendered = !1;
24882
+ if (label && (rows.push({ label: "Decision", value: label }), decisionRendered = !0), asRecord2(decisionRaw)) {
24883
+ let decObj = asRecord2(decisionRaw), decConsumed = /* @__PURE__ */ new Set();
24884
+ decisionRendered && decObj.kind !== void 0 && decConsumed.add("kind"), typeof decObj.reason == "string" && decObj.reason.trim().length > 0 && (rows.push({ label: "Reason", value: decObj.reason.trim() }), decConsumed.add("reason")), appendRemainingScalarRows(rows, decObj, decConsumed) && (ctx.hasUnrenderedComplex = !0), consumed.add(decisionKey);
24885
+ } else typeof decisionRaw == "string" || typeof decisionRaw == "number" || typeof decisionRaw == "boolean" ? (decisionRendered || rows.push({ label: "Decision", value: String(decisionRaw) }), consumed.add(decisionKey)) : ctx.hasUnrenderedComplex = !0;
24886
+ } else
24887
+ appendString(rows, payload, ["state"], "State", consumed);
24888
+ return appendString(rows, payload, ["exhaust_reason", "exhaustReason"], "Exhaust reason", consumed), appendString(rows, payload, ["dispatch_ulid", "dispatchUlid"], "Dispatch ULID", consumed), appendString(rows, payload, ["evidence_artifact_id", "evidenceArtifactId"], "Evidence artifact", consumed), appendString(rows, payload, ["provenance"], "Provenance", consumed), rows;
24889
+ }
24890
+ function buildGateLifecycleRows(payload, ctx) {
24891
+ let rows = [], { consumed } = ctx;
24892
+ appendString(
24893
+ rows,
24894
+ payload,
24895
+ ["gate_type", "gateType", "gate_kind", "gateKind", "gate_id", "gateId"],
24896
+ "Gate",
24897
+ consumed
24898
+ ), appendString(rows, payload, ["from", "from_status", "from_state"], "From", consumed), appendString(rows, payload, ["to", "to_status", "to_state"], "To", consumed);
24899
+ let decisionKey = ["decision", "verdict"].find((k) => payload[k] !== void 0);
24900
+ if (decisionKey) {
24901
+ let decisionRaw = payload[decisionKey], formatted = formatDecisionValue(decisionRaw), decisionRendered = !1;
24902
+ if (formatted && (rows.push({ label: "Decision", value: formatted }), decisionRendered = !0), asRecord2(decisionRaw)) {
24903
+ let decObj = asRecord2(decisionRaw), decConsumed = /* @__PURE__ */ new Set();
24904
+ if (decisionRendered && decObj.kind !== void 0 && decConsumed.add("kind"), decObj.next_round !== void 0 && Number.isFinite(decObj.next_round) && (rows.push({ label: "Next round", value: String(decObj.next_round) }), decConsumed.add("next_round")), typeof decObj.reason == "string" && decObj.reason.trim().length > 0)
24905
+ rows.push({ label: "Reason", value: decObj.reason.trim() }), decConsumed.add("reason");
24906
+ else if (asRecord2(decObj.reason)) {
24907
+ let reasonObj = asRecord2(decObj.reason), reasonConsumed = /* @__PURE__ */ new Set(), rawReasonKind = reasonObj.kind;
24908
+ typeof rawReasonKind == "string" && rawReasonKind.trim().length > 0 ? (rows.push({ label: "Escalation reason", value: humanize(rawReasonKind.trim()) }), reasonConsumed.add("kind")) : (typeof rawReasonKind == "number" || typeof rawReasonKind == "boolean") && (rows.push({ label: "Escalation reason", value: String(rawReasonKind) }), reasonConsumed.add("kind")), typeof reasonObj.message == "string" && reasonObj.message.trim().length > 0 && (rows.push({ label: "Escalation message", value: reasonObj.message.trim() }), reasonConsumed.add("message")), appendRemainingScalarRows(rows, reasonObj, reasonConsumed) && (ctx.hasUnrenderedComplex = !0), decConsumed.add("reason");
24909
+ } else decObj.reason !== void 0 && (ctx.hasUnrenderedComplex = !0);
24910
+ appendRemainingScalarRows(rows, decObj, decConsumed) && (ctx.hasUnrenderedComplex = !0), consumed.add(decisionKey);
24911
+ } else typeof decisionRaw == "string" || typeof decisionRaw == "number" || typeof decisionRaw == "boolean" ? (decisionRendered || rows.push({ label: "Decision", value: String(decisionRaw) }), consumed.add(decisionKey)) : ctx.hasUnrenderedComplex = !0;
24912
+ }
24913
+ return appendString(rows, payload, ["outcome", "merge_outcome", "mergeOutcome"], "Outcome", consumed), appendString(rows, payload, ["reason"], "Reason", consumed), appendInt(rows, payload, ["round_number", "round", "roundNumber", "current_round"], "Round", consumed), appendInt(rows, payload, ["next_round", "nextRound"], "Next round", consumed), appendInt(rows, payload, ["verdict_count", "verdictCount"], "Verdicts", consumed), appendStringList(rows, payload, ["blocking_seat_ids", "blockingSeatIds"], "Blocking seats", consumed), appendInt(rows, payload, ["cap"], "Cap", consumed), rows;
24914
+ }
24915
+ function buildToolUseRows(payload, ctx) {
24916
+ let rows = [], { consumed } = ctx;
24917
+ return appendString(rows, payload, ["tool_name", "toolName", "tool"], "Tool", consumed), appendString(rows, payload, ["file_path", "target", "filePath", "path"], "Target", consumed), appendString(rows, payload, ["command", "action", "input"], "Action", consumed), appendString(rows, payload, ["status"], "Status", consumed), appendInt(rows, payload, ["duration_ms", "durationMs"], "Duration (ms)", consumed), rows;
24918
+ }
24919
+ function buildEscalationRows(payload, ctx) {
24920
+ let rows = [], { consumed } = ctx;
24921
+ return appendString(rows, payload, ["action", "tool_name", "toolName"], "Action", consumed), appendString(rows, payload, ["refusal_category", "refusalCategory"], "Refusal category", consumed), appendString(rows, payload, ["risk_level", "riskLevel", "risk"], "Risk level", consumed), appendString(rows, payload, ["justification", "rationale", "reason"], "Justification", consumed), appendString(rows, payload, ["policy_rule", "rule"], "Policy rule", consumed), appendString(rows, payload, ["gate_id", "gateId"], "Gate", consumed), rows;
24922
+ }
24923
+ function buildUserDecisionRows(payload, ctx) {
24924
+ let rows = [], { consumed } = ctx, decisionRaw = payload.decision;
24925
+ if (decisionRaw !== void 0) {
24926
+ let formatted = formatDecisionValue(decisionRaw), decisionRendered = !1;
24927
+ if (formatted && (rows.push({ label: "Decision", value: formatted }), decisionRendered = !0), asRecord2(decisionRaw)) {
24928
+ let decObj = asRecord2(decisionRaw), decConsumed = /* @__PURE__ */ new Set();
24929
+ decisionRendered && decObj.kind !== void 0 && decConsumed.add("kind"), typeof decObj.reason == "string" && decObj.reason.trim().length > 0 && (rows.push({ label: "Reason", value: decObj.reason.trim() }), decConsumed.add("reason")), appendRemainingScalarRows(rows, decObj, decConsumed) && (ctx.hasUnrenderedComplex = !0), consumed.add("decision");
24930
+ } else typeof decisionRaw == "string" || typeof decisionRaw == "number" || typeof decisionRaw == "boolean" ? (decisionRendered || rows.push({ label: "Decision", value: String(decisionRaw) }), consumed.add("decision")) : ctx.hasUnrenderedComplex = !0;
24931
+ }
24932
+ appendString(rows, payload, ["choice", "selected_option", "selectedOption"], "Selected option", consumed), appendString(rows, payload, ["notes", "note", "reason"], "Note", consumed);
24933
+ let resActionKey = ["resulting_action", "resultingAction", "action"].find(
24934
+ (k) => payload[k] !== void 0
24935
+ );
24936
+ if (resActionKey) {
24937
+ let resAction = payload[resActionKey];
24938
+ if (typeof resAction == "string")
24939
+ consumed.add(resActionKey), rows.push({ label: "Resulting action", value: humanize(resAction) });
24940
+ else if (asRecord2(resAction)) {
24941
+ let actObj = asRecord2(resAction), actConsumed = /* @__PURE__ */ new Set(), actKind = null;
24942
+ typeof actObj.kind == "string" ? (actKind = actObj.kind, actConsumed.add("kind")) : typeof actObj.action == "string" && (actKind = actObj.action, actConsumed.add("action")), actKind && rows.push({ label: "Resulting action", value: humanize(actKind) }), actObj.next_round !== void 0 && Number.isFinite(actObj.next_round) && (rows.push({ label: "Next round", value: String(actObj.next_round) }), actConsumed.add("next_round")), typeof actObj.user_notes == "string" && actObj.user_notes.trim().length > 0 && (rows.push({ label: "User notes", value: actObj.user_notes.trim() }), actConsumed.add("user_notes")), typeof actObj.notes == "string" && actObj.notes.trim().length > 0 && (rows.push({ label: "Notes", value: actObj.notes.trim() }), actConsumed.add("notes")), appendRemainingScalarRows(rows, actObj, actConsumed) && (ctx.hasUnrenderedComplex = !0), !actKind && Object.keys(actObj).length > 0 && rows.every((r) => r.label !== "Resulting action") && (ctx.hasUnrenderedComplex = !0), consumed.add(resActionKey);
24943
+ } else
24944
+ ctx.hasUnrenderedComplex = !0;
24945
+ }
24946
+ return appendInt(rows, payload, ["current_round", "round_number", "round"], "Round", consumed), appendString(rows, payload, ["provenance", "source"], "Provenance", consumed), appendString(rows, payload, ["offer_id", "offerId"], "Offer ID", consumed), appendString(rows, payload, ["source_agent", "sourceAgent"], "Source agent", consumed), appendString(rows, payload, ["target_agent", "targetAgent"], "Target agent", consumed), appendString(rows, payload, ["approver_user_id", "approverUserId"], "Approver", consumed), appendString(rows, payload, ["flagged_entry_id", "flaggedEntryId"], "Flagged entry", consumed), appendString(rows, payload, ["flagged_kind", "flaggedKind"], "Flagged kind", consumed), rows;
24947
+ }
24948
+ function buildPlannerDecisionRows(payload, ctx) {
24949
+ let rows = [], { consumed } = ctx;
24950
+ appendString(rows, payload, ["action"], "Action", consumed);
24951
+ let resultKey = ["result", "result_discriminant", "discriminant"].find(
24952
+ (k) => payload[k] !== void 0
24953
+ );
24954
+ if (resultKey) {
24955
+ let resultRaw = payload[resultKey];
24956
+ if (typeof resultRaw == "string")
24957
+ consumed.add(resultKey), rows.push({ label: "Result", value: resultRaw });
24958
+ else if (asRecord2(resultRaw)) {
24959
+ let resObj = asRecord2(resultRaw), resConsumed = /* @__PURE__ */ new Set(), outcome = asString(resObj.outcome);
24960
+ outcome && (rows.push({ label: "Result", value: humanize(outcome) }), resConsumed.add("outcome"));
24961
+ let reason = asString(resObj.reason);
24962
+ reason && (rows.push({ label: "Reason", value: reason }), resConsumed.add("reason")), appendRemainingScalarRows(rows, resObj, resConsumed) && (ctx.hasUnrenderedComplex = !0), consumed.add(resultKey);
24963
+ } else
24964
+ ctx.hasUnrenderedComplex = !0;
24965
+ }
24966
+ let decisionRaw = payload.decision;
24967
+ if (decisionRaw !== void 0) {
24968
+ let formatted = formatDecisionValue(decisionRaw), decisionRendered = !1;
24969
+ if (formatted && (rows.push({ label: "Decision", value: formatted }), decisionRendered = !0), asRecord2(decisionRaw)) {
24970
+ let decObj = asRecord2(decisionRaw), decConsumed = /* @__PURE__ */ new Set();
24971
+ decisionRendered && decObj.kind !== void 0 && decConsumed.add("kind"), typeof decObj.reason == "string" && decObj.reason.trim().length > 0 && (rows.push({ label: "Reason", value: decObj.reason.trim() }), decConsumed.add("reason")), appendRemainingScalarRows(rows, decObj, decConsumed) && (ctx.hasUnrenderedComplex = !0), consumed.add("decision");
24972
+ } else typeof decisionRaw == "string" || typeof decisionRaw == "number" || typeof decisionRaw == "boolean" ? (decisionRendered || rows.push({ label: "Decision", value: String(decisionRaw) }), consumed.add("decision")) : ctx.hasUnrenderedComplex = !0;
24973
+ }
24974
+ return appendString(
24975
+ rows,
24976
+ payload,
24977
+ ["validated_by", "validatedBy", "validator_id", "validatorId"],
24978
+ "Validated by",
24979
+ consumed
24980
+ ), appendString(rows, payload, ["rationale", "reason"], "Rationale", consumed), appendString(rows, payload, ["step", "planned_action"], "Step", consumed), rows;
24981
+ }
24982
+ function buildPolicyRows(payload, ctx) {
24983
+ let rows = [], { consumed } = ctx;
24984
+ return appendInt(rows, payload, ["current_round", "round_number", "round", "roundNumber"], "Round", consumed), appendInt(rows, payload, ["consecutive_rounds", "consecutiveRounds"], "Consecutive rounds", consumed), appendInt(rows, payload, ["finding_count", "findingCount", "count"], "Finding count", consumed), appendInt(rows, payload, ["repeat_count", "repeatCount", "repeated_count"], "Repeat count", consumed), appendString(
24985
+ rows,
24986
+ payload,
24987
+ ["finding_signature_hex", "finding_signature", "signature"],
24988
+ "Signature",
24989
+ consumed
24990
+ ), appendString(rows, payload, ["matched_pattern", "matchedPattern"], "Matched pattern", consumed), appendString(
24991
+ rows,
24992
+ payload,
24993
+ ["aggregate_status_label", "aggregateStatusLabel"],
24994
+ "Aggregate status",
24995
+ consumed
24996
+ ), appendString(rows, payload, ["resolve_error_kind", "resolveErrorKind"], "Resolve error", consumed), appendString(rows, payload, ["gate_id", "gateId"], "Gate", consumed), appendString(rows, payload, ["task_id", "taskId"], "Task ID", consumed), appendString(rows, payload, ["risk_level", "riskLevel"], "Risk level", consumed), appendString(rows, payload, ["risk_category", "category"], "Risk category", consumed), appendString(rows, payload, ["reason", "message", "explanation"], "Reason", consumed), rows;
24997
+ }
24998
+ function buildTaskLifecycleRows(payload, ctx) {
24999
+ let rows = [], { consumed } = ctx;
25000
+ return appendString(rows, payload, ["task_id", "taskId"], "Task ID", consumed), appendString(rows, payload, ["task_group_id", "taskGroupId"], "Task group", consumed), appendStringList(rows, payload, ["member_task_ids", "memberTaskIds"], "Member tasks", consumed), appendString(rows, payload, ["track_id", "trackId"], "Track", consumed), appendString(rows, payload, ["from_state", "from"], "From", consumed), appendString(rows, payload, ["to_state", "to"], "To", consumed), appendString(rows, payload, ["status"], "Status", consumed), appendString(rows, payload, ["reason", "terminal_reason"], "Reason", consumed), rows;
25001
+ }
25002
+ function buildVerificationRows(payload, ctx) {
25003
+ let rows = [], { consumed } = ctx;
25004
+ return appendString(rows, payload, ["check_name", "check_id", "name", "check"], "Check", consumed), appendString(rows, payload, ["gate_id", "gateId"], "Gate", consumed), appendString(rows, payload, ["gate_kind", "gateKind"], "Gate kind", consumed), appendString(rows, payload, ["status", "result"], "Status", consumed), appendInt(rows, payload, ["exit_code", "exitCode"], "Exit code", consumed), appendString(rows, payload, ["details", "reason"], "Details", consumed), rows;
25005
+ }
25006
+ function buildContinuationRows(payload, ctx) {
25007
+ let rows = [], { consumed } = ctx;
25008
+ return appendString(rows, payload, ["offer_id", "offerId"], "Offer ID", consumed), appendString(rows, payload, ["handoff_kind", "handoffKind"], "Handoff kind", consumed), appendString(rows, payload, ["source_agent", "sourceAgent"], "Source agent", consumed), appendString(rows, payload, ["target_agent", "targetAgent"], "Target agent", consumed), appendString(rows, payload, ["blocked_reason", "blockedReason"], "Blocked reason", consumed), appendString(rows, payload, ["packet_relative_path", "packetRelativePath"], "Packet path", consumed), appendString(rows, payload, ["packet_hash", "packetHash"], "Packet hash", consumed), rows;
25009
+ }
25010
+ function appendRemainingScalarRows(rows, dict, consumed, options) {
25011
+ let hasUnrenderedComplex = !1, isTopLevel = options?.isTopLevel ?? !1, sortedKeys = Object.keys(dict).sort();
25012
+ for (let key of sortedKeys) {
25013
+ if (consumed.has(key) || isTopLevel && (key === "kind" || key === "spec")) continue;
25014
+ let val = dict[key];
25015
+ typeof val == "string" ? (val.trim().length > 0 && rows.push({ label: humanize(key), value: val.trim() }), consumed.add(key)) : typeof val == "number" && Number.isFinite(val) ? (rows.push({ label: humanize(key), value: String(val) }), consumed.add(key)) : typeof val == "boolean" ? (rows.push({ label: humanize(key), value: val ? "true" : "false" }), consumed.add(key)) : Array.isArray(val) ? val.every(
25016
+ (x) => typeof x == "string" || typeof x == "number" || typeof x == "boolean"
25017
+ ) ? (rows.push({
25018
+ label: humanize(key),
25019
+ value: val.length > 0 ? val.join(", ") : "(none)"
25020
+ }), consumed.add(key)) : hasUnrenderedComplex = !0 : val == null ? consumed.add(key) : hasUnrenderedComplex = !0;
25021
+ }
25022
+ return hasUnrenderedComplex;
25023
+ }
24775
25024
  function buildSafePayloadModel(kind, payload, status) {
24776
- let rec = asRecord2(payload);
24777
- if (kind === "reviewer_verdict_recorded" && rec) {
24778
- let model = buildReviewerVerdictModel(rec);
25025
+ let { dict } = extractEffectivePayload(payload), rec = asRecord2(payload);
25026
+ if (kind === "reviewer_verdict_recorded" && (rec || Object.keys(dict).length > 0)) {
25027
+ let model = buildReviewerVerdictModel(dict);
24779
25028
  if (model)
24780
25029
  return {
24781
25030
  status,
24782
25031
  reviewerVerdict: model,
24783
25032
  taskAuthorized: null,
25033
+ detailRows: [],
24784
25034
  rawJson: null,
24785
25035
  unavailableLine: null
24786
25036
  };
24787
25037
  }
24788
- if (kind === "task_authorized" && rec) {
24789
- let model = buildTaskAuthorizedModel(rec);
25038
+ if (kind === "task_authorized" && (rec || Object.keys(dict).length > 0)) {
25039
+ let model = buildTaskAuthorizedModel(rec ?? dict);
24790
25040
  if (model)
24791
25041
  return {
24792
25042
  status,
24793
25043
  reviewerVerdict: null,
24794
25044
  taskAuthorized: model,
25045
+ detailRows: [],
24795
25046
  rawJson: null,
24796
25047
  unavailableLine: null
24797
25048
  };
24798
25049
  }
25050
+ if (kind in auditKindCopy && Object.keys(dict).length > 0) {
25051
+ let ctx = {
25052
+ consumed: /* @__PURE__ */ new Set(),
25053
+ hasUnrenderedComplex: !1
25054
+ }, rows = [];
25055
+ kind === "reviewer_verdict" || kind === "reviewer_verdict_received" ? rows = buildCompactVerdictRows(dict, ctx) : kind === "gate_transition" || kind === "gate_resolved" || kind === "auto_revise_triggered" || kind === "gateplan_transition" || kind === "merge_gate_result" || kind === "gate_blocked_by_review" || kind === "auto_revise_cap_exhausted" ? rows = buildGateLifecycleRows(dict, ctx) : kind === "tool_use" ? rows = buildToolUseRows(dict, ctx) : kind === "destructive_action_escalated" || kind === "unsafe_action_escalated" || kind === "insufficient_quorum_escalated" ? rows = buildEscalationRows(dict, ctx) : kind === "user_decision_recorded" || kind === "flag_bad_approval" || kind === "final_approval" ? rows = buildUserDecisionRows(dict, ctx) : kind === "planner_decision" ? rows = buildPlannerDecisionRows(dict, ctx) : kind.startsWith("policy_") || kind === "custom_panel_rejected" ? rows = buildPolicyRows(dict, ctx) : kind === "task_created" || kind === "task_terminated" || kind === "task_group_scheduled" || kind === "track_transition" ? rows = buildTaskLifecycleRows(dict, ctx) : kind === "verification_result" || kind === "verification_result_recorded" ? rows = buildVerificationRows(dict, ctx) : (kind === "continuation" || kind === "continuation_packet_written" || kind === "continuation_switch_accepted" || kind === "continuation_switch_declined") && (rows = buildContinuationRows(dict, ctx));
25056
+ let topLevelUnrendered = appendRemainingScalarRows(rows, dict, ctx.consumed, { isTopLevel: !0 }), hasUnrenderedComplex = ctx.hasUnrenderedComplex || topLevelUnrendered;
25057
+ if (rows.length > 0)
25058
+ return {
25059
+ status,
25060
+ reviewerVerdict: null,
25061
+ taskAuthorized: null,
25062
+ detailRows: rows,
25063
+ rawJson: hasUnrenderedComplex ? prettyJson(payload) : null,
25064
+ unavailableLine: null
25065
+ };
25066
+ }
24799
25067
  return {
24800
25068
  status,
24801
25069
  reviewerVerdict: null,
24802
25070
  taskAuthorized: null,
25071
+ detailRows: [],
24803
25072
  rawJson: prettyJson(payload),
24804
25073
  unavailableLine: null
24805
25074
  };
@@ -24809,6 +25078,7 @@ function failClosedModel() {
24809
25078
  status: "unavailable",
24810
25079
  reviewerVerdict: null,
24811
25080
  taskAuthorized: null,
25081
+ detailRows: [],
24812
25082
  rawJson: null,
24813
25083
  unavailableLine: ENTRY_DETAILS_UNAVAILABLE
24814
25084
  };
@@ -24831,10 +25101,10 @@ function routeAuditEntry(row, sessionKey, decrypt) {
24831
25101
  }
24832
25102
  let gateResolved = null;
24833
25103
  if (kind === "gate_resolved") {
24834
- let rec = asRecord2(plaintextObj);
24835
- gateResolved = {
24836
- outcome: rec ? asString(rec.outcome) : null,
24837
- decisionKind: rec ? asString(asRecord2(rec.decision)?.kind ?? null) : null
25104
+ let { dict } = extractEffectivePayload(plaintextObj), decRaw = dict.decision, decisionKind = null;
25105
+ typeof decRaw == "string" ? decisionKind = decRaw : asRecord2(decRaw) && (decisionKind = asString(asRecord2(decRaw).kind)), gateResolved = {
25106
+ outcome: asString(dict.outcome),
25107
+ decisionKind
24838
25108
  };
24839
25109
  }
24840
25110
  return {
@@ -24845,13 +25115,73 @@ function routeAuditEntry(row, sessionKey, decrypt) {
24845
25115
  }
24846
25116
  return WIRE_PUBLIC_PLAINTEXT_KINDS.has(kind) ? { ...base, ...buildSafePayloadModel(kind, payload, "plaintext") } : { ...base, ...failClosedModel() };
24847
25117
  }
24848
- function buildAuditBrowserModel(rows, sessionKey, decrypt) {
24849
- if (rows.length === 0)
24850
- return { title: AUDIT_LOG_TITLE, entries: [], emptyLine: NO_AUDIT_ENTRIES };
24851
- let entries = rows.slice().reverse().map(
25118
+ function buildAuditBrowserModel(rows, sessionKey, decrypt, options) {
25119
+ let totalCount = rows.length;
25120
+ if (totalCount === 0)
25121
+ return {
25122
+ title: AUDIT_LOG_TITLE,
25123
+ entries: [],
25124
+ emptyLine: NO_AUDIT_ENTRIES,
25125
+ totalCount: 0,
25126
+ filteredCount: 0,
25127
+ limit: options?.limit,
25128
+ offset: options?.offset
25129
+ };
25130
+ let orderedRows = rows.slice().reverse();
25131
+ if (options?.verdictsOnly) {
25132
+ let verdictKinds = /* @__PURE__ */ new Set([
25133
+ "reviewer_verdict_recorded",
25134
+ "reviewer_verdict",
25135
+ "reviewer_verdict_received"
25136
+ ]);
25137
+ orderedRows = orderedRows.filter((r) => {
25138
+ let k = asString(r.kind) ?? asString(r.kindWire);
25139
+ return k !== null && verdictKinds.has(k);
25140
+ });
25141
+ }
25142
+ if (options?.kind && options.kind.trim().length > 0) {
25143
+ let targetKind = options.kind.trim();
25144
+ orderedRows = orderedRows.filter((r) => (asString(r.kind) ?? asString(r.kindWire)) === targetKind);
25145
+ }
25146
+ let filteredCount = orderedRows.length;
25147
+ if (filteredCount === 0)
25148
+ return {
25149
+ title: AUDIT_LOG_TITLE,
25150
+ entries: [],
25151
+ emptyLine: "No audit entries match the specified filter.",
25152
+ totalCount,
25153
+ filteredCount: 0,
25154
+ limit: options?.limit,
25155
+ offset: options?.offset
25156
+ };
25157
+ let offset = options?.offset !== void 0 && options.offset > 0 ? options.offset : 0, windowedRows = orderedRows.slice(offset);
25158
+ options?.limit !== void 0 && options.limit > 0 && (windowedRows = windowedRows.slice(0, options.limit));
25159
+ let entries = windowedRows.map(
24852
25160
  (row) => routeAuditEntry(row, sessionKey, decrypt)
24853
- );
24854
- return { title: AUDIT_LOG_TITLE, entries, emptyLine: null };
25161
+ ), emptyLine = entries.length === 0 && filteredCount > 0 ? "No audit entries in this window." : null;
25162
+ return {
25163
+ title: AUDIT_LOG_TITLE,
25164
+ entries,
25165
+ emptyLine,
25166
+ totalCount,
25167
+ filteredCount,
25168
+ limit: options?.limit,
25169
+ offset: options?.offset
25170
+ };
25171
+ }
25172
+ function formatAuditExport(model, format = "text", meta) {
25173
+ if (format === "json") {
25174
+ let payload = {
25175
+ taskId: meta?.taskId,
25176
+ sessionId: meta?.sessionId,
25177
+ exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
25178
+ totalCount: model.totalCount,
25179
+ filteredCount: model.filteredCount,
25180
+ entries: model.entries
25181
+ };
25182
+ return JSON.stringify(payload, null, 2);
25183
+ }
25184
+ return renderAuditBrowserText(model);
24855
25185
  }
24856
25186
  function renderAuditEntryText(entry) {
24857
25187
  let lines = [entry.timestamp !== null ? `${entry.kindLabel} \xB7 ${entry.timestamp}` : entry.kindLabel];
@@ -24865,12 +25195,15 @@ function renderAuditEntryText(entry) {
24865
25195
  let ta = entry.taskAuthorized;
24866
25196
  return ta.authorizedAction && lines.push(` Action: ${ta.authorizedAction}`), ta.authorityScope && lines.push(` Scope: ${ta.authorityScope}`), ta.authorityExpiresAt && lines.push(` Expires: ${ta.authorityExpiresAt}`), ta.approvalEventId && lines.push(` Approval: ${ta.approvalEventId}`), lines;
24867
25197
  }
24868
- return entry.rawJson && entry.rawJson.split(`
24869
- `).forEach((l) => lines.push(` ${l}`)), lines;
25198
+ return entry.detailRows && entry.detailRows.length > 0 ? (entry.detailRows.forEach((r) => lines.push(` ${r.label}: ${r.value}`)), entry.rawJson && (lines.push(" Payload:"), entry.rawJson.split(`
25199
+ `).forEach((l) => lines.push(` ${l}`))), lines) : (entry.rawJson && entry.rawJson.split(`
25200
+ `).forEach((l) => lines.push(` ${l}`)), lines);
24870
25201
  }
24871
25202
  function renderAuditBrowserText(model) {
24872
25203
  let lines = [model.title];
24873
- return model.emptyLine ? (lines.push(model.emptyLine), lines.join(`
25204
+ return model.totalCount > 0 && (model.limit !== void 0 || model.offset !== void 0 || model.filteredCount !== model.totalCount) && lines.push(
25205
+ `Showing ${model.entries.length} of ${model.filteredCount} entries (total: ${model.totalCount})`
25206
+ ), model.emptyLine ? (lines.push(model.emptyLine), lines.join(`
24874
25207
  `)) : (model.entries.forEach((entry) => {
24875
25208
  lines.push(""), lines.push(...renderAuditEntryText(entry));
24876
25209
  }), lines.join(`
@@ -24908,7 +25241,19 @@ async function runAuditBrowser(deps) {
24908
25241
  let reason = err?.message ?? String(err);
24909
25242
  return logger.warn("[audit-browser] queryAudit failed", { reason }), { kind: "error", line: AUDIT_LOG_TOO_LARGE, reason };
24910
25243
  }
24911
- let getSessionKey = deps.getSessionKeyFn ?? ((sid) => keychainManager.getSessionKey(sid)), sessionKey = null;
25244
+ let getSessionKey = deps.getSessionKeyFn ?? (async (sid) => {
25245
+ let key = await keychainManager.getSessionKey(sid);
25246
+ if (!key && deps.appsyncClient.getSession)
25247
+ try {
25248
+ let session = await deps.appsyncClient.getSession(sid);
25249
+ if (session?.encryptedKeys && session.encryptedKeys.length > 0) {
25250
+ let gen = session.sessionKeyGen != null ? String(session.sessionKeyGen) : null;
25251
+ key = await keychainManager.getSessionKey(sid, session.encryptedKeys, gen);
25252
+ }
25253
+ } catch {
25254
+ }
25255
+ return key;
25256
+ }), sessionKey = null;
24912
25257
  try {
24913
25258
  sessionKey = await getSessionKey(deps.sessionId);
24914
25259
  } catch (err) {
@@ -24918,7 +25263,12 @@ async function runAuditBrowser(deps) {
24918
25263
  });
24919
25264
  }
24920
25265
  let decryptFn = deps.decryptFn ?? ((ct, key) => cryptoService.decryptContent(ct, key));
24921
- return { kind: "ok", model: buildAuditBrowserModel(rows, sessionKey, decryptFn) };
25266
+ return { kind: "ok", model: buildAuditBrowserModel(rows, sessionKey, decryptFn, {
25267
+ kind: deps.kind,
25268
+ verdictsOnly: deps.verdictsOnly,
25269
+ limit: deps.limit,
25270
+ offset: deps.offset
25271
+ }) };
24922
25272
  }
24923
25273
  function renderAuditResultText(result) {
24924
25274
  switch (result.kind) {
@@ -24998,7 +25348,7 @@ function dedupKeyForBrokerCredentialLoaded(taskId, credentialIssuanceId) {
24998
25348
 
24999
25349
  // src/orchestration-shell/flag-command.ts
25000
25350
  init_logger2();
25001
- function buildAuditFlagIndex(taskId, model) {
25351
+ function buildAuditFlagIndex(taskId, model, sessionId) {
25002
25352
  let entries = /* @__PURE__ */ new Map();
25003
25353
  for (let entry of model.entries)
25004
25354
  entries.set(entry.entryId, {
@@ -25006,7 +25356,12 @@ function buildAuditFlagIndex(taskId, model) {
25006
25356
  kind: entry.kind,
25007
25357
  flaggable: isFlaggableAuditEntry(entry)
25008
25358
  });
25009
- return { taskId, entries, flagged: /* @__PURE__ */ new Set() };
25359
+ return {
25360
+ taskId,
25361
+ entries,
25362
+ flagged: /* @__PURE__ */ new Set(),
25363
+ ...sessionId !== void 0 ? { sessionId } : {}
25364
+ };
25010
25365
  }
25011
25366
  var FLAG_NO_INDEX_LINE = "No /audit listing to flag from yet. Run /audit <task-id> first, then /flag <entry-id> using an id it shows.", SEQ_NUM_SHAPE = /^\d{16}$/, UUID_SHAPE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
25012
25367
  function mapServerRejection(reason) {
@@ -25016,6 +25371,11 @@ async function runFlagCommand(deps) {
25016
25371
  let { index, entryId } = deps;
25017
25372
  if (!index)
25018
25373
  return { kind: "no_index", line: FLAG_NO_INDEX_LINE };
25374
+ if (index.sessionId && deps.sessionId && index.sessionId.trim().length > 0 && deps.sessionId.trim().length > 0 && index.sessionId.trim() !== deps.sessionId.trim())
25375
+ return {
25376
+ kind: "cross_session_unsupported",
25377
+ line: `Cannot flag audit entries from another session (${index.sessionId}). /flag only supports entries from the current orchestration session.`
25378
+ };
25019
25379
  let entry = index.entries.get(entryId);
25020
25380
  if (!entry)
25021
25381
  return {
@@ -25040,12 +25400,12 @@ async function runFlagCommand(deps) {
25040
25400
  line: `Entry id ${entryId} is not a valid audit entry id.`,
25041
25401
  reason: "entry id is not a canonical UUID"
25042
25402
  };
25043
- let dedupKeyHex = dedupKeyForFlagBadApproval(entryId), getSessionKey = deps.getSessionKeyFn ?? ((sid) => keychainManager.getSessionKey(sid)), sessionKey = null;
25403
+ let dedupKeyHex = dedupKeyForFlagBadApproval(entryId), targetSessionId = deps.sessionId, getSessionKey = deps.getSessionKeyFn ?? ((sid) => keychainManager.getSessionKey(sid)), sessionKey = null;
25044
25404
  try {
25045
- sessionKey = await getSessionKey(deps.sessionId);
25405
+ sessionKey = await getSessionKey(targetSessionId);
25046
25406
  } catch (err) {
25047
25407
  sessionKey = null, logger.warn("[flag-command] session-key resolve threw", {
25048
- sessionId: deps.sessionId,
25408
+ sessionId: targetSessionId,
25049
25409
  errorName: err?.name ?? "Error"
25050
25410
  });
25051
25411
  }
@@ -25058,7 +25418,7 @@ async function runFlagCommand(deps) {
25058
25418
  await deps.appsyncClient.recordExecutionEvent(
25059
25419
  {
25060
25420
  taskId: index.taskId,
25061
- sessionId: deps.sessionId,
25421
+ sessionId: targetSessionId,
25062
25422
  kind: "FLAG_BAD_APPROVAL",
25063
25423
  payload: {
25064
25424
  note: deps.note ?? null,
@@ -61782,6 +62142,37 @@ async function resolvePlannerOffer(deps) {
61782
62142
  `)
61783
62143
  );
61784
62144
  }
62145
+ function tokenizeCommandLine(input) {
62146
+ let tokens = [], current = "", inDouble = !1, inSingle = !1, escaping = !1, hasToken = !1;
62147
+ for (let i = 0; i < input.length; i++) {
62148
+ let ch = input[i];
62149
+ if (escaping) {
62150
+ current += ch, hasToken = !0, escaping = !1;
62151
+ continue;
62152
+ }
62153
+ if (ch === "\\" && !inSingle) {
62154
+ escaping = !0;
62155
+ continue;
62156
+ }
62157
+ if (ch === '"' && !inSingle) {
62158
+ inDouble = !inDouble, hasToken = !0;
62159
+ continue;
62160
+ }
62161
+ if (ch === "'" && !inDouble) {
62162
+ inSingle = !inSingle, hasToken = !0;
62163
+ continue;
62164
+ }
62165
+ if (/\s/.test(ch) && !inDouble && !inSingle) {
62166
+ hasToken && (tokens.push(current), current = "", hasToken = !1);
62167
+ continue;
62168
+ }
62169
+ current += ch, hasToken = !0;
62170
+ }
62171
+ return escaping ? { tokens: [], error: "Trailing escape character in command input" } : inDouble || inSingle ? { tokens: [], error: "Unmatched quote in command input" } : (hasToken && tokens.push(current), { tokens });
62172
+ }
62173
+ function isFlagToken(tok) {
62174
+ return tok.startsWith("-") && !/^-\d+$/.test(tok);
62175
+ }
61785
62176
  async function handleShellUserInput(deps) {
61786
62177
  let {
61787
62178
  text: text2,
@@ -61974,36 +62365,126 @@ async function handleShellUserInput(deps) {
61974
62365
  }
61975
62366
  }
61976
62367
  else if (output.command === "/audit" && !output.sideEffect && output.output === "PENDING \u2014 entrypoint runs audit browser") {
61977
- let taskId = text2.trim().split(/\s+/)[1];
61978
- if (!taskId)
61979
- output.output = args.tier !== "MAX" ? renderAuditResultText({
61980
- kind: "gated",
61981
- headline: AUDIT_BROWSER_MAX_HEADLINE,
61982
- upgradeHint: AUDIT_BROWSER_UPGRADE_HINT
61983
- }) : renderSessionTaskList(store.getState(), args.quorumLoop?.activeTask ?? null);
61984
- else
61985
- try {
61986
- let result = runAuditBrowserFn ? await runAuditBrowserFn(taskId) : await runAuditBrowser({
61987
- appsyncClient: args.appsyncClient,
61988
- taskId,
61989
- sessionId: args.session.sessionId,
61990
- tier: args.tier
61991
- });
61992
- output.output = renderAuditResultText(result), result.kind === "ok" && store.dispatch({
61993
- type: "AUDIT_FLAG_INDEX_RETAINED",
61994
- index: buildAuditFlagIndex(taskId, result.model)
61995
- });
61996
- } catch (err) {
61997
- output.output = `Audit browser error: ${err.message ?? String(err)}`, logger.warn("[orchestration-shell] /audit dispatch failed", {
61998
- error: err.message
61999
- });
62368
+ let { tokens: cmdTokens, error: tokenizeErr } = tokenizeCommandLine(text2.trim());
62369
+ if (tokenizeErr)
62370
+ output.output = tokenizeErr;
62371
+ else {
62372
+ let rawTokens = cmdTokens.slice(1), taskId, explicitSessionId, kind, verdictsOnly = !1, limit, offset, exportPath, json = !1, parseError;
62373
+ for (let i = 0; i < rawTokens.length; i++) {
62374
+ let tok = rawTokens[i];
62375
+ if (tok === "--kind") {
62376
+ let val = rawTokens[++i];
62377
+ if (!val || val.length === 0 || isFlagToken(val)) {
62378
+ parseError = "Missing value for --kind";
62379
+ break;
62380
+ }
62381
+ kind = val;
62382
+ } else if (tok === "--session") {
62383
+ let val = rawTokens[++i];
62384
+ if (!val || val.length === 0 || isFlagToken(val)) {
62385
+ parseError = "Missing value for --session";
62386
+ break;
62387
+ }
62388
+ explicitSessionId = val;
62389
+ } else if (tok === "--verdicts-only")
62390
+ verdictsOnly = !0;
62391
+ else if (tok === "--limit") {
62392
+ let raw = rawTokens[++i];
62393
+ if (!raw || raw.length === 0 || isFlagToken(raw)) {
62394
+ parseError = "Missing value for --limit";
62395
+ break;
62396
+ }
62397
+ let parsed = parseInt(raw, 10);
62398
+ if (Number.isNaN(parsed) || parsed <= 0 || String(parsed) !== raw) {
62399
+ parseError = `Invalid value for --limit: expected a positive integer, got "${raw}"`;
62400
+ break;
62401
+ }
62402
+ limit = parsed;
62403
+ } else if (tok === "--offset") {
62404
+ let raw = rawTokens[++i];
62405
+ if (!raw || raw.length === 0 || isFlagToken(raw)) {
62406
+ parseError = "Missing value for --offset";
62407
+ break;
62408
+ }
62409
+ let parsed = parseInt(raw, 10);
62410
+ if (Number.isNaN(parsed) || parsed < 0 || String(parsed) !== raw) {
62411
+ parseError = `Invalid value for --offset: expected a non-negative integer, got "${raw}"`;
62412
+ break;
62413
+ }
62414
+ offset = parsed;
62415
+ } else if (tok === "--export") {
62416
+ let val = rawTokens[++i];
62417
+ if (!val || val.length === 0 || isFlagToken(val)) {
62418
+ parseError = "Missing value for --export";
62419
+ break;
62420
+ }
62421
+ exportPath = val;
62422
+ } else if (tok === "--json")
62423
+ json = !0;
62424
+ else if (tok.startsWith("-")) {
62425
+ parseError = `Unrecognized option: "${tok}"`;
62426
+ break;
62427
+ } else if (!taskId)
62428
+ taskId = tok;
62429
+ else {
62430
+ parseError = `Unexpected argument: "${tok}"`;
62431
+ break;
62432
+ }
62000
62433
  }
62434
+ if (parseError)
62435
+ output.output = parseError;
62436
+ else if (!taskId)
62437
+ output.output = args.tier !== "MAX" ? renderAuditResultText({
62438
+ kind: "gated",
62439
+ headline: AUDIT_BROWSER_MAX_HEADLINE,
62440
+ upgradeHint: AUDIT_BROWSER_UPGRADE_HINT
62441
+ }) : renderSessionTaskList(store.getState(), args.quorumLoop?.activeTask ?? null);
62442
+ else
62443
+ try {
62444
+ let effectiveSessionId = explicitSessionId || args.session.sessionId, result = runAuditBrowserFn ? await runAuditBrowserFn(taskId, {
62445
+ kind,
62446
+ verdictsOnly,
62447
+ limit,
62448
+ offset,
62449
+ sessionId: effectiveSessionId
62450
+ }) : await runAuditBrowser({
62451
+ appsyncClient: args.appsyncClient,
62452
+ taskId,
62453
+ sessionId: effectiveSessionId,
62454
+ tier: args.tier,
62455
+ kind,
62456
+ verdictsOnly,
62457
+ limit,
62458
+ offset
62459
+ });
62460
+ if (result.kind === "ok" && exportPath)
62461
+ try {
62462
+ let formatted = formatAuditExport(
62463
+ result.model,
62464
+ json ? "json" : "text",
62465
+ { taskId, sessionId: effectiveSessionId }
62466
+ );
62467
+ (0, import_node_fs26.writeFileSync)(exportPath, formatted, "utf8"), output.output = `Audit log exported to ${exportPath} (${result.model.entries.length} entries)`;
62468
+ } catch (err) {
62469
+ output.output = `Failed to export audit log to ${exportPath}: ${err.message ?? String(err)}`;
62470
+ }
62471
+ else exportPath && result.kind !== "ok" ? result.kind === "gated" ? output.output = `Cannot export audit log: ${result.headline} \u2014 ${result.upgradeHint}` : output.output = `Cannot export audit log: ${result.line} (${result.reason})` : json ? output.output = JSON.stringify(result, null, 2) : output.output = renderAuditResultText(result);
62472
+ result.kind === "ok" && store.dispatch({
62473
+ type: "AUDIT_FLAG_INDEX_RETAINED",
62474
+ index: buildAuditFlagIndex(taskId, result.model, effectiveSessionId)
62475
+ });
62476
+ } catch (err) {
62477
+ output.output = `Audit browser error: ${err.message ?? String(err)}`, logger.warn("[orchestration-shell] /audit dispatch failed", {
62478
+ error: err.message
62479
+ });
62480
+ }
62481
+ }
62001
62482
  } else if (output.command === "/flag" && !output.sideEffect && output.output === "PENDING \u2014 entrypoint records bad-approval flag") {
62002
62483
  let flagParts = slashCommandText.trim().split(/\s+/), flagEntryId = flagParts[1] ?? "", flagNote = flagParts.length > 2 ? flagParts.slice(2).join(" ") : void 0;
62003
62484
  try {
62004
- let result = runFlagCommandFn ? await runFlagCommandFn(flagEntryId, flagNote) : await runFlagCommand({
62485
+ let retainedIndex = store.getState().auditFlagIndex, result = runFlagCommandFn ? await runFlagCommandFn(flagEntryId, flagNote) : await runFlagCommand({
62005
62486
  appsyncClient: args.appsyncClient,
62006
- index: store.getState().auditFlagIndex,
62487
+ index: retainedIndex,
62007
62488
  entryId: flagEntryId,
62008
62489
  ...flagNote !== void 0 ? { note: flagNote } : {},
62009
62490
  sessionId: args.session.sessionId
@@ -63280,7 +63761,7 @@ function renderStructuralSummaryPreview(summary, error, tier) {
63280
63761
  }
63281
63762
 
63282
63763
  // src/planner/cache.ts
63283
- var import_node_fs26 = require("node:fs"), path65 = __toESM(require("node:path")), os36 = __toESM(require("node:os")), crypto26 = __toESM(require("node:crypto")), TAXONOMY_VERSION = 2, CACHE_SCHEMA_VERSION = 2, WORKFLOW_CACHE_TTL_MS = 1440 * 60 * 1e3, SIGNATURE_CACHE_TTL_MS = 300 * 1e3, WORKFLOW_CACHE_MAX_ENTRIES = 1e3, CACHE_FILE_PERMS = 384, CACHE_ROOT_PERMS = 448, VALID_KINDS = /* @__PURE__ */ new Set([
63764
+ var import_node_fs27 = require("node:fs"), path65 = __toESM(require("node:path")), os36 = __toESM(require("node:os")), crypto26 = __toESM(require("node:crypto")), TAXONOMY_VERSION = 2, CACHE_SCHEMA_VERSION = 2, WORKFLOW_CACHE_TTL_MS = 1440 * 60 * 1e3, SIGNATURE_CACHE_TTL_MS = 300 * 1e3, WORKFLOW_CACHE_MAX_ENTRIES = 1e3, CACHE_FILE_PERMS = 384, CACHE_ROOT_PERMS = 448, VALID_KINDS = /* @__PURE__ */ new Set([
63284
63765
  "workflow_status_query",
63285
63766
  "workflow_audit_query",
63286
63767
  "workflow_review_query",
@@ -63370,7 +63851,7 @@ var import_node_fs26 = require("node:fs"), path65 = __toESM(require("node:path")
63370
63851
  await this.mutex.run(async () => {
63371
63852
  this.workflowCache.clear(), this.signatureCache.clear(), this.hydrated.clear();
63372
63853
  try {
63373
- let entries = await import_node_fs26.promises.readdir(this.cacheRoot, { withFileTypes: !0 });
63854
+ let entries = await import_node_fs27.promises.readdir(this.cacheRoot, { withFileTypes: !0 });
63374
63855
  for (let ent of entries)
63375
63856
  ent.isDirectory() && await this.rmRecursiveSafe(path65.join(this.cacheRoot, ent.name));
63376
63857
  } catch {
@@ -63381,7 +63862,7 @@ var import_node_fs26 = require("node:fs"), path65 = __toESM(require("node:path")
63381
63862
  await this.mutex.run(async () => {
63382
63863
  let newPrefix = this.userIdPrefix(newUserId), markerPath = path65.join(this.cacheRoot, ".last-user"), lastUserPrefix = null;
63383
63864
  try {
63384
- let raw = (await import_node_fs26.promises.readFile(markerPath, "utf-8")).trim();
63865
+ let raw = (await import_node_fs27.promises.readFile(markerPath, "utf-8")).trim();
63385
63866
  /^[0-9a-f]{16}$/.test(raw) ? lastUserPrefix = raw : lastUserPrefix = "__corrupt__";
63386
63867
  } catch (err) {
63387
63868
  err?.code !== "ENOENT" && (lastUserPrefix = "__error__");
@@ -63389,7 +63870,7 @@ var import_node_fs26 = require("node:fs"), path65 = __toESM(require("node:path")
63389
63870
  if (lastUserPrefix && lastUserPrefix !== newPrefix) {
63390
63871
  this.workflowCache.clear(), this.signatureCache.clear(), this.hydrated.clear();
63391
63872
  try {
63392
- let entries = await import_node_fs26.promises.readdir(this.cacheRoot, { withFileTypes: !0 });
63873
+ let entries = await import_node_fs27.promises.readdir(this.cacheRoot, { withFileTypes: !0 });
63393
63874
  for (let ent of entries)
63394
63875
  ent.isDirectory() && await this.rmRecursiveSafe(path65.join(this.cacheRoot, ent.name));
63395
63876
  } catch {
@@ -63398,8 +63879,8 @@ var import_node_fs26 = require("node:fs"), path65 = __toESM(require("node:path")
63398
63879
  await this.ensureCacheRoot();
63399
63880
  let tmp = markerPath + ".tmp";
63400
63881
  try {
63401
- await import_node_fs26.promises.writeFile(tmp, newPrefix + `
63402
- `, { mode: CACHE_FILE_PERMS }), await import_node_fs26.promises.rename(tmp, markerPath);
63882
+ await import_node_fs27.promises.writeFile(tmp, newPrefix + `
63883
+ `, { mode: CACHE_FILE_PERMS }), await import_node_fs27.promises.rename(tmp, markerPath);
63403
63884
  } catch {
63404
63885
  }
63405
63886
  });
@@ -63409,11 +63890,11 @@ var import_node_fs26 = require("node:fs"), path65 = __toESM(require("node:path")
63409
63890
  this.hydrated.add(userId);
63410
63891
  let filePath = this.workflowFilePath(userId);
63411
63892
  try {
63412
- if (((await import_node_fs26.promises.stat(filePath)).mode & 63) !== 0) {
63893
+ if (((await import_node_fs27.promises.stat(filePath)).mode & 63) !== 0) {
63413
63894
  await this.rotateCorrupt(filePath);
63414
63895
  return;
63415
63896
  }
63416
- let raw = await import_node_fs26.promises.readFile(filePath, "utf-8"), parsed = JSON.parse(raw);
63897
+ let raw = await import_node_fs27.promises.readFile(filePath, "utf-8"), parsed = JSON.parse(raw);
63417
63898
  if (parsed.schemaVersion !== CACHE_SCHEMA_VERSION) {
63418
63899
  await this.rotateCorrupt(filePath);
63419
63900
  return;
@@ -63426,7 +63907,7 @@ var import_node_fs26 = require("node:fs"), path65 = __toESM(require("node:path")
63426
63907
  }
63427
63908
  async rotateCorrupt(filePath) {
63428
63909
  try {
63429
- await import_node_fs26.promises.rename(filePath, filePath + ".bak");
63910
+ await import_node_fs27.promises.rename(filePath, filePath + ".bak");
63430
63911
  } catch {
63431
63912
  }
63432
63913
  }
@@ -63437,7 +63918,7 @@ var import_node_fs26 = require("node:fs"), path65 = __toESM(require("node:path")
63437
63918
  schemaVersion: CACHE_SCHEMA_VERSION,
63438
63919
  entries: Array.from(userMap.entries())
63439
63920
  };
63440
- await import_node_fs26.promises.writeFile(tmp, JSON.stringify(data), { mode: CACHE_FILE_PERMS }), await import_node_fs26.promises.rename(tmp, filePath);
63921
+ await import_node_fs27.promises.writeFile(tmp, JSON.stringify(data), { mode: CACHE_FILE_PERMS }), await import_node_fs27.promises.rename(tmp, filePath);
63441
63922
  }
63442
63923
  cacheDir(userId) {
63443
63924
  return path65.join(this.cacheRoot, this.userIdPrefix(userId));
@@ -63467,14 +63948,14 @@ var import_node_fs26 = require("node:fs"), path65 = __toESM(require("node:path")
63467
63948
  oldestKey !== null && userMap.delete(oldestKey);
63468
63949
  }
63469
63950
  async ensureCacheRoot() {
63470
- await import_node_fs26.promises.mkdir(this.cacheRoot, { recursive: !0, mode: CACHE_ROOT_PERMS });
63951
+ await import_node_fs27.promises.mkdir(this.cacheRoot, { recursive: !0, mode: CACHE_ROOT_PERMS });
63471
63952
  }
63472
63953
  async ensureDir(dir) {
63473
- await import_node_fs26.promises.mkdir(dir, { recursive: !0, mode: CACHE_ROOT_PERMS });
63954
+ await import_node_fs27.promises.mkdir(dir, { recursive: !0, mode: CACHE_ROOT_PERMS });
63474
63955
  }
63475
63956
  async rmRecursiveSafe(dir) {
63476
63957
  try {
63477
- await import_node_fs26.promises.rm(dir, { recursive: !0, force: !0 });
63958
+ await import_node_fs27.promises.rm(dir, { recursive: !0, force: !0 });
63478
63959
  } catch {
63479
63960
  }
63480
63961
  }
@@ -63769,7 +64250,7 @@ async function registerDeviceEncryptionKey(appSyncClient, logger2, options = {})
63769
64250
  }
63770
64251
 
63771
64252
  // src/session/pending-session-create.ts
63772
- var crypto27 = __toESM(require("node:crypto")), import_node_fs27 = require("node:fs"), fs45 = __toESM(require("node:fs/promises")), os37 = __toESM(require("node:os")), path66 = __toESM(require("node:path"));
64253
+ var crypto27 = __toESM(require("node:crypto")), import_node_fs28 = require("node:fs"), fs45 = __toESM(require("node:fs/promises")), os37 = __toESM(require("node:os")), path66 = __toESM(require("node:path"));
63773
64254
  var pendingRemovalFaultForTests = null, PermanentlyUnreadablePendingLedgerError = class extends Error {
63774
64255
  constructor(sessionId, message) {
63775
64256
  super(message);
@@ -63802,7 +64283,7 @@ function isTombstone(value) {
63802
64283
  }
63803
64284
  async function syncPendingDirectory() {
63804
64285
  if (process.platform === "win32") return;
63805
- let handle = await fs45.open(pendingDirectory(), import_node_fs27.constants.O_RDONLY);
64286
+ let handle = await fs45.open(pendingDirectory(), import_node_fs28.constants.O_RDONLY);
63806
64287
  try {
63807
64288
  await handle.sync();
63808
64289
  } finally {
@@ -64210,10 +64691,10 @@ async function prepareSessionEncryption(sessionId, appSyncClient, logger2) {
64210
64691
  }
64211
64692
 
64212
64693
  // src/orchestration-shell/cli.ts
64213
- var import_uuid14 = require("uuid");
64694
+ var import_uuid14 = require("uuid"), fs51 = __toESM(require("fs"));
64214
64695
 
64215
64696
  // src/substrate-launch/engage-substrate.ts
64216
- var import_node_fs28 = require("node:fs"), os38 = __toESM(require("node:os")), path67 = __toESM(require("node:path"));
64697
+ var import_node_fs29 = require("node:fs"), os38 = __toESM(require("node:os")), path67 = __toESM(require("node:path"));
64217
64698
 
64218
64699
  // src/credential-broker/types.ts
64219
64700
  var BROKER_ROUTES = [
@@ -65805,17 +66286,17 @@ function deriveAuditPath(workdir) {
65805
66286
  async function assertAuditOutsideWorkdir(auditPath, workdir) {
65806
66287
  let realWorkdir;
65807
66288
  try {
65808
- realWorkdir = await import_node_fs28.promises.realpath(workdir);
66289
+ realWorkdir = await import_node_fs29.promises.realpath(workdir);
65809
66290
  } catch {
65810
66291
  throw new Error(
65811
66292
  `CP-7 W3: cannot realpath workdir "${workdir}" \u2014 refusing to launch (audit containment fail-closed)`
65812
66293
  );
65813
66294
  }
65814
66295
  let auditDir = path67.dirname(auditPath);
65815
- await import_node_fs28.promises.mkdir(auditDir, { recursive: !0 });
66296
+ await import_node_fs29.promises.mkdir(auditDir, { recursive: !0 });
65816
66297
  let realAuditDir;
65817
66298
  try {
65818
- realAuditDir = await import_node_fs28.promises.realpath(auditDir);
66299
+ realAuditDir = await import_node_fs29.promises.realpath(auditDir);
65819
66300
  } catch {
65820
66301
  throw new Error(
65821
66302
  `CP-7 W3: cannot realpath audit dir "${auditDir}" \u2014 refusing to launch (fail-closed)`
@@ -65823,14 +66304,14 @@ async function assertAuditOutsideWorkdir(auditPath, workdir) {
65823
66304
  }
65824
66305
  let resolvedAuditPath = path67.join(realAuditDir, path67.basename(auditPath)), leafStat;
65825
66306
  try {
65826
- leafStat = await import_node_fs28.promises.lstat(resolvedAuditPath);
66307
+ leafStat = await import_node_fs29.promises.lstat(resolvedAuditPath);
65827
66308
  } catch {
65828
66309
  leafStat = void 0;
65829
66310
  }
65830
66311
  let resolvedLeafTarget = resolvedAuditPath;
65831
66312
  if (leafStat?.isSymbolicLink())
65832
66313
  try {
65833
- resolvedLeafTarget = await import_node_fs28.promises.realpath(resolvedAuditPath);
66314
+ resolvedLeafTarget = await import_node_fs29.promises.realpath(resolvedAuditPath);
65834
66315
  } catch {
65835
66316
  throw new Error(
65836
66317
  `CP-7 W3: audit leaf "${resolvedAuditPath}" is a symlink that does not resolve (dangling) \u2014 refusing to launch (fail-closed). The audit file must be a regular file in the sibling .codevibe/audit/ tree.`
@@ -66116,7 +66597,7 @@ async function engageWriteConfinedResolverSandbox(input) {
66116
66597
  homedir29,
66117
66598
  ...RESOLVER_AGENT_STATE_DIR_SEGMENTS[agentKind]
66118
66599
  );
66119
- await import_node_fs28.promises.mkdir(stateDir, { recursive: !0 }).catch(() => {
66600
+ await import_node_fs29.promises.mkdir(stateDir, { recursive: !0 }).catch(() => {
66120
66601
  });
66121
66602
  let env = {}, nodeDir = process.execPath.slice(0, process.execPath.lastIndexOf("/"));
66122
66603
  env.PATH = `${SANDBOX_DEFAULT_PATH}:${nodeDir}`, env.HOME = homedir29;
@@ -67935,25 +68416,76 @@ async function runCompanion(args) {
67935
68416
  passthrough: args.passthrough
67936
68417
  });
67937
68418
  }
68419
+ function isFlagToken2(tok) {
68420
+ return tok ? tok.startsWith("--") ? !0 : tok.startsWith("-") && !/^-\d+$/.test(tok) : !1;
68421
+ }
67938
68422
  function parseAuditArgs(argv) {
67939
- if (argv[0] !== "audit" || argv[1] !== "show") return null;
67940
- let rest = argv.slice(2), taskId, json = !1, sessionId;
68423
+ let args = argv[0] === "node" || argv[0]?.endsWith("/node") || argv[0]?.endsWith("node.exe") ? argv.slice(2) : argv;
68424
+ if (args[0] !== "audit" || args[1] !== "show")
68425
+ return null;
68426
+ let taskId, json = !1, sessionId, kind, verdictsOnly = !1, limit, offset, exportPath, rest = args.slice(2);
67941
68427
  for (let i = 0; i < rest.length; i++) {
67942
68428
  let a = rest[i];
67943
68429
  if (a === "--json") {
67944
68430
  json = !0;
67945
68431
  continue;
67946
68432
  }
68433
+ if (a === "--verdicts-only") {
68434
+ verdictsOnly = !0;
68435
+ continue;
68436
+ }
67947
68437
  if (a === "--session") {
67948
- sessionId = rest[++i];
68438
+ let val = rest[++i];
68439
+ if (!val || isFlagToken2(val))
68440
+ return { taskId: taskId ?? "", json: !1, error: "Missing value for --session" };
68441
+ sessionId = val;
68442
+ continue;
68443
+ }
68444
+ if (a === "--kind") {
68445
+ let val = rest[++i];
68446
+ if (!val || isFlagToken2(val))
68447
+ return { taskId: taskId ?? "", json: !1, error: "Missing value for --kind" };
68448
+ kind = val;
67949
68449
  continue;
67950
68450
  }
67951
- if (!taskId && !a.startsWith("-")) {
67952
- taskId = a;
68451
+ if (a === "--export") {
68452
+ let val = rest[++i];
68453
+ if (!val || isFlagToken2(val))
68454
+ return { taskId: taskId ?? "", json: !1, error: "Missing value for --export" };
68455
+ exportPath = val;
67953
68456
  continue;
67954
68457
  }
68458
+ if (a === "--limit") {
68459
+ let raw = rest[++i];
68460
+ if (!raw || isFlagToken2(raw))
68461
+ return { taskId: taskId ?? "", json: !1, error: "Missing value for --limit" };
68462
+ let parsed = parseInt(raw, 10);
68463
+ if (Number.isNaN(parsed) || parsed <= 0 || String(parsed) !== raw)
68464
+ return { taskId: taskId ?? "", json: !1, error: `Invalid value for --limit: expected a positive integer, got "${raw}"` };
68465
+ limit = parsed;
68466
+ continue;
68467
+ }
68468
+ if (a === "--offset") {
68469
+ let raw = rest[++i];
68470
+ if (!raw || isFlagToken2(raw))
68471
+ return { taskId: taskId ?? "", json: !1, error: "Missing value for --offset" };
68472
+ let parsed = parseInt(raw, 10);
68473
+ if (Number.isNaN(parsed) || parsed < 0 || String(parsed) !== raw)
68474
+ return { taskId: taskId ?? "", json: !1, error: `Invalid value for --offset: expected a non-negative integer, got "${raw}"` };
68475
+ offset = parsed;
68476
+ continue;
68477
+ }
68478
+ if (!a.startsWith("-")) {
68479
+ if (!taskId)
68480
+ taskId = a;
68481
+ else
68482
+ return { taskId, json: !1, error: `Unexpected argument: "${a}"` };
68483
+ continue;
68484
+ }
68485
+ return { taskId: taskId ?? "", json: !1, error: `Unrecognized option: "${a}"` };
67955
68486
  }
67956
- return taskId ? { taskId, json, sessionId } : { taskId: "", json, sessionId };
68487
+ let result = { taskId: taskId ?? "", json, sessionId };
68488
+ return kind !== void 0 && (result.kind = kind), verdictsOnly && (result.verdictsOnly = !0), limit !== void 0 && (result.limit = limit), offset !== void 0 && (result.offset = offset), exportPath !== void 0 && (result.exportPath = exportPath), result;
67957
68489
  }
67958
68490
  var MODEL_COMMANDS = /* @__PURE__ */ new Set([
67959
68491
  "install",
@@ -68095,9 +68627,14 @@ async function buildLocalGemmaPlannerAdapter(args) {
68095
68627
  }
68096
68628
  async function runAuditCli(parsed, deps) {
68097
68629
  let out = deps?.stdout ?? ((s) => process.stdout.write(s)), err = deps?.stderr ?? ((s) => process.stderr.write(s));
68630
+ if (parsed.error)
68631
+ return err(`${parsed.error}
68632
+ `), 2;
68098
68633
  if (!parsed.taskId)
68099
68634
  return err(
68100
- `Usage: codevibe audit show <task-id> [--json] [--session <session-id>]
68635
+ `Usage: codevibe audit show <task-id> [--json] [--session <session-id>] [--kind <kind>] [--verdicts-only] [--limit <n>] [--offset <n>] [--export <path>]
68636
+
68637
+ Note: --export will overwrite any existing file at <path>.
68101
68638
  `
68102
68639
  ), 2;
68103
68640
  let appsyncClient = deps?.appsyncClient ?? new AppSyncClient(), authenticated;
@@ -68130,9 +68667,34 @@ async function runAuditCli(parsed, deps) {
68130
68667
  let result = await runAuditBrowser({
68131
68668
  appsyncClient,
68132
68669
  taskId: parsed.taskId,
68133
- sessionId
68670
+ sessionId,
68671
+ kind: parsed.kind,
68672
+ verdictsOnly: parsed.verdictsOnly,
68673
+ limit: parsed.limit,
68674
+ offset: parsed.offset
68134
68675
  });
68135
- return parsed.json ? (out(`${JSON.stringify(result, null, 2)}
68676
+ if (result.kind === "ok" && parsed.exportPath) {
68677
+ let writeFile4 = deps?.writeFileFn ?? ((p, c) => fs51.writeFileSync(p, c, "utf8"));
68678
+ try {
68679
+ let formatted = formatAuditExport(
68680
+ result.model,
68681
+ parsed.json ? "json" : "text",
68682
+ { taskId: parsed.taskId, sessionId }
68683
+ );
68684
+ return writeFile4(parsed.exportPath, formatted), out(
68685
+ `Audit log exported to ${parsed.exportPath} (${result.model.entries.length} entries)
68686
+ `
68687
+ ), 0;
68688
+ } catch (e) {
68689
+ return err(
68690
+ `Failed to export audit log to ${parsed.exportPath}: ${e?.message}
68691
+ `
68692
+ ), 2;
68693
+ }
68694
+ }
68695
+ return parsed.exportPath && result.kind !== "ok" ? (result.kind === "gated" ? err(`Cannot export audit log: ${result.headline} \u2014 ${result.upgradeHint}
68696
+ `) : err(`Cannot export audit log: ${result.line} (${result.reason})
68697
+ `), 1) : parsed.json ? (out(`${JSON.stringify(result, null, 2)}
68136
68698
  `), 0) : (out(`${renderAuditResultText(result)}
68137
68699
  `), 0);
68138
68700
  }