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.
Files changed (105) hide show
  1. taskcarry/__init__.py +3 -0
  2. taskcarry/__main__.py +4 -0
  3. taskcarry/adapter_contracts.py +166 -0
  4. taskcarry/agy_turns.py +282 -0
  5. taskcarry/api.py +111 -0
  6. taskcarry/board.py +313 -0
  7. taskcarry/board_assets/board.css +1087 -0
  8. taskcarry/board_assets/board.js +1187 -0
  9. taskcarry/board_assets/browse.js +214 -0
  10. taskcarry/board_assets/index.html +43 -0
  11. taskcarry/board_assets/taskcarry-icon.ico +0 -0
  12. taskcarry/board_assets/taskcarry-mark.svg +28 -0
  13. taskcarry/board_data.py +466 -0
  14. taskcarry/chat_joins.py +157 -0
  15. taskcarry/cli.py +119 -0
  16. taskcarry/codex_capture.py +184 -0
  17. taskcarry/codex_host.py +293 -0
  18. taskcarry/collaboration_exchange.py +316 -0
  19. taskcarry/connection.py +159 -0
  20. taskcarry/continuity.py +300 -0
  21. taskcarry/contracts.py +165 -0
  22. taskcarry/conversation_capture.py +669 -0
  23. taskcarry/core.py +896 -0
  24. taskcarry/cycle_contracts.py +73 -0
  25. taskcarry/discovery.py +434 -0
  26. taskcarry/discovery_contracts.py +52 -0
  27. taskcarry/exchange_contracts.py +67 -0
  28. taskcarry/exchange_endpoint.py +377 -0
  29. taskcarry/exchange_packets.py +142 -0
  30. taskcarry/experience_contracts.py +129 -0
  31. taskcarry/experience_exchange.py +214 -0
  32. taskcarry/experience_notes.py +433 -0
  33. taskcarry/experience_storage.py +125 -0
  34. taskcarry/experience_tools.py +26 -0
  35. taskcarry/feishu/__init__.py +1 -0
  36. taskcarry/feishu/display.py +122 -0
  37. taskcarry/feishu/project_watch.py +145 -0
  38. taskcarry/feishu/review_sets.py +80 -0
  39. taskcarry/feishu/sender.py +42 -0
  40. taskcarry/feishu/subscription.py +193 -0
  41. taskcarry/feishu/windows_agent.py +287 -0
  42. taskcarry/feishu/windows_secret.py +34 -0
  43. taskcarry/gitops.py +170 -0
  44. taskcarry/governance.py +88 -0
  45. taskcarry/governance_cycle.py +775 -0
  46. taskcarry/identification.py +82 -0
  47. taskcarry/integration.py +663 -0
  48. taskcarry/maintenance.py +118 -0
  49. taskcarry/mcp.py +183 -0
  50. taskcarry/member_join.py +184 -0
  51. taskcarry/member_routing.py +145 -0
  52. taskcarry/onboarding.py +272 -0
  53. taskcarry/onboarding_complete.py +252 -0
  54. taskcarry/path_batches.py +19 -0
  55. taskcarry/preservation.py +257 -0
  56. taskcarry/project_collaboration.py +453 -0
  57. taskcarry/project_history.py +166 -0
  58. taskcarry/project_identity.py +51 -0
  59. taskcarry/project_recovery.py +824 -0
  60. taskcarry/recovery_contracts.py +25 -0
  61. taskcarry/recovery_files.py +153 -0
  62. taskcarry/recovery_git.py +234 -0
  63. taskcarry/remote_capture.py +89 -0
  64. taskcarry/remote_transfer.py +356 -0
  65. taskcarry/role_connection.py +215 -0
  66. taskcarry/setup.py +597 -0
  67. taskcarry/shared_workbench.py +480 -0
  68. taskcarry/skill_data/taskcarry-experience-recovery/SKILL.md +37 -0
  69. taskcarry/skill_data/taskcarry-governance-reconcile/SKILL.md +47 -0
  70. taskcarry/skill_data/taskcarry-governance-reconcile/references/daily-governance.md +72 -0
  71. taskcarry/skill_data/taskcarry-project-setup/SKILL.md +48 -0
  72. taskcarry/skill_data/taskcarry-project-setup/references/onboarding.md +198 -0
  73. taskcarry/skill_data/taskcarry-task-delivery/SKILL.md +32 -0
  74. taskcarry/skill_data/taskcarry-task-delivery/references/conditional-experience.md +93 -0
  75. taskcarry/skill_data/taskcarry-task-delivery/references/worker-channel.md +41 -0
  76. taskcarry/source_review_set.py +80 -0
  77. taskcarry/state_format.py +47 -0
  78. taskcarry/store.py +472 -0
  79. taskcarry/task_context.py +141 -0
  80. taskcarry/text_handback.py +98 -0
  81. taskcarry/transfer_contracts.py +18 -0
  82. taskcarry/updates.py +351 -0
  83. taskcarry/workbench.py +625 -0
  84. taskcarry/workbench_contracts.py +32 -0
  85. taskcarry/workbuddy_capture.py +451 -0
  86. taskcarry/workbuddy_setup.py +212 -0
  87. taskcarry/worker_channel.py +859 -0
  88. taskcarry/worker_contracts.py +190 -0
  89. taskcarry/worker_storage.py +60 -0
  90. taskcarry/worker_tools.py +111 -0
  91. taskcarry-0.3.2.dist-info/METADATA +203 -0
  92. taskcarry-0.3.2.dist-info/RECORD +105 -0
  93. taskcarry-0.3.2.dist-info/WHEEL +5 -0
  94. taskcarry-0.3.2.dist-info/entry_points.txt +5 -0
  95. taskcarry-0.3.2.dist-info/licenses/LICENSE +21 -0
  96. taskcarry-0.3.2.dist-info/licenses/LICENSE_SCOPE.md +31 -0
  97. taskcarry-0.3.2.dist-info/top_level.txt +2 -0
  98. taskcarry_https/__init__.py +1 -0
  99. taskcarry_https/consent.py +207 -0
  100. taskcarry_https/reader.py +132 -0
  101. taskcarry_https/review.py +116 -0
  102. taskcarry_https/server.py +163 -0
  103. taskcarry_https/team.py +335 -0
  104. taskcarry_https/team_host.py +109 -0
  105. taskcarry_https/web_host.py +82 -0
