@guided-context-ledger/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 The Guided Context Ledger Authors
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,10 @@
1
+ Guided Context Ledger (GCL)
2
+ Copyright 2026 The Guided Context Ledger Authors
3
+
4
+ This product includes software developed for the Guided Context Ledger project.
5
+
6
+ Licensed under the Apache License, Version 2.0. See the LICENSE file.
7
+
8
+ The knowledge layer is aligned with the Open Knowledge Format (OKF),
9
+ introduced by Google Cloud (2026). OKF is credited as the origin of that
10
+ format; GCL claims no authorship of it.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @guided-context-ledger/core
2
+
3
+ Transport-agnostic core runtime for the **Guided Context Ledger (GCL)** — the auditable provenance layer for multi-agent work.
4
+
5
+ This package is the engine, with no transport or MCP dependency. It gives you:
6
+
7
+ - **Workspace I/O** — read/write a plain-Markdown workspace (`Workspace`).
8
+ - **The append-only coordination trail** — events, claims, leases, `orient`/`needs_me`, task pool projections (`EventLog`).
9
+ - **The content-addressed revision ledger** — `HEAD`, CAS advance, hash-linked revisions with declared-vs-derived provenance (`GclLedger`).
10
+
11
+ It is the shared substrate the reference connector is built on. Bring your own transport (MCP, HTTP, CLI) on top of it.
12
+
13
+ ```bash
14
+ npm install @guided-context-ledger/core
15
+ ```
16
+
17
+ ```ts
18
+ import { Workspace, EventLog, GclLedger } from "@guided-context-ledger/core";
19
+ ```
20
+
21
+ For the protocol itself, the starter workspace, and a runnable MCP connector, see the monorepo:
22
+ **https://github.com/guided-context-ledger/guided-context-ledger**
23
+
24
+ Apache-2.0. Pre-1.0 alpha — interfaces may change between minor releases (see the repo `CHANGELOG.md`).
@@ -0,0 +1,430 @@
1
+ export declare const EVENT_TYPES: readonly ["message", "ack", "handoff", "conflict", "claim", "task", "task_state", "task_authorization", "task_condition"];
2
+ export type EventType = (typeof EVENT_TYPES)[number];
3
+ /** Lifecycle states a `claim` event can assert over a work item. Ratified: the GCL coordination spec (codex). */
4
+ export declare const CLAIM_STATUSES: readonly ["claimed", "released", "completed"];
5
+ export type ClaimStatus = (typeof CLAIM_STATUSES)[number];
6
+ /**
7
+ * Truth lifecycle a `task_state` event asserts over a task. Distinct from claim ownership (§2.3).
8
+ * Both values are TERMINAL and IMMUTABLE: once a task is completed or cancelled its truth is settled
9
+ * for good. There is deliberately no `reopened` — reopening a closed task retroactively mutates a
10
+ * recorded completion, which is tampering with the append-only truth trail (Kyle, 2026-06-19). Forward
11
+ * work is a NEW successor task that references the original (see SUCCESSION_RELATIONS), yielding a
12
+ * visible lineage chain instead of a muddied open/close/open history.
13
+ */
14
+ export declare const TASK_STATUSES: readonly ["completed", "cancelled"];
15
+ export type TaskStatus = (typeof TASK_STATUSES)[number];
16
+ /**
17
+ * How a successor task relates to the original it supersedes (forward work after a terminal close,
18
+ * GCL-State-Model §"Task re-opening"). The relation tells an observer WHY a closed task reappeared:
19
+ * - `continuation` — a clean follow-on; the original finished and this carries it forward.
20
+ * - `redo` — the original regressed or proved insufficient; redo the work.
21
+ * - `correction` — the original was closed in error or is disputed; this corrects the record.
22
+ * Carried on the SUCCESSOR's creation event via `succeeds` (the original task_id) + `succession`.
23
+ */
24
+ export declare const SUCCESSION_RELATIONS: readonly ["continuation", "redo", "correction"];
25
+ export type SuccessionRelation = (typeof SUCCESSION_RELATIONS)[number];
26
+ /**
27
+ * Conditions an item can carry (GCL-State-Model §"The dimensions" axis 3). FACTS ONLY — the system
28
+ * reports facts, the human assigns meaning (facts-vs-meaning, locked). Conditions STACK and each carries
29
+ * an inspectable reason. They are orthogonal to lifecycle (an in-progress task can become blocked/stale).
30
+ * - `overdue` — DERIVED fact: now is past `due_date` (zero-threshold, no "soon" opinion).
31
+ * - `stale` — DERIVED fact: no qualifying/semantic-transition activity within the cadence window.
32
+ * - `pending` — DECLARED: a decision/input is awaited but a path forward exists (the ball is in
33
+ * someone's court who CAN act). Author-set; no auto-derivation mechanism in v0.
34
+ * - `blocked` — DECLARED: a hard stop (missing parts/upstream/broken) — cannot proceed regardless.
35
+ * Author-set; no auto-derivation mechanism in v0.
36
+ * - `undetermined` — honest fallback: a determination was expected but inputs are missing (e.g. no
37
+ * `due_date` → can't assess overdue). Distinct from *clear*; quiet, not an alarm.
38
+ * v0 auto-emits only the two purely-derived facts (`overdue`, `stale`); `pending`/`blocked` await a
39
+ * declaration mechanism and `undetermined` is emitted only where a determination is genuinely expected.
40
+ */
41
+ export declare const TASK_CONDITIONS: readonly ["pending", "blocked", "overdue", "stale", "undetermined"];
42
+ export type TaskCondition = (typeof TASK_CONDITIONS)[number];
43
+ /**
44
+ * The DECLARED conditions — the author-set subset of the conditions axis (the rest are derived facts).
45
+ * `pending` (a decision/input is awaited but a path forward exists) vs `blocked` (a hard stop). Declared
46
+ * via a `task_condition` event, not derived, because intent isn't computable from timestamps.
47
+ */
48
+ export declare const DECLARABLE_CONDITIONS: readonly ["pending", "blocked"];
49
+ export type DeclarableCondition = (typeof DECLARABLE_CONDITIONS)[number];
50
+ /** A `task_condition` event either asserts a condition (`set`) or retracts a specific prior assertion (`cleared`). */
51
+ export declare const CONDITION_STATES: readonly ["set", "cleared"];
52
+ export type ConditionState = (typeof CONDITION_STATES)[number];
53
+ /**
54
+ * One ACTIVE declared-condition assertion on a task (a `set` not yet `cleared`). Assertion identity is the
55
+ * `set` event's id, so clearing one actor's blocker can't erase another's independent blocker (codex
56
+ * the GCL coordination spec). Each carries its own author + reason.
57
+ */
58
+ export interface DeclaredCondition {
59
+ assertion_id: string;
60
+ condition: DeclarableCondition;
61
+ reason: string;
62
+ actor: string;
63
+ since: string;
64
+ }
65
+ /** A condition fact plus the inspectable reason behind it (reasons render in the surface, not just provenance). */
66
+ export interface ConditionFlag {
67
+ condition: TaskCondition;
68
+ reason: string;
69
+ }
70
+ /** A `task_authorization` event's assertion. `approved` makes a task claim-eligible; `revoked` withdraws it. */
71
+ export declare const TASK_AUTHORIZATIONS: readonly ["approved", "revoked"];
72
+ export type TaskAuthorization = (typeof TASK_AUTHORIZATIONS)[number];
73
+ /**
74
+ * Workspace pull policy — gates autonomous CLAIM eligibility over the pool, never visibility.
75
+ * Default `human_directed` (unassigned-by-default; Kyle #239 / codex #242). A default, not a constant.
76
+ */
77
+ export declare const TASK_PULL_POLICIES: readonly ["human_directed", "proactive_until_stale", "proactive"];
78
+ export type TaskPullPolicy = (typeof TASK_PULL_POLICIES)[number];
79
+ export declare const DEFAULT_TASK_PULL_POLICY: TaskPullPolicy;
80
+ /** Optional scope envelope on a task. v0 matches project/space; principal_scope is opaque (OI-001 deferred). */
81
+ export interface TaskScope {
82
+ project?: string;
83
+ space?: string;
84
+ principal_scope?: string;
85
+ }
86
+ /** Default lease window for a claim with no explicit lease_expires_at (interactive coordination work). */
87
+ export declare const DEFAULT_LEASE_MS: number;
88
+ export declare class EventError extends Error {
89
+ readonly code: string;
90
+ constructor(message: string, code: string);
91
+ }
92
+ export interface AgentEvent {
93
+ seq: number;
94
+ event_id: string;
95
+ thread: string;
96
+ actor: string;
97
+ type: EventType;
98
+ parent_event_id: string | null;
99
+ created_at: string;
100
+ body: string;
101
+ /** Coordination actor ids this event is directed at (NOT humans/principals). Empty = unaddressed. */
102
+ addressed_to: string[];
103
+ /** Whether an addressee owes a causal response. Defaults by type when unstated (see RESPONSE_REQUIRED_BY_TYPE). */
104
+ requires_response: boolean;
105
+ /** For type=claim only: the lifecycle assertion. null for non-claim events. */
106
+ claim_status: ClaimStatus | null;
107
+ /** For type=claim only: ISO-8601 lease end, or null for an indefinite hold. */
108
+ lease_expires_at: string | null;
109
+ /** For type=task only: short title (the body carries the full description). null otherwise. */
110
+ task_title: string | null;
111
+ /** For type=task only: capabilities a claimant needs. [] = any capable reasoner. */
112
+ requires: string[];
113
+ /** For type=task only: optional role hint. null otherwise. */
114
+ role: string | null;
115
+ /** For type=task only: optional scope envelope (project/space/principal_scope). null otherwise. */
116
+ scope: TaskScope | null;
117
+ /** For type=task only: the task_id this one supersedes (forward work after a terminal close). null otherwise. */
118
+ succeeds: string | null;
119
+ /** For type=task only: how this task relates to the one it `succeeds`. Required iff `succeeds` is set. null otherwise. */
120
+ succession: SuccessionRelation | null;
121
+ /** For type=task only: optional raw start date (ISO-8601 / any Date-parseable string). Stored verbatim; null otherwise. */
122
+ start_date: string | null;
123
+ /** For type=task only: optional raw due date. `overdue`/`days_remaining` derive from it; null = no deadline (clear, not undetermined). */
124
+ due_date: string | null;
125
+ /** For type=task_state only: the truth transition. null otherwise. */
126
+ task_status: TaskStatus | null;
127
+ /** For type=task_condition only: the declared condition (pending|blocked). null otherwise. */
128
+ condition: DeclarableCondition | null;
129
+ /** For type=task_condition only: set (assert) or cleared (retract a prior assertion). null otherwise. */
130
+ condition_state: ConditionState | null;
131
+ /** For type=task_authorization only: the assignment assertion. null otherwise. */
132
+ authorization: TaskAuthorization | null;
133
+ /** For type=task_state / task_authorization: optional human-readable reason. null otherwise. */
134
+ reason: string | null;
135
+ /** For type=task_state: optional refs to the produced result (paths/event ids). [] otherwise. */
136
+ result_refs: string[];
137
+ }
138
+ /** Optional structured addressing / claim payload for an appended event. */
139
+ export interface AppendOptions {
140
+ /** Coordination actor ids this event is directed at. Use even for one recipient. */
141
+ addressedTo?: string[];
142
+ /** Override the type-derived default for whether the addressee owes a response. */
143
+ requiresResponse?: boolean;
144
+ /** For type=claim: the lifecycle assertion (claimed|released|completed). Required when type=claim. */
145
+ claimStatus?: ClaimStatus;
146
+ /**
147
+ * For type=claim with claimStatus=claimed: ISO-8601 lease end. Omitted → server stamps
148
+ * created_at + DEFAULT_LEASE_MS. Pass null explicitly for an indefinite hold (no expiry).
149
+ */
150
+ leaseExpiresAt?: string | null;
151
+ /** For type=task: short title (body carries the description). */
152
+ taskTitle?: string;
153
+ /** For type=task: capabilities a claimant needs (`[]`/omitted = any capable reasoner). */
154
+ requires?: string[];
155
+ /** For type=task: optional role hint. */
156
+ role?: string;
157
+ /** For type=task: optional scope envelope. */
158
+ scope?: TaskScope;
159
+ /** For type=task: the task_id this task supersedes (forward work after a terminal close). Pair with `succession`. */
160
+ succeeds?: string;
161
+ /** For type=task: how this task relates to the one it `succeeds` (continuation|redo|correction). Required iff `succeeds` is set. */
162
+ succession?: SuccessionRelation;
163
+ /** For type=task: optional raw start date (any Date-parseable string), stored verbatim. */
164
+ startDate?: string;
165
+ /** For type=task: optional raw due date (any Date-parseable string). Drives derived `overdue`/`days_remaining`. */
166
+ dueDate?: string;
167
+ /** For type=task_state: the truth transition (completed|cancelled — both terminal/immutable). Required when type=task_state. */
168
+ taskStatus?: TaskStatus;
169
+ /** For type=task_condition with conditionState=set: the declared condition (pending|blocked). Required on a `set`. */
170
+ condition?: DeclarableCondition;
171
+ /** For type=task_condition: `set` (parent=task) asserts; `cleared` (parent=the set assertion) retracts it. Required. */
172
+ conditionState?: ConditionState;
173
+ /** For type=task_authorization: the assignment assertion (approved|revoked). Required when type=task_authorization. */
174
+ authorization?: TaskAuthorization;
175
+ /** For type=task_state / task_authorization / task_condition: optional human-readable reason (required on a condition `set`). */
176
+ reason?: string;
177
+ /** For type=task_state: optional refs to the produced result. */
178
+ resultRefs?: string[];
179
+ }
180
+ export declare class EventLog {
181
+ readonly root: string;
182
+ readonly dir: string;
183
+ constructor(workspaceRoot: string);
184
+ private threadFile;
185
+ /** The workspace root must already exist — we never silently create it. */
186
+ private assertRoot;
187
+ private acquireLock;
188
+ private releaseLock;
189
+ private countLines;
190
+ /**
191
+ * Append one event. Server-stamps created_at. Returns the assigned seq
192
+ * (line ordinal) and a stable event_id. Cross-process safe via the lockfile.
193
+ */
194
+ append(thread: string, actor: string, body: string, type?: EventType, parentEventId?: string | null, opts?: AppendOptions): Promise<{
195
+ seq: number;
196
+ event_id: string;
197
+ created_at: string;
198
+ }>;
199
+ private parseLine;
200
+ private readRaw;
201
+ /**
202
+ * Read events with seq > afterSeq (the cursor → only deltas). If waitMs > 0
203
+ * and there are no new events, long-poll: re-check until new events arrive or
204
+ * the wait elapses (collapses idle polling into one call). Pass `actor` to
205
+ * record presence (so peers can tell you are alive even while only reading).
206
+ */
207
+ read(thread: string, afterSeq?: number, waitMs?: number, actor?: string): Promise<{
208
+ events: AgentEvent[];
209
+ latest_seq: number;
210
+ corrupt: number;
211
+ presence: Record<string, string>;
212
+ }>;
213
+ /** Advisory last-active map; last-write-wins (races tolerable, parse errors reset). */
214
+ private touchPresence;
215
+ private readPresence;
216
+ /** List thread ids that have an event log. */
217
+ listThreads(): Promise<string[]>;
218
+ /**
219
+ * Cross-thread overview for `orient`: per-thread cursor state relative to
220
+ * `actor` (deterministic, no inference). `unread` = events after the actor's
221
+ * own last post; `needs_me` flags threads whose latest event is from someone
222
+ * else and is unread by the actor. Records presence for the actor.
223
+ */
224
+ overview(actor?: string): Promise<{
225
+ threads: ThreadOverview[];
226
+ open_for_me: OpenForMeItem[];
227
+ presence: Record<string, string>;
228
+ }>;
229
+ /**
230
+ * Cross-thread causal responses to an owed event — the addresser-side "answered in …" projection
231
+ * (the GCL coordination spec). Walks the GLOBAL causal DAG from `eventRef` across all threads and returns each
232
+ * non-`claim` descendant response, flagging the ones that landed in a different thread so a connector can
233
+ * render "answered in <thread>". A `claim` is excluded for the same reason discharge excludes it (taking
234
+ * work ≠ answering). Optionally filter to one actor's responses. Pure read-time projection, zero mutation.
235
+ */
236
+ causalResponses(eventRef: string, opts?: {
237
+ byActor?: string;
238
+ }): Promise<CausalResponse[]>;
239
+ /**
240
+ * Project a SINGLE task's full state by id (truth, ownership, lineage, ignored terminal attempts).
241
+ * Closed tasks leave the open pool but remain inspectable here — this is the read path that makes the
242
+ * append-only invariant explainable: a later terminal attempt is ignored, not invisible (the GCL coordination spec).
243
+ */
244
+ projectTask(thread: string, taskId: string, now?: number): Promise<TaskProjection | null>;
245
+ /**
246
+ * Capability-routed pool of unassigned open tasks across all threads (the GCL coordination spec–#244).
247
+ * Visibility is unconditional; per-row `eligibility` reflects whether the active `policy`
248
+ * lets THIS actor claim now. Live-claimed (assigned) tasks are excluded — they are
249
+ * in-progress, not pool work; terminal tasks leave the pool but remain in history.
250
+ * Returns the full structured rows + total count — the discoverability anchor: a caller
251
+ * MUST NOT hide rows beyond this without surfacing the count and an expand path (AC n).
252
+ */
253
+ taskPool(opts?: TaskPoolOptions): Promise<{
254
+ open_pool: TaskRow[];
255
+ total_eligible: number;
256
+ staleness_assessment: StalenessAssessment;
257
+ }>;
258
+ }
259
+ /** Projected ownership of a work item, folded from its claim events at read time. */
260
+ export interface ClaimState {
261
+ /** Current owner actor, or null if unclaimed / released / completed. */
262
+ owner: string | null;
263
+ /** The owner's lease end (ISO-8601), or null for an indefinite hold. */
264
+ expires: string | null;
265
+ /** True when an owner holds the item but the lease has lapsed vs the read clock — re-claimable. */
266
+ stale: boolean;
267
+ /** Latest lifecycle status seen for the item (claimed while owned; released/completed when freed). */
268
+ status: ClaimStatus | null;
269
+ }
270
+ export type TaskTruth = "open" | "completed" | "cancelled";
271
+ /** Why a still-open task is flagged for human attention. Derived only — never an event/terminal state (§2.6). */
272
+ export type StaleReason = "unclaimed_age_exceeded" | "verification_pending_age_exceeded" | "no_capable_route" | "creator_unavailable";
273
+ /** Whether the orienting actor may claim a pool task right now, under the active policy. */
274
+ export type TaskEligibility = "claimable_now" | "needs_authorization";
275
+ /**
276
+ * A terminal `task_state` event that arrived AFTER the task's truth was already settled — ignored by
277
+ * first-terminal-wins, but never invisible: retained here with provenance so a connector can explain the
278
+ * conflict ("X tried to mark this cancelled, but it was already completed"). The first terminal stays
279
+ * authoritative; these supersede nothing (the GCL coordination spec, codex's naming).
280
+ */
281
+ export interface TerminalAttempt {
282
+ event_id: string;
283
+ actor: string;
284
+ attempted_status: TaskStatus;
285
+ at: string;
286
+ reason: "already_terminal";
287
+ /** The winning terminal event that had already settled the truth — the provenance edge that makes the
288
+ * conflict self-explaining ("ignored because settled_by_event_id closed it first"). Part of the
289
+ * explanation contract, not cosmetic (codex the GCL coordination spec). */
290
+ settled_by_event_id: string;
291
+ }
292
+ export interface TaskProjection {
293
+ task_id: string;
294
+ thread: string;
295
+ creation: AgentEvent;
296
+ truth: TaskTruth;
297
+ /** Ownership was `completed` but truth never closed → work done, acceptance pending (§2.3). */
298
+ verification_pending: boolean;
299
+ ownership: ClaimState;
300
+ /** Latest task_authorization: approved (and not later revoked). */
301
+ authorized: boolean;
302
+ /** Later terminal task_state events ignored by first-terminal-wins — retained, never silently dropped. */
303
+ ignored_terminal_attempts: TerminalAttempt[];
304
+ /** ACTIVE declared conditions (pending/blocked `set` and not yet `cleared`), each with its own author + reason. */
305
+ declared_conditions: DeclaredCondition[];
306
+ created_at: string;
307
+ last_activity_at: string;
308
+ }
309
+ /** One structured `open_pool` row (codex #243). Grouping/sorting is the client's view choice. */
310
+ export interface TaskRow {
311
+ task_id: string;
312
+ thread: string;
313
+ title: string;
314
+ requires: string[];
315
+ role: string | null;
316
+ scope: TaskScope | null;
317
+ /** Lineage: the task_id this one supersedes (forward work after a terminal close), or null. */
318
+ succeeds: string | null;
319
+ /** Lineage: how this task relates to the one it `succeeds` (continuation|redo|correction), or null. */
320
+ succession: SuccessionRelation | null;
321
+ truth: TaskTruth;
322
+ verification_pending: boolean;
323
+ authorized: boolean;
324
+ /** Eligibility UNDER THE ACTIVE POLICY — visibility is unconditional, claimability is gated. */
325
+ eligibility: TaskEligibility;
326
+ /** Hygiene flags (§2.6); presence never changes claimability or hides the row. */
327
+ stale_reasons: StaleReason[];
328
+ /** Derived condition FACTS (overdue/stale, each with a reason); facts-vs-meaning — shown, never blended into a score. */
329
+ conditions: ConditionFlag[];
330
+ /** Raw temporal facts (sparse). null = no such date recorded. */
331
+ start_date: string | null;
332
+ due_date: string | null;
333
+ /** Computed view of `due_date` vs now in whole days (negative = past due); null when no due_date. */
334
+ days_remaining: number | null;
335
+ /** Computed view: whole days since the last qualifying activity. */
336
+ days_since_activity: number;
337
+ /** Routing metadata only — never ownership (codex #242). */
338
+ addressed_to: string[];
339
+ created_at: string;
340
+ last_activity_at: string;
341
+ age_seconds: number;
342
+ }
343
+ /**
344
+ * Pool-wide staleness COVERAGE — reported once at the aggregate boundary, not per row (codex
345
+ * the GCL coordination spec). `undetermined` here means the pool was assessed for staleness but no cadence policy
346
+ * was supplied, so the dimension is honestly unknown for every open task — a "set a cadence" hygiene signal
347
+ * that keeps the corpus from turning yellow row-by-row. `assessed` means a policy was in force.
348
+ */
349
+ export interface StalenessAssessment {
350
+ status: "assessed" | "undetermined";
351
+ /** Present when `undetermined`: the machine reason a connector can label. */
352
+ reason?: "no_cadence_policy";
353
+ /** Present when `assessed`: the cadence window applied. */
354
+ cadence_ms?: number;
355
+ }
356
+ export interface TaskPoolOptions {
357
+ /** The orienting actor (for mine/eligibility framing). */
358
+ actor?: string;
359
+ /** The actor's capabilities; when given, only tasks whose `requires ⊆ capabilities` are in MY pool (AC d). */
360
+ capabilities?: string[];
361
+ /** Active pull policy. Default `human_directed` (unassigned-by-default). */
362
+ policy?: TaskPullPolicy;
363
+ /** Filter to a scope (project/space). principal_scope never gates in v0 (AC e). */
364
+ scope?: TaskScope;
365
+ /** Read clock; defaults to now. */
366
+ now?: number;
367
+ /** Age after which an unclaimed open task is flagged `unclaimed_age_exceeded`. */
368
+ staleUnclaimedMs?: number;
369
+ /** Age after which a verification_pending task is flagged `verification_pending_age_exceeded`. */
370
+ staleVerificationMs?: number;
371
+ /** Cadence window after which an open task with no qualifying activity derives the `stale` condition. */
372
+ staleCadenceMs?: number;
373
+ }
374
+ export interface ThreadOverview {
375
+ thread: string;
376
+ latest_seq: number;
377
+ my_last_seq: number;
378
+ unread: number;
379
+ last_event: {
380
+ seq: number;
381
+ actor: string;
382
+ type: EventType;
383
+ summary: string;
384
+ } | null;
385
+ needs_me: boolean;
386
+ /** Count of open responsibilities directed at the orienting actor in this thread. */
387
+ open_for_me: number;
388
+ }
389
+ /** One open responsibility directed at the orienting actor (an unanswered, response-requiring address). */
390
+ export interface OpenForMeItem {
391
+ thread: string;
392
+ seq: number;
393
+ event_id: string;
394
+ /** Who addressed the actor (the event author). */
395
+ actor: string;
396
+ type: EventType;
397
+ summary: string;
398
+ /** structured = explicit addressed_to; heuristic = prose @mention bridge (lower confidence). */
399
+ source: "structured" | "heuristic";
400
+ /**
401
+ * Present when the item has been claimed. Items live-claimed by ANOTHER actor are suppressed
402
+ * (absent from open_for_me); this surfaces only items the actor owns (`mine: true`) or whose
403
+ * claim has gone stale (`stale: true`, re-claimable).
404
+ */
405
+ claim?: {
406
+ status: "claimed";
407
+ claimed_by: string;
408
+ /** ISO-8601 lease end, or null for an indefinite hold. */
409
+ expires: string | null;
410
+ /** True when the lease lapsed vs the read clock — re-claimable. */
411
+ stale: boolean;
412
+ /** True when the orienting actor is the owner. */
413
+ mine: boolean;
414
+ };
415
+ /**
416
+ * True when this owed event's own causal parent lives in ANOTHER thread — the discussion it belongs to
417
+ * spans threads. A coordination-integrity signal (not stale): it flags the "right thread name, wrong live
418
+ * discussion" split so a connector can surface "continued in …". Derived, never authored.
419
+ */
420
+ cross_thread?: boolean;
421
+ }
422
+ /** A causal response to an owed event, possibly in a different thread (the addresser-side "answered in …" view). */
423
+ export interface CausalResponse {
424
+ event_id: string;
425
+ thread: string;
426
+ actor: string;
427
+ type: EventType;
428
+ /** True when the response landed in a different thread than the event it answers. */
429
+ cross_thread: boolean;
430
+ }