@adhdev/mesh-shared 1.0.82-rc.46 → 1.0.82-rc.48

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.
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Same-machine light task — shared vocabulary and wire shapes (design
3
+ * docs/design/2026-11-01-same-machine-light-task.md).
4
+ *
5
+ * A light task is a `code_change` queue row that runs in a per-task scratch checkout
6
+ * (light workspace) on the coordinator's machine, based on the coordinator checkout's
7
+ * commit. Dependency-free leaf: daemon-core, mcp-server and web-core all import this.
8
+ */
9
+ /** Enqueue refusals (thrown as `<code>: <message>`). */
10
+ export declare const LIGHT_REJECT: {
11
+ readonly REQUIRES_LOCAL_BASE: "light_requires_local_base";
12
+ readonly NOT_CONFIGURED: "light_workspace_not_configured";
13
+ readonly REQUIRES_OWNED_PATHS: "light_requires_owned_paths";
14
+ readonly MODE_CONFLICT: "light_mode_conflict";
15
+ };
16
+ export type LightRejectCode = typeof LIGHT_REJECT[keyof typeof LIGHT_REJECT];
17
+ /** Pending-row hold reasons set by the light dispatcher. */
18
+ export declare const LIGHT_HOLD: {
19
+ readonly PREPARE_FAILED: "light_workspace_prepare_failed";
20
+ readonly LIMIT: "light_workspace_limit";
21
+ readonly DISK_LOW: "light_workspace_disk_low";
22
+ readonly CAP: "max_light_parallel_tasks_reached";
23
+ };
24
+ /** Reasons a finished light result is not landable (`landing: 'blocked'`). */
25
+ export declare const LIGHT_BLOCK_REASONS: readonly ["light_uncommitted_changes", "light_dependency_change", "light_lineage_unproven", "shared_checkout_mutated"];
26
+ export type LightBlockReason = typeof LIGHT_BLOCK_REASONS[number];
27
+ /** Non-blocking observations recorded on the result. */
28
+ export declare const LIGHT_WARNINGS: readonly ["shared_checkout_changed_during_task", "light_base_dirty_overlap"];
29
+ export type LightWarning = typeof LIGHT_WARNINGS[number];
30
+ export declare const LIGHT_LAND_MODES: readonly ["refine", "apply_to_checkout"];
31
+ export type LightLandMode = typeof LIGHT_LAND_MODES[number];
32
+ export type LightLandingState = 'ready' | 'conflict' | 'blocked' | 'landed' | 'discarded';
33
+ export interface LightApplyCheckSide {
34
+ /** Commit the result was checked against. */
35
+ against: string;
36
+ status: 'clean' | 'conflict' | 'base_unavailable';
37
+ conflictPaths?: string[];
38
+ }
39
+ /** merge-tree apply-check of the root (`.`) and each submodule, vs the base HEAD and `origin/<base>`. */
40
+ export interface LightApplyCheck {
41
+ head: LightApplyCheckSide;
42
+ remote?: LightApplyCheckSide;
43
+ }
44
+ /** Worker-reported test run (`report_completion.testsRun`). Self-reported, never trusted as evidence. */
45
+ export interface LightTestRun {
46
+ command: string;
47
+ exit: number;
48
+ passed?: number;
49
+ failed?: number;
50
+ note?: string;
51
+ }
52
+ export declare const LIGHT_TESTS_RUN_MAX = 20;
53
+ export interface LightTaskResult {
54
+ workspaceId: string;
55
+ /** root branch (`mesh/light/<taskId8>`) */
56
+ branch: string;
57
+ /** submodule path -> branch */
58
+ submoduleBranches?: Record<string, string>;
59
+ rootBaseSha: string;
60
+ rootHeadSha?: string;
61
+ submoduleHeads?: Record<string, {
62
+ base: string;
63
+ head: string;
64
+ }>;
65
+ touchedPaths: string[];
66
+ ownedPathsMismatch?: string[];
67
+ applyCheck?: LightApplyCheck;
68
+ patchArtifactIds: string[];
69
+ testsRun?: LightTestRun[];
70
+ landing: LightLandingState;
71
+ blockedReason?: LightBlockReason;
72
+ blockedDetail?: string;
73
+ warnings?: LightWarning[];
74
+ landedAt?: string;
75
+ landedVia?: LightLandMode;
76
+ /** The verified source packet (`MeshSourceCandidate`) for this result; tests carry no log hashes. */
77
+ sourceCandidate?: import('./task-source-phase').MeshSourceCandidate;
78
+ capturedAt: string;
79
+ }
80
+ export interface LightLandRequest {
81
+ taskIds: string[];
82
+ mode?: LightLandMode;
83
+ dryRun?: boolean;
84
+ /** Required when a result touched paths outside its `owned_paths`. */
85
+ acceptPathsOutsideOwned?: boolean;
86
+ /** Land the leading non-conflicting tasks when a later one conflicts. */
87
+ partial?: boolean;
88
+ approvedPublishShas?: string[];
89
+ }
90
+ /**
91
+ * True when a session record/state (or a bare settings object) belongs to a light-task worker, i.e.
92
+ * it was launched with `settings.lightWorkspaceId`. A light session is bound to ONE task's scratch
93
+ * workspace and, by the central claim rule, can never claim any other row — so it is never "the
94
+ * node's worker" for duplicate-launch guards, auto-launch gating or concurrency counts.
95
+ */
96
+ export declare function isLightWorkerSession(session: unknown): boolean;
@@ -18,10 +18,10 @@
18
18
  * Order mirrors mcp-server `ALL_MESH_TOOLS` for easy visual diffing, but the consistency
