taskcarry 0.3.2__py3-none-any.whl
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.
- taskcarry/__init__.py +3 -0
- taskcarry/__main__.py +4 -0
- taskcarry/adapter_contracts.py +166 -0
- taskcarry/agy_turns.py +282 -0
- taskcarry/api.py +111 -0
- taskcarry/board.py +313 -0
- taskcarry/board_assets/board.css +1087 -0
- taskcarry/board_assets/board.js +1187 -0
- taskcarry/board_assets/browse.js +214 -0
- taskcarry/board_assets/index.html +43 -0
- taskcarry/board_assets/taskcarry-icon.ico +0 -0
- taskcarry/board_assets/taskcarry-mark.svg +28 -0
- taskcarry/board_data.py +466 -0
- taskcarry/chat_joins.py +157 -0
- taskcarry/cli.py +119 -0
- taskcarry/codex_capture.py +184 -0
- taskcarry/codex_host.py +293 -0
- taskcarry/collaboration_exchange.py +316 -0
- taskcarry/connection.py +159 -0
- taskcarry/continuity.py +300 -0
- taskcarry/contracts.py +165 -0
- taskcarry/conversation_capture.py +669 -0
- taskcarry/core.py +896 -0
- taskcarry/cycle_contracts.py +73 -0
- taskcarry/discovery.py +434 -0
- taskcarry/discovery_contracts.py +52 -0
- taskcarry/exchange_contracts.py +67 -0
- taskcarry/exchange_endpoint.py +377 -0
- taskcarry/exchange_packets.py +142 -0
- taskcarry/experience_contracts.py +129 -0
- taskcarry/experience_exchange.py +214 -0
- taskcarry/experience_notes.py +433 -0
- taskcarry/experience_storage.py +125 -0
- taskcarry/experience_tools.py +26 -0
- taskcarry/feishu/__init__.py +1 -0
- taskcarry/feishu/display.py +122 -0
- taskcarry/feishu/project_watch.py +145 -0
- taskcarry/feishu/review_sets.py +80 -0
- taskcarry/feishu/sender.py +42 -0
- taskcarry/feishu/subscription.py +193 -0
- taskcarry/feishu/windows_agent.py +287 -0
- taskcarry/feishu/windows_secret.py +34 -0
- taskcarry/gitops.py +170 -0
- taskcarry/governance.py +88 -0
- taskcarry/governance_cycle.py +775 -0
- taskcarry/identification.py +82 -0
- taskcarry/integration.py +663 -0
- taskcarry/maintenance.py +118 -0
- taskcarry/mcp.py +183 -0
- taskcarry/member_join.py +184 -0
- taskcarry/member_routing.py +145 -0
- taskcarry/onboarding.py +272 -0
- taskcarry/onboarding_complete.py +252 -0
- taskcarry/path_batches.py +19 -0
- taskcarry/preservation.py +257 -0
- taskcarry/project_collaboration.py +453 -0
- taskcarry/project_history.py +166 -0
- taskcarry/project_identity.py +51 -0
- taskcarry/project_recovery.py +824 -0
- taskcarry/recovery_contracts.py +25 -0
- taskcarry/recovery_files.py +153 -0
- taskcarry/recovery_git.py +234 -0
- taskcarry/remote_capture.py +89 -0
- taskcarry/remote_transfer.py +356 -0
- taskcarry/role_connection.py +215 -0
- taskcarry/setup.py +597 -0
- taskcarry/shared_workbench.py +480 -0
- taskcarry/skill_data/taskcarry-experience-recovery/SKILL.md +37 -0
- taskcarry/skill_data/taskcarry-governance-reconcile/SKILL.md +47 -0
- taskcarry/skill_data/taskcarry-governance-reconcile/references/daily-governance.md +72 -0
- taskcarry/skill_data/taskcarry-project-setup/SKILL.md +48 -0
- taskcarry/skill_data/taskcarry-project-setup/references/onboarding.md +198 -0
- taskcarry/skill_data/taskcarry-task-delivery/SKILL.md +32 -0
- taskcarry/skill_data/taskcarry-task-delivery/references/conditional-experience.md +93 -0
- taskcarry/skill_data/taskcarry-task-delivery/references/worker-channel.md +41 -0
- taskcarry/source_review_set.py +80 -0
- taskcarry/state_format.py +47 -0
- taskcarry/store.py +472 -0
- taskcarry/task_context.py +141 -0
- taskcarry/text_handback.py +98 -0
- taskcarry/transfer_contracts.py +18 -0
- taskcarry/updates.py +351 -0
- taskcarry/workbench.py +625 -0
- taskcarry/workbench_contracts.py +32 -0
- taskcarry/workbuddy_capture.py +451 -0
- taskcarry/workbuddy_setup.py +212 -0
- taskcarry/worker_channel.py +859 -0
- taskcarry/worker_contracts.py +190 -0
- taskcarry/worker_storage.py +60 -0
- taskcarry/worker_tools.py +111 -0
- taskcarry-0.3.2.dist-info/METADATA +203 -0
- taskcarry-0.3.2.dist-info/RECORD +105 -0
- taskcarry-0.3.2.dist-info/WHEEL +5 -0
- taskcarry-0.3.2.dist-info/entry_points.txt +5 -0
- taskcarry-0.3.2.dist-info/licenses/LICENSE +21 -0
- taskcarry-0.3.2.dist-info/licenses/LICENSE_SCOPE.md +31 -0
- taskcarry-0.3.2.dist-info/top_level.txt +2 -0
- taskcarry_https/__init__.py +1 -0
- taskcarry_https/consent.py +207 -0
- taskcarry_https/reader.py +132 -0
- taskcarry_https/review.py +116 -0
- taskcarry_https/server.py +163 -0
- taskcarry_https/team.py +335 -0
- taskcarry_https/team_host.py +109 -0
- taskcarry_https/web_host.py +82 -0
taskcarry/continuity.py
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"""Host-supplied evidence and bounded run receipts over existing local records.
|
|
2
|
+
|
|
3
|
+
These records do not read chats, authorize actions, run Git or accept business
|
|
4
|
+
outcomes. The host supplies its already-reviewed references; the shared engine
|
|
5
|
+
preserves their versions and checks only the selected recorded work.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
|
|
11
|
+
from .core import Core, _id, digest_bytes
|
|
12
|
+
from .store import GovernanceError, now
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _fingerprint(value):
|
|
16
|
+
return digest_bytes(json.dumps(value, sort_keys=True, ensure_ascii=False,
|
|
17
|
+
separators=(',', ':'), allow_nan=False).encode('utf-8'))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _text(value, label, maximum=2048):
|
|
21
|
+
if not isinstance(value, str) or not value.strip() or len(value) > maximum or '\x00' in value:
|
|
22
|
+
raise GovernanceError('INVALID_EVIDENCE', f'{label} must be nonempty text of at most {maximum} characters.')
|
|
23
|
+
return value
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _ids(values, label):
|
|
27
|
+
if values is None:
|
|
28
|
+
return []
|
|
29
|
+
if not isinstance(values, list) or len(values) > 100:
|
|
30
|
+
raise GovernanceError('INVALID_SELECTION', f'{label} must be a list of at most 100 identities.')
|
|
31
|
+
result = [_id(value, label) for value in values]
|
|
32
|
+
if len(set(result)) != len(result):
|
|
33
|
+
raise GovernanceError('INVALID_SELECTION', f'{label} must not contain duplicates.')
|
|
34
|
+
return sorted(result)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class Continuity(Core):
|
|
38
|
+
def observe(self, observation_id, workspace, task_id, source_ref, source_revision,
|
|
39
|
+
summary, relations=None, expected_revision=None):
|
|
40
|
+
"""Record a host-reviewed reference; replacing it requires its prior revision."""
|
|
41
|
+
observation_id = _id(observation_id, 'Observation ID')
|
|
42
|
+
workspace = _id(workspace, 'Workspace') if workspace is not None else None
|
|
43
|
+
task_id = _id(task_id, 'Task ID')
|
|
44
|
+
_text(source_ref, 'Source reference')
|
|
45
|
+
_text(source_revision, 'Source revision', 512)
|
|
46
|
+
_text(summary, 'Evidence summary', 8192)
|
|
47
|
+
if expected_revision is not None and (isinstance(expected_revision, bool)
|
|
48
|
+
or not isinstance(expected_revision, int) or expected_revision < 1):
|
|
49
|
+
raise GovernanceError('INVALID_REVISION', 'Expected revision must be a positive integer.')
|
|
50
|
+
if relations is None:
|
|
51
|
+
relations = []
|
|
52
|
+
if not isinstance(relations, list) or len(relations) > 100:
|
|
53
|
+
raise GovernanceError('INVALID_RELATION', 'Evidence may name at most 100 explicit relationships.')
|
|
54
|
+
with self.store.transaction():
|
|
55
|
+
self._task(task_id)
|
|
56
|
+
registered = self.store.get('workspaces', workspace) if workspace else None
|
|
57
|
+
if workspace is not None and not registered:
|
|
58
|
+
raise GovernanceError('WORKSPACE_UNKNOWN', 'Register this workspace before recording its evidence.')
|
|
59
|
+
if registered and not registered.get('identity'):
|
|
60
|
+
raise GovernanceError('WORKSPACE_IDENTITY_MISSING', 'The workspace needs a registered identity.')
|
|
61
|
+
linked, seen = [], set()
|
|
62
|
+
for relation in relations:
|
|
63
|
+
if not isinstance(relation, dict) or set(relation) != {'kind', 'id'} or relation['kind'] not in ('stage', 'artifact'):
|
|
64
|
+
raise GovernanceError('INVALID_RELATION', 'Use a stage or artifact relationship with an exact id.')
|
|
65
|
+
identity = _id(relation['id'], 'Related object ID')
|
|
66
|
+
if workspace is None and relation['kind'] == 'stage':
|
|
67
|
+
raise GovernanceError('RELATION_SCOPE_MISMATCH', 'Git stages require their real registered workspace.')
|
|
68
|
+
key = (relation['kind'], identity)
|
|
69
|
+
if key in seen:
|
|
70
|
+
raise GovernanceError('INVALID_RELATION', 'Evidence relationships must be unique.')
|
|
71
|
+
seen.add(key)
|
|
72
|
+
collection = 'stages' if relation['kind'] == 'stage' else 'artifacts'
|
|
73
|
+
item = self.store.get(collection, identity)
|
|
74
|
+
if not item:
|
|
75
|
+
raise GovernanceError('RELATED_RECORD_UNKNOWN', 'Register the related object first.', relation)
|
|
76
|
+
if item.get('task_id') != task_id or item.get('workspace', workspace) != workspace:
|
|
77
|
+
raise GovernanceError('RELATION_SCOPE_MISMATCH', 'A relationship must match the observed task and its workspace.', relation)
|
|
78
|
+
content = ({'commit': item.get('commit'), 'base': item.get('base'), 'paths': item.get('paths'),
|
|
79
|
+
'declaration_hash': item.get('declaration_hash')} if relation['kind'] == 'stage'
|
|
80
|
+
else {'sha256': item.get('sha256'), 'size': item.get('size'), 'path': item.get('path')})
|
|
81
|
+
linked.append({**relation, 'content_fingerprint': _fingerprint(content)})
|
|
82
|
+
linked.sort(key=lambda value: (value['kind'], value['id']))
|
|
83
|
+
body = {'observation_id': observation_id, 'workspace': workspace, 'task_id': task_id,
|
|
84
|
+
'workspace_identity': registered['identity'] if registered else None, 'source_ref': source_ref,
|
|
85
|
+
'source_revision': source_revision, 'summary': summary, 'relations': linked}
|
|
86
|
+
fingerprint = _fingerprint(body)
|
|
87
|
+
prior = self.store.get('observations', observation_id)
|
|
88
|
+
if prior:
|
|
89
|
+
if any(prior[key] != body[key] for key in ('workspace', 'task_id', 'source_ref')):
|
|
90
|
+
raise GovernanceError('OBSERVATION_ID_CONFLICT', 'An observation identity cannot move to another source, task or workspace.')
|
|
91
|
+
if prior['fingerprint'] == fingerprint:
|
|
92
|
+
return {'observation': prior, 'reused': True}
|
|
93
|
+
if expected_revision != prior['revision']:
|
|
94
|
+
raise GovernanceError('OBSERVATION_CHANGED', 'Reread the current observation before replacing it.',
|
|
95
|
+
{'current_revision': prior['revision']})
|
|
96
|
+
elif expected_revision is not None:
|
|
97
|
+
raise GovernanceError('OBSERVATION_CHANGED', 'This observation does not yet have a revision.')
|
|
98
|
+
revision = prior['revision'] + 1 if prior else 1
|
|
99
|
+
record = {**body, 'fingerprint': fingerprint, 'revision': revision,
|
|
100
|
+
'recorded_at': now(), 'host_reviewed': True,
|
|
101
|
+
'meaning': 'Host-supplied evidence reference, not independent source verification or authorization.'}
|
|
102
|
+
self.store.put('observations', observation_id, record)
|
|
103
|
+
self.store.put('observation_history', observation_id + ':' + str(revision), record)
|
|
104
|
+
self.store.event('observation_recorded', {'observation_id': observation_id, 'revision': revision,
|
|
105
|
+
'fingerprint': fingerprint, 'task_id': task_id})
|
|
106
|
+
return {'observation': record, 'reused': False}
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
def _read(db, collection, key):
|
|
110
|
+
row = db.execute('SELECT value FROM records WHERE collection=? AND key=?', (collection, key)).fetchone()
|
|
111
|
+
return json.loads(row[0]) if row else None
|
|
112
|
+
|
|
113
|
+
@staticmethod
|
|
114
|
+
def _covers(load, successor, identity):
|
|
115
|
+
remaining, seen = list(successor.get('supersedes', [])), set()
|
|
116
|
+
while remaining:
|
|
117
|
+
ancestor = remaining.pop()
|
|
118
|
+
if ancestor in seen:
|
|
119
|
+
continue
|
|
120
|
+
seen.add(ancestor)
|
|
121
|
+
old = load('stages', ancestor)
|
|
122
|
+
if (not old or old.get('task_id') != successor.get('task_id')
|
|
123
|
+
or old.get('workspace') != successor.get('workspace')):
|
|
124
|
+
return False
|
|
125
|
+
if ancestor == identity:
|
|
126
|
+
return True
|
|
127
|
+
remaining.extend(old.get('supersedes', []))
|
|
128
|
+
return False
|
|
129
|
+
|
|
130
|
+
@staticmethod
|
|
131
|
+
def _stage_complete(load, identity):
|
|
132
|
+
"""Check receipt linkage; no external effects are executed or re-verified."""
|
|
133
|
+
seen = set()
|
|
134
|
+
while identity not in seen:
|
|
135
|
+
seen.add(identity)
|
|
136
|
+
stage = load('stages', identity)
|
|
137
|
+
if not stage:
|
|
138
|
+
return False, 'RECORD_MISSING'
|
|
139
|
+
if stage.get('status') == 'COMMITTED':
|
|
140
|
+
if not stage.get('accepted_commit'):
|
|
141
|
+
return False, 'RECEIPT_INCOMPLETE'
|
|
142
|
+
if stage.get('operation_id'):
|
|
143
|
+
operation = load('operations', stage['operation_id'])
|
|
144
|
+
if (not operation or operation.get('status') != 'COMPLETED'
|
|
145
|
+
or operation.get('candidate') != stage['accepted_commit']
|
|
146
|
+
or operation.get('stage_id') != identity):
|
|
147
|
+
return False, 'RECEIPT_INCOMPLETE'
|
|
148
|
+
return True, None
|
|
149
|
+
if stage.get('status') != 'SUPERSEDED':
|
|
150
|
+
return False, stage.get('code') or stage.get('status') or 'STATE_UNKNOWN'
|
|
151
|
+
successor = load('stages', stage.get('successor', ''))
|
|
152
|
+
if (not successor or successor.get('task_id') != stage.get('task_id')
|
|
153
|
+
or successor.get('workspace') != stage.get('workspace')
|
|
154
|
+
or not Continuity._covers(load, successor, identity)):
|
|
155
|
+
return False, 'SUPERSESSION_UNVERIFIED'
|
|
156
|
+
identity = successor['stage_id']
|
|
157
|
+
return False, 'SUPERSESSION_CYCLE'
|
|
158
|
+
|
|
159
|
+
@staticmethod
|
|
160
|
+
def _operation_complete(load, identity, seen=None):
|
|
161
|
+
"""Follow verified named replacements without treating a label as proof."""
|
|
162
|
+
seen = set() if seen is None else seen
|
|
163
|
+
if identity in seen:
|
|
164
|
+
return False, 'SUPERSESSION_CYCLE'
|
|
165
|
+
seen.add(identity)
|
|
166
|
+
operation = load('operations', identity)
|
|
167
|
+
if not operation:
|
|
168
|
+
return False, 'RECORD_MISSING'
|
|
169
|
+
if operation.get('status') == 'SUPERSEDED':
|
|
170
|
+
# Adoption retires only a no-effect preparation after its explicit
|
|
171
|
+
# successor is verified. Never infer this from newer timestamps.
|
|
172
|
+
successor = load('operations', operation.get('resolved_by_operation', ''))
|
|
173
|
+
if (operation.get('kind') != 'adopt' or operation.get('effect_state') != 'NOT_APPLIED'
|
|
174
|
+
or operation.get('candidate') or operation.get('stash') or not successor
|
|
175
|
+
or successor.get('kind') != 'adopt'
|
|
176
|
+
or operation.get('workspace') != successor.get('workspace')
|
|
177
|
+
or operation.get('baseline') != successor.get('baseline')
|
|
178
|
+
or not operation.get('resolved_by_plan')
|
|
179
|
+
or operation['resolved_by_plan'] != successor.get('plan_id')
|
|
180
|
+
or identity not in successor.get('resolves_preparation_failures', [])):
|
|
181
|
+
return False, 'SUPERSESSION_UNVERIFIED'
|
|
182
|
+
return Continuity._operation_complete(load, successor['operation_id'], seen)
|
|
183
|
+
if operation.get('status') != 'COMPLETED':
|
|
184
|
+
return False, operation.get('code') or operation.get('status') or 'STATE_UNKNOWN'
|
|
185
|
+
if operation.get('resolved_by_successor'):
|
|
186
|
+
if operation.get('kind') != 'reconcile':
|
|
187
|
+
return False, 'SUPERSESSION_UNVERIFIED'
|
|
188
|
+
successor = load('stages', operation['resolved_by_successor'])
|
|
189
|
+
if (not successor or operation.get('task_id') != successor.get('task_id')
|
|
190
|
+
or not operation.get('stage_id')
|
|
191
|
+
or not Continuity._covers(load, successor, operation['stage_id'])):
|
|
192
|
+
return False, 'SUPERSESSION_UNVERIFIED'
|
|
193
|
+
return Continuity._stage_complete(load, successor['stage_id'])
|
|
194
|
+
if operation.get('kind') == 'reconcile':
|
|
195
|
+
stage = load('stages', operation.get('stage_id', ''))
|
|
196
|
+
if (not stage or not operation.get('candidate')
|
|
197
|
+
or stage.get('accepted_commit') != operation['candidate']
|
|
198
|
+
or stage.get('operation_id') not in (None, identity)
|
|
199
|
+
or stage.get('task_id') != operation.get('task_id')):
|
|
200
|
+
return False, 'RECEIPT_INCOMPLETE'
|
|
201
|
+
# A formerly received stage keeps its accepted_commit after a
|
|
202
|
+
# cumulative successor. Check that successor rather than reopening
|
|
203
|
+
# the old completed operation just because its stage was retired.
|
|
204
|
+
return Continuity._stage_complete(load, stage['stage_id'])
|
|
205
|
+
if operation.get('kind') == 'adopt':
|
|
206
|
+
if operation.get('effect_state') == 'VERIFIED' and operation.get('candidate'):
|
|
207
|
+
return True, None
|
|
208
|
+
return False, 'RECEIPT_INCOMPLETE'
|
|
209
|
+
if operation.get('kind') == 'restore':
|
|
210
|
+
receipt = load('restore_receipts', identity)
|
|
211
|
+
checkpoint = load('checkpoints', operation.get('checkpoint_id', ''))
|
|
212
|
+
fields = ('operation_id', 'checkpoint_id', 'checkpoint_sha256', 'destination', 'effect_sha256')
|
|
213
|
+
if (any(type(operation.get(key)) is not int or operation[key] != 1
|
|
214
|
+
for key in ('operation_protocol', 'restore_protocol'))
|
|
215
|
+
or operation.get('effect_state') != 'VERIFIED'
|
|
216
|
+
or not receipt or receipt.get('verified') is not True
|
|
217
|
+
or not checkpoint or checkpoint.get('task_id') != operation.get('task_id')
|
|
218
|
+
or Core._restore_digest(checkpoint) != operation.get('checkpoint_sha256')
|
|
219
|
+
or any(not operation.get(field) or receipt.get(field) != operation[field] for field in fields)):
|
|
220
|
+
return False, 'RECEIPT_INCOMPLETE'
|
|
221
|
+
# This closes a selected recorded operation, not a fresh claim
|
|
222
|
+
# that the restored destination remains unchanged today.
|
|
223
|
+
return True, None
|
|
224
|
+
return False, 'OPERATION_KIND_UNSUPPORTED'
|
|
225
|
+
|
|
226
|
+
def _inspection(self, record, load):
|
|
227
|
+
pending, changed = [], []
|
|
228
|
+
for identity in record['stage_ids']:
|
|
229
|
+
complete, reason = self._stage_complete(load, identity)
|
|
230
|
+
if not complete:
|
|
231
|
+
pending.append({'kind': 'stage', 'id': identity, 'reason': reason})
|
|
232
|
+
for identity in record['operation_ids']:
|
|
233
|
+
complete, reason = self._operation_complete(load, identity)
|
|
234
|
+
if not complete:
|
|
235
|
+
pending.append({'kind': 'operation', 'id': identity, 'reason': reason})
|
|
236
|
+
for identity in record['observation_ids']:
|
|
237
|
+
observed = load('observations', identity)
|
|
238
|
+
if not observed or observed.get('fingerprint') != record['observation_fingerprints'][identity]:
|
|
239
|
+
changed.append(identity)
|
|
240
|
+
return {'scope': 'selected_records', 'selected_complete': not pending,
|
|
241
|
+
'pending': pending, 'changed_observations': changed,
|
|
242
|
+
'effects_executed': False, 'project_complete': None,
|
|
243
|
+
'meaning': 'Checks selected durable receipts only; does not reverify external effects, accept business outcomes or complete the project.'}
|
|
244
|
+
|
|
245
|
+
def run(self, run_id, mode='start', stage_ids=None, operation_ids=None,
|
|
246
|
+
observation_ids=None, note=''):
|
|
247
|
+
"""Freeze a finite selection, inspect its receipts, then record its closeout."""
|
|
248
|
+
run_id = _id(run_id, 'Run ID')
|
|
249
|
+
if mode not in ('start', 'finish', 'inspect'):
|
|
250
|
+
raise GovernanceError('INVALID_RUN_MODE', 'Use start, finish or inspect.')
|
|
251
|
+
if mode != 'inspect' and run_id in (self.store.get('config', 'project') or {}).get('recovery_inert_run_ids', []):
|
|
252
|
+
raise GovernanceError('RESTORED_RUN_INERT', 'Historical runs cannot be replayed on a recovered replica.')
|
|
253
|
+
if not isinstance(note, str) or len(note) > 8192 or '\x00' in note:
|
|
254
|
+
raise GovernanceError('INVALID_NOTE', 'A run note must be text of at most 8192 characters.')
|
|
255
|
+
supplied = (stage_ids, operation_ids, observation_ids)
|
|
256
|
+
if mode != 'start' and (any(value is not None for value in supplied) or note):
|
|
257
|
+
raise GovernanceError('RUN_SELECTION_FROZEN', 'Finish and inspect use the original selection and note.')
|
|
258
|
+
if mode == 'inspect':
|
|
259
|
+
with self.store._connect(readonly=True) as db:
|
|
260
|
+
load = lambda collection, key: self._read(db, collection, key)
|
|
261
|
+
record = load('runs', run_id)
|
|
262
|
+
if not record:
|
|
263
|
+
raise GovernanceError('RUN_UNKNOWN', 'Start this run before inspecting it.')
|
|
264
|
+
return {'run': record, 'inspection': self._inspection(record, load), 'reused': True}
|
|
265
|
+
with self.store.transaction():
|
|
266
|
+
prior = self.store.get('runs', run_id)
|
|
267
|
+
if mode == 'start':
|
|
268
|
+
selection = {'stage_ids': _ids(stage_ids, 'Stage ID'),
|
|
269
|
+
'operation_ids': _ids(operation_ids, 'Operation ID'),
|
|
270
|
+
'observation_ids': _ids(observation_ids, 'Observation ID')}
|
|
271
|
+
if prior:
|
|
272
|
+
if any(prior[key] != value for key, value in selection.items()) or prior['note'] != note:
|
|
273
|
+
raise GovernanceError('RUN_ID_CONFLICT', 'This run already has a different frozen selection or note.')
|
|
274
|
+
return {'run': prior, 'inspection': self._inspection(prior, self.store.get), 'reused': True}
|
|
275
|
+
for field, collection in (('stage_ids', 'stages'), ('operation_ids', 'operations'), ('observation_ids', 'observations')):
|
|
276
|
+
for identity in selection[field]:
|
|
277
|
+
if not self.store.get(collection, identity):
|
|
278
|
+
raise GovernanceError('RUN_RECORD_UNKNOWN', 'A selected record is not registered.',
|
|
279
|
+
{'kind': collection, 'id': identity})
|
|
280
|
+
record = {'run_id': run_id, **selection, 'note': note, 'state': 'OPEN', 'created_at': now(),
|
|
281
|
+
'observation_fingerprints': {identity: self.store.get('observations', identity)['fingerprint']
|
|
282
|
+
for identity in selection['observation_ids']}}
|
|
283
|
+
self.store.put('runs', run_id, record)
|
|
284
|
+
self.store.event('run_started', {'run_id': run_id, **selection})
|
|
285
|
+
return {'run': record, 'inspection': self._inspection(record, self.store.get), 'reused': False}
|
|
286
|
+
if not prior:
|
|
287
|
+
raise GovernanceError('RUN_UNKNOWN', 'Start this run before finishing it.')
|
|
288
|
+
inspection = self._inspection(prior, self.store.get)
|
|
289
|
+
state = 'COMPLETED' if inspection['selected_complete'] else 'WAITING'
|
|
290
|
+
if prior.get('last_inspection') == inspection and prior['state'] == state:
|
|
291
|
+
return {'run': prior, 'inspection': inspection, 'reused': True}
|
|
292
|
+
record = {**prior, 'state': state, 'last_inspection': inspection, 'checked_at': now()}
|
|
293
|
+
if state == 'COMPLETED':
|
|
294
|
+
record['completed_at'] = prior.get('completed_at', now())
|
|
295
|
+
elif 'completed_at' in record:
|
|
296
|
+
record['previous_completed_at'] = record.pop('completed_at')
|
|
297
|
+
self.store.put('runs', run_id, record)
|
|
298
|
+
self.store.event('run_finished' if state == 'COMPLETED' else 'run_waiting',
|
|
299
|
+
{'run_id': run_id, 'inspection': inspection})
|
|
300
|
+
return {'run': record, 'inspection': inspection, 'reused': False}
|
taskcarry/contracts.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""Shared typed public contracts for CLI, API and MCP. No runtime dependencies."""
|
|
2
|
+
from copy import deepcopy
|
|
3
|
+
|
|
4
|
+
def string(description="", **kwargs):
|
|
5
|
+
return {"type": "string", "description": description, **kwargs}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def schema(properties=None, required=()):
|
|
9
|
+
return {"type": "object", "properties": properties or {}, "required": list(required), "additionalProperties": False}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
PATHS = {"type": "array", "items": string("Exact workspace-relative file path"), "minItems": 1, "uniqueItems": True}
|
|
13
|
+
BOOL = {"type": "boolean"}
|
|
14
|
+
OPEN_OBJECT = {"type": "object", "additionalProperties": True}
|
|
15
|
+
SCHEMAS = {
|
|
16
|
+
"identity": schema({"action": string(enum=["status", "plan", "execute"]), "plan_id": string()}),
|
|
17
|
+
"onboarding": schema({"onboarding_id": string(), "action": string(enum=["start", "update", "status"]),
|
|
18
|
+
"scope": schema({"governance_thread": string(), "channel": string(enum=["rc", "stable"]),
|
|
19
|
+
"schedule": schema({"time": string(), "timezone": string()}, ["time", "timezone"]),
|
|
20
|
+
"windows": {"type": "array", "minItems": 1, "maxItems": 100,
|
|
21
|
+
"items": schema({"thread_id": string(), "mode": string(enum=["active", "reference"]),
|
|
22
|
+
"task_id": string(), "workspace": string(), "source_ref": string(), "responsibility": string()},
|
|
23
|
+
["thread_id", "mode", "source_ref", "responsibility"])}},
|
|
24
|
+
["governance_thread", "channel", "schedule", "windows"]),
|
|
25
|
+
"item": schema({"key": string(), "status": string(enum=["verified", "pending", "declined"]),
|
|
26
|
+
"evidence": OPEN_OBJECT, "next_step": string()}, ["key", "status", "evidence", "next_step"]),
|
|
27
|
+
"expected_revision": {"type": "integer", "minimum": 1}}, ["onboarding_id"]),
|
|
28
|
+
"schedule_plan": schema({"onboarding_id": string()}, ["onboarding_id"]),
|
|
29
|
+
"preserve": schema({"action": string(enum=["plan", "execute", "status"]), "repository": string(),
|
|
30
|
+
"paths": {**PATHS, "maxItems": 500}, "message": string(), "plan_id": string()}),
|
|
31
|
+
"connect": schema({"action": string(enum=["plan", "execute", "status"]),
|
|
32
|
+
"target": string(), "workspace": string(), "task_id": string(), "plan_id": string(),
|
|
33
|
+
"binding_mode": string(enum=["task", "directory"])}),
|
|
34
|
+
"identify": schema(),
|
|
35
|
+
"context": schema({"task_id": string(), "limit": {"type": "integer", "minimum": 1, "maximum": 100},
|
|
36
|
+
"cursor": string(), "previous_fingerprint": string(),
|
|
37
|
+
"issue_ids": {"type": "array", "items": string(), "maxItems": 50, "uniqueItems": True},
|
|
38
|
+
"fix_ids": {"type": "array", "items": string(), "maxItems": 50, "uniqueItems": True}}, ["task_id"]),
|
|
39
|
+
"governance": schema({"mode": string(enum=["inspect", "record"]),
|
|
40
|
+
"rule_paths": {"type": "array", "items": string(), "maxItems": 100, "uniqueItems": True},
|
|
41
|
+
"record_id": string(), "expected_fingerprint": string(),
|
|
42
|
+
"evidence_refs": {"type": "array", "items": string(), "minItems": 1, "maxItems": 50, "uniqueItems": True},
|
|
43
|
+
"expected_revision": {"type": "integer", "minimum": 0}}),
|
|
44
|
+
"upgrade": schema(),
|
|
45
|
+
"observe": schema({"observation_id": string(), "workspace": {"type": ["string", "null"]}, "task_id": string(),
|
|
46
|
+
"source_ref": string(), "source_revision": string(), "summary": string(),
|
|
47
|
+
"relations": {"type": "array", "items": schema({"kind": string(enum=["stage", "artifact"]), "id": string()}, ["kind", "id"])},
|
|
48
|
+
"expected_revision": {"type": "integer", "minimum": 1}},
|
|
49
|
+
["observation_id", "workspace", "task_id", "source_ref", "source_revision", "summary"]),
|
|
50
|
+
"run": schema({"run_id": string(), "mode": string(enum=["start", "finish", "inspect"]),
|
|
51
|
+
"stage_ids": {"type": "array", "items": string(), "uniqueItems": True},
|
|
52
|
+
"operation_ids": {"type": "array", "items": string(), "uniqueItems": True},
|
|
53
|
+
"observation_ids": {"type": "array", "items": string(), "uniqueItems": True}, "note": string()}, ["run_id"]),
|
|
54
|
+
"issue": schema({"issue_id": string(), "condition": string(), "summary": string(),
|
|
55
|
+
"state": string(enum=["open", "resolved"]), "resolution_ref": string(),
|
|
56
|
+
"expected_revision": {"type": "integer", "minimum": 1}}, ["issue_id", "condition", "summary"]),
|
|
57
|
+
"fix": schema({"fix_id": string(), "issue_id": string(), "version": string(),
|
|
58
|
+
"evidence_refs": {"type": "array", "items": string(), "minItems": 1, "uniqueItems": True},
|
|
59
|
+
"summary": string(), "expected_revision": {"type": "integer", "minimum": 1}},
|
|
60
|
+
["fix_id", "issue_id", "version", "evidence_refs"]),
|
|
61
|
+
"status": schema(),
|
|
62
|
+
"agenda": schema({"limit": {"type": "integer", "minimum": 1, "maximum": 100}, "previous_fingerprint": string(), "cursor": string()}),
|
|
63
|
+
"doctor": schema(),
|
|
64
|
+
"task": schema({"task_id": string(), "title": string(), "workstream": string(), "state": string(enum=["active", "paused", "waiting", "complete"])}, ["task_id"]),
|
|
65
|
+
"checkpoint": schema({"task_id": string(), "workspace": string(), "paths": PATHS, "next_step": string(), "decision": string(), "paused": BOOL}, ["task_id", "workspace", "paths", "next_step"]),
|
|
66
|
+
"restore": schema({"checkpoint_id": string(), "destination": string("Absent or empty independent destination; repeat the same checkpoint and destination to verify and finish a recorded restore")}, ["checkpoint_id", "destination"]),
|
|
67
|
+
"artifact": schema({"task_id": string(), "path": string(), "role": string(), "backup": string(),
|
|
68
|
+
"decision": string("Content-bound review choice, not free-text checkpoint reasoning. retain keeps unverified backup work actionable; ignore/dismiss/no_backup_needed suppress that item only after an authorized decision. Omit to preserve a choice for unchanged content; registration does not create a backup.",
|
|
69
|
+
enum=["ignore", "dismiss", "no_backup_needed", "retain"])}, ["task_id", "path"]),
|
|
70
|
+
"experience": schema({"rule_id": string(), "code": string(), "operation": string(), "action": string(enum=["verify_and_finalize", "refresh_plan"]), "task_id": string(), "version": string(), "enabled": BOOL}, ["rule_id", "code", "operation", "action"]),
|
|
71
|
+
"workspace": schema({"name": string(), "path": string("Existing local Git worktree")}, ["name", "path"]),
|
|
72
|
+
"submit": schema({"task_id": string(), "workspace": string(), "commit": string(), "base": string(), "paths": PATHS, "stage_id": string(), "relation": string(enum=["independent", "cumulative"]), "supersedes": {"type": "array", "items": string(), "uniqueItems": True}}, ["task_id", "workspace", "commit", "base", "paths"]),
|
|
73
|
+
"reconcile": schema({"baseline": string(), "execute": BOOL, "plan_id": string(), "limit": {"type": "integer", "minimum": 1, "maximum": 100, "description": "Maximum distinct work items frozen into a new plan; execution uses its existing plan scope."}}, ["baseline"]),
|
|
74
|
+
"adopt": schema({"workspace": string(), "baseline": string(), "execute": BOOL, "plan_id": string()}, ["workspace", "baseline"]),
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
from .adapter_contracts import SCHEMAS as ADAPTER_SCHEMAS
|
|
78
|
+
SCHEMAS.update(ADAPTER_SCHEMAS)
|
|
79
|
+
from .cycle_contracts import SCHEMAS as CYCLE_SCHEMAS
|
|
80
|
+
from .workbench_contracts import SCHEMAS as WORKBENCH_SCHEMAS
|
|
81
|
+
from .recovery_contracts import SCHEMAS as RECOVERY_SCHEMAS
|
|
82
|
+
SCHEMAS.update(CYCLE_SCHEMAS)
|
|
83
|
+
SCHEMAS.update(WORKBENCH_SCHEMAS)
|
|
84
|
+
SCHEMAS.update(RECOVERY_SCHEMAS)
|
|
85
|
+
from .transfer_contracts import SCHEMAS as TRANSFER_SCHEMAS
|
|
86
|
+
SCHEMAS.update(TRANSFER_SCHEMAS)
|
|
87
|
+
from .discovery_contracts import SCHEMAS as DISCOVERY_SCHEMAS
|
|
88
|
+
SCHEMAS.update(DISCOVERY_SCHEMAS)
|
|
89
|
+
from .worker_tools import SCHEMAS as WORKER_SCHEMAS
|
|
90
|
+
SCHEMAS.update(WORKER_SCHEMAS)
|
|
91
|
+
from .exchange_contracts import SCHEMAS as EXCHANGE_SCHEMAS
|
|
92
|
+
SCHEMAS.update(EXCHANGE_SCHEMAS)
|
|
93
|
+
|
|
94
|
+
# Missing profile retains the legacy receipt contract. New complete setup must
|
|
95
|
+
# explicitly choose its versioned coverage rather than relabel old acceptance.
|
|
96
|
+
_scope_properties = SCHEMAS['onboarding']['properties']['scope']['properties']
|
|
97
|
+
_scope_properties['profile'] = string(enum=['complete_v1'])
|
|
98
|
+
_schedule = _scope_properties['schedule']
|
|
99
|
+
_schedule['required'] = ['timezone']
|
|
100
|
+
_schedule['properties']['slots'] = {
|
|
101
|
+
'type': 'array', 'minItems': 2, 'maxItems': 3,
|
|
102
|
+
'items': schema({'slot_id': string(), 'purpose': string(enum=['report', 'absorb']), 'time': string()},
|
|
103
|
+
['slot_id', 'purpose', 'time'])}
|
|
104
|
+
def validate(value, definition, location="arguments"):
|
|
105
|
+
"""Validate the deliberately small schema subset used by these public tools."""
|
|
106
|
+
kind = definition.get("type")
|
|
107
|
+
if isinstance(kind, list):
|
|
108
|
+
for member in kind:
|
|
109
|
+
try:
|
|
110
|
+
validate(value, {**definition, 'type': member}, location)
|
|
111
|
+
return
|
|
112
|
+
except ValueError:
|
|
113
|
+
pass
|
|
114
|
+
raise ValueError(f"{location} has an unsupported type")
|
|
115
|
+
if kind == "null":
|
|
116
|
+
if value is not None:
|
|
117
|
+
raise ValueError(f"{location} must be null")
|
|
118
|
+
return
|
|
119
|
+
if kind == "object":
|
|
120
|
+
if not isinstance(value, dict):
|
|
121
|
+
raise ValueError(f"{location} must be an object")
|
|
122
|
+
props = definition.get("properties", {})
|
|
123
|
+
extra = set(value) - set(props)
|
|
124
|
+
missing = set(definition.get("required", [])) - set(value)
|
|
125
|
+
if extra and definition.get("additionalProperties") is not True:
|
|
126
|
+
raise ValueError(f"{location} has unknown fields: {', '.join(sorted(extra))}")
|
|
127
|
+
if missing:
|
|
128
|
+
raise ValueError(f"{location} lacks required fields: {', '.join(sorted(missing))}")
|
|
129
|
+
for name, item in value.items():
|
|
130
|
+
if name in props:
|
|
131
|
+
validate(item, props[name], f"{location}.{name}")
|
|
132
|
+
elif kind == "string" and not isinstance(value, str):
|
|
133
|
+
raise ValueError(f"{location} must be a string")
|
|
134
|
+
elif kind == "boolean" and not isinstance(value, bool):
|
|
135
|
+
raise ValueError(f"{location} must be a boolean")
|
|
136
|
+
elif kind == "integer":
|
|
137
|
+
if isinstance(value, bool) or not isinstance(value, int):
|
|
138
|
+
raise ValueError(f"{location} must be an integer")
|
|
139
|
+
if value < definition.get("minimum", value) or value > definition.get("maximum", value):
|
|
140
|
+
raise ValueError(f"{location} is outside the supported range")
|
|
141
|
+
elif kind == "array":
|
|
142
|
+
if not isinstance(value, list):
|
|
143
|
+
raise ValueError(f"{location} must be an array")
|
|
144
|
+
if not definition.get("minItems", 0) <= len(value) <= definition.get("maxItems", len(value)):
|
|
145
|
+
raise ValueError(f"{location} has an unsupported item count")
|
|
146
|
+
for index, item in enumerate(value):
|
|
147
|
+
validate(item, definition["items"], f"{location}[{index}]")
|
|
148
|
+
if definition.get("uniqueItems") and len(value) != len(set(value)):
|
|
149
|
+
raise ValueError(f"{location} must contain unique items")
|
|
150
|
+
if "enum" in definition and value not in definition["enum"]:
|
|
151
|
+
raise ValueError(f"{location} is outside the supported values")
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def action_schema(action, allow_fault=False):
|
|
155
|
+
if action == "init":
|
|
156
|
+
return schema({"name": string()})
|
|
157
|
+
if action not in SCHEMAS:
|
|
158
|
+
raise ValueError("Unknown action: " + str(action))
|
|
159
|
+
definition = deepcopy(SCHEMAS[action])
|
|
160
|
+
if allow_fault and action in {"reconcile", "adopt"}:
|
|
161
|
+
choices = ["after_candidate", "after_effect"] if action == "reconcile" else ["after_stash", "after_adopt", "after_restore"]
|
|
162
|
+
definition["properties"]["fault"] = string(enum=choices)
|
|
163
|
+
return definition
|
|
164
|
+
|
|
165
|
+
|