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/onboarding.py
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"""Resumable, evidence-qualified onboarding; never activates a host or scheduler."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
|
8
|
+
|
|
9
|
+
from .core import Core, _id, digest_bytes
|
|
10
|
+
from .gitops import repo, identity
|
|
11
|
+
from .store import GovernanceError, now
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def fingerprint(value):
|
|
15
|
+
return digest_bytes(json.dumps(value, sort_keys=True, ensure_ascii=False,
|
|
16
|
+
separators=(',', ':'), allow_nan=False).encode('utf-8'))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def text(value, label, maximum=8192):
|
|
20
|
+
if not isinstance(value, str) or not value.strip() or len(value) > maximum or '\0' in value:
|
|
21
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', f'{label} requires bounded nonempty text.')
|
|
22
|
+
return value
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Onboarding(Core):
|
|
26
|
+
def _scope(self, scope):
|
|
27
|
+
if not isinstance(scope, dict) or set(scope) != {'governance_thread', 'windows', 'schedule', 'channel'}:
|
|
28
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Specify governance_thread, windows, schedule and channel.')
|
|
29
|
+
text(scope['governance_thread'], 'Governance thread', 256)
|
|
30
|
+
if scope['channel'] not in ('stable', 'rc'):
|
|
31
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Select stable or rc updates.')
|
|
32
|
+
schedule = scope['schedule']
|
|
33
|
+
if (not isinstance(schedule, dict) or set(schedule) != {'time', 'timezone'}
|
|
34
|
+
or not isinstance(schedule['time'], str)
|
|
35
|
+
or not re.fullmatch(r'(?:[01][0-9]|2[0-3]):[0-5][0-9]', schedule['time'])):
|
|
36
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Specify a daily HH:MM time and timezone.')
|
|
37
|
+
text(schedule['timezone'], 'Timezone', 128)
|
|
38
|
+
# ZoneInfo databases are not bundled on every supported Windows host.
|
|
39
|
+
# Require the host to verify its zone in the schedule readback below.
|
|
40
|
+
try:
|
|
41
|
+
ZoneInfo(schedule['timezone'])
|
|
42
|
+
except ZoneInfoNotFoundError:
|
|
43
|
+
if not re.fullmatch(r'[A-Za-z_]+(?:/[A-Za-z0-9_+.-]+)+|UTC', schedule['timezone']):
|
|
44
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Use a named IANA timezone.')
|
|
45
|
+
windows = scope['windows']
|
|
46
|
+
if not isinstance(windows, list) or not windows or len(windows) > 100:
|
|
47
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Select 1-100 explicit windows or history sources.')
|
|
48
|
+
seen = set()
|
|
49
|
+
for window in windows:
|
|
50
|
+
if not isinstance(window, dict) or window.get('mode') not in ('active', 'reference'):
|
|
51
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Each window needs active or reference mode.')
|
|
52
|
+
allowed = {'thread_id', 'mode', 'task_id', 'workspace', 'source_ref', 'responsibility'}
|
|
53
|
+
if set(window) - allowed:
|
|
54
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Unknown window fields.')
|
|
55
|
+
tid = text(window.get('thread_id'), 'Thread ID', 256)
|
|
56
|
+
if tid in seen:
|
|
57
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Duplicate thread selection.')
|
|
58
|
+
seen.add(tid)
|
|
59
|
+
text(window.get('source_ref'), 'Source reference')
|
|
60
|
+
text(window.get('responsibility'), 'Responsibility', 2048)
|
|
61
|
+
if window['mode'] == 'active':
|
|
62
|
+
_id(window.get('task_id'), 'Task ID')
|
|
63
|
+
_id(window.get('workspace'), 'Workspace')
|
|
64
|
+
return json.loads(json.dumps(scope))
|
|
65
|
+
|
|
66
|
+
@staticmethod
|
|
67
|
+
def _keys(scope):
|
|
68
|
+
return ['scope', 'runtime', 'local_git', 'update_check', 'schedule_config'] + [
|
|
69
|
+
'window:' + item['thread_id'] for item in scope['windows'] if item['mode'] == 'active']
|
|
70
|
+
|
|
71
|
+
def _optional_keys(self, scope):
|
|
72
|
+
return ['schedule_trigger', 'remote', 'cloud']
|
|
73
|
+
|
|
74
|
+
def _verify_item_binding(self, prior, item):
|
|
75
|
+
if item['key'] == 'schedule_trigger':
|
|
76
|
+
cfg = prior['items'].get('schedule_config', {}).get('evidence', {})
|
|
77
|
+
if cfg.get('automation_id') != item['evidence']['automation_id']:
|
|
78
|
+
raise GovernanceError('ONBOARDING_BINDING', 'Natural trigger must match the configured automation.')
|
|
79
|
+
|
|
80
|
+
def _verify(self, scope, key, evidence):
|
|
81
|
+
if not isinstance(evidence, dict) or len(json.dumps(evidence)) > 65536:
|
|
82
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Use bounded structured evidence.')
|
|
83
|
+
text(evidence.get('receipt_ref'), 'Actual evidence receipt reference')
|
|
84
|
+
if key.startswith('window:'):
|
|
85
|
+
window = next(w for w in scope['windows'] if 'window:' + w['thread_id'] == key)
|
|
86
|
+
self._task(window['task_id'])
|
|
87
|
+
registered = self.store.get('workspaces', window['workspace'])
|
|
88
|
+
if not registered or 'path' not in registered:
|
|
89
|
+
raise GovernanceError('WORKSPACE_UNKNOWN', 'Prepare and register the actual Git worktree first.')
|
|
90
|
+
path = repo(registered['path'])
|
|
91
|
+
if identity(path) != registered['identity']:
|
|
92
|
+
raise GovernanceError('WORKSPACE_CHANGED', 'Recheck the registered Git identity.')
|
|
93
|
+
expected = {'thread_id': window['thread_id'], 'task_id': window['task_id'],
|
|
94
|
+
'workspace': window['workspace'], 'transport': 'native_mcp',
|
|
95
|
+
'doctor_ok': True, 'status_ok': True}
|
|
96
|
+
if any(evidence.get(k) != v for k, v in expected.items()):
|
|
97
|
+
raise GovernanceError('ONBOARDING_BINDING', 'Use native doctor/status from the selected window and task.')
|
|
98
|
+
if Path(text(evidence.get('cwd'), 'Actual cwd')).resolve() != path:
|
|
99
|
+
raise GovernanceError('ONBOARDING_BINDING', 'The host cwd must match its registered worktree.')
|
|
100
|
+
if Path(text(evidence.get('control'), 'Actual control')).resolve() != self.root:
|
|
101
|
+
raise GovernanceError('ONBOARDING_BINDING', 'The native calls must use this control.')
|
|
102
|
+
runtime = evidence.get('runtime', {})
|
|
103
|
+
if not isinstance(runtime, dict):
|
|
104
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Use a structured native runtime result.')
|
|
105
|
+
for field in ('version', 'interpreter', 'module_root'):
|
|
106
|
+
text(runtime.get(field), 'Runtime ' + field)
|
|
107
|
+
elif key == 'scope':
|
|
108
|
+
if evidence.get('user_confirmed') is not True or evidence.get('scope_fingerprint') != fingerprint(scope):
|
|
109
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Confirm this exact project/window scope.')
|
|
110
|
+
elif key == 'runtime':
|
|
111
|
+
if evidence.get('isolated') is not True:
|
|
112
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Verify isolated package startup.')
|
|
113
|
+
required = {'thread_id': scope['governance_thread'], 'transport': 'native_mcp',
|
|
114
|
+
'doctor_ok': True, 'status_ok': True}
|
|
115
|
+
if any(evidence.get(k) != v for k, v in required.items()):
|
|
116
|
+
raise GovernanceError('ONBOARDING_BINDING', 'Verify native doctor/status in the governance window itself.')
|
|
117
|
+
if Path(text(evidence.get('control'), 'Governance control')).resolve() != self.root:
|
|
118
|
+
raise GovernanceError('ONBOARDING_BINDING', 'The governance window must use this control.')
|
|
119
|
+
for field in ('version', 'interpreter', 'module_root', 'identity_ref'):
|
|
120
|
+
text(evidence.get(field), 'Runtime ' + field)
|
|
121
|
+
elif key == 'local_git':
|
|
122
|
+
from .preservation import Preservation
|
|
123
|
+
plan = Preservation(self.root).preserve(action='status', plan_id=text(evidence.get('plan_id'), 'Save plan'))
|
|
124
|
+
if plan['state'] != 'COMPLETED' or plan.get('commit') != evidence.get('commit'):
|
|
125
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Reference an actual completed local preservation record.')
|
|
126
|
+
elif key == 'update_check':
|
|
127
|
+
if evidence.get('channel') != scope['channel'] or evidence.get('checked') is not True:
|
|
128
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Check the selected official release channel.')
|
|
129
|
+
if evidence.get('source') != 'https://github.com/bryan123466/taskcarry/releases':
|
|
130
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Use the official release source.')
|
|
131
|
+
text(evidence.get('result_fingerprint'), 'Update result fingerprint', 128)
|
|
132
|
+
text(evidence.get('assessment_ref'), 'Update assessment')
|
|
133
|
+
assessment = self.store.get('update_assessments', evidence['assessment_ref'])
|
|
134
|
+
source = self.store.get('update_sources', 'official')
|
|
135
|
+
if not assessment or not source:
|
|
136
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Save the official source and actual update assessment first.')
|
|
137
|
+
check = assessment.get('check', {})
|
|
138
|
+
if (assessment.get('check_fingerprint') != evidence['result_fingerprint']
|
|
139
|
+
or check.get('fingerprint') != evidence['result_fingerprint']
|
|
140
|
+
or check.get('channel') != scope['channel'] or source.get('channel') != scope['channel']
|
|
141
|
+
or check.get('source_revision') != source.get('revision')
|
|
142
|
+
or check.get('release_source') != evidence['source']
|
|
143
|
+
or check.get('status') not in ('CANDIDATE', 'CURRENT_MATCHES', 'CURRENT_IDENTITY_INCOMPLETE',
|
|
144
|
+
'NO_RELEASE_IN_WINDOW', 'NO_NEWER_RELEASE_IN_WINDOW',
|
|
145
|
+
'LEGACY_REVIEW_REQUIRED', 'SAME_VERSION_CONFLICT')):
|
|
146
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Use a current, completed official check; offline/unverified remains pending.')
|
|
147
|
+
elif key == 'schedule_config':
|
|
148
|
+
expected = {'thread_id': scope['governance_thread'], 'time': scope['schedule']['time'],
|
|
149
|
+
'timezone': scope['schedule']['timezone'], 'frequency': 'daily',
|
|
150
|
+
'readback': True, 'active': True, 'kind': 'heartbeat',
|
|
151
|
+
'prompt_sha256': digest_bytes(self._prompt(scope).encode('utf-8'))}
|
|
152
|
+
if any(evidence.get(k) != v for k, v in expected.items()):
|
|
153
|
+
raise GovernanceError('ONBOARDING_BINDING', 'Read back the exact native schedule, original thread and prompt.')
|
|
154
|
+
text(evidence.get('automation_id'), 'Automation ID', 256)
|
|
155
|
+
if Path(text(evidence.get('cwd'), 'Schedule working directory')).resolve() != self.root:
|
|
156
|
+
raise GovernanceError('ONBOARDING_BINDING', 'The native schedule must use the selected governance directory.')
|
|
157
|
+
text(evidence.get('runtime_ref'), 'Verified fixed runtime identity reference')
|
|
158
|
+
elif key == 'schedule_trigger':
|
|
159
|
+
if evidence.get('thread_id') != scope['governance_thread'] or evidence.get('trigger') != 'natural_heartbeat':
|
|
160
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'A manual run is not a natural heartbeat.')
|
|
161
|
+
for field in ('automation_id', 'received_at', 'run_ref', 'update_check_ref', 'local_save_ref'):
|
|
162
|
+
text(evidence.get(field), field)
|
|
163
|
+
elif key in ('remote', 'cloud'):
|
|
164
|
+
text(evidence.get('coverage_ref'), 'Explicit capture/upload/download/restore coverage')
|
|
165
|
+
text(evidence.get('destination'), 'User-selected destination')
|
|
166
|
+
|
|
167
|
+
def _report(self, record):
|
|
168
|
+
scope, items = record['scope'], record['items']
|
|
169
|
+
pending, invalid = [], {}
|
|
170
|
+
for key in self._keys(scope):
|
|
171
|
+
item = items.get(key)
|
|
172
|
+
if not item or item['status'] != 'verified':
|
|
173
|
+
pending.append(key)
|
|
174
|
+
continue
|
|
175
|
+
try:
|
|
176
|
+
self._verify(scope, key, item['evidence'])
|
|
177
|
+
except (GovernanceError, OSError) as error:
|
|
178
|
+
pending.append(key)
|
|
179
|
+
invalid[key] = {'code': getattr(error, 'code', 'ONBOARDING_EVIDENCE_UNAVAILABLE'),
|
|
180
|
+
'message': getattr(error, 'message', str(error))}
|
|
181
|
+
trigger = items.get('schedule_trigger', {})
|
|
182
|
+
config = items.get('schedule_config', {})
|
|
183
|
+
natural = (trigger.get('status') == 'verified' and config.get('status') == 'verified'
|
|
184
|
+
and 'schedule_config' not in pending and trigger.get('evidence', {}).get('automation_id')
|
|
185
|
+
== config.get('evidence', {}).get('automation_id'))
|
|
186
|
+
return {'onboarding': record, 'required': self._keys(scope), 'pending': pending,
|
|
187
|
+
'invalidated': invalid, 'standard_ready': not pending,
|
|
188
|
+
'natural_trigger_verified': bool(natural), 'closed_loop_verified': not pending and bool(natural),
|
|
189
|
+
'evidence_scope': 'host_reviewed_receipts_and_live_local_bindings',
|
|
190
|
+
'host_effects_executed': False,
|
|
191
|
+
'meaning': 'Recorded host evidence is not independent host access; configuration and natural trigger are distinct.'}
|
|
192
|
+
|
|
193
|
+
def onboarding(self, onboarding_id, action='status', scope=None, item=None, expected_revision=None):
|
|
194
|
+
onboarding_id = _id(onboarding_id, 'Onboarding ID')
|
|
195
|
+
if action not in ('start', 'update', 'status'):
|
|
196
|
+
raise GovernanceError('ONBOARDING_ACTION', 'Use start, update or status.')
|
|
197
|
+
if expected_revision is not None and (type(expected_revision) is not int or expected_revision < 1):
|
|
198
|
+
raise GovernanceError('INVALID_REVISION', 'Use a positive expected revision.')
|
|
199
|
+
if action == 'status':
|
|
200
|
+
if any(value is not None for value in (scope, item, expected_revision)):
|
|
201
|
+
raise GovernanceError('ONBOARDING_ACTION', 'Status does not accept update fields.')
|
|
202
|
+
record = self.store.get('onboarding', onboarding_id)
|
|
203
|
+
if not record:
|
|
204
|
+
raise GovernanceError('ONBOARDING_UNKNOWN', 'Start this onboarding first.')
|
|
205
|
+
return self._report(record)
|
|
206
|
+
with self.store.transaction():
|
|
207
|
+
prior = self.store.get('onboarding', onboarding_id)
|
|
208
|
+
if action == 'start':
|
|
209
|
+
if item is not None:
|
|
210
|
+
raise GovernanceError('ONBOARDING_ACTION', 'Start does not accept an item update.')
|
|
211
|
+
scope = self._scope(scope)
|
|
212
|
+
body = {'onboarding_id': onboarding_id, 'scope': scope, 'items': {}}
|
|
213
|
+
if prior and prior['scope'] == scope:
|
|
214
|
+
return {**self._report(prior), 'reused': True}
|
|
215
|
+
else:
|
|
216
|
+
if scope is not None:
|
|
217
|
+
raise GovernanceError('ONBOARDING_ACTION', 'Use start with an expected revision to replace the scope.')
|
|
218
|
+
if not prior:
|
|
219
|
+
raise GovernanceError('ONBOARDING_UNKNOWN', 'Start this onboarding first.')
|
|
220
|
+
if not isinstance(item, dict) or set(item) != {'key', 'status', 'evidence', 'next_step'}:
|
|
221
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Provide key, status, evidence and next_step.')
|
|
222
|
+
allowed = self._keys(prior['scope']) + self._optional_keys(prior['scope'])
|
|
223
|
+
if item['key'] not in allowed or item['status'] not in ('verified', 'pending', 'declined'):
|
|
224
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Unknown item or status.')
|
|
225
|
+
if item['status'] == 'verified':
|
|
226
|
+
self._verify(prior['scope'], item['key'], item['evidence'])
|
|
227
|
+
self._verify_item_binding(prior, item)
|
|
228
|
+
else:
|
|
229
|
+
if not isinstance(item['evidence'], dict):
|
|
230
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Use a structured evidence object, including pending items.')
|
|
231
|
+
text(item['next_step'], 'Remaining step')
|
|
232
|
+
if not isinstance(item['next_step'], str) or len(json.dumps(item)) > 65536:
|
|
233
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Use bounded item text.')
|
|
234
|
+
body = {k: prior[k] for k in ('onboarding_id', 'scope', 'items')}
|
|
235
|
+
body['items'] = {**body['items'], item['key']: item}
|
|
236
|
+
if prior['items'].get(item['key']) == item:
|
|
237
|
+
return {**self._report(prior), 'reused': True}
|
|
238
|
+
if prior and expected_revision != prior['revision']:
|
|
239
|
+
raise GovernanceError('ONBOARDING_CHANGED', 'Reread onboarding before changing it.', {'revision': prior['revision']})
|
|
240
|
+
if not prior and expected_revision is not None:
|
|
241
|
+
raise GovernanceError('ONBOARDING_CHANGED', 'This onboarding has no prior revision.')
|
|
242
|
+
record = {**body, 'revision': prior['revision'] + 1 if prior else 1, 'updated_at': now(),
|
|
243
|
+
'scope_fingerprint': fingerprint(body['scope'])}
|
|
244
|
+
self.store.put('onboarding', onboarding_id, record)
|
|
245
|
+
self.store.put('onboarding_history', onboarding_id + ':' + str(record['revision']), record)
|
|
246
|
+
self.store.event('onboarding_updated', {'onboarding_id': onboarding_id, 'revision': record['revision']})
|
|
247
|
+
return {**self._report(record), 'reused': False}
|
|
248
|
+
|
|
249
|
+
def _prompt(self, scope):
|
|
250
|
+
selected = [{'task_id': w['task_id'], 'workspace': w['workspace']} for w in scope['windows'] if w['mode'] == 'active']
|
|
251
|
+
return ('Continue this original governance conversation using its existing model and permissions. '
|
|
252
|
+
'Use the fixed isolated TaskCarry runtime and control ' + str(self.root) + '. '
|
|
253
|
+
'Read its recorded runtime identity before executing; do not import source from cwd. '
|
|
254
|
+
'Selected active tasks/workspaces: ' + json.dumps(selected, sort_keys=True) + '. '
|
|
255
|
+
'Reference-only historical chats do not become active work. '
|
|
256
|
+
'Read bounded agenda and relevant task context; verify actual effects before retrying. '
|
|
257
|
+
'Continue only authorized work, retain decisions and next steps, and preserve exact local Git files. '
|
|
258
|
+
'Check https://github.com/bryan123466/taskcarry/releases on the ' + scope['channel'] +
|
|
259
|
+
' channel and record an applicability assessment; do not install updates automatically. '
|
|
260
|
+
'No change means no new task, commit or repeated reminder. Report effects, evidence and missing conditions. '
|
|
261
|
+
'Do not publish, message other chats or change production scope without authorization. '
|
|
262
|
+
'A skipped interval is not permission to replay all previous work.')
|
|
263
|
+
|
|
264
|
+
def schedule_plan(self, onboarding_id):
|
|
265
|
+
record = self.onboarding(onboarding_id)['onboarding']
|
|
266
|
+
scope = record['scope']
|
|
267
|
+
prompt = self._prompt(scope)
|
|
268
|
+
return {'thread_id': scope['governance_thread'], 'kind': 'heartbeat', 'frequency': 'daily',
|
|
269
|
+
**scope['schedule'], 'prompt': prompt, 'prompt_sha256': digest_bytes(prompt.encode('utf-8')),
|
|
270
|
+
'control': str(self.root), 'action': 'create_or_reuse_with_native_host', 'execute': False,
|
|
271
|
+
'preserve_model_and_permissions': True, 'natural_trigger_verified': False,
|
|
272
|
+
'next_step': 'Use supported native host scheduling; read back this exact configuration. Do not edit host databases.'}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"""Versioned complete-governance acceptance without changing legacy receipts."""
|
|
2
|
+
import re
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from .core import digest_bytes
|
|
6
|
+
from .onboarding import Onboarding, fingerprint, text
|
|
7
|
+
from .store import GovernanceError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
PROFILE = 'complete_v1'
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CompleteOnboarding(Onboarding):
|
|
14
|
+
def _scope(self, scope):
|
|
15
|
+
if not isinstance(scope, dict) or scope.get('profile') != PROFILE:
|
|
16
|
+
return super()._scope(scope)
|
|
17
|
+
if set(scope) != {'profile', 'governance_thread', 'windows', 'schedule', 'channel'}:
|
|
18
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Use the complete_v1 project, windows, channel and schedule scope.')
|
|
19
|
+
schedule = scope['schedule']
|
|
20
|
+
if not isinstance(schedule, dict) or set(schedule) != {'timezone', 'slots'}:
|
|
21
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Choose a timezone, one report and one or two absorption slots.')
|
|
22
|
+
slots = schedule['slots']
|
|
23
|
+
if not isinstance(slots, list) or not 2 <= len(slots) <= 3:
|
|
24
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Choose two or three daily slots.')
|
|
25
|
+
ids, times, reports = set(), set(), 0
|
|
26
|
+
for slot in slots:
|
|
27
|
+
if not isinstance(slot, dict) or set(slot) != {'slot_id', 'purpose', 'time'}:
|
|
28
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Each slot needs slot_id, purpose and time.')
|
|
29
|
+
sid = text(slot['slot_id'], 'Slot ID', 64)
|
|
30
|
+
if not re.fullmatch(r'[a-zA-Z0-9_-]+', sid) or sid in ids or slot['time'] in times:
|
|
31
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Use unique simple slot IDs and distinct daily times.')
|
|
32
|
+
if slot['purpose'] not in ('report', 'absorb'):
|
|
33
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Slot purpose must be report or absorb.')
|
|
34
|
+
reports += slot['purpose'] == 'report'
|
|
35
|
+
ids.add(sid)
|
|
36
|
+
times.add(slot['time'])
|
|
37
|
+
base = {k: scope[k] for k in ('governance_thread', 'windows', 'channel')}
|
|
38
|
+
base['schedule'] = {'time': slot['time'], 'timezone': schedule['timezone']}
|
|
39
|
+
super()._scope(base)
|
|
40
|
+
if reports != 1:
|
|
41
|
+
raise GovernanceError('ONBOARDING_SCOPE', 'Exactly one report slot is required; others absorb changes.')
|
|
42
|
+
return {**base, 'profile': PROFILE, 'schedule': schedule}
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def _keys(scope):
|
|
46
|
+
keys = Onboarding._keys(scope)
|
|
47
|
+
if scope.get('profile') == PROFILE:
|
|
48
|
+
keys += ['identity', 'sources', 'workbenches', 'recovery', 'first_cycle']
|
|
49
|
+
return keys
|
|
50
|
+
|
|
51
|
+
def _optional_keys(self, scope):
|
|
52
|
+
if scope.get('profile') != PROFILE:
|
|
53
|
+
return super()._optional_keys(scope)
|
|
54
|
+
return ['remote', 'cloud'] + ['schedule_trigger:' + s['slot_id'] for s in scope['schedule']['slots']]
|
|
55
|
+
|
|
56
|
+
def _slot_prompt(self, scope, slot):
|
|
57
|
+
return (super()._prompt(scope) + ' Complete-governance profile complete_v1; slot ' + slot['slot_id'] +
|
|
58
|
+
' has purpose ' + slot['purpose'] + '. '
|
|
59
|
+
'Read the current workspace view and project rules. Reserve one bounded governance cycle with '
|
|
60
|
+
'an exact owner and resource scope; resume its saved effects after interruption. '
|
|
61
|
+
'Read only selected chat/material sources, record revisions and distinguish observed, understood, '
|
|
62
|
+
'published and consumed. Reconcile current facts, decisions and dependencies without reviving '
|
|
63
|
+
'completed history. Review applicable fixes and update identities; do not equate recorded fixes '
|
|
64
|
+
'with installation. Publish current rules/progress to affected workbenches with exact plans and '
|
|
65
|
+
'preserve their configuration and WIP. Verify selected recovery coverage and health; a local '
|
|
66
|
+
'manifest is not an offsite download or restore. Record execution separately from actual report '
|
|
67
|
+
'delivery; count unanswered questions only on distinct dates with a real delivery receipt. ' +
|
|
68
|
+
('Deliver one concise project report with decisions, evidence, missing conditions and next work.'
|
|
69
|
+
if slot['purpose'] == 'report' else
|
|
70
|
+
'Absorb meaningful changes; stay quiet if unchanged, and escalate only a necessary decision.'))
|
|
71
|
+
|
|
72
|
+
def _verify_item_binding(self, prior, item):
|
|
73
|
+
if prior['scope'].get('profile') != PROFILE:
|
|
74
|
+
return super()._verify_item_binding(prior, item)
|
|
75
|
+
if item['key'].startswith('schedule_trigger:'):
|
|
76
|
+
slot_id = item['key'].split(':', 1)[1]
|
|
77
|
+
slots = prior['items'].get('schedule_config', {}).get('evidence', {}).get('slots', [])
|
|
78
|
+
config = next((s for s in slots if s.get('slot_id') == slot_id), {})
|
|
79
|
+
if config.get('automation_id') != item['evidence'].get('automation_id'):
|
|
80
|
+
raise GovernanceError('ONBOARDING_BINDING', 'The actual trigger must match this configured slot.')
|
|
81
|
+
|
|
82
|
+
def _verify(self, scope, key, evidence):
|
|
83
|
+
if scope.get('profile') != PROFILE:
|
|
84
|
+
return super()._verify(scope, key, evidence)
|
|
85
|
+
if not isinstance(evidence, dict):
|
|
86
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Provide structured actual evidence.')
|
|
87
|
+
text(evidence.get('receipt_ref'), 'Evidence receipt')
|
|
88
|
+
if key == 'identity':
|
|
89
|
+
actual = self.source()
|
|
90
|
+
if (actual['identity_scope'] != 'persistent_project'
|
|
91
|
+
or evidence.get('source_id') != actual['source_id']
|
|
92
|
+
or evidence.get('replica_id') != actual['replica_id']):
|
|
93
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Verify this portable project and replica identity.')
|
|
94
|
+
elif key == 'workbenches':
|
|
95
|
+
from .workbench import Workbench
|
|
96
|
+
windows = [w for w in scope['windows'] if w['mode'] == 'active']
|
|
97
|
+
identity_fields = ('workspace', 'task_id', 'thread_id')
|
|
98
|
+
expected = {tuple(w[k] for k in identity_fields) for w in windows}
|
|
99
|
+
entries = evidence.get('entries')
|
|
100
|
+
if (not isinstance(entries, list) or any(not isinstance(e, dict) for e in entries)
|
|
101
|
+
or len(entries) != len(windows)):
|
|
102
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Verify each selected active chat current entry and consumption.')
|
|
103
|
+
selected_entries, seen = [], set()
|
|
104
|
+
for entry in entries:
|
|
105
|
+
# Older evidence named only a workspace. Keep it readable when
|
|
106
|
+
# exactly one selected chat owns that workspace, without
|
|
107
|
+
# rewriting the stored receipt or inferring another consumer.
|
|
108
|
+
selected = dict(entry)
|
|
109
|
+
if any(k not in entry for k in ('task_id', 'thread_id')):
|
|
110
|
+
candidates = [w for w in windows if w['workspace'] == entry.get('workspace')]
|
|
111
|
+
if len(candidates) != 1:
|
|
112
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Shared-workspace evidence must identify each original task and chat.')
|
|
113
|
+
for field in ('task_id', 'thread_id'):
|
|
114
|
+
selected.setdefault(field, candidates[0][field])
|
|
115
|
+
if any(not isinstance(selected.get(k), str) for k in identity_fields):
|
|
116
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Use the exact workspace, task and chat identity.')
|
|
117
|
+
identity = tuple(selected[k] for k in identity_fields)
|
|
118
|
+
if identity not in expected or identity in seen:
|
|
119
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Each selected active chat needs exactly one matching entry.')
|
|
120
|
+
seen.add(identity)
|
|
121
|
+
selected_entries.append(selected)
|
|
122
|
+
if seen != expected:
|
|
123
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Current-entry evidence does not cover every selected active chat.')
|
|
124
|
+
for entry in selected_entries:
|
|
125
|
+
items = Workbench(self.root).workbench('status', workspace=entry['workspace'],
|
|
126
|
+
thread_id=entry['thread_id'])['items']
|
|
127
|
+
if (len(items) != 1 or items[0].get('view_id') != entry.get('view_id')
|
|
128
|
+
or any(items[0].get(k) != entry[k] for k in identity_fields)
|
|
129
|
+
or items[0].get('state') != 'PUBLISHED'
|
|
130
|
+
or items[0].get('consumer_state') != 'REVIEWED_EVIDENCE_RECORDED'
|
|
131
|
+
or items[0].get('finalization_pending') is not False
|
|
132
|
+
or not items[0].get('source_freshness')
|
|
133
|
+
or any(s.get('state') != 'MATCHES' for s in items[0]['source_freshness'])
|
|
134
|
+
or entry.get('native_doctor_status_verified') is not True):
|
|
135
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Each selected chat needs its own consumed current entry and native evidence.')
|
|
136
|
+
elif key == 'recovery':
|
|
137
|
+
from .project_recovery import ProjectRecovery
|
|
138
|
+
verified = ProjectRecovery(self.root).recovery('verify', manifest=text(evidence.get('manifest'), 'Recovery manifest'),
|
|
139
|
+
expected_sha256=text(evidence.get('manifest_sha256'), 'Manifest hash'))
|
|
140
|
+
# A success return proves verified bytes; the separately reviewed
|
|
141
|
+
# rehearsal receipt describes its selected restore and exclusions.
|
|
142
|
+
if verified.get('verified') is not True or verified.get('complete_scope') is not True:
|
|
143
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'The recovery set failed byte verification.')
|
|
144
|
+
status = ProjectRecovery(self.root).recovery('status', plan_id=text(evidence.get('restore_plan_id'), 'Restore plan'))
|
|
145
|
+
receipt = status.get('receipt') or {}
|
|
146
|
+
effect = status.get('observed_effect') or {}
|
|
147
|
+
if (status['plan']['kind'] != 'restore' or receipt.get('manifest_sha256') != evidence['manifest_sha256']
|
|
148
|
+
or receipt.get('state') != 'RESTORED_STANDBY' or effect.get('state_verified') is not True
|
|
149
|
+
or effect.get('complete_scope') is not True
|
|
150
|
+
or effect.get('git_verified') is not True):
|
|
151
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Verify the actual isolated restore and its exact manifest receipt.')
|
|
152
|
+
text(evidence.get('restore_receipt_ref'), 'Independent restore receipt')
|
|
153
|
+
if evidence.get('restore_verified') is not True:
|
|
154
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Perform an isolated restore before completing setup.')
|
|
155
|
+
elif key in ('sources', 'first_cycle'):
|
|
156
|
+
from .governance_cycle import GovernanceCycle
|
|
157
|
+
result = GovernanceCycle(self.root).cycle('status', cycle_id=text(evidence.get('cycle_id'), 'Cycle ID'))
|
|
158
|
+
record = result.get('cycle', result)
|
|
159
|
+
if record.get('state') != 'completed':
|
|
160
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Reference the completed bounded first governance cycle.')
|
|
161
|
+
if key == 'sources':
|
|
162
|
+
expected_sources = {w['source_ref'] for w in scope['windows']}
|
|
163
|
+
understood = {s['source_id'] for s in record.get('sources', {}).values()
|
|
164
|
+
if s.get('source_revision') and 'observed' in s.get('phases', {})
|
|
165
|
+
and 'understood' in s.get('phases', {})}
|
|
166
|
+
unread = [s for s in record.get('sources', {}).values()
|
|
167
|
+
if s.get('source_id') in expected_sources and 'observed' in s.get('phases', {})
|
|
168
|
+
and 'understood' not in s.get('phases', {})]
|
|
169
|
+
if not expected_sources <= understood or unread:
|
|
170
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Understand every selected exact source revision; unrelated sources cannot fill the gap.',
|
|
171
|
+
{'missing_sources': sorted(expected_sources - understood),
|
|
172
|
+
'unread_revisions': [{'source_id': s['source_id'], 'source_revision': s['source_revision']}
|
|
173
|
+
for s in unread]})
|
|
174
|
+
if key == 'first_cycle' and (not record.get('health') or any(
|
|
175
|
+
h.get('effective_status') != 'healthy' for h in record['health'].values())):
|
|
176
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Review current healthy evidence or retain the concrete setup gap.')
|
|
177
|
+
text(evidence.get('coverage_ref'), 'Reviewed coverage, exclusions and next work')
|
|
178
|
+
elif key == 'schedule_config':
|
|
179
|
+
entries = evidence.get('slots')
|
|
180
|
+
if (not isinstance(entries, list) or any(not isinstance(e, dict) for e in entries)
|
|
181
|
+
or len(entries) != len(scope['schedule']['slots'])):
|
|
182
|
+
raise GovernanceError('ONBOARDING_BINDING', 'Read back every configured native schedule slot.')
|
|
183
|
+
seen = set()
|
|
184
|
+
for slot in scope['schedule']['slots']:
|
|
185
|
+
actual = [e for e in entries if e.get('slot_id') == slot['slot_id']]
|
|
186
|
+
if len(actual) != 1:
|
|
187
|
+
raise GovernanceError('ONBOARDING_BINDING', 'Each exact slot needs one native schedule readback.')
|
|
188
|
+
actual = actual[0]
|
|
189
|
+
expected = {'thread_id': scope['governance_thread'], 'time': slot['time'],
|
|
190
|
+
'timezone': scope['schedule']['timezone'], 'frequency': 'daily', 'kind': 'heartbeat',
|
|
191
|
+
'readback': True, 'active': True,
|
|
192
|
+
'prompt_sha256': digest_bytes(self._slot_prompt(scope, slot).encode('utf-8'))}
|
|
193
|
+
if any(actual.get(k) != v for k, v in expected.items()):
|
|
194
|
+
raise GovernanceError('ONBOARDING_BINDING', 'Read back the exact prompt, time, zone and original chat.')
|
|
195
|
+
aid = text(actual.get('automation_id'), 'Automation ID', 256)
|
|
196
|
+
if aid in seen or Path(text(actual.get('cwd'), 'Schedule cwd')).resolve() != self.root:
|
|
197
|
+
raise GovernanceError('ONBOARDING_BINDING', 'Use distinct native schedules in the same control.')
|
|
198
|
+
seen.add(aid)
|
|
199
|
+
text(actual.get('runtime_ref'), 'Fixed isolated runtime receipt')
|
|
200
|
+
elif key.startswith('schedule_trigger:'):
|
|
201
|
+
slot = next(s for s in scope['schedule']['slots'] if 'schedule_trigger:' + s['slot_id'] == key)
|
|
202
|
+
if (evidence.get('thread_id') != scope['governance_thread']
|
|
203
|
+
or evidence.get('trigger') != 'natural_heartbeat' or evidence.get('ai_execution_verified') is not True):
|
|
204
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Actual natural trigger and original-chat AI execution are distinct required evidence.')
|
|
205
|
+
for field in ('automation_id', 'received_at', 'run_ref', 'update_check_ref', 'local_save_ref'):
|
|
206
|
+
text(evidence.get(field), field)
|
|
207
|
+
if slot['purpose'] == 'report':
|
|
208
|
+
text(evidence.get('delivered_at'), 'Actual report delivery time')
|
|
209
|
+
text(evidence.get('delivery_ref'), 'Actual report delivery reference')
|
|
210
|
+
elif evidence.get('outcome') not in ('changed', 'quiet_no_change', 'needs_decision'):
|
|
211
|
+
raise GovernanceError('ONBOARDING_EVIDENCE', 'Record the actual absorption outcome, including a quiet no-change run.')
|
|
212
|
+
else:
|
|
213
|
+
return super()._verify(scope, key, evidence)
|
|
214
|
+
|
|
215
|
+
def _report(self, record):
|
|
216
|
+
result = super()._report(record)
|
|
217
|
+
complete = record['scope'].get('profile') == PROFILE
|
|
218
|
+
result.update(profile=PROFILE if complete else 'legacy_v1', complete_governance_ready=complete and not result['pending'])
|
|
219
|
+
if not complete:
|
|
220
|
+
result['meaning'] += ' Legacy readiness does not attest complete_v1 governance coverage.'
|
|
221
|
+
return result
|
|
222
|
+
verified = []
|
|
223
|
+
for slot in record['scope']['schedule']['slots']:
|
|
224
|
+
key = 'schedule_trigger:' + slot['slot_id']
|
|
225
|
+
item = record['items'].get(key, {})
|
|
226
|
+
try:
|
|
227
|
+
if item.get('status') != 'verified':
|
|
228
|
+
continue
|
|
229
|
+
self._verify(record['scope'], key, item['evidence'])
|
|
230
|
+
self._verify_item_binding(record, item)
|
|
231
|
+
verified.append(slot['slot_id'])
|
|
232
|
+
except GovernanceError:
|
|
233
|
+
continue
|
|
234
|
+
result.update(natural_trigger_verified=len(verified) == len(record['scope']['schedule']['slots']),
|
|
235
|
+
verified_natural_slots=verified,
|
|
236
|
+
closed_loop_verified=result['complete_governance_ready'] and len(verified) == len(record['scope']['schedule']['slots']))
|
|
237
|
+
return result
|
|
238
|
+
|
|
239
|
+
def schedule_plan(self, onboarding_id):
|
|
240
|
+
record = self.onboarding(onboarding_id)['onboarding']
|
|
241
|
+
scope = record['scope']
|
|
242
|
+
if scope.get('profile') != PROFILE:
|
|
243
|
+
return super().schedule_plan(onboarding_id)
|
|
244
|
+
slots = []
|
|
245
|
+
for slot in scope['schedule']['slots']:
|
|
246
|
+
prompt = self._slot_prompt(scope, slot)
|
|
247
|
+
slots.append({**slot, 'thread_id': scope['governance_thread'], 'kind': 'heartbeat', 'frequency': 'daily',
|
|
248
|
+
'timezone': scope['schedule']['timezone'], 'cwd': str(self.root), 'prompt': prompt,
|
|
249
|
+
'prompt_sha256': digest_bytes(prompt.encode('utf-8'))})
|
|
250
|
+
return {'profile': PROFILE, 'slots': slots, 'control': str(self.root), 'execute': False,
|
|
251
|
+
'preserve_model_and_permissions': True, 'natural_trigger_verified': False,
|
|
252
|
+
'next_step': 'Use native host tools to create or reuse each exact original-chat slot, then read back all fields.'}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Bound exact path arguments below platform command-line limits."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def path_batches(paths, budget=4096):
|
|
5
|
+
"""Keep order and literal paths; never broaden a selection to the repository.
|
|
6
|
+
|
|
7
|
+
UTF-16 units plus quoting overhead are conservative for Windows and remain
|
|
8
|
+
small on POSIX. Each caller still validates individual relative paths.
|
|
9
|
+
"""
|
|
10
|
+
batch, used = [], 0
|
|
11
|
+
for path in paths:
|
|
12
|
+
size = len(path.encode('utf-16-le')) // 2 + path.count('"') + path.count('\\') + 3
|
|
13
|
+
if batch and used + size > budget:
|
|
14
|
+
yield batch
|
|
15
|
+
batch, used = [], 0
|
|
16
|
+
batch.append(path)
|
|
17
|
+
used += size
|
|
18
|
+
if batch:
|
|
19
|
+
yield batch
|