19
19
  * checks are set-based (order-insensitive).
20
20
  */
21
- export declare const CANONICAL_MESH_TOOL_NAMES: readonly ["mesh_status", "mesh_route_preview", "mesh_list_nodes", "mesh_enqueue_batch", "mesh_enqueue_task", "mesh_view_queue", "mesh_queue_cancel", "mesh_direct_cancel", "mesh_queue_requeue", "mesh_queue_revise", "mesh_send_task", "mesh_read_chat", "mesh_read_debug", "mesh_read_terminal", "mesh_send_keys", "mesh_launch_session", "mesh_git_status", "mesh_read_node_logs", "mesh_fast_forward_node", "mesh_restart_daemon", "mesh_checkpoint", "mesh_approve", "mesh_answer_question", "mesh_list_pending_approvals", "mesh_create", "mesh_add_node", "mesh_reattach_source_parent", "mesh_attach_remote", "mesh_clone_node", "mesh_remove_node", "mesh_retry_node_bootstrap", "mesh_cleanup_worktree_nodes", "mesh_refine_node", "mesh_refine_batch", "mesh_config", "mesh_init", "mesh_cleanup_sessions", "mesh_task_history", "mesh_ledger_query", "mesh_note", "mesh_reconcile_ledger", "mesh_mission_upsert", "mesh_mission_list", "mesh_mission_git_eval", "mesh_release_upsert", "mesh_release_scope", "mesh_release_list", "mesh_release_record_deploy", "mesh_release_changelog_draft", "mesh_review_inbox", "mesh_node_slots", "driver_list", "driver_describe", "artifact_list", "artifact_read", "artifact_register"];
21
+ export declare const CANONICAL_MESH_TOOL_NAMES: readonly ["mesh_status", "mesh_route_preview", "mesh_list_nodes", "mesh_enqueue_batch", "mesh_enqueue_task", "mesh_view_queue", "mesh_queue_cancel", "mesh_task_stage_decide", "mesh_direct_cancel", "mesh_queue_requeue", "mesh_queue_revise", "mesh_light_land", "mesh_light_discard", "mesh_send_task", "mesh_read_chat", "mesh_read_debug", "mesh_read_terminal", "mesh_send_keys", "mesh_launch_session", "mesh_git_status", "mesh_read_node_logs", "mesh_fast_forward_node", "mesh_restart_daemon", "mesh_checkpoint", "mesh_approve", "mesh_answer_question", "mesh_list_pending_approvals", "mesh_create", "mesh_add_node", "mesh_reattach_source_parent", "mesh_attach_remote", "mesh_clone_node", "mesh_remove_node", "mesh_retry_node_bootstrap", "mesh_cleanup_worktree_nodes", "mesh_refine_node", "mesh_refine_batch", "mesh_config", "mesh_init", "mesh_cleanup_sessions", "mesh_task_history", "mesh_ledger_query", "mesh_note", "mesh_reconcile_ledger", "mesh_mission_upsert", "mesh_mission_list", "mesh_mission_git_eval", "mesh_release_upsert", "mesh_release_scope", "mesh_release_list", "mesh_release_record_deploy", "mesh_release_changelog_draft", "mesh_review_inbox", "mesh_node_slots", "driver_list", "driver_describe", "artifact_list", "artifact_read", "artifact_register"];
22
22
  export type CanonicalMeshToolName = typeof CANONICAL_MESH_TOOL_NAMES[number];
23
23
  /** The count the `NN tools` barrel doc comments and consistency test assert against. */
24
- export declare const CANONICAL_MESH_TOOL_COUNT: 56;
24
+ export declare const CANONICAL_MESH_TOOL_COUNT: 59;
25
25
  /**
26
26
  * Tool names retired by the 2026-09-26 tool-surface consolidation (60 → 48).
27
27
  * Every capability behind them is still reachable: each retired name maps to the
@@ -69,7 +69,15 @@ export interface MeshRoutingPreferences {
69
69
  nodeIds?: string[];
70
70
  providers?: string[];
71
71
  }
72
+ export type MeshReviewIndependence = 'different_provider' | 'fresh_session';
73
+ /**
74
+ * Review row constraint. `differentProvider: true` is the legacy spelling of
75
+ * `independence: 'different_provider'`; `independence: 'fresh_session'` is the stage pipeline's
76
+ * fallback (same provider allowed, but never the implementer's session).
77
+ */
72
78
  export interface MeshReviewConstraint {
73
79
  sourceTaskId: string;
74
- differentProvider: true;
80
+ differentProvider?: true;
81
+ independence?: MeshReviewIndependence;
75
82
  }
