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
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""Finite data contracts; natural-language experience never becomes executable code."""
|
|
2
|
+
from copy import deepcopy
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
|
|
6
|
+
from .contracts import validate
|
|
7
|
+
from .worker_tools import schema, string, REF
|
|
8
|
+
from .worker_contracts import _walk
|
|
9
|
+
from .store import GovernanceError
|
|
10
|
+
|
|
11
|
+
VERSION = 1
|
|
12
|
+
MAX_RECORD_BYTES = 4096
|
|
13
|
+
CONDITION = schema({'key': string(), 'equals': string()}, ['key', 'equals'])
|
|
14
|
+
CONDITIONS = {'type': 'array', 'maxItems': 8, 'items': CONDITION}
|
|
15
|
+
REFS = {'type': 'array', 'minItems': 1, 'maxItems': 8, 'items': REF}
|
|
16
|
+
DECISION = schema({'source_id': string(), 'fact_id': string(),
|
|
17
|
+
'revision': {'type': 'integer', 'minimum': 1}}, ['source_id', 'fact_id', 'revision'])
|
|
18
|
+
BASE = {'contract_version': {'type': 'integer', 'enum': [VERSION]},
|
|
19
|
+
'project_id': string(), 'revision': {'type': 'integer', 'minimum': 1},
|
|
20
|
+
'owner_binding_id': string(), 'task_id': string(), 'workspace_id': string(), 'change_reason': string()}
|
|
21
|
+
NOTE_SCHEMA = schema({**BASE, 'experience_id': string(), 'scope': string(enum=['task', 'project']),
|
|
22
|
+
'state': string(enum=['proposed', 'active', 'paused', 'retired']),
|
|
23
|
+
'kind': string(enum=['pitfall', 'practice', 'rejected_option', 'note']),
|
|
24
|
+
'problem': string(), 'suggestion': string(), 'rationale': string(),
|
|
25
|
+
'applies_when': {**CONDITIONS, 'minItems': 1}, 'exclusions': CONDITIONS,
|
|
26
|
+
'reevaluate_when': CONDITIONS, 'evidence_refs': REFS,
|
|
27
|
+
'exclusion_groups': {'type': 'array', 'maxItems': 4, 'items': {**CONDITIONS, 'minItems': 1}},
|
|
28
|
+
'bound_versions': {**REFS, 'minItems': 0},
|
|
29
|
+
'decision_refs': {'type': 'array', 'maxItems': 4, 'items': DECISION},
|
|
30
|
+
'rejected_alternatives': {'type': 'array', 'maxItems': 4, 'items': schema({
|
|
31
|
+
'option': string(), 'reason': string(), 'reconsider_when': string()},
|
|
32
|
+
['option', 'reason', 'reconsider_when'])}},
|
|
33
|
+
[*BASE, 'experience_id', 'scope', 'state', 'problem', 'suggestion',
|
|
34
|
+
'applies_when', 'exclusions', 'reevaluate_when', 'evidence_refs'])
|
|
35
|
+
FEEDBACK_SCHEMA = schema({**BASE, 'feedback_id': string(), 'experience_id': string(),
|
|
36
|
+
'note_revision': {'type': 'integer', 'minimum': 1},
|
|
37
|
+
'outcome': string(enum=['helpful', 'failed', 'corrected', 'not_applicable', 'observation']),
|
|
38
|
+
'summary': string(), 'evidence_refs': REFS,
|
|
39
|
+
'visibility': string(enum=['self', 'task', 'project']),
|
|
40
|
+
'use': schema({'status': string(enum=['applied', 'not_applied', 'unknown']),
|
|
41
|
+
'context': {'type': 'array', 'maxItems': 8, 'items': schema({'key': string(), 'value': string(), 'source': REF}, ['key', 'value', 'source'])}}, ['status', 'context']),
|
|
42
|
+
'application_ref': schema({'feedback_id': string(), 'revision': {'type': 'integer', 'minimum': 1}}, ['feedback_id', 'revision'])},
|
|
43
|
+
[*BASE, 'feedback_id', 'experience_id', 'note_revision', 'outcome', 'summary', 'evidence_refs'])
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def text_bounds(value, key=''):
|
|
47
|
+
if isinstance(value, dict):
|
|
48
|
+
for name, child in value.items():
|
|
49
|
+
text_bounds(child, name)
|
|
50
|
+
elif isinstance(value, list):
|
|
51
|
+
for child in value:
|
|
52
|
+
text_bounds(child, key)
|
|
53
|
+
elif isinstance(value, str):
|
|
54
|
+
if not value.strip() or '\x00' in value or len(value.encode('utf-8')) > 1200:
|
|
55
|
+
raise ValueError('Use nonempty bounded text without NUL')
|
|
56
|
+
if key == 'key' and not re.fullmatch(r'[a-zA-Z0-9][a-zA-Z0-9_.-]{0,79}', value):
|
|
57
|
+
raise ValueError('Condition keys must be finite portable names')
|
|
58
|
+
if key in {'equals', 'value'} and len(value.encode('utf-8')) > 300:
|
|
59
|
+
raise ValueError('Condition values exceed 300 UTF-8 bytes')
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def validate_record(kind, supplied):
|
|
63
|
+
try:
|
|
64
|
+
value = deepcopy(supplied)
|
|
65
|
+
if kind == 'note' and isinstance(value, dict):
|
|
66
|
+
value.setdefault('kind', 'note')
|
|
67
|
+
elif isinstance(value, dict):
|
|
68
|
+
value.setdefault('visibility', 'task')
|
|
69
|
+
validate(value, NOTE_SCHEMA if kind == 'note' else FEEDBACK_SCHEMA)
|
|
70
|
+
_walk(value)
|
|
71
|
+
text_bounds(value)
|
|
72
|
+
if len(json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(',', ':'), allow_nan=False).encode()) > MAX_RECORD_BYTES:
|
|
73
|
+
raise ValueError('Reference long content; experience records allow 4096 UTF-8 bytes')
|
|
74
|
+
for group in ('applies_when', 'exclusions', 'reevaluate_when') if kind == 'note' else ():
|
|
75
|
+
keys = [item['key'] for item in value[group]]
|
|
76
|
+
if len(keys) != len(set(keys)):
|
|
77
|
+
raise ValueError('A condition group cannot repeat a key')
|
|
78
|
+
for field in ('evidence_refs', 'bound_versions'):
|
|
79
|
+
refs = value.get(field, [])
|
|
80
|
+
if len({ref['reference_id'] for ref in refs}) != len(refs):
|
|
81
|
+
raise ValueError('Use one exact revision per source within each group')
|
|
82
|
+
for group in value.get('exclusion_groups', []):
|
|
83
|
+
if len({c['key'] for c in group}) != len(group):
|
|
84
|
+
raise ValueError('Conjunctive exclusion keys must be unique')
|
|
85
|
+
if 'use' in value:
|
|
86
|
+
context = value['use']['context']
|
|
87
|
+
if len({c['key'] for c in context}) != len(context):
|
|
88
|
+
raise ValueError('Application condition keys must be unique')
|
|
89
|
+
except (TypeError, ValueError, UnicodeError, RecursionError) as exc:
|
|
90
|
+
raise GovernanceError('EXPERIENCE_CONTRACT_INVALID', str(exc)) from exc
|
|
91
|
+
return value
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def compare_conditions(note, values):
|
|
95
|
+
"""Pure tri-state selection. Caller values require separate source checking."""
|
|
96
|
+
reasons, missing, missing_groups = [], [], []
|
|
97
|
+
excluded = any(values.get(c['key']) == c['equals'] for c in note['exclusions'])
|
|
98
|
+
mismatched = any(c['key'] in values and values[c['key']] != c['equals'] for c in note['applies_when'])
|
|
99
|
+
for name in ('applies_when', 'exclusions', 'reevaluate_when'):
|
|
100
|
+
absent = [c['key'] for c in note[name] if c['key'] not in values]
|
|
101
|
+
if absent:
|
|
102
|
+
missing_groups.append(name)
|
|
103
|
+
missing.extend(key for key in absent if key not in missing)
|
|
104
|
+
for group in note.get('exclusion_groups', []):
|
|
105
|
+
known_false = any(c['key'] in values and values[c['key']] != c['equals'] for c in group)
|
|
106
|
+
if not known_false:
|
|
107
|
+
absent = [c['key'] for c in group if c['key'] not in values]
|
|
108
|
+
if absent:
|
|
109
|
+
missing.extend(key for key in absent if key not in missing)
|
|
110
|
+
if 'exclusion_groups' not in missing_groups:
|
|
111
|
+
missing_groups.append('exclusion_groups')
|
|
112
|
+
else:
|
|
113
|
+
excluded = True
|
|
114
|
+
reevaluate = any(values.get(c['key']) == c['equals'] for c in note['reevaluate_when'])
|
|
115
|
+
if excluded or mismatched:
|
|
116
|
+
state = 'not_applicable'
|
|
117
|
+
reasons.append('excluded_condition' if excluded else 'prerequisite_mismatch')
|
|
118
|
+
elif missing:
|
|
119
|
+
state = 'unknown'; reasons.append('missing_conditions')
|
|
120
|
+
elif reevaluate:
|
|
121
|
+
state = 'review_required'; reasons.append('reevaluation_condition')
|
|
122
|
+
else:
|
|
123
|
+
state = 'candidate'; reasons.append('supplied_conditions_match')
|
|
124
|
+
if reevaluate and 'reevaluation_condition' not in reasons:
|
|
125
|
+
reasons.append('reevaluation_condition')
|
|
126
|
+
# Bounded group names explain a gap without duplicating potentially long
|
|
127
|
+
# condition keys or weakening the existing tri-state comparison.
|
|
128
|
+
return {'applicability': state, 'reason_codes': reasons, 'missing_evidence': missing,
|
|
129
|
+
'missing_condition_groups': missing_groups}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"""Selected experience in pinned Git views, with no remote task database."""
|
|
2
|
+
import json
|
|
3
|
+
from types import SimpleNamespace
|
|
4
|
+
|
|
5
|
+
from .experience_notes import ExperienceNotes
|
|
6
|
+
from .experience_contracts import validate_record
|
|
7
|
+
from .experience_storage import feedback_scope
|
|
8
|
+
from .worker_contracts import validate_record as validate_worker_record
|
|
9
|
+
from .worker_channel import WorkerChannel, fingerprint, packed, wire_size
|
|
10
|
+
from .exchange_packets import require
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def export_selected(member, references, sources, objects):
|
|
14
|
+
require(isinstance(references, list) and len(references) <= 32, 'Select at most 32 exact experiences.')
|
|
15
|
+
engine = ExperienceNotes(member)
|
|
16
|
+
notes, current, feedback, decisions = {}, {}, {}, {}
|
|
17
|
+
source_map = {(s['reference_id'], s['revision']): s for s in sources}
|
|
18
|
+
|
|
19
|
+
def add_source(ref):
|
|
20
|
+
source = member._source(ref)
|
|
21
|
+
source_map[(source['reference_id'], source['revision'])] = source
|
|
22
|
+
objects[source['content_sha256']] = member._bytes(source)
|
|
23
|
+
|
|
24
|
+
def add_record(record):
|
|
25
|
+
for ref in engine.references(record):
|
|
26
|
+
add_source(ref)
|
|
27
|
+
for ref in record.get('decision_refs', []):
|
|
28
|
+
old, latest = engine.decision(ref, True), engine.decision(ref)
|
|
29
|
+
for value in (old, latest):
|
|
30
|
+
require(value is not None, 'A selected decision dependency is unavailable.', 'EXPERIENCE_DECISION_MISSING')
|
|
31
|
+
decisions[(value['source_id'], value['fact_id'], value['revision'])] = {
|
|
32
|
+
k: value[k] for k in ('source_id', 'fact_id', 'revision', 'kind', 'standing', 'task_id')}
|
|
33
|
+
|
|
34
|
+
for ref in references:
|
|
35
|
+
require(set(ref) == {'experience_id', 'revision', 'content_sha256'}, 'Use an exact experience identity.')
|
|
36
|
+
note = engine.note(ref['experience_id'], ref['revision'])
|
|
37
|
+
require(fingerprint(note) == ref['content_sha256'], 'Selected experience content changed.', 'EXPERIENCE_REVISION_CONFLICT')
|
|
38
|
+
notes[(note['experience_id'], note['revision'])] = note
|
|
39
|
+
latest = engine.note(note['experience_id'])
|
|
40
|
+
current[latest['experience_id']] = latest
|
|
41
|
+
add_record(note); add_record(latest)
|
|
42
|
+
where, params = feedback_scope(member)
|
|
43
|
+
with member.store._connect(readonly=True) as db:
|
|
44
|
+
rows = []
|
|
45
|
+
for row in db.execute("SELECT value FROM records f WHERE collection='experience_feedback' AND json_extract(value,'$.experience_id')=? AND json_extract(value,'$.note_revision')=? AND " + where + ' ORDER BY key', [note['experience_id'], note['revision'], *params]):
|
|
46
|
+
value = validate_record('feedback', json.loads(row[0]))
|
|
47
|
+
if engine.feedback_readable(value):
|
|
48
|
+
rows.append(value)
|
|
49
|
+
require(len(rows) <= 64, 'Select a smaller feedback closure; this experience exceeds one packet.')
|
|
50
|
+
for value in rows:
|
|
51
|
+
feedback[(value['feedback_id'], value['revision'])] = value
|
|
52
|
+
add_record(value)
|
|
53
|
+
if value.get('application_ref'):
|
|
54
|
+
applied = engine.application(value)
|
|
55
|
+
feedback[(applied['feedback_id'], applied['revision'])] = applied
|
|
56
|
+
add_record(applied)
|
|
57
|
+
require(len(source_map) <= 256 and len(feedback) <= 128, 'Select a smaller experience closure.')
|
|
58
|
+
sources[:] = sorted(source_map.values(), key=lambda s: (s['reference_id'], s['revision']))
|
|
59
|
+
heads = []
|
|
60
|
+
for key in sorted({s['reference_id'] for s in sources}):
|
|
61
|
+
latest = member.store.get('worker_sources', key)
|
|
62
|
+
member._source({k: latest[k] for k in ('reference_id', 'revision', 'content_sha256')})
|
|
63
|
+
heads.append(latest)
|
|
64
|
+
return {'version': 1, 'notes': list(notes.values()), 'current_notes': list(current.values()),
|
|
65
|
+
'feedback': list(feedback.values()), 'decisions': list(decisions.values()), 'source_heads': heads,
|
|
66
|
+
'coverage': 'Explicit selected revisions and their accessible dependencies; not all project experience.'}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def validate_view(view, objects):
|
|
70
|
+
value = view.get('experience')
|
|
71
|
+
require(isinstance(value, dict) and set(value) == {'version', 'notes', 'current_notes', 'feedback', 'decisions', 'source_heads', 'coverage'}
|
|
72
|
+
and value['version'] == 1, 'Conditional experience packet is unsupported.', 'EXPERIENCE_CAPABILITY_MISSING')
|
|
73
|
+
require(isinstance(value['notes'], list) and len(value['notes']) <= 32
|
|
74
|
+
and isinstance(value['current_notes'], list) and len(value['current_notes']) <= 32
|
|
75
|
+
and isinstance(value['feedback'], list) and len(value['feedback']) <= 128
|
|
76
|
+
and isinstance(value['decisions'], list) and len(value['decisions']) <= 256, 'Experience view is too large.')
|
|
77
|
+
refs = {(r['reference_id'], r['revision'], r['content_sha256']) for r in view['sources']}
|
|
78
|
+
require(isinstance(value['source_heads'], list) and len(value['source_heads']) <= 256, 'Source policy proof must be bounded.')
|
|
79
|
+
heads = {}
|
|
80
|
+
for supplied in value['source_heads']:
|
|
81
|
+
head = validate_worker_record('source', supplied)
|
|
82
|
+
require(head['reference_id'] not in heads and head['project_id'] == view['project_id']
|
|
83
|
+
and head['state'] == 'active', 'Invalid current source policy proof.')
|
|
84
|
+
heads[head['reference_id']] = head
|
|
85
|
+
require(set(heads) == {s['reference_id'] for s in view['sources']}, 'Current source policy coverage is incomplete.')
|
|
86
|
+
for source in view['sources']:
|
|
87
|
+
head = heads[source['reference_id']]
|
|
88
|
+
require(head['revision'] >= source['revision'] and
|
|
89
|
+
(head['revision'] != source['revision'] or head == source), 'Conflicting current source proof.')
|
|
90
|
+
for kind, records in [('note', value['notes']), ('note', value['current_notes']), ('feedback', value['feedback'])]:
|
|
91
|
+
seen = {}
|
|
92
|
+
for supplied in records:
|
|
93
|
+
record = validate_record(kind, supplied)
|
|
94
|
+
key = (ExperienceNotes.identity(kind, record), record['revision'])
|
|
95
|
+
require(key not in seen, 'Duplicate experience identities in a view.')
|
|
96
|
+
seen[key] = record
|
|
97
|
+
require(record['project_id'] == view['project_id'], 'Experience project mismatch.')
|
|
98
|
+
require(all((r['reference_id'], r['revision'], r['content_sha256']) in refs for r in ExperienceNotes.references(record)), 'Experience evidence closure is incomplete.')
|
|
99
|
+
current = {n['experience_id']: n for n in value['current_notes']}
|
|
100
|
+
require(len(current) == len(value['current_notes']), 'A view has only one current revision per experience.')
|
|
101
|
+
for note in value['notes']:
|
|
102
|
+
latest = current.get(note['experience_id'])
|
|
103
|
+
require(latest is not None and latest['revision'] >= note['revision'], 'Current experience policy is missing.')
|
|
104
|
+
require(all(latest[k] == note[k] for k in ('project_id','owner_binding_id','task_id','workspace_id')), 'Experience identity changed.')
|
|
105
|
+
require(latest['revision'] != note['revision'] or latest == note, 'One revision has conflicting contents.')
|
|
106
|
+
pairs = {(n['experience_id'], n['revision']) for n in value['notes']}
|
|
107
|
+
require(all((f['experience_id'], f['note_revision']) in pairs for f in value['feedback']), 'Feedback targets an unselected revision.')
|
|
108
|
+
decisions = {}
|
|
109
|
+
for d in value['decisions']:
|
|
110
|
+
require(isinstance(d, dict) and set(d) == {'source_id','fact_id','revision','kind','standing','task_id'}
|
|
111
|
+
and d.get('source_id') == view['project_id'] and isinstance(d.get('fact_id'), str)
|
|
112
|
+
and type(d.get('revision')) is int and d['revision'] > 0 and d.get('kind') == 'decision'
|
|
113
|
+
and d.get('standing') in {'current','superseded','historical','disputed'}, 'Invalid decision dependency.')
|
|
114
|
+
key = (d['source_id'], d['fact_id'], d['revision'])
|
|
115
|
+
require(key not in decisions, 'Duplicate decision dependency.')
|
|
116
|
+
decisions[key] = d
|
|
117
|
+
require(all((r['source_id'], r['fact_id'], r['revision']) in decisions
|
|
118
|
+
for n in value['notes'] + value['current_notes'] for r in n.get('decision_refs', [])), 'Missing exact decision dependency.')
|
|
119
|
+
# Ordinary source validation verifies every selected byte/hash at endpoint join.
|
|
120
|
+
return value
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def validate_reply(view, records):
|
|
124
|
+
require('experience' in view, 'Refresh to an experience-enabled view before reporting results.', 'EXPERIENCE_CAPABILITY_MISSING')
|
|
125
|
+
require(isinstance(records, list) and len(records) <= 32, 'A reply contains at most 32 selected experience results.')
|
|
126
|
+
selected = {(n['experience_id'], n['revision']) for n in view['experience']['notes']}
|
|
127
|
+
seen = set()
|
|
128
|
+
for supplied in records:
|
|
129
|
+
record = validate_record('feedback', supplied)
|
|
130
|
+
require(record['feedback_id'] not in seen, 'Select one revision per feedback identity.')
|
|
131
|
+
seen.add(record['feedback_id'])
|
|
132
|
+
require(record['project_id'] == view['project_id'] and record['owner_binding_id'] == view['binding_id'],
|
|
133
|
+
'A reply cannot author another member result.', 'WORKER_ACTOR_MISMATCH')
|
|
134
|
+
require((record['experience_id'], record['note_revision']) in selected, 'Feedback needs the exact selected experience revision.', 'EXPERIENCE_VERSION_MISSING')
|
|
135
|
+
require(any(a['task_id'] == record['task_id'] and a['workspace_id'] == record['workspace_id'] and
|
|
136
|
+
'experience_feedback' in a['write_actions'] for a in view['binding']['assignments']),
|
|
137
|
+
'The cached member does not have result-reporting scope.', 'WORKER_SCOPE_DENIED')
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class CachedExperience(ExperienceNotes):
|
|
141
|
+
"""The same assessment implementation backed by immutable view records only."""
|
|
142
|
+
def __init__(self, view, objects):
|
|
143
|
+
selected = validate_view(view, objects)
|
|
144
|
+
self.selected = selected
|
|
145
|
+
rows = {}
|
|
146
|
+
for note in selected['notes'] + selected['current_notes']:
|
|
147
|
+
rows[('experience_note_versions', self.version_key(note['experience_id'], note['revision']))] = note
|
|
148
|
+
for note in selected['current_notes']:
|
|
149
|
+
rows[('experience_notes', note['experience_id'])] = note
|
|
150
|
+
for feedback in selected['feedback']:
|
|
151
|
+
key = feedback['feedback_id']
|
|
152
|
+
rows[('experience_feedback_versions', self.version_key(key, feedback['revision']))] = feedback
|
|
153
|
+
if rows.get(('experience_feedback', key), {}).get('revision', 0) < feedback['revision']:
|
|
154
|
+
rows[('experience_feedback', key)] = feedback
|
|
155
|
+
for decision in selected['decisions']:
|
|
156
|
+
key = fingerprint(decision['source_id']) + ':' + decision['fact_id']
|
|
157
|
+
rows[('governance_fact_history', self.version_key(key, decision['revision']))] = decision
|
|
158
|
+
if rows.get(('governance_facts', key), {}).get('revision', 0) < decision['revision']:
|
|
159
|
+
rows[('governance_facts', key)] = decision
|
|
160
|
+
for source in view['sources']:
|
|
161
|
+
key = source['reference_id']
|
|
162
|
+
rows[('worker_versions', 'source:' + key + ':' + str(source['revision']))] = source
|
|
163
|
+
for source in selected['source_heads']:
|
|
164
|
+
rows[('worker_sources', source['reference_id'])] = source
|
|
165
|
+
|
|
166
|
+
store = SimpleNamespace(get=lambda collection, key, default=None: rows.get((collection, key), default))
|
|
167
|
+
channel = SimpleNamespace(store=store, project_id=view['project_id'], actor=view['binding_id'], binding=view['binding'])
|
|
168
|
+
channel._source = lambda ref: WorkerChannel._source(channel, ref)
|
|
169
|
+
channel._bytes = lambda source: objects[source['content_sha256']]
|
|
170
|
+
super().__init__(channel)
|
|
171
|
+
|
|
172
|
+
def feedback_count(self, key, revision):
|
|
173
|
+
latest = {f['feedback_id']: self.store.get('experience_feedback', f['feedback_id']) for f in self.selected['feedback']}
|
|
174
|
+
return sum(1 for f in latest.values() if f['experience_id'] == key and f['note_revision'] == revision
|
|
175
|
+
and f['outcome'] in {'failed', 'corrected'} and self.feedback_readable(f))
|
|
176
|
+
|
|
177
|
+
def read(self, view, section='notes', experience_id=None, revision=None, task_id=None, state='active', feedback_id=None,
|
|
178
|
+
context=None, limit=5, cursor=None, previous_fingerprint=None):
|
|
179
|
+
require(section in {'notes', 'get', 'history', 'feedback', 'feedback_get', 'feedback_history'}, 'Unsupported cached experience query.')
|
|
180
|
+
key = fingerprint([view['view_id'], section, experience_id, feedback_id, revision, task_id, state, context])
|
|
181
|
+
start = WorkerChannel._cursor(cursor, key, view['view_id']) if cursor else 0
|
|
182
|
+
require(type(start) is int and start >= 0, 'Invalid cached experience cursor.')
|
|
183
|
+
base = {'last_known': True, 'live_governor_checked': False, 'read_only': True, 'effects_executed': False,
|
|
184
|
+
'observed_at': view['created_at'], 'coverage': self.selected['coverage'], 'fingerprint': key}
|
|
185
|
+
if section == 'get':
|
|
186
|
+
return {**base, **self.get('note', experience_id, revision)}
|
|
187
|
+
if section == 'feedback_get':
|
|
188
|
+
return {**base, **self.get('feedback', feedback_id, revision)}
|
|
189
|
+
if section == 'feedback_history':
|
|
190
|
+
self.get('feedback', feedback_id)
|
|
191
|
+
if section in {'history', 'feedback'}:
|
|
192
|
+
self.note(experience_id)
|
|
193
|
+
values, gaps = self.context_values(context or [])
|
|
194
|
+
if section == 'feedback_history':
|
|
195
|
+
rows = [f for f in self.selected['feedback'] if f['feedback_id'] == feedback_id and self.feedback_readable(f)]
|
|
196
|
+
elif section == 'feedback':
|
|
197
|
+
latest = {f['feedback_id']: self.store.get('experience_feedback', f['feedback_id']) for f in self.selected['feedback']}
|
|
198
|
+
rows = [f for f in latest.values() if f['experience_id'] == experience_id and
|
|
199
|
+
(revision is None or f['note_revision'] == revision) and self.feedback_readable(f)]
|
|
200
|
+
else:
|
|
201
|
+
rows = [n for n in self.selected['notes'] if self.visible(n) and
|
|
202
|
+
(n['experience_id'] == experience_id if section == 'history' else n['state'] == state and
|
|
203
|
+
(task_id is None or n['scope'] == 'project' or n['task_id'] == task_id))]
|
|
204
|
+
items = []
|
|
205
|
+
for record in rows[start:start + limit]:
|
|
206
|
+
item = (self.get('feedback', record['feedback_id'], record['revision']) if section in {'feedback', 'feedback_history'} else self.assessed(record, values))
|
|
207
|
+
candidate = {**base, 'items': items + [item], 'context_gaps': gaps}
|
|
208
|
+
if len(packed(candidate)) > 5700 or wire_size(candidate) > 14500:
|
|
209
|
+
break
|
|
210
|
+
items.append(item)
|
|
211
|
+
require(not rows[start:] or items, 'A cached record exceeds the response budget.')
|
|
212
|
+
end = start + len(items)
|
|
213
|
+
return {**base, 'items': items, 'returned': len(items), 'context_gaps': gaps, 'has_more': end < len(rows),
|
|
214
|
+
'next_cursor': WorkerChannel._encode(key, view['view_id'], end) if end < len(rows) else None}
|