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
@@ -0,0 +1,212 @@
1
+ """Configure one WorkBuddy conversation in its working folder without creating another ledger."""
2
+ import base64
3
+ from contextlib import ExitStack
4
+ import hashlib
5
+ import json
6
+ import os
7
+ from pathlib import Path
8
+ import re
9
+ import shlex
10
+ import sys
11
+
12
+ from .member_join import checked_url, fingerprint, read_configuration
13
+ from .member_routing import connector_path, host_directory, read_route, workbuddy_scope
14
+ from .setup import atomic_write, encoded, safe_target, setup_lock
15
+ from .workbuddy_capture import CONFIG, EVENTS, STATUS, device_call, note, ordinary, read_json, session_id
16
+
17
+
18
+ def workspace_session(root, host, requested):
19
+ if requested != 'auto':
20
+ if session_id(requested):
21
+ return requested
22
+ raise ValueError('Use the native ID of this WorkBuddy chat.')
23
+ for name in ('WORKBUDDY_SESSION_ID', 'CODEBUDDY_SESSION_ID'):
24
+ native = os.environ.get(name)
25
+ if session_id(native):
26
+ return native
27
+ # Only look under the selected workspace's project-folder name. An
28
+ # unfamiliar layout requires an explicit host ID, never a guess from text.
29
+ slugs = set()
30
+ for raw in {str(root), root.as_posix()}:
31
+ slugs.add(re.sub(r'[^\w-]', '-', raw).casefold())
32
+ slugs.add(re.sub(r'[/\\:]', '-', raw).casefold())
33
+ slugs.add(hashlib.sha256(raw.encode()).hexdigest())
34
+ projects = host / 'projects'
35
+ candidates = set()
36
+ if projects.is_dir() and ordinary(projects):
37
+ for directory in projects.iterdir():
38
+ if directory.name.casefold() not in slugs or not ordinary(directory) or not directory.is_dir():
39
+ continue
40
+ for path in directory.glob('*.jsonl'):
41
+ if not session_id(path.stem) or not ordinary(path) or not path.is_file():
42
+ continue
43
+ with path.open('rb') as stream:
44
+ prefix = stream.read(131072)
45
+ for line in prefix.splitlines()[:24]:
46
+ try:
47
+ row = json.loads(line)
48
+ except (ValueError, UnicodeError):
49
+ continue
50
+ if isinstance(row, dict) and isinstance(row.get('cwd'), str) and Path(row['cwd']) == root:
51
+ if row.get('sessionId', path.stem) == path.stem:
52
+ candidates.add(path.stem)
53
+ break
54
+ if len(candidates) != 1:
55
+ raise ValueError("Supply this chat's native session_id from WorkBuddy. This folder has no unique matching session.")
56
+ return candidates.pop()
57
+
58
+
59
+ def hook_command(root):
60
+ location = base64.urlsafe_b64encode(str(root).encode('utf-8')).decode('ascii')
61
+ args = '-I -B -X utf8 -m taskcarry.workbuddy_capture --workspace64 ' + location
62
+ if os.name != 'nt':
63
+ return shlex.quote(sys.executable) + ' ' + args
64
+ # WorkBuddy can launch commands through different Windows shells. Do not
65
+ # interpolate user paths in them; preserve the callback's byte streams.
66
+ executable = sys.executable.replace("'", "''")
67
+ script = ("$p=New-Object System.Diagnostics.ProcessStartInfo;"
68
+ "$p.UseShellExecute=$false;$p.FileName='" + executable + "';$p.Arguments='" + args + "';"
69
+ "$c=[System.Diagnostics.Process]::Start($p);$c.WaitForExit();exit $c.ExitCode")
70
+ script64 = base64.b64encode(script.encode('utf-16le')).decode('ascii')
71
+ return 'powershell.exe -NoLogo -NoProfile -NonInteractive -EncodedCommand ' + script64
72
+
73
+
74
+ def contents(path):
75
+ if not path.exists():
76
+ return None
77
+ if not path.is_file() or path.stat().st_size > 1024 * 1024:
78
+ raise ValueError('Existing settings cannot be safely merged.')
79
+ return path.read_bytes()
80
+
81
+
82
+ def hook_settings(raw, command, previous, enable):
83
+ value = json.loads(raw.decode('utf-8-sig')) if raw is not None else {}
84
+ if not isinstance(value, dict) or not isinstance(value.get('hooks', {}), dict):
85
+ raise ValueError('Preserve existing WorkBuddy settings and review their format.')
86
+ hooks = value.setdefault('hooks', {})
87
+ def group(cmd):
88
+ return {'matcher':'', 'hooks':[{'type':'command', 'command':cmd}]}
89
+ for event in EVENTS:
90
+ groups = hooks.get(event, [])
91
+ if not isinstance(groups, list):
92
+ raise ValueError('Preserve existing hook groups and review their format.')
93
+ keep = [g for g in groups if g != group(command) and (not previous or g != group(previous))]
94
+ if enable:
95
+ keep.append(group(command))
96
+ if keep or event in hooks:
97
+ hooks[event] = keep
98
+ if raw is not None and value == json.loads(raw.decode('utf-8-sig')):
99
+ return raw
100
+ return encoded(value) + b'\n'
101
+
102
+
103
+ def configure(workspace, *, mode='plan', server=None, conversation_id='auto', settings_scope='auto',
104
+ edition='workbuddy', plan_id=None, home=None, call=device_call):
105
+ selected = Path(workspace).absolute()
106
+ if not ordinary(selected) or not selected.is_dir() or selected in (Path.home(), Path(selected.anchor)):
107
+ raise ValueError("Select the working chat's own ordinary folder.")
108
+ root = selected.resolve()
109
+ local = safe_target(root, CONFIG)
110
+ prior = read_json(local) if local.is_file() else {}
111
+ if mode == 'status':
112
+ status = safe_target(root, STATUS)
113
+ return {'configured':bool(prior), 'session_id':prior.get('session_id'),
114
+ 'server':prior.get('server'), 'settings_scope':prior.get('settings_scope'),
115
+ 'last_event':read_json(status) if status.is_file() else None}
116
+ if mode not in ('plan','execute') or settings_scope not in ('auto','project','user'):
117
+ raise ValueError('Preview the project or user WorkBuddy settings before applying them.')
118
+ host = host_directory(edition, home)
119
+ sid = workspace_session(root, host, conversation_id)
120
+ if not isinstance(server, str) or not re.fullmatch('taskcarry-member-[a-f0-9]{16}', server):
121
+ raise ValueError('Use the exact server name returned by join_worker.')
122
+ route = read_route(root, server)
123
+ if route and route.get('edition') != edition:
124
+ raise ValueError('Use the WorkBuddy edition selected for this invitation.')
125
+ settings_scope, reason = workbuddy_scope(settings_scope, prior or route, host, server)
126
+ target = connector_path(root, host, route.get('settings_scope', 'project'))
127
+ entry = read_configuration(target).get('mcpServers', {}).get(server) or {}
128
+ endpoint = entry.get('url', '')
129
+ if not isinstance(endpoint, str) or not endpoint.endswith('/mcp'):
130
+ raise ValueError('Join the invited team from this work folder first.')
131
+ checked_url(endpoint[:-4] + '/join')
132
+ if prior and (prior.get('session_id'), prior.get('server'), prior.get('host_home')) != (sid, server, str(host)):
133
+ raise ValueError('This folder already belongs to a different chat. Select its own working folder.')
134
+ command = hook_command(root)
135
+ cfg = dict(server=server, endpoint=endpoint, session_id=sid, host_home=str(host),
136
+ settings_scope=settings_scope, command=command)
137
+
138
+ def prepare():
139
+ if read_configuration(target).get('mcpServers', {}).get(server) != entry:
140
+ raise ValueError('The project member connection changed. Preview again.')
141
+ old_cfg = contents(local)
142
+ if (json.loads(old_cfg) if old_cfg else {}) != prior:
143
+ raise ValueError('The selected chat changed. Preview again.')
144
+ targets = []
145
+ scopes = {settings_scope}
146
+ if prior:
147
+ scopes.add(prior['settings_scope'])
148
+ for scope in sorted(scopes):
149
+ path = (safe_target(root, '.workbuddy/settings.json') if scope == 'project'
150
+ else safe_target(host, 'settings.json'))
151
+ old = contents(path)
152
+ if old is not None or scope == settings_scope:
153
+ targets.append((path, old, hook_settings(old, command, prior.get('command'), scope == settings_scope)))
154
+ effective_mcp = connector_path(root, host, settings_scope)
155
+ if effective_mcp != target:
156
+ old = contents(effective_mcp)
157
+ existing = read_configuration(effective_mcp)
158
+ servers = existing.setdefault('mcpServers', {})
159
+ if server in servers and servers[server] != entry:
160
+ raise ValueError('The installed connector differs. Preserve it and review the connection.')
161
+ if server in servers:
162
+ new = old
163
+ else:
164
+ servers[server] = entry
165
+ new = encoded(existing) + b'\n'
166
+ targets.append((effective_mcp, old, new))
167
+ targets.append((local, old_cfg, encoded(cfg)))
168
+ basis = [(str(path), hashlib.sha256(new).hexdigest()) for path, old, new in targets]
169
+ return [(p, a, b) for p, a, b in targets if a != b], fingerprint([cfg, fingerprint(entry), basis])
170
+
171
+ edits, plan = prepare()
172
+ summary = {'server':server, 'session_id':sid, 'settings_scope':settings_scope, 'scope_reason':reason,
173
+ 'targets':[str(p) for p,_,_ in edits], 'plan_id':plan}
174
+ if mode == 'plan':
175
+ return {**summary, 'state':'planned', 'effects_executed':False}
176
+ if plan != plan_id:
177
+ raise ValueError('Preview the current WorkBuddy settings before applying them.')
178
+ with ExitStack() as stack:
179
+ stack.enter_context(setup_lock(root))
180
+ if 'user' in (settings_scope, prior.get('settings_scope')):
181
+ stack.enter_context(setup_lock(host))
182
+ edits, current = prepare()
183
+ if current != plan_id:
184
+ raise ValueError('WorkBuddy settings changed. Preview again.')
185
+ written = []
186
+ try:
187
+ for path, old, new in edits:
188
+ if contents(path) != old:
189
+ raise ValueError('WorkBuddy settings changed while applying them.')
190
+ atomic_write(path, new)
191
+ written.append((path, old, new))
192
+ except Exception:
193
+ for path, old, new in reversed(written):
194
+ if contents(path) == new:
195
+ if old is None:
196
+ path.unlink()
197
+ else:
198
+ atomic_write(path, old)
199
+ raise
200
+ # Repeating registration is safe if the response was lost after writing
201
+ # the local settings. It never changes an existing board consent.
202
+ try:
203
+ state = call(root, cfg, 'register')
204
+ except (OSError, ValueError):
205
+ note(root, 'registration_pending')
206
+ return {**summary, 'state':'registration_pending', 'effects_executed':bool(edits),
207
+ 'native_loading_verified':False,
208
+ 'next_step':'Local settings are in place. Restore the member connection, then preview and retry.'}
209
+ if not safe_target(root, STATUS).is_file() or read_json(safe_target(root, STATUS)).get('status') == 'registration_pending':
210
+ note(root, 'registered')
211
+ return {**summary, 'state':'registered', 'effects_executed':True, 'sharing':state['state'],
212
+ 'conversation_id':state['conversation_id'], 'native_loading_verified':False}