83
+ export declare function reviewIndependenceOf(review: Pick<MeshReviewConstraint, 'differentProvider' | 'independence'>): MeshReviewIndependence;
@@ -0,0 +1,206 @@
1
+ /**
2
+ * task-stages — vocabulary, shapes and validators for "review in task".
3
+ *
4
+ * A medium/difficult `code_change` can be enqueued as ONE stage task: the daemon runs
5
+ * implement → self-check → independent review → (bounded) revise inside the task and the
6
+ * coordinator is woken once, by the parent's terminal. Design:
7
+ * docs/design/2026-11-01-review-in-task.md (§3 model, §5 data contract).
8
+ *
9
+ * Dependency-free leaf: every cap and enum the daemon validator, the MCP schemas and the
10
+ * dashboard chips read lives here once.
11
+ */
12
+ import type { LightTestRun } from './light-task';
13
+ export declare const REVIEW_VERDICTS: readonly ["approve", "approve_with_nits", "changes_requested", "reject_approach"];
14
+ export type MeshReviewVerdict = typeof REVIEW_VERDICTS[number];
15
+ export declare const FINDING_SEVERITIES: readonly ["blocking", "major", "minor", "nit"];
16
+ export type MeshFindingSeverity = typeof FINDING_SEVERITIES[number];
17
+ export declare const FINDING_CATEGORIES: readonly ["correctness", "regression", "test_gap", "scope", "security", "performance", "maintainability"];
18
+ export type MeshFindingCategory = typeof FINDING_CATEGORIES[number];
19
+ export declare const PRIOR_FINDING_STATUSES: readonly ["resolved", "unresolved", "dispute_accepted", "dispute_rejected"];
20
+ export type MeshPriorFindingStatus = typeof PRIOR_FINDING_STATUSES[number];
21
+ export declare const FINDING_RESPONSE_KINDS: readonly ["fixed", "disputed"];
22
+ export type MeshFindingResponseKind = typeof FINDING_RESPONSE_KINDS[number];
23
+ export declare const STAGE_PHASES: readonly ["implementing", "self_checking", "awaiting_review", "reviewing", "revising", "done"];
24
+ export type MeshStagePhase = typeof STAGE_PHASES[number];
25
+ /** Phases in which the parent row holds NO open attempt but is waiting on the daemon (watchdogs must skip it). */
26
+ export declare const STAGE_PARKED_PHASES: readonly MeshStagePhase[];
27
+ export declare const STAGE_INDEPENDENCE_MODES: readonly ["different_provider", "fresh_session_ok"];
28
+ export type MeshStageIndependenceMode = typeof STAGE_INDEPENDENCE_MODES[number];
29
+ /** What actually reviewed (recorded on the verdict and in the final report). */
30
+ export type MeshStageIndependenceUsed = 'different_provider' | 'fresh_session_fallback';
31
+ export declare const STAGE_ROLES: readonly ["implement", "revise", "review"];
32
+ export type MeshStageRole = typeof STAGE_ROLES[number];
33
+ /** Why a stage parent ended `blocked` (R4/R12, doc §3.2). */
34
+ export declare const STAGE_BLOCKED_REASONS: readonly ["review_unresolved", "review_rejected_approach", "review_unavailable", "self_check_failed", "stage_pipeline_ceiling", "reviewer_mutated_source", "reviewer_integrity_unverifiable"];
35
+ export type MeshStageBlockedReason = typeof STAGE_BLOCKED_REASONS[number];
36
+ export declare const STAGE_DECIDE_ACTIONS: readonly ["accept", "revise_once", "rereview", "abandon"];
37
+ export type MeshStageDecideAction = typeof STAGE_DECIDE_ACTIONS[number];
38
+ export declare const STAGE_MAX_REVISIONS_LIMIT = 3;
39
+ export declare const STAGE_DEFAULT_MAX_REVISIONS = 2;
40
+ export declare const STAGE_SELF_CHECK_MAX_BOUNCES = 2;
41
+ /** Minutes a review child may be refused only for `review_independence_required` before fresh_session fallback (R2). */
42
+ export declare const STAGE_INDEPENDENCE_FALLBACK_MS: number;
43
+ /** Parent pipeline ceiling from first dispatch (R12). */
44
+ export declare const STAGE_PIPELINE_CEILING_DEFAULT_MS: number;
45
+ export declare const REVIEW_FINDINGS_MAX = 30;
46
+ export declare const REVIEW_CLAIM_MAX_CHARS = 500;
47
+ export declare const REVIEW_EVIDENCE_MAX_CHARS = 1000;
48
+ export declare const REVIEW_FIX_MAX_CHARS = 500;
49
+ export declare const REVIEW_FINDING_ID_MAX_CHARS = 40;
50
+ export declare const REVIEW_CHECKED_MAX = 20;
51
+ export declare const REVIEW_NOTE_MAX_CHARS = 500;
52
+ export declare const REVIEW_TESTS_RUN_MAX = 20;
53
+ export declare const FINDING_RESPONSES_MAX = 30;
54
+ export interface MeshTaskStagePlan {
55
+ review: true;
56
+ maxRevisions: 0 | 1 | 2 | 3;
57
+ independence: MeshStageIndependenceMode;
58
+ }
59
+ export interface MeshStageHead {
60
+ round: number;
61
+ rootSha: string;
62
+ submodules?: Record<string, string>;
63
+ }
64
+ export interface MeshTaskStageState {
65
+ phase: MeshStagePhase;
66
+ /** Review round in progress (0 before the first review child exists). */
67
+ round: number;
68
+ selfCheckBounces: number;
69
+ startedAt: string;
70
+ phaseSince: string;
71
+ baseSha: string;
72
+ stageHeads: MeshStageHead[];
73
+ reviewTaskIds: string[];
74
+ lastVerdict?: MeshReviewVerdict;
75
+ openFindingIds: string[];
76
+ artifacts: {
77
+ diff: string[];
78
+ selfCheck: string[];
79
+ verdict: string[];
80
+ };
81
+ reviewerSessionId?: string;
82
+ independenceUsed?: MeshStageIndependenceUsed;
83
+ /** Attempts the reducer already consumed (idempotency against the two terminal paths). */
84
+ handledAttemptIds?: string[];
85
+ /** Consecutive reviewer-unavailable outcomes (2 → review_unavailable). */
86
+ reviewerFailures?: number;
87
+ /** Coordinator-granted extra revision rounds (`mesh_task_stage_decide revise_once`). */
88
+ extraRevisions?: number;
89
+ /** Why the parent is blocked, once it is. */
90
+ blockedReason?: MeshStageBlockedReason;
91
+ /** Unresolved findings snapshot kept for the final report (id + severity + claim). */
92
+ openFindings?: Array<{
93
+ id: string;
94
+ severity: MeshFindingSeverity;
95
+ claim: string;
96
+ }>;
97
+ /** Nits/minors from the approving verdict, delivered in the final report. */
98
+ openNits?: Array<{
99
+ id: string;
100
+ severity: MeshFindingSeverity;
101
+ claim: string;
102
+ }>;
103
+ /** Self-check outcome summary for the final report. */
104
+ selfCheck?: 'passed' | 'skipped_not_configured' | 'skipped_infra_error' | 'unavailable' | 'failed';
105
+ /** Resolved/disputed counters for the verdict line. */
106
+ findingsFixed?: number;
107
+ /** The original coordinator message, preserved while revise memos replace `message`. */
108
+ originalMessage?: string;
109
+ /** Artifact ids the implementer cited in its own report (feed the next stage's input, top 4). */
110
+ workerArtifactIds?: string[];
111
+ /** Read-lease reviews only: HEAD + working-tree fingerprint of the parent checkout taken when the review child was created (§11). */
112
+ reviewFingerprint?: string;
113
+ /** Read-lease review whose baseline fingerprint could not be taken (after one retry): the verdict is never accepted. */
114
+ reviewFingerprintUnavailable?: boolean;
115
+ /** True once the parent was released to a terminal by the pipeline (hold lifted). */
116
+ released?: boolean;
117
+ }
118
+ export interface MeshReviewFinding {
119
+ id: string;
120
+ severity: MeshFindingSeverity;
121
+ category: MeshFindingCategory;
122
+ file?: string;
123
+ line?: number;
124
+ claim: string;
125
+ evidence: string;
126
+ suggestedFix?: string;
127
+ }
128
+ export interface MeshPriorFindingStatusEntry {
129
+ id: string;
130
+ status: MeshPriorFindingStatus;
131
+ note?: string;
132
+ }
133
+ /** One definition: the light-task `LightTestRun` (same {command, exit, passed?, failed?, note?} shape). */
134
+ export type MeshTestRun = LightTestRun;
135
+ export interface MeshReviewReport {
136
+ verdict: MeshReviewVerdict;
137
+ findings: MeshReviewFinding[];
138
+ priorFindings?: MeshPriorFindingStatusEntry[];
139
+ checked: string[];
140
+ notChecked: string[];
141
+ testsRun?: MeshTestRun[];
142
+ }
143
+ export interface MeshFindingResponse {
144
+ id: string;
145
+ response: MeshFindingResponseKind;
146
+ note: string;
147
+ }
148
+ export interface StageValidationError {
149
+ field: string;
150
+ message: string;
151
+ }
152
+ export declare const isReviewVerdict: (value: unknown) => value is "approve" | "approve_with_nits" | "changes_requested" | "reject_approach";
153
+ export declare const isFindingSeverity: (value: unknown) => value is "major" | "minor" | "blocking" | "nit";
154
+ export declare const isFindingCategory: (value: unknown) => value is "scope" | "correctness" | "regression" | "test_gap" | "security" | "performance" | "maintainability";
155
+ export declare const isPriorFindingStatus: (value: unknown) => value is "resolved" | "unresolved" | "dispute_accepted" | "dispute_rejected";
156
+ export declare const isFindingResponseKind: (value: unknown) => value is "fixed" | "disputed";
157
+ export declare const isStageBlockedReason: (value: unknown) => value is "review_unresolved" | "review_rejected_approach" | "review_unavailable" | "self_check_failed" | "stage_pipeline_ceiling" | "reviewer_mutated_source" | "reviewer_integrity_unverifiable";
158
+ /** Blocking/major findings keep a review from passing. */
159
+ export declare function isBlockingSeverity(severity: MeshFindingSeverity): boolean;
160
+ export interface StagePlanDefaultsInput {
161
+ taskMode?: string;
162
+ difficulty?: string;
163
+ readonly?: boolean;
164
+ }
165
+ /**
166
+ * Resolve the enqueue-time `review` option into a stage plan, or null when review is off.
167
+ * `review` undefined → R5 default (applied by the MCP layer; the daemon's enqueueTask passes `defaultOn: false` so internal and legacy callers never get a pipeline they did not ask for) (medium/difficult non-readonly `code_change` → on; easy/freeform/readonly → off).
168
+ * Throws `invalid_review_option: …` on malformed input (rejected, never coerced).
169
+ */
170
+ export declare function resolveStagePlan(raw: unknown, task: StagePlanDefaultsInput, opts?: {
171
+ defaultOn?: boolean;
172
+ }): MeshTaskStagePlan | null;
173
+ export declare function defaultStagePlan(): MeshTaskStagePlan;
174
+ /** R5: only non-readonly code_change tasks run the pipeline by default (medium/difficult). */
175
+ export declare function isStageEligibleTask(task: StagePlanDefaultsInput): boolean;
176
+ export interface ReviewValidationContext {
177
+ /** 1-based review round of the child this report is for. */
178
+ round: number;
179
+ /** Blocking/major finding ids still open from the previous round (round ≥ 2 must answer each). */
180
+ priorOpenBlockingIds?: readonly string[];
181
+ }
182
+ /**
183
+ * Validate the `review` field of a reviewer's `report_completion`. Rejects, never coerces;
184
+ * unknown keys are rejected (a misspelled `notChecked` must not silently vanish).
185
+ */
186
+ export declare function validateReviewReport(raw: unknown, ctx: ReviewValidationContext): {
187
+ report?: MeshReviewReport;
188
+ errors: StageValidationError[];
189
+ };
190
+ /** Shared by the reviewer's `review.testsRun` and the top-level `testsRun` of any report. */
191
+ export declare function validateTestsRun(raw: unknown, field: string, errors: StageValidationError[]): MeshTestRun[];
192
+ /** Validate an implementer's `findingResponses` (§5.3). */
193
+ export declare function validateFindingResponses(raw: unknown, field?: string): {
194
+ responses?: MeshFindingResponse[];
195
+ errors: StageValidationError[];
196
+ };
197
+ export interface StageVerdictLineInput {
198
+ verdict: MeshReviewVerdict | 'skipped_no_diff';
199
+ rounds: number;
200
+ reviewerProvider?: string;
201
+ independenceUsed?: MeshStageIndependenceUsed;
202
+ fixed?: number;
203
+ openNits?: number;
204
+ }
205
+ /** One human-readable line: `review: approve_with_nits · 2 rounds · reviewer codex-cli (different_provider) · 3 findings fixed, 1 nit open`. */
206
+ export declare function formatStageVerdictLine(input: StageVerdictLineInput): string;
@@ -56,6 +56,20 @@ export type DispatchFailureReason = typeof DISPATCH_FAILURE_REASONS[number];
56
56
  * (see the field's doc comment — this evidence replicates cross-machine).
57
57
  */
58
58
  export declare function sanitizeRefusalCode(value: unknown): string | undefined;
59
+ /** Longest refusal message kept on a failed dispatch (see {@link sanitizeDispatchRefusalDetail}). */
60
+ export declare const DISPATCH_REFUSAL_DETAIL_MAX = 200;
61
+ /**
62
+ * Bounded, sanitized "why was this dispatch refused" detail for triage:
63
+ * `{code, message}` with the code in the refusal-code identifier shape and the
64
+ * message a single printable line of at most {@link DISPATCH_REFUSAL_DETAIL_MAX}
65
+ * chars (home-directory prefixes collapsed to `~`). Refusal texts are generated
66
+ * by the daemon / transport, never by a user or an agent. LOCAL records only:
67
+ * it is deliberately NOT part of the replicated turn evidence (content-free).
68
+ */
69
+ export declare function sanitizeDispatchRefusalDetail(code: unknown, message: unknown): {
70
+ code?: string;
71
+ message?: string;
72
+ } | undefined;
59
73
  export declare const CONSUME_PROFILES: readonly ["default", "native_source"];
60
74
  export type ConsumeProfile = typeof CONSUME_PROFILES[number];
61
75
  export declare const SESSION_REBOUND_REASONS: readonly ["restart", "live_holder"];
@@ -110,7 +124,7 @@ export type TurnOutcome = typeof TURN_OUTCOMES[number];
110
124
  export declare const COMMIT_STRENGTHS: readonly ["genuine", "weak", "tool_report", "operator"];
111
125
  export type CommitStrength = typeof COMMIT_STRENGTHS[number];
112
126
  /** Every terminal or reclaim reason the ledger writes. Closed: no free-text reasons. */
113
- export declare const TURN_REASONS: readonly ["turn_end", "weak_end_confirmed", "transcript_final", "worker_reported", "finalization_timeout_no_response", "weak_end_liveness_unconfirmed", "weak_end_probe_unobserved", "report_correction_expired", "session_error", "provider_auth_failed", "provider_billing_failed", "provider_usage_limit_exceeded", "provider_server_overloaded", "provider_error", "operator_cancel", "intentional_cleanup", "task_removed", "mission_abandoned", "superseded", "operator_update", "refine_terminal", "validation_terminal", "hard_ceiling", "reclaim_budget_exhausted", "hollow_max_retries", "migration_orphan", "dispatch_refused_session_exited", "dispatch_refused_no_target", "dispatch_refused_unsupported_input", "dispatch_failed", "session_exit", "session_exit_before_turn", "session_dead", "hollow_completion", "assigned_stranded_dispatch_unconfirmed", "delivered_not_consumed_redrive", "delivered_no_turn_deadline"];
127
+ export declare const TURN_REASONS: readonly ["turn_end", "weak_end_confirmed", "transcript_final", "worker_reported", "finalization_timeout_no_response", "weak_end_liveness_unconfirmed", "weak_end_probe_unobserved", "report_correction_expired", "session_error", "provider_auth_failed", "provider_billing_failed", "provider_usage_limit_exceeded", "provider_server_overloaded", "provider_error", "operator_cancel", "intentional_cleanup", "task_removed", "mission_abandoned", "superseded", "operator_update", "refine_terminal", "validation_terminal", "hard_ceiling", "reclaim_budget_exhausted", "hollow_max_retries", "migration_orphan", "writer_unreachable", "dispatch_refused_session_exited", "dispatch_refused_no_target", "dispatch_refused_unsupported_input", "dispatch_failed", "session_exit", "session_exit_before_turn", "session_dead", "hollow_completion", "assigned_stranded_dispatch_unconfirmed", "delivered_not_consumed_redrive", "delivered_no_turn_deadline"];
114
128
  export type TurnReason = typeof TURN_REASONS[number];
115
129
  /**
116
130
  * What a `turn.notify` entry tells a coordinator.
@@ -387,7 +401,7 @@ export declare const TURN_EVIDENCE_KINDS: readonly TurnEvidenceKind[];
387
401
  /** Evidence kinds that, on their own, can end a turn (the ones R18/R19/R27 reason about). */
388
402
  export declare const TERMINAL_CLASS_EVIDENCE_KINDS: readonly ["turn_end", "transcript_final", "no_progress", "worker_report", "session_error", "process_exit", "cancel", "operator_status"];
389
403
  export declare const isTurnEvidenceKind: (value: unknown) => value is "no_progress" | "delivered" | "liveness" | "turn_end" | "transcript_final" | "session_error" | "dispatch_failed" | "dispatch_accepted" | "delivery_refused" | "duplicate_dispatch_refusal" | "session_rebound" | "turn_started" | "suspension" | "suspension_resolved" | "transcript_activity" | "process_exit" | "worker_report" | "worker_report_correction_requested" | "worker_progress" | "git_side_effect" | "cancel" | "operator_status" | "coordinator_ack" | "hold_expired";
390
- export declare const isTurnReason: (value: unknown) => value is "provider_error" | "intentional_cleanup" | "operator_cancel" | "task_removed" | "mission_abandoned" | "superseded" | "operator_update" | "refine_terminal" | "validation_terminal" | "hard_ceiling" | "turn_end" | "weak_end_confirmed" | "transcript_final" | "worker_reported" | "finalization_timeout_no_response" | "weak_end_liveness_unconfirmed" | "weak_end_probe_unobserved" | "report_correction_expired" | "session_error" | "provider_auth_failed" | "provider_billing_failed" | "provider_usage_limit_exceeded" | "provider_server_overloaded" | "reclaim_budget_exhausted" | "hollow_max_retries" | "migration_orphan" | "dispatch_refused_session_exited" | "dispatch_refused_no_target" | "dispatch_refused_unsupported_input" | "dispatch_failed" | "session_exit" | "session_exit_before_turn" | "session_dead" | "hollow_completion" | "assigned_stranded_dispatch_unconfirmed" | "delivered_not_consumed_redrive" | "delivered_no_turn_deadline";
404
+ export declare const isTurnReason: (value: unknown) => value is "provider_error" | "intentional_cleanup" | "operator_cancel" | "task_removed" | "mission_abandoned" | "superseded" | "operator_update" | "refine_terminal" | "validation_terminal" | "hard_ceiling" | "turn_end" | "weak_end_confirmed" | "transcript_final" | "worker_reported" | "finalization_timeout_no_response" | "weak_end_liveness_unconfirmed" | "weak_end_probe_unobserved" | "report_correction_expired" | "session_error" | "provider_auth_failed" | "provider_billing_failed" | "provider_usage_limit_exceeded" | "provider_server_overloaded" | "reclaim_budget_exhausted" | "hollow_max_retries" | "migration_orphan" | "writer_unreachable" | "dispatch_refused_session_exited" | "dispatch_refused_no_target" | "dispatch_refused_unsupported_input" | "dispatch_failed" | "session_exit" | "session_exit_before_turn" | "session_dead" | "hollow_completion" | "assigned_stranded_dispatch_unconfirmed" | "delivered_not_consumed_redrive" | "delivered_no_turn_deadline";
391
405
  export declare const isNotifyKind: (value: unknown) => value is "stopped" | "failed" | "blocked" | "no_progress" | "completed" | "cancelled" | "approval" | "choice" | "approval_resolved" | "candidate" | "progress" | "late_completion" | "mesh_event";
392
406
  export declare const isTurnOutcome: (value: unknown) => value is "failed" | "blocked" | "completed" | "cancelled";
393
407
  export declare const isCommitStrength: (value: unknown) => value is "operator" | "genuine" | "weak" | "tool_report";
@@ -298,6 +298,8 @@ export interface LedgerQueryEntryWire {
298
298
  export interface LedgerQuerySummaryWire {
299
299
  /** Absent on older peers; never folded into failed by the decoder. */
300
300
  taskBlocked?: number;
301
+ /** Failed Refinery jobs (not tasks). Absent on older peers. */
302
+ refineFailed?: number;
301
303
  meshId: string;
302
304
  totalEntries: number;
303
305
  taskDispatched: number;
@@ -53,7 +53,37 @@ export interface WorkerProtocolFooterInput {
53
53
  * which is what every worker launched with the default gate receives.
54
54
  */
55
55
  workerMcp?: boolean;
56
+ /**
57
+ * Same-machine light task: the worker runs in a temporary light workspace.
58
+ * Renders the light-workspace rules (stay inside, commit there, no installs).
59
+ */
60
+ light?: {
61
+ workspace: string;
62
+ baseSha: string;
63
+ ossBaseSha?: string;
64
+ ownedPaths: string[];
65
+ };
66
+ /**
67
+ * Code-changing task on a shared (non-worktree) node checkout, not a light task: the worker commits on the
68
+ * branch that is currently checked out. Renders the "do not create or switch branches" rule.
69
+ */
70
+ commitOnCurrentBranch?: boolean;
71
+ /**
72
+ * Review-in-task (docs/design/2026-11-01-review-in-task.md §9.3): present when this
73
+ * dispatch is one stage of a stage pipeline. `workspace` is the reviewer's pinned
74
+ * workspace path when the daemon prepared one.
75
+ */
76
+ stage?: {
77
+ role: 'implement' | 'revise' | 'review';
78
+ round: number;
79
+ maxRevisions: number;
80
+ workspace?: string;
81
+ };
56
82
  }
83
+ /** Light-workspace worker rules (design §9). */
84
+ export declare function renderLightWorkspaceRules(light: NonNullable<WorkerProtocolFooterInput['light']>): string[];
85
+ /** Base-node code changes land on the branch the coordinator and review expect: the one already checked out. */
86
+ export declare const WORKER_CURRENT_BRANCH_RULE: string;
57
87
  export declare function hasWorkerProtocolFooter(body: string): boolean;
58
88
  /**
59
89
  * The protocol block appended to a dispatched task. Written for the model that
@@ -61,6 +91,8 @@ export declare function hasWorkerProtocolFooter(body: string): boolean;
61
91
  * the worker does not go looking for coordinator tools.
62
92
  */
63
93
  export declare function renderWorkerProtocolFooter(input?: WorkerProtocolFooterInput): string;
94
+ /** The stage-pipeline paragraph of the worker footer (implement / revise / review). */
95
+ export declare function renderStageProtocolLines(stage: NonNullable<WorkerProtocolFooterInput['stage']>): string[];
64
96
  /**
65
97
  * The authored text of a dispatched body: everything before the footer marker.
66
98
  * Ledger descriptors, replay fixtures and tests compare authored text, never
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/mesh-shared",
3
- "version": "1.0.82-rc.46",
3
+ "version": "1.0.82-rc.48",
4
4
  "description": "ADHDev mesh-shared — pure mesh/git status normalizers shared by daemon-core and web-core",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -52,4 +52,6 @@ export * from './launch-defaults'
52
52
 
53
53
  export * from './role-launch';
54
54
  export * from './task-source-phase';
55
+ export * from './light-task';
55
56
  export * from './relay-reprobe'
57
+ export * from './task-stages'
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Same-machine light task — shared vocabulary and wire shapes (design
3
+ * docs/design/2026-11-01-same-machine-light-task.md).
4
+ *
5
+ * A light task is a `code_change` queue row that runs in a per-task scratch checkout
6
+ * (light workspace) on the coordinator's machine, based on the coordinator checkout's
7
+ * commit. Dependency-free leaf: daemon-core, mcp-server and web-core all import this.
8
+ */
9
+
10
+ /** Enqueue refusals (thrown as `<code>: <message>`). */
11
+ export const LIGHT_REJECT = {
12
+ REQUIRES_LOCAL_BASE: 'light_requires_local_base',
13
+ NOT_CONFIGURED: 'light_workspace_not_configured',
14
+ REQUIRES_OWNED_PATHS: 'light_requires_owned_paths',
15
+ MODE_CONFLICT: 'light_mode_conflict',
16
+ } as const
17
+ export type LightRejectCode = typeof LIGHT_REJECT[keyof typeof LIGHT_REJECT]
18
+
19
+ /** Pending-row hold reasons set by the light dispatcher. */
20
+ export const LIGHT_HOLD = {
21
+ PREPARE_FAILED: 'light_workspace_prepare_failed',
22
+ LIMIT: 'light_workspace_limit',
23
+ DISK_LOW: 'light_workspace_disk_low',
24
+ CAP: 'max_light_parallel_tasks_reached',
25
+ } as const
26
+
27
+ /** Reasons a finished light result is not landable (`landing: 'blocked'`). */
28
+ export const LIGHT_BLOCK_REASONS = [
29
+ 'light_uncommitted_changes',
30
+ 'light_dependency_change',
31
+ 'light_lineage_unproven',
32
+ 'shared_checkout_mutated',
33
+ ] as const
34
+ export type LightBlockReason = typeof LIGHT_BLOCK_REASONS[number]
35
+
36
+ /** Non-blocking observations recorded on the result. */
37
+ export const LIGHT_WARNINGS = ['shared_checkout_changed_during_task', 'light_base_dirty_overlap'] as const
38
+ export type LightWarning = typeof LIGHT_WARNINGS[number]
39
+
40
+ export const LIGHT_LAND_MODES = ['refine', 'apply_to_checkout'] as const
41
+ export type LightLandMode = typeof LIGHT_LAND_MODES[number]
42
+
43
+ export type LightLandingState = 'ready' | 'conflict' | 'blocked' | 'landed' | 'discarded'
44
+
45
+ export interface LightApplyCheckSide {
46
+ /** Commit the result was checked against. */
47
+ against: string
48
+ status: 'clean' | 'conflict' | 'base_unavailable'
49
+ conflictPaths?: string[]
50
+ }
51
+
52
+ /** merge-tree apply-check of the root (`.`) and each submodule, vs the base HEAD and `origin/<base>`. */
53
+ export interface LightApplyCheck {
54
+ head: LightApplyCheckSide
55
+ remote?: LightApplyCheckSide
56
+ }
57
+
58
+ /** Worker-reported test run (`report_completion.testsRun`). Self-reported, never trusted as evidence. */
59
+ export interface LightTestRun {
60
+ command: string
61
+ exit: number
62
+ passed?: number
63
+ failed?: number
64
+ note?: string
65
+ }
66
+
67
+ export const LIGHT_TESTS_RUN_MAX = 20
68
+
69
+ export interface LightTaskResult {
70
+ workspaceId: string
71
+ /** root branch (`mesh/light/<taskId8>`) */
72
+ branch: string
73
+ /** submodule path -> branch */
74
+ submoduleBranches?: Record<string, string>
75
+ rootBaseSha: string
76
+ rootHeadSha?: string
77
+ submoduleHeads?: Record<string, { base: string; head: string }>
78
+ touchedPaths: string[]
79
+ ownedPathsMismatch?: string[]
80
+ applyCheck?: LightApplyCheck
81
+ patchArtifactIds: string[]
82
+ testsRun?: LightTestRun[]
83
+ landing: LightLandingState
84
+ blockedReason?: LightBlockReason
85
+ blockedDetail?: string
86
+ warnings?: LightWarning[]
87
+ landedAt?: string
88
+ landedVia?: LightLandMode
89
+ /** The verified source packet (`MeshSourceCandidate`) for this result; tests carry no log hashes. */
90
+ sourceCandidate?: import('./task-source-phase').MeshSourceCandidate
91
+ capturedAt: string
92
+ }
93
+
94
+ export interface LightLandRequest {
95
+ taskIds: string[]
96
+ mode?: LightLandMode
97
+ dryRun?: boolean
98
+ /** Required when a result touched paths outside its `owned_paths`. */
99
+ acceptPathsOutsideOwned?: boolean
100
+ /** Land the leading non-conflicting tasks when a later one conflicts. */
101
+ partial?: boolean
102
+ approvedPublishShas?: string[]
103
+ }
104
+
105
+ /**
106
+ * True when a session record/state (or a bare settings object) belongs to a light-task worker, i.e.
107
+ * it was launched with `settings.lightWorkspaceId`. A light session is bound to ONE task's scratch
108
+ * workspace and, by the central claim rule, can never claim any other row — so it is never "the
109
+ * node's worker" for duplicate-launch guards, auto-launch gating or concurrency counts.
110
+ */
111
+ export function isLightWorkerSession(session: unknown): boolean {
112
+ const s = session as any
113
+ if (!s || typeof s !== 'object') return false
114
+ const has = (o: any): boolean => !!o && typeof o === 'object' && typeof o.lightWorkspaceId === 'string' && o.lightWorkspaceId.trim() !== ''
115
+ return has(s.settings) || has(s.launchRecord?.settings) || has(s)
116
+ }
@@ -27,9 +27,12 @@ export const CANONICAL_MESH_TOOL_NAMES = [
27
27
  'mesh_enqueue_task',
28
28
  'mesh_view_queue',
29
29
  'mesh_queue_cancel',
30
+ 'mesh_task_stage_decide',
30
31
  'mesh_direct_cancel',
31
32
  'mesh_queue_requeue',
32
33
  'mesh_queue_revise',
34
+ 'mesh_light_land',
35
+ 'mesh_light_discard',
33
36
  'mesh_send_task',
34
37
  'mesh_read_chat',
35
38
  'mesh_read_debug',
@@ -58,4 +58,13 @@ export interface MeshIntegrationBatchContract {
58
58
 
59
59
  /** These only rank legal targets; targetNodeId/SessionId and requiredTags remain hard. */
60
60
  export interface MeshRoutingPreferences { nodeIds?: string[]; providers?: string[] }
61
- export interface MeshReviewConstraint { sourceTaskId: string; differentProvider: true }
61
+ export type MeshReviewIndependence = 'different_provider' | 'fresh_session'
62
+ /**
63
+ * Review row constraint. `differentProvider: true` is the legacy spelling of
64
+ * `independence: 'different_provider'`; `independence: 'fresh_session'` is the stage pipeline's
65
+ * fallback (same provider allowed, but never the implementer's session).
66
+ */
67
+ export interface MeshReviewConstraint { sourceTaskId: string; differentProvider?: true; independence?: MeshReviewIndependence }
68
+ export function reviewIndependenceOf(review: Pick<MeshReviewConstraint, 'differentProvider' | 'independence'>): MeshReviewIndependence {
69
+ return review.independence ?? 'different_provider'
70
+ }