taskcarry/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """TaskCarry: one local engine, several explicit interfaces."""
2
+
3
+ __version__ = "0.3.2"
taskcarry/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(main())
@@ -0,0 +1,166 @@
1
+ """Bounded contracts for optional host and official-release adapters."""
2
+
3
+ SCHEMAS = {
4
+ "codex": {
5
+ "type": "object",
6
+ "properties": {
7
+ "action": {
8
+ "type": "string",
9
+ "enum": [
10
+ "capabilities",
11
+ "list",
12
+ "read"
13
+ ]
14
+ },
15
+ "executable": {
16
+ "type": "string"
17
+ },
18
+ "codex_home": {
19
+ "type": "string"
20
+ },
21
+ "limit": {
22
+ "type": "integer",
23
+ "minimum": 1,
24
+ "maximum": 50
25
+ },
26
+ "cursor": {
27
+ "type": "string"
28
+ },
29
+ "archived": {
30
+ "type": "boolean"
31
+ },
32
+ "thread_id": {
33
+ "type": "string"
34
+ },
35
+ "timeout": {
36
+ "type": "integer",
37
+ "minimum": 1,
38
+ "maximum": 60
39
+ },
40
+ "max_bytes": {
41
+ "type": "integer",
42
+ "minimum": 1024,
43
+ "maximum": 2097152
44
+ }
45
+ },
46
+ "required": [
47
+ "action",
48
+ "executable"
49
+ ],
50
+ "additionalProperties": False
51
+ },
52
+ "update_source": {
53
+ "type": "object",
54
+ "properties": {
55
+ "channel": {
56
+ "type": "string",
57
+ "enum": [
58
+ "rc",
59
+ "stable"
60
+ ]
61
+ },
62
+ "current_version": {
63
+ "type": "string"
64
+ },
65
+ "current_artifacts": {
66
+ "type": "array",
67
+ "items": {
68
+ "type": "object",
69
+ "properties": {
70
+ "name": {
71
+ "type": "string"
72
+ },
73
+ "sha256": {
74
+ "type": "string"
75
+ },
76
+ "size": {
77
+ "type": "integer",
78
+ "minimum": 0
79
+ }
80
+ },
81
+ "required": [
82
+ "name",
83
+ "sha256",
84
+ "size"
85
+ ],
86
+ "additionalProperties": False
87
+ },
88
+ "maxItems": 20
89
+ },
90
+ "method_refs": {
91
+ "type": "array",
92
+ "items": {
93
+ "type": "string"
94
+ },
95
+ "maxItems": 30
96
+ },
97
+ "maintenance": {
98
+ "type": "string",
99
+ "enum": [
100
+ "review",
101
+ "authorized_maintenance"
102
+ ]
103
+ },
104
+ "expected_revision": {
105
+ "type": "integer",
106
+ "minimum": 0
107
+ }
108
+ },
109
+ "required": [],
110
+ "additionalProperties": False
111
+ },
112
+ "update_check": {
113
+ "type": "object",
114
+ "properties": {
115
+ "channel": {
116
+ "type": "string",
117
+ "enum": [
118
+ "rc",
119
+ "stable"
120
+ ]
121
+ }
122
+ },
123
+ "required": [],
124
+ "additionalProperties": False
125
+ },
126
+ "update_assess": {
127
+ "type": "object",
128
+ "properties": {
129
+ "check": {
130
+ "type": "object",
131
+ "additionalProperties": True,
132
+ "description": "Unmodified update_check object; validated fingerprint and source revision by engine."
133
+ },
134
+ "decision": {
135
+ "type": "string",
136
+ "enum": [
137
+ "prioritize",
138
+ "plan",
139
+ "keep",
140
+ "wait",
141
+ "reject"
142
+ ]
143
+ },
144
+ "reason": {
145
+ "type": "string"
146
+ },
147
+ "evidence_refs": {
148
+ "type": "array",
149
+ "items": {
150
+ "type": "string"
151
+ },
152
+ "maxItems": 30
153
+ },
154
+ "expected_revision": {
155
+ "type": "integer",
156
+ "minimum": 0
157
+ }
158
+ },
159
+ "required": [
160
+ "check",
161
+ "decision",
162
+ "reason"
163
+ ],
164
+ "additionalProperties": False
165
+ }
166
+ }
taskcarry/agy_turns.py ADDED
@@ -0,0 +1,282 @@
1
+ """Select the two visible messages from completed Antigravity transcript steps."""
2
+ import json
3
+ from contextlib import closing
4
+ from pathlib import Path
5
+ import re
6
+ import sqlite3
7
+ from urllib.parse import urlsplit
8
+ from urllib.request import url2pathname
9
+ from uuid import UUID
10
+
11
+ from .core import _linked
12
+
13
+
14
+ MAX_WINDOW = 8 * 1024 * 1024
15
+ MAX_MESSAGE = 256 * 1024
16
+ USER = re.compile(r'\s*<USER_REQUEST>(.*?)</USER_REQUEST>\s*(?:<(?:ADDITIONAL_METADATA|USER_SETTINGS_CHANGE)>.*)?\Z', re.S)
17
+ FENCE = re.compile(r'(?ms)^([~' + chr(96) + r']{3,})([^\n]*)\n(.*?)^\1[ \t]*\r?$')
18
+ LOG_LINE = re.compile(r'(?im)^\s*(?:Traceback \(most recent call last\)|File "[^"]+", line \d+|at \S+ \(|PS [^\n]*>|(?:DEBUG|INFO|ERROR|WARN)\s*[:\[])')
19
+
20
+
21
+ def transcript_path(home, provider, cid):
22
+ if provider not in {'antigravity', 'antigravity-cli', 'antigravity-ide'} or str(UUID(cid)) != cid:
23
+ raise ValueError('Unrecognized conversation identity.')
24
+ base = Path(home).absolute() / '.gemini' / provider / 'brain'
25
+ path = base / cid / '.system_generated' / 'logs' / 'transcript.jsonl'
26
+ if any(_linked(p) for p in (path, *path.parents)):
27
+ raise ValueError('The selected history must be an ordinary local file.')
28
+ return path
29
+
30
+
31
+ def workspace_path(value):
32
+ """AGY uses both absolute paths and escaped local file URIs for a workspace."""
33
+ if not isinstance(value, str):
34
+ return None
35
+ if value.lower().startswith('file:'):
36
+ uri = urlsplit(value)
37
+ if uri.netloc or uri.query or uri.fragment:
38
+ return None
39
+ # Windows clients also encode the drive separator; urllib checks for it before unquoting.
40
+ uri_path = re.sub(r'^/([a-zA-Z])%3[aA]/', r'/\1:/', uri.path)
41
+ value = url2pathname(uri_path)
42
+ path = Path(value)
43
+ return path if path.is_absolute() else None
44
+
45
+
46
+ def indexed_chats(home, provider, workspace, cid=None, *, archived=False):
47
+ """Read only root conversation identities for exactly this workspace, never titles or bodies."""
48
+ db_path = Path(home) / '.gemini' / provider / 'conversation_summaries.db'
49
+ if not db_path.is_file() or any(_linked(p) for p in (db_path, *db_path.parents)):
50
+ return []
51
+
52
+ def matches(value):
53
+ try:
54
+ roots = json.loads(value)
55
+ return isinstance(roots, list) and len(roots) == 1 and workspace_path(roots[0]) == workspace
56
+ except (ValueError, TypeError, OSError):
57
+ return False
58
+
59
+ query = """SELECT conversation_id FROM conversation_summaries
60
+ WHERE coalesce(parent_conversation_id, '') = '' AND coalesce(nesting_depth, 0) = 0
61
+ AND matches_workspace(workspace_uris)"""
62
+ args = ()
63
+ if cid is not None:
64
+ query += ' AND conversation_id = ?'
65
+ args = (cid,)
66
+ found = []
67
+ try:
68
+ with closing(sqlite3.connect(db_path.as_uri() + '?mode=ro', uri=True, timeout=0.25)) as db:
69
+ db.create_function('matches_workspace', 1, matches)
70
+ columns = {row[1] for row in db.execute('PRAGMA table_info(conversation_summaries)')}
71
+ flags = [f'coalesce({name},0)=1' for name in ('archived', 'is_archived') if name in columns]
72
+ if 'status' in columns:
73
+ flags.append("upper(coalesce(status,'')) IN ('ARCHIVED','CONVERSATION_STATUS_ARCHIVED')")
74
+ if flags:
75
+ query += ' AND (' + ' OR '.join(flags) + ') = ?'
76
+ args += (int(archived),)
77
+ elif archived:
78
+ return []
79
+ for (ident,) in db.execute(query, args):
80
+ try:
81
+ if str(UUID(ident)) == ident and (archived or transcript_path(home, provider, ident).is_file()):
82
+ found.append(ident)
83
+ except (TypeError, AttributeError, ValueError, OSError):
84
+ continue
85
+ except sqlite3.Error:
86
+ # Some clients only implement lifecycle hooks and have no compatible index.
87
+ return []
88
+ return sorted(found)
89
+
90
+
91
+ def indexed_run(home, provider, workspace, cid):
92
+ """Read the host's run boundary for one root chat in its exact workspace."""
93
+ transcript_path(home, provider, cid)
94
+ path = Path(home) / '.gemini' / provider / 'conversation_summaries.db'
95
+ if not path.is_file() or any(_linked(p) for p in (path, *path.parents)):
96
+ return None
97
+ try:
98
+ with closing(sqlite3.connect(path.as_uri() + '?mode=ro', uri=True, timeout=0.25)) as db:
99
+ row = db.execute("""SELECT workspace_uris, status, not_fully_idle, killed,
100
+ last_user_input_time, last_user_input_step_index, step_count
101
+ FROM conversation_summaries WHERE conversation_id=?
102
+ AND coalesce(parent_conversation_id, '')='' AND coalesce(nesting_depth, 0)=0""",
103
+ (cid,)).fetchone()
104
+ if row is None:
105
+ return None
106
+ roots = json.loads(row[0])
107
+ if not isinstance(roots, list) or len(roots) != 1 or workspace_path(roots[0]) != workspace:
108
+ return None
109
+ except (sqlite3.Error, OSError, TypeError, ValueError):
110
+ return None
111
+ return row[1:]
112
+
113
+
114
+ def recent_lines(stream):
115
+ end = stream.seek(0, 2)
116
+ if not end:
117
+ return
118
+ stream.seek(end - 1)
119
+ if stream.read(1) != b'\n':
120
+ return
121
+ position = end - 1
122
+ floor = max(0, end - MAX_WINDOW)
123
+ partial = b''
124
+ while position > floor:
125
+ start = max(floor, position - 65536)
126
+ stream.seek(start)
127
+ lines = (stream.read(position - start) + partial).split(b'\n')
128
+ yield from reversed(lines[1:])
129
+ partial, position = lines[0], start
130
+ if floor == 0 and partial:
131
+ yield partial
132
+
133
+
134
+ def restore_visible_rows(path, rows):
135
+ """Resolve only the two visible step bodies when the short transcript elided their middle."""
136
+ needed = {row['step_index']: row for row in rows if 'content' in (row.get('truncated_fields') or ())}
137
+ if not needed:
138
+ return rows
139
+ if path is None or _linked(path) or not path.is_file():
140
+ return None
141
+ restored = {}
142
+ with path.open('rb') as stream:
143
+ for line in recent_lines(stream):
144
+ try:
145
+ full = json.loads(line)
146
+ except (ValueError, UnicodeError):
147
+ continue
148
+ if not isinstance(full, dict) or type(full.get('step_index')) is not int:
149
+ continue
150
+ index = full['step_index']
151
+ row = needed.get(index)
152
+ if row is None:
153
+ continue
154
+ if (index in restored or not row.get('created_at') or
155
+ any(full.get(k) != row.get(k) for k in ('type','source','status','created_at')) or
156
+ 'content' in (full.get('truncated_fields') or ()) or full.get('tool_calls')):
157
+ return None
158
+ short, body = row.get('content'), full.get('content')
159
+ if not isinstance(short, str) or not isinstance(body, str):
160
+ return None
161
+ parts = re.split(r'\n<truncated ([0-9]{1,12}) bytes>\n', short)
162
+ if (len(parts) != 3 or not parts[0] or not parts[2] or not body.startswith(parts[0])
163
+ or not body.endswith(parts[2]) or
164
+ len(body.encode('utf-8')) != len((parts[0]+parts[2]).encode('utf-8')) + int(parts[1])):
165
+ return None
166
+ restored[index] = {**row, 'content':body, 'truncated_fields':[]}
167
+ if len(restored) == len(needed):
168
+ break
169
+ if restored.keys() != needed.keys():
170
+ return None
171
+ return [restored.get(row['step_index'], row) for row in rows]
172
+
173
+
174
+ def indexed_pair(data, first, count, full_path=None):
175
+ """Require a contiguous run ending in the host index's exact final step."""
176
+ if type(first) is not int or type(count) is not int or not 0 <= first < count or not data.endswith(b'\n'):
177
+ return None
178
+ user = None
179
+ expected = first
180
+ users = 0
181
+ for line in data.splitlines(keepends=True):
182
+ try:
183
+ row = json.loads(line)
184
+ except (ValueError, UnicodeError):
185
+ if user is not None:
186
+ return None
187
+ continue
188
+ if not isinstance(row, dict) or type(row.get('step_index')) is not int:
189
+ return None
190
+ users += row.get('type') == 'USER_INPUT'
191
+ if row['step_index'] < first and user is None:
192
+ continue
193
+ # A failed tool call can be followed by a normal, completed user-visible answer.
194
+ # Its error payload never supplies either half of the shared conversation.
195
+ failed_tool_step = (first < expected < count - 1 and row.get('type') == 'GENERIC'
196
+ and row.get('status') == 'ERROR')
197
+ if row['step_index'] != expected or (row.get('status') != 'DONE' and not failed_tool_step):
198
+ return None
199
+ if expected == first:
200
+ if (row.get('type'), row.get('source')) != ('USER_INPUT', 'USER_EXPLICIT'):
201
+ return None
202
+ user = row
203
+ if expected > first and row.get('type') == 'USER_INPUT':
204
+ return None
205
+ expected += 1
206
+ if (expected != count or user is None or (row.get('type'), row.get('source')) != ('PLANNER_RESPONSE','MODEL')
207
+ or row.get('tool_calls')):
208
+ return None
209
+ visible = restore_visible_rows(full_path, (user, row))
210
+ if not visible:
211
+ return None
212
+ question, answer = visible
213
+ pair = visible_pair(first, user_visible(question.get('content')), answer.get('content'))
214
+ return (pair, users == 1) if pair else None
215
+
216
+
217
+ def user_visible(content):
218
+ if not isinstance(content, str):
219
+ return None
220
+ match = USER.fullmatch(content)
221
+ if not match or content.count('<USER_REQUEST>') != 1 or content.count('</USER_REQUEST>') != 1:
222
+ return None
223
+ return match[1].removeprefix('\r\n').removeprefix('\n').removesuffix('\r\n').removesuffix('\n')
224
+
225
+
226
+ def visible_body(value):
227
+ if not isinstance(value, str) or not value.strip() or len(value.encode('utf-8')) > MAX_MESSAGE:
228
+ return None, True
229
+ omitted = False
230
+ def redact(match):
231
+ nonlocal omitted
232
+ body = match[3]
233
+ if (len(body) > 900 or body.count('\n') > 15) and (match[2].strip().lower() in {
234
+ 'log', 'console', 'terminal', 'shell', 'powershell', 'bash', 'sh', 'stdout', 'stderr',
235
+ 'text', 'plaintext', ''} or LOG_LINE.search(body)):
236
+ omitted = True
237
+ return '[terminal output omitted]'
238
+ return match[0]
239
+ text = FENCE.sub(redact, value)
240
+ if len(text) > 900 and len(LOG_LINE.findall(text)) >= 3:
241
+ return None, True
242
+ return text, omitted
243
+
244
+
245
+ def completed_turn(data):
246
+ """Extract a visible pair; the caller establishes the host's terminal boundary."""
247
+ if not data.endswith(b'\n'):
248
+ return None
249
+ user = final = None
250
+ for line in data.splitlines():
251
+ try:
252
+ row = json.loads(line)
253
+ except (ValueError, UnicodeError):
254
+ user = final = None
255
+ continue
256
+ if not isinstance(row, dict):
257
+ return None
258
+ if row.get('type') == 'USER_INPUT':
259
+ final = user = None
260
+ if row.get('source') == 'USER_EXPLICIT' and row.get('status') == 'DONE':
261
+ text = user_visible(row.get('content'))
262
+ if text is not None and type(row.get('step_index')) is int and 'content' not in (row.get('truncated_fields') or ()):
263
+ user = (row['step_index'], text)
264
+ elif row.get('type') == 'PLANNER_RESPONSE':
265
+ final = None
266
+ if (row.get('source') == 'MODEL' and row.get('status') == 'DONE' and not row.get('tool_calls')
267
+ and isinstance(row.get('content'), str) and 'content' not in (row.get('truncated_fields') or ())):
268
+ final = row['content']
269
+ elif row.get('type') == 'GENERIC':
270
+ final = None
271
+ if user is None or final is None:
272
+ return None
273
+ return visible_pair(user[0], user[1], final)
274
+
275
+
276
+ def visible_pair(index, prompt, final):
277
+ question, q_gap = visible_body(prompt)
278
+ answer, a_gap = visible_body(final)
279
+ if question is None or answer is None:
280
+ return None
281
+ return {'turn_id': f'turn-{index:012d}', 'user': question, 'assistant': answer,
282
+ 'omissions': q_gap or a_gap}
taskcarry/api.py ADDED
@@ -0,0 +1,111 @@
1
+ """The single dispatch surface shared by CLI and MCP."""
2
+ from .core import Core
3
+ from .integration import Integration
4
+ from .store import GovernanceError
5
+ from .contracts import action_schema, validate
6
+
7
+
8
+ def invoke(project, action, arguments=None, *, caller=None):
9
+ args = {} if arguments is None else arguments
10
+ if not isinstance(args, dict):
11
+ raise GovernanceError("INVALID_ARGUMENT", "Arguments must be a JSON object")
12
+ try:
13
+ validate(args, action_schema(action, allow_fault=True))
14
+ except (ValueError, KeyError) as exc:
15
+ raise GovernanceError("INVALID_ARGUMENT", str(exc)) from exc
16
+ from .worker_tools import SCHEMAS as WORKER_SCHEMAS
17
+ if caller is not None or action in WORKER_SCHEMAS:
18
+ from .worker_channel import WorkerChannel
19
+ return WorkerChannel(project, caller).invoke(action, args)
20
+ if action == 'endpoint':
21
+ from .exchange_endpoint import ExchangeEndpoint
22
+ return ExchangeEndpoint(project).invoke(**args)
23
+ if action == "init":
24
+ return Core.initialize(project, **args)
25
+ if action == "identify":
26
+ return Core.identify(project)
27
+ if action == "codex":
28
+ from .codex_host import codex_read
29
+ return codex_read(**args)
30
+ if action == "discovery":
31
+ from .discovery import Discovery
32
+ return Discovery(project).discovery(**args)
33
+ if action == "recovery":
34
+ from .project_recovery import ProjectRecovery
35
+ return ProjectRecovery(project).recovery(**args)
36
+ # Restored replicas must not execute old plans or mutate until an explicit
37
+ # writer handoff. This preflight precedes external Git/filesystem effects;
38
+ # Store also guards direct record writes and transactions.
39
+ state = Core(project)
40
+ config = state.store.get('config', 'project') or {}
41
+ read_modes = {
42
+ 'identity': {'status'}, 'onboarding': {'status'}, 'preserve': {'status'},
43
+ 'connect': {'status'}, 'governance': {'inspect'}, 'run': {'inspect'},
44
+ 'workbench': {'status'}, 'cycle': {'status', 'list', 'question_check', 'join_inbox'}, 'source_scan': {'status', 'registry'},
45
+ 'facts': {'get', 'history', 'list'},
46
+ 'transfer': {'verify', 'status'},
47
+ }
48
+ mode = args.get('action', args.get('mode', {
49
+ 'identity': 'status', 'onboarding': 'status', 'governance': 'inspect',
50
+ 'workbench': 'status', 'cycle': 'status', 'source_scan': 'status', 'facts': 'list',
51
+ }.get(action)))
52
+ readonly = (action in {'status', 'agenda', 'context', 'doctor', 'schedule_plan', 'update_check'}
53
+ or mode in read_modes.get(action, set()))
54
+ if not readonly:
55
+ state.store.assert_writable()
56
+ if args.get('plan_id') in config.get('recovery_inert_plan_ids', []):
57
+ raise GovernanceError('RESTORED_PLAN_INERT',
58
+ 'Historical plans are evidence only after recovery; prepare a new local plan.')
59
+ if (args.get('cycle_id') in config.get('recovery_inert_cycle_ids', [])
60
+ or args.get('run_id') in config.get('recovery_inert_run_ids', [])):
61
+ raise GovernanceError('RESTORED_RUN_INERT',
62
+ 'Retain the historical run and start a new bounded cycle on this replica.')
63
+ if action == "identity":
64
+ from .project_identity import ProjectIdentity
65
+ return ProjectIdentity(project).identity(**args)
66
+ if action in {"cycle", "facts", "source_scan"}:
67
+ from .governance_cycle import GovernanceCycle
68
+ return getattr(GovernanceCycle(project), action)(**args)
69
+ if action == "workbench":
70
+ from .workbench import Workbench
71
+ return Workbench(project).workbench(**args)
72
+ if action == "transfer":
73
+ from .remote_transfer import RemoteTransfer
74
+ return RemoteTransfer(project).transfer(**args)
75
+ if action in {"update_source", "update_check", "update_assess"}:
76
+ from .updates import Updates
77
+ return getattr(Updates(project), action)(**args)
78
+ if action in {"onboarding", "schedule_plan"}:
79
+ from .onboarding_complete import CompleteOnboarding
80
+ return getattr(CompleteOnboarding(project), action)(**args)
81
+ if action == "preserve":
82
+ from .preservation import Preservation
83
+ return Preservation(project).preserve(**args)
84
+ core_actions = {"status", "agenda", "context", "task", "checkpoint", "restore", "artifact", "experience", "upgrade"}
85
+ git_actions = {"workspace", "submit", "reconcile", "adopt", "doctor"}
86
+ continuity_actions = {"observe", "run"}
87
+ maintenance_actions = {"issue", "fix"}
88
+ if action == "governance":
89
+ from .governance import Governance
90
+ return Governance(project).governance(**args)
91
+ if action == "connect":
92
+ from .connection import Connection
93
+ return Connection(project).connect(**args)
94
+ if action not in core_actions | git_actions | continuity_actions | maintenance_actions:
95
+ raise GovernanceError("UNKNOWN_ACTION", f"Unknown action: {action}")
96
+ if action in continuity_actions:
97
+ from .continuity import Continuity
98
+ obj = Continuity(project)
99
+ elif action in maintenance_actions:
100
+ from .maintenance import Maintenance
101
+ obj = Maintenance(project)
102
+ else:
103
+ obj = Core(project) if action in core_actions else Integration(project)
104
+ if action == "checkpoint" and isinstance(args.get("workspace"), str):
105
+ registered = obj.store.get("workspaces", args["workspace"])
106
+ if registered:
107
+ args = {**args, "workspace": str(Integration(project)._ws(args["workspace"]))}
108
+ try:
109
+ return getattr(obj, action)(**args)
110
+ except TypeError as exc:
111
+ raise GovernanceError("INVALID_ARGUMENT", str(exc)) from exc