@pennixrv/trellis 0.7.2-beta.24 → 0.7.2-beta.26
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.
- package/dist/commands/ablate.d.ts.map +1 -1
- package/dist/commands/ablate.js +13 -0
- package/dist/commands/ablate.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +13 -9
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +82 -7
- package/dist/commands/update.js.map +1 -1
- package/dist/configurators/codex.d.ts.map +1 -1
- package/dist/configurators/codex.js +10 -6
- package/dist/configurators/codex.js.map +1 -1
- package/dist/migrations/manifests/0.7.2-beta.25.json +8 -0
- package/dist/migrations/manifests/0.7.2-beta.26.json +8 -0
- package/dist/templates/codex/config.toml +2 -0
- package/dist/templates/codex/hooks/turn-guard.py +66 -0
- package/dist/templates/codex/hooks.json +63 -0
- package/dist/templates/common/bundled-skills/trellis-decision-space-construction-and-merging/workflow.md +3 -1
- package/dist/templates/common/bundled-skills/trellis-delivery-review-and-closeout/workflow.md +4 -0
- package/dist/templates/common/bundled-skills/trellis-goal-exploration-and-requirements/workflow.md +2 -0
- package/dist/templates/common/bundled-skills/trellis-solution-design-and-convergence/workflow.md +4 -0
- package/dist/templates/common/bundled-skills/trellis-task-implementation/workflow.md +3 -1
- package/dist/templates/common/commands/continue.md +7 -0
- package/dist/templates/shared-hooks/index.d.ts.map +1 -1
- package/dist/templates/shared-hooks/index.js +1 -0
- package/dist/templates/shared-hooks/index.js.map +1 -1
- package/dist/templates/shared-hooks/inject-shell-session-context.py +24 -1
- package/dist/templates/trellis/index.d.ts.map +1 -1
- package/dist/templates/trellis/index.js +1 -0
- package/dist/templates/trellis/index.js.map +1 -1
- package/dist/templates/trellis/scripts/common/task_move.py +9 -3
- package/dist/templates/trellis/scripts/common/task_turn.py +471 -0
- package/dist/templates/trellis/scripts/task.py +11 -0
- package/dist/templates/trellis/workflow.md +2 -0
- package/dist/utils/ablation-store.d.ts.map +1 -1
- package/dist/utils/ablation-store.js +17 -1
- package/dist/utils/ablation-store.js.map +1 -1
- package/dist/utils/asset-backup.d.ts +1 -0
- package/dist/utils/asset-backup.d.ts.map +1 -1
- package/dist/utils/asset-backup.js +110 -15
- package/dist/utils/asset-backup.js.map +1 -1
- package/dist/utils/atomic-write.d.ts +1 -1
- package/dist/utils/atomic-write.d.ts.map +1 -1
- package/dist/utils/atomic-write.js +8 -2
- package/dist/utils/atomic-write.js.map +1 -1
- package/dist/utils/codex-config-ownership.d.ts +13 -0
- package/dist/utils/codex-config-ownership.d.ts.map +1 -0
- package/dist/utils/codex-config-ownership.js +64 -0
- package/dist/utils/codex-config-ownership.js.map +1 -0
- package/dist/utils/managed-removal.d.ts.map +1 -1
- package/dist/utils/managed-removal.js +36 -6
- package/dist/utils/managed-removal.js.map +1 -1
- package/dist/utils/retired-native-assets.d.ts.map +1 -1
- package/dist/utils/retired-native-assets.js +5 -19
- package/dist/utils/retired-native-assets.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
"""Codex turn exit evidence; not a task lifecycle or permission authority."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import hashlib
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
import re
|
|
11
|
+
import shlex
|
|
12
|
+
import time
|
|
13
|
+
import uuid
|
|
14
|
+
|
|
15
|
+
from .active_task import _context_path, _write_json, resolve_context_key
|
|
16
|
+
from .io import JSON_READ_MISSING, read_json_checked, write_json
|
|
17
|
+
from .task_move import layout_lock, require_settled_layout
|
|
18
|
+
from .task_utils import resolve_task_dir
|
|
19
|
+
from .task_workflow import _artifact_digest, _state
|
|
20
|
+
|
|
21
|
+
KINDS = ("bounded_reply", "task_complete", "waiting_authorization",
|
|
22
|
+
"waiting_input", "external_block", "user_stop")
|
|
23
|
+
SCOPES = ("explanation", "inspection", "handoff_admission")
|
|
24
|
+
TICKET_ID = re.compile(r"[0-9a-f]{32}\Z")
|
|
25
|
+
MAX_CORRECTIONS = 2
|
|
26
|
+
TICKET_SECONDS = 30
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TurnError(ValueError):
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _digest(value: object) -> str:
|
|
34
|
+
return hashlib.sha256(json.dumps(value, ensure_ascii=False, sort_keys=True,
|
|
35
|
+
separators=(",", ":")).encode()).hexdigest()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _text(value: object, name: str, limit: int = 512) -> str:
|
|
39
|
+
if not isinstance(value, str) or not value.strip() or len(value) > limit:
|
|
40
|
+
raise TurnError(f"TASK_TURN_INVALID: missing or invalid {name}")
|
|
41
|
+
return value
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _runtime_path(root: Path, path: Path) -> Path:
|
|
45
|
+
runtime = root / ".trellis/.runtime"
|
|
46
|
+
path.relative_to(runtime)
|
|
47
|
+
if runtime.is_symlink():
|
|
48
|
+
raise TurnError("TASK_TURN_WITHHELD: redirected runtime")
|
|
49
|
+
current = runtime
|
|
50
|
+
for part in path.relative_to(runtime).parts:
|
|
51
|
+
current = current / part
|
|
52
|
+
if current.is_symlink():
|
|
53
|
+
raise TurnError("TASK_TURN_WITHHELD: redirected runtime")
|
|
54
|
+
if path.exists() and not path.is_file():
|
|
55
|
+
raise TurnError("TASK_TURN_WITHHELD: runtime record is not a regular file")
|
|
56
|
+
return path
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _read(path: Path, *, missing: bool = False) -> dict:
|
|
60
|
+
value, reason = read_json_checked(path)
|
|
61
|
+
if value is None:
|
|
62
|
+
if missing and reason == JSON_READ_MISSING:
|
|
63
|
+
return {}
|
|
64
|
+
raise TurnError("TASK_TURN_WITHHELD: runtime record is " + str(reason))
|
|
65
|
+
return value
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _session(root: Path, key: str) -> tuple[Path, dict]:
|
|
69
|
+
path = _runtime_path(root, _context_path(root, key))
|
|
70
|
+
return path, _read(path, missing=True)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _save(path: Path, context: dict) -> None:
|
|
74
|
+
if not _write_json(path, context):
|
|
75
|
+
raise TurnError("TASK_TURN_WRITE_FAILED: could not save session")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _turn(context: dict, session: str | None = None, turn_id: str | None = None) -> dict:
|
|
79
|
+
value = context.get("turn")
|
|
80
|
+
if (not isinstance(value, dict)
|
|
81
|
+
or set(value) != {"schema_version", "session_id", "turn_id", "prompt_digest", "corrections",
|
|
82
|
+
"evidence", "answers", "interrupted", "observed_task"}
|
|
83
|
+
or type(value.get("schema_version")) is not int
|
|
84
|
+
or value["schema_version"] != 1
|
|
85
|
+
or type(value.get("corrections")) is not int
|
|
86
|
+
or not 0 <= value["corrections"] <= MAX_CORRECTIONS
|
|
87
|
+
or not isinstance(value.get("answers"), dict)
|
|
88
|
+
or not isinstance(value.get("interrupted"), bool)
|
|
89
|
+
or not isinstance(value.get("session_id"), str) or not value["session_id"]
|
|
90
|
+
or not isinstance(value.get("turn_id"), str) or not value["turn_id"]
|
|
91
|
+
or not re.fullmatch(r"[0-9a-f]{64}", str(value.get("prompt_digest")))
|
|
92
|
+
or session is not None and value.get("session_id") != session
|
|
93
|
+
or turn_id is not None and value.get("turn_id") != turn_id):
|
|
94
|
+
raise TurnError("TASK_TURN_WITHHELD: missing, stale or incompatible turn")
|
|
95
|
+
for call_id, answer in value["answers"].items():
|
|
96
|
+
if (not isinstance(call_id, str) or not call_id
|
|
97
|
+
or not isinstance(answer, dict) or set(answer) != {"input_digest", "response_digest", "status"}
|
|
98
|
+
or not re.fullmatch(r"[0-9a-f]{64}", str(answer["input_digest"]))
|
|
99
|
+
or answer["response_digest"] is not None and not re.fullmatch(r"[0-9a-f]{64}", str(answer["response_digest"]))
|
|
100
|
+
or not isinstance(answer["status"], str)
|
|
101
|
+
or answer["status"] not in {"pending", "complete", "incomplete"}):
|
|
102
|
+
raise TurnError("TASK_TURN_WITHHELD: incompatible answer observation")
|
|
103
|
+
return value
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _identity(event: dict) -> tuple[str, str, str]:
|
|
107
|
+
session = _text(event.get("session_id"), "native session_id")
|
|
108
|
+
turn_id = _text(event.get("turn_id"), "native turn_id")
|
|
109
|
+
key = resolve_context_key(event, platform="codex", allow_environment_context=False)
|
|
110
|
+
if key is None:
|
|
111
|
+
raise TurnError("TASK_TURN_WITHHELD: direct Codex identity is required")
|
|
112
|
+
return key, session, turn_id
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _snapshot(root: Path, context: dict, turn: dict) -> dict | None:
|
|
116
|
+
ref = context.get("current_task") or turn.get("observed_task")
|
|
117
|
+
if ref is None:
|
|
118
|
+
return None
|
|
119
|
+
if not isinstance(ref, str):
|
|
120
|
+
raise TurnError("TASK_TURN_WITHHELD: invalid task pointer")
|
|
121
|
+
# Native basename resolution also handles a task moved by complete/cancel.
|
|
122
|
+
directory = resolve_task_dir(ref if (root / ref).exists() else Path(ref).name, root)
|
|
123
|
+
if directory is None:
|
|
124
|
+
raise TurnError("TASK_TURN_WITHHELD: task is missing or ambiguous")
|
|
125
|
+
task = _read(directory / "task.json")
|
|
126
|
+
meta = task.get("meta", {})
|
|
127
|
+
if not isinstance(meta, dict):
|
|
128
|
+
raise TurnError("TASK_TURN_WITHHELD: invalid task metadata")
|
|
129
|
+
state = _state(meta) if meta.get("task_workflow") is not None else None
|
|
130
|
+
artifacts = {}
|
|
131
|
+
if state:
|
|
132
|
+
for phase, record in state["phases"].items():
|
|
133
|
+
artifacts[phase] = _artifact_digest(directory, record["artifact_refs"])
|
|
134
|
+
phase_id = state["current_phase_id"] if state else None
|
|
135
|
+
return {"id": task.get("id") or task.get("name"),
|
|
136
|
+
"path": directory.relative_to(root).as_posix(), "status": task.get("status"),
|
|
137
|
+
"record_digest": _digest(task), "artifacts": artifacts,
|
|
138
|
+
"phase_id": phase_id,
|
|
139
|
+
"phase_status": state["phases"][phase_id]["status"] if state and phase_id else None,
|
|
140
|
+
"route_revision": state["task_route_revision"] if state else None,
|
|
141
|
+
"input_revision": state["input_revision"] if state else None,
|
|
142
|
+
"closeout": state.get("closeout_disposition") if state else None}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def begin(root: Path, event: dict) -> dict:
|
|
146
|
+
key, session, turn_id = _identity(event)
|
|
147
|
+
prompt = _text(event.get("prompt"), "prompt", 1024 * 1024)
|
|
148
|
+
with layout_lock(root):
|
|
149
|
+
require_settled_layout(root)
|
|
150
|
+
path, context = _session(root, key)
|
|
151
|
+
previous = _turn(context) if "turn" in context else None
|
|
152
|
+
if previous and previous["turn_id"] == turn_id and previous["prompt_digest"] == _digest(prompt):
|
|
153
|
+
_turn(context, session, turn_id)
|
|
154
|
+
return previous
|
|
155
|
+
turn = {"schema_version": 1, "session_id": session, "turn_id": turn_id,
|
|
156
|
+
"prompt_digest": _digest(prompt),
|
|
157
|
+
"corrections": 0,
|
|
158
|
+
"evidence": None, "answers": {}, "interrupted": False,
|
|
159
|
+
}
|
|
160
|
+
snapshot = _snapshot(root, context, {})
|
|
161
|
+
turn["observed_task"] = snapshot["path"] if snapshot else None
|
|
162
|
+
context["turn"] = turn
|
|
163
|
+
_save(path, context)
|
|
164
|
+
return turn
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _invocation(root: Path, command: str) -> tuple[list[str], str | None]:
|
|
168
|
+
if os.name != "posix":
|
|
169
|
+
raise TurnError("TASK_TURN_UNSUPPORTED: invocation rewriting requires a verified POSIX shell")
|
|
170
|
+
if any(c in command for c in ("$", "`", "\n", "\r")):
|
|
171
|
+
raise TurnError("TASK_TURN_WITHHELD: expansions and multiline shell commands are unsupported")
|
|
172
|
+
lexer = shlex.shlex(command, posix=True, punctuation_chars=";&|<>()")
|
|
173
|
+
lexer.whitespace_split = True
|
|
174
|
+
lexer.commenters = ""
|
|
175
|
+
tokens = list(lexer)
|
|
176
|
+
if any(token and all(c in ";&|<>()" for c in token) for token in tokens):
|
|
177
|
+
raise TurnError("TASK_TURN_WITHHELD: use one direct Python task.py turn command")
|
|
178
|
+
if len(tokens) < 4 or Path(tokens[0]).name not in {"python", "python3"}:
|
|
179
|
+
raise TurnError("TASK_TURN_WITHHELD: use Python directly")
|
|
180
|
+
index = 3 if tokens[1:3] == ["-X", "utf8"] else 1
|
|
181
|
+
if (len(tokens) <= index + 2 or (root / tokens[index]).resolve() != (root / ".trellis/scripts/task.py").resolve()
|
|
182
|
+
or tokens[index + 1] != "turn" or tokens[index + 2] not in {"show", "record"}):
|
|
183
|
+
raise TurnError("TASK_TURN_WITHHELD: not a native turn invocation")
|
|
184
|
+
argv = tokens[index + 2:]
|
|
185
|
+
ticket = None
|
|
186
|
+
if "--invocation-ticket" in argv:
|
|
187
|
+
if len(argv) < 3 or argv[-2] != "--invocation-ticket" or argv.count("--invocation-ticket") != 1:
|
|
188
|
+
raise TurnError("TASK_TURN_WITHHELD: invalid invocation ticket argument")
|
|
189
|
+
ticket = argv[-1]
|
|
190
|
+
argv = argv[:-2]
|
|
191
|
+
return argv, ticket
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _ticket_path(root: Path, ticket_id: str) -> Path:
|
|
195
|
+
if not TICKET_ID.fullmatch(ticket_id):
|
|
196
|
+
raise TurnError("TASK_TURN_WITHHELD: invalid invocation ticket")
|
|
197
|
+
return _runtime_path(root, root / ".trellis/.runtime/shell-tickets" / f"turn-{ticket_id}.json")
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _expire_tickets(root: Path) -> None:
|
|
201
|
+
directory = root / ".trellis/.runtime/shell-tickets"
|
|
202
|
+
for path in directory.glob("turn-*.json"):
|
|
203
|
+
if not TICKET_ID.fullmatch(path.stem[5:]):
|
|
204
|
+
continue
|
|
205
|
+
try:
|
|
206
|
+
ticket = _read(_runtime_path(root, path))
|
|
207
|
+
except TurnError:
|
|
208
|
+
continue
|
|
209
|
+
if (set(ticket) == {"schema_version", "context_key", "session_id", "turn_id", "tool_use_id",
|
|
210
|
+
"cwd", "argv_digest", "snapshot_digest", "expires_at_epoch", "used"}
|
|
211
|
+
and type(ticket.get("schema_version")) is int and ticket["schema_version"] == 1
|
|
212
|
+
and ticket.get("cwd") == str(root.resolve())
|
|
213
|
+
and type(ticket.get("used")) is bool
|
|
214
|
+
and type(ticket.get("expires_at_epoch")) in (int, float)
|
|
215
|
+
and ticket["expires_at_epoch"] < time.time()):
|
|
216
|
+
path.unlink()
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def ticket_input(root: Path, event: dict) -> dict:
|
|
220
|
+
key, session, turn_id = _identity(event)
|
|
221
|
+
tool_input = event.get("tool_input")
|
|
222
|
+
if not isinstance(tool_input, dict):
|
|
223
|
+
raise TurnError("TASK_TURN_WITHHELD: invalid Bash input")
|
|
224
|
+
command = _text(tool_input.get("command"), "Bash command", 16384)
|
|
225
|
+
argv, existing = _invocation(root, command)
|
|
226
|
+
call_id = _text(event.get("tool_use_id"), "tool_use_id")
|
|
227
|
+
cwd = Path(_text(event.get("cwd"), "cwd", 4096)).resolve()
|
|
228
|
+
if cwd != root.resolve():
|
|
229
|
+
raise TurnError("TASK_TURN_WITHHELD: run turn commands from the project root")
|
|
230
|
+
with layout_lock(root):
|
|
231
|
+
require_settled_layout(root)
|
|
232
|
+
_, context = _session(root, key)
|
|
233
|
+
turn = _turn(context, session, turn_id)
|
|
234
|
+
if turn["interrupted"]:
|
|
235
|
+
raise TurnError("TASK_TURN_WITHHELD: user interrupted this turn")
|
|
236
|
+
snapshot = _digest(_snapshot(root, context, turn))
|
|
237
|
+
if existing:
|
|
238
|
+
ticket = _read(_ticket_path(root, existing))
|
|
239
|
+
_check_ticket(ticket, root, argv, turn)
|
|
240
|
+
if ticket.get("tool_use_id") != call_id:
|
|
241
|
+
raise TurnError("TASK_TURN_WITHHELD: rewritten call identity changed")
|
|
242
|
+
return tool_input
|
|
243
|
+
_expire_tickets(root)
|
|
244
|
+
ticket_id = uuid.uuid4().hex
|
|
245
|
+
ticket = {"schema_version": 1, "context_key": key, "session_id": session,
|
|
246
|
+
"turn_id": turn_id, "tool_use_id": call_id, "cwd": str(root.resolve()),
|
|
247
|
+
"argv_digest": _digest(argv), "snapshot_digest": snapshot,
|
|
248
|
+
"expires_at_epoch": time.time() + TICKET_SECONDS, "used": False}
|
|
249
|
+
ticket_path = _ticket_path(root, ticket_id)
|
|
250
|
+
ticket_path.parent.mkdir(parents=True, exist_ok=True)
|
|
251
|
+
if ticket_path.exists():
|
|
252
|
+
raise TurnError("TASK_TURN_WITHHELD: invocation ticket collision")
|
|
253
|
+
if not write_json(ticket_path, ticket):
|
|
254
|
+
raise TurnError("TASK_TURN_WRITE_FAILED: could not issue invocation ticket")
|
|
255
|
+
return {**tool_input, "command": command + " --invocation-ticket " + ticket_id}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def _check_ticket(ticket: dict, root: Path, argv: list[str], turn: dict) -> None:
|
|
259
|
+
if (ticket.get("schema_version") != 1 or ticket.get("used") is not False
|
|
260
|
+
or ticket.get("cwd") != str(root.resolve())
|
|
261
|
+
or ticket.get("session_id") != turn["session_id"] or ticket.get("turn_id") != turn["turn_id"]
|
|
262
|
+
or ticket.get("argv_digest") != _digest(argv)
|
|
263
|
+
or type(ticket.get("expires_at_epoch")) not in (int, float)
|
|
264
|
+
or not 0 <= ticket["expires_at_epoch"] - time.time() <= TICKET_SECONDS):
|
|
265
|
+
raise TurnError("TASK_TURN_WITHHELD: expired, replayed or mismatched invocation")
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def _evidence(args: argparse.Namespace, turn: dict, snapshot: dict | None) -> dict:
|
|
269
|
+
refs = args.evidence_ref or []
|
|
270
|
+
if not refs or any(not re.fullmatch(r"[A-Za-z0-9_.:/@-]{1,512}", ref) for ref in refs):
|
|
271
|
+
raise TurnError("TASK_TURN_INVALID: nonempty evidence references are required")
|
|
272
|
+
kind = args.kind
|
|
273
|
+
if kind not in KINDS:
|
|
274
|
+
raise TurnError("TASK_TURN_INVALID: unsupported exit kind")
|
|
275
|
+
result = {"kind": kind, "evidence_refs": refs, "snapshot_digest": _digest(snapshot)}
|
|
276
|
+
if kind == "bounded_reply":
|
|
277
|
+
result["scope"] = args.scope
|
|
278
|
+
elif kind in {"waiting_authorization", "waiting_input", "external_block"}:
|
|
279
|
+
result["no_independent_work"] = args.no_independent_work
|
|
280
|
+
if kind != "external_block":
|
|
281
|
+
question = _text(args.question, "explicit final question")
|
|
282
|
+
result.update(question_digest=_digest(question), question_length=len(question))
|
|
283
|
+
elif kind == "user_stop":
|
|
284
|
+
result["user_prompt_digest"] = _digest(_text(args.user_instruction, "user instruction", 1024 * 1024))
|
|
285
|
+
if not _valid_exit(result, snapshot, turn):
|
|
286
|
+
raise TurnError("TASK_TURN_WITHHELD: exit evidence does not match native task, scope or user input")
|
|
287
|
+
return result
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _valid_exit(evidence: object, snapshot: dict | None, turn: dict) -> bool:
|
|
291
|
+
if not isinstance(evidence, dict) or evidence.get("kind") not in KINDS or evidence.get("snapshot_digest") != _digest(snapshot):
|
|
292
|
+
return False
|
|
293
|
+
refs = evidence.get("evidence_refs")
|
|
294
|
+
if not isinstance(refs, list) or not refs or not all(isinstance(ref, str) and re.fullmatch(r"[A-Za-z0-9_.:/@-]{1,512}", ref) for ref in refs):
|
|
295
|
+
return False
|
|
296
|
+
kind = evidence["kind"]
|
|
297
|
+
if kind == "bounded_reply":
|
|
298
|
+
return evidence.get("scope") in SCOPES
|
|
299
|
+
if kind == "task_complete":
|
|
300
|
+
return snapshot is not None and (snapshot["status"] in {"completed", "cancelled"}
|
|
301
|
+
or snapshot["phase_id"] is None and snapshot["closeout"] in {"delivery_ready", "no_go"})
|
|
302
|
+
if kind == "user_stop":
|
|
303
|
+
return evidence.get("user_prompt_digest") == turn["prompt_digest"]
|
|
304
|
+
expected = "blocked" if kind == "external_block" else "waiting_user"
|
|
305
|
+
return evidence.get("no_independent_work") is True and (
|
|
306
|
+
snapshot is not None and snapshot["phase_status"] == expected
|
|
307
|
+
or snapshot is None and kind != "external_block"
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def cli(root: Path, args: argparse.Namespace, argv: list[str]) -> dict:
|
|
312
|
+
with layout_lock(root):
|
|
313
|
+
require_settled_layout(root)
|
|
314
|
+
ticket_id = args.invocation_ticket
|
|
315
|
+
if ticket_id is None:
|
|
316
|
+
if args.turn_action == "record":
|
|
317
|
+
raise TurnError("TASK_TURN_WITHHELD: record requires the exact PreToolUse invocation ticket")
|
|
318
|
+
key = resolve_context_key()
|
|
319
|
+
if key is None:
|
|
320
|
+
return {"status": "unavailable", "reason": "no direct session identity"}
|
|
321
|
+
_, context = _session(root, key)
|
|
322
|
+
return {"status": "observed" if "turn" in context else "absent",
|
|
323
|
+
"turn": _turn(context) if "turn" in context else None}
|
|
324
|
+
ticket_path = _ticket_path(root, ticket_id)
|
|
325
|
+
ticket = _read(ticket_path)
|
|
326
|
+
key = _text(ticket.get("context_key"), "ticket context_key")
|
|
327
|
+
if not re.fullmatch(r"[A-Za-z0-9_.-]+", key):
|
|
328
|
+
raise TurnError("TASK_TURN_WITHHELD: invalid ticket context key")
|
|
329
|
+
path, context = _session(root, key)
|
|
330
|
+
turn = _turn(context)
|
|
331
|
+
_check_ticket(ticket, root, argv, turn)
|
|
332
|
+
direct = resolve_context_key(allow_environment_context=True)
|
|
333
|
+
if direct is not None and direct != key:
|
|
334
|
+
raise TurnError("TASK_TURN_WITHHELD: native session and ticket disagree")
|
|
335
|
+
if turn["interrupted"]:
|
|
336
|
+
raise TurnError("TASK_TURN_WITHHELD: interrupted turn")
|
|
337
|
+
snapshot = _snapshot(root, context, turn)
|
|
338
|
+
if ticket.get("snapshot_digest") != _digest(snapshot):
|
|
339
|
+
raise TurnError("TASK_TURN_WITHHELD: task or artifact revision changed")
|
|
340
|
+
evidence = _evidence(args, turn, snapshot) if args.turn_action == "record" else None
|
|
341
|
+
# Burn first: a crash can withhold evidence, never reuse a successful call.
|
|
342
|
+
ticket["used"] = True
|
|
343
|
+
if not write_json(ticket_path, ticket):
|
|
344
|
+
raise TurnError("TASK_TURN_WRITE_FAILED: could not consume invocation ticket")
|
|
345
|
+
if evidence is not None:
|
|
346
|
+
turn["evidence"] = evidence
|
|
347
|
+
if snapshot:
|
|
348
|
+
turn["observed_task"] = snapshot["path"]
|
|
349
|
+
_save(path, context)
|
|
350
|
+
return {"status": "recorded" if evidence is not None else "observed", "turn": turn}
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def observe(root: Path, event: dict) -> dict:
|
|
354
|
+
key, session, turn_id = _identity(event)
|
|
355
|
+
with layout_lock(root):
|
|
356
|
+
path, context = _session(root, key)
|
|
357
|
+
turn = _turn(context, session, turn_id)
|
|
358
|
+
snapshot = _snapshot(root, context, turn)
|
|
359
|
+
if snapshot:
|
|
360
|
+
turn["observed_task"] = snapshot["path"]
|
|
361
|
+
if event.get("tool_name") != "request_user_input":
|
|
362
|
+
_save(path, context)
|
|
363
|
+
return {}
|
|
364
|
+
call_id = _text(event.get("tool_use_id"), "tool_use_id")
|
|
365
|
+
input_digest = _digest(event.get("tool_input"))
|
|
366
|
+
response_digest = _digest(event.get("tool_response"))
|
|
367
|
+
prior = turn["answers"].get(call_id)
|
|
368
|
+
if not isinstance(prior, dict) or prior.get("input_digest") != input_digest:
|
|
369
|
+
turn["evidence"] = None
|
|
370
|
+
_save(path, context)
|
|
371
|
+
raise TurnError("TASK_TURN_WITHHELD: answer has no matching native question invocation")
|
|
372
|
+
if prior.get("status") != "pending":
|
|
373
|
+
if prior.get("response_digest") != response_digest:
|
|
374
|
+
turn["evidence"] = None
|
|
375
|
+
_save(path, context)
|
|
376
|
+
raise TurnError("TASK_TURN_WITHHELD: conflicting duplicate answer")
|
|
377
|
+
return {}
|
|
378
|
+
response = event.get("tool_response")
|
|
379
|
+
if isinstance(response, str):
|
|
380
|
+
try:
|
|
381
|
+
response = json.loads(response)
|
|
382
|
+
except ValueError:
|
|
383
|
+
response = None
|
|
384
|
+
tool_input = event.get("tool_input")
|
|
385
|
+
questions = tool_input.get("questions") if isinstance(tool_input, dict) else None
|
|
386
|
+
questions = questions if isinstance(questions, list) else []
|
|
387
|
+
answers = response.get("answers") if isinstance(response, dict) else None
|
|
388
|
+
ids = [q.get("id") if isinstance(q, dict) else None for q in questions]
|
|
389
|
+
complete = (0 < len(ids) <= 3 and all(isinstance(i, str) and i for i in ids)
|
|
390
|
+
and len(set(ids)) == len(ids) and isinstance(answers, dict) and set(ids) == set(answers)
|
|
391
|
+
and all(isinstance(q, dict) and isinstance(q.get("question"), str) and q["question"].strip()
|
|
392
|
+
for q in questions)
|
|
393
|
+
and all(isinstance(answers[i], dict) and isinstance(answers[i].get("answers"), list)
|
|
394
|
+
and answers[i]["answers"] and all(isinstance(v, str) and v.strip() for v in answers[i]["answers"]) for i in ids))
|
|
395
|
+
turn["answers"][call_id] = {"input_digest": input_digest, "response_digest": response_digest,
|
|
396
|
+
"status": "complete" if complete else "incomplete"}
|
|
397
|
+
turn["evidence"] = None
|
|
398
|
+
_save(path, context)
|
|
399
|
+
return {"hookSpecificOutput": {"hookEventName": "PostToolUse", "additionalContext":
|
|
400
|
+
"A real answer returned. Record it, resume a resolved phase wait, and continue authorized work."
|
|
401
|
+
if complete else "No complete answer is established. Do not invent a choice; follow the host cancellation/empty-answer contract and continue independent authorized work."}}
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
def question_started(root: Path, event: dict) -> None:
|
|
405
|
+
key, session, turn_id = _identity(event)
|
|
406
|
+
call_id = _text(event.get("tool_use_id"), "tool_use_id")
|
|
407
|
+
input_digest = _digest(event.get("tool_input"))
|
|
408
|
+
with layout_lock(root):
|
|
409
|
+
path, context = _session(root, key)
|
|
410
|
+
turn = _turn(context, session, turn_id)
|
|
411
|
+
prior = turn["answers"].get(call_id)
|
|
412
|
+
if prior is not None:
|
|
413
|
+
if not isinstance(prior, dict) or prior.get("input_digest") != input_digest:
|
|
414
|
+
turn["evidence"] = None
|
|
415
|
+
_save(path, context)
|
|
416
|
+
raise TurnError("TASK_TURN_WITHHELD: question invocation identity changed")
|
|
417
|
+
return
|
|
418
|
+
turn["answers"][call_id] = {"input_digest": input_digest, "response_digest": None, "status": "pending"}
|
|
419
|
+
turn["evidence"] = None
|
|
420
|
+
_save(path, context)
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
def stop(root: Path, event: dict) -> dict:
|
|
424
|
+
key, session, turn_id = _identity(event)
|
|
425
|
+
with layout_lock(root):
|
|
426
|
+
path, context = _session(root, key)
|
|
427
|
+
turn = _turn(context, session, turn_id)
|
|
428
|
+
if turn["interrupted"]:
|
|
429
|
+
return {"continue": False, "systemMessage": "Trellis: user interruption preserved; no automatic continuation."}
|
|
430
|
+
evidence = turn.get("evidence")
|
|
431
|
+
valid = _valid_exit(evidence, _snapshot(root, context, turn), turn)
|
|
432
|
+
if valid and isinstance(evidence, dict) and evidence.get("kind") in {"waiting_authorization", "waiting_input"}:
|
|
433
|
+
message = event.get("last_assistant_message")
|
|
434
|
+
length = evidence.get("question_length")
|
|
435
|
+
valid = (isinstance(message, str) and len(message) <= 65536 and type(length) is int
|
|
436
|
+
and 0 < length <= 512 and any(_digest(message[i:i + length]) == evidence["question_digest"]
|
|
437
|
+
for i in range(len(message) - length + 1)))
|
|
438
|
+
if valid:
|
|
439
|
+
return {}
|
|
440
|
+
if turn["corrections"] >= MAX_CORRECTIONS:
|
|
441
|
+
return {"continue": False, "systemMessage": "TASK_TURN_PROTECTION_FAILED: correction limit reached; task remains unfinished. Inspect turn evidence before continuing manually."}
|
|
442
|
+
reason = ("Trellis turn guard: continue independent authorized work or ask the actual blocking question; "
|
|
443
|
+
"record native task.py turn evidence before ending. This feedback is not a user answer or approval. "
|
|
444
|
+
"Correction " + str(turn["corrections"] + 1) + " of " + str(MAX_CORRECTIONS) + ".")
|
|
445
|
+
turn["corrections"] += 1
|
|
446
|
+
_save(path, context)
|
|
447
|
+
return {"decision": "block", "reason": reason}
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def interrupt(root: Path, event: dict) -> None:
|
|
451
|
+
key, session, turn_id = _identity(event)
|
|
452
|
+
with layout_lock(root):
|
|
453
|
+
path, context = _session(root, key)
|
|
454
|
+
turn = _turn(context, session, turn_id)
|
|
455
|
+
turn.update(interrupted=True, evidence=None)
|
|
456
|
+
_save(path, context)
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def add_turn_commands(subparsers: argparse._SubParsersAction) -> None:
|
|
460
|
+
parser = subparsers.add_parser("turn", help="Observe or record native current-turn exit evidence")
|
|
461
|
+
actions = parser.add_subparsers(dest="turn_action", required=True)
|
|
462
|
+
show = actions.add_parser("show", help="Read current native turn; missing identity never grants exit evidence")
|
|
463
|
+
show.add_argument("--invocation-ticket")
|
|
464
|
+
record = actions.add_parser("record", help="Record exit evidence using the exact hook-issued invocation")
|
|
465
|
+
record.add_argument("--invocation-ticket")
|
|
466
|
+
record.add_argument("--kind", choices=KINDS, required=True)
|
|
467
|
+
record.add_argument("--scope", choices=SCOPES)
|
|
468
|
+
record.add_argument("--evidence-ref", action="append", required=True)
|
|
469
|
+
record.add_argument("--no-independent-work", action="store_true")
|
|
470
|
+
record.add_argument("--question")
|
|
471
|
+
record.add_argument("--user-instruction")
|
|
@@ -96,6 +96,7 @@ from common.task_continuity import (
|
|
|
96
96
|
continuity_show,
|
|
97
97
|
transfer_task_ownership,
|
|
98
98
|
)
|
|
99
|
+
from common.task_turn import TurnError, add_turn_commands, cli as turn_cli
|
|
99
100
|
|
|
100
101
|
|
|
101
102
|
# =============================================================================
|
|
@@ -904,6 +905,7 @@ def main() -> int:
|
|
|
904
905
|
p_runtime.add_argument("dir", nargs="?", help="Optional existing task scope")
|
|
905
906
|
p_runtime.add_argument("--confirm", help="Exact digest from a fresh native preview")
|
|
906
907
|
|
|
908
|
+
add_turn_commands(subparsers)
|
|
907
909
|
args = parser.parse_args()
|
|
908
910
|
|
|
909
911
|
if os.environ.get("TRELLIS_DELEGATION_CONTEXT") and args.command not in {"current", "list", "list-context", "validate"}:
|
|
@@ -956,6 +958,12 @@ def main() -> int:
|
|
|
956
958
|
return continuity_show(args) if args.continuity_action == "show" else continuity_capture(args)
|
|
957
959
|
if args.command == "transfer":
|
|
958
960
|
return transfer_task_ownership(args)
|
|
961
|
+
if args.command == "turn":
|
|
962
|
+
turn_argv = sys.argv[2:]
|
|
963
|
+
if len(turn_argv) >= 2 and turn_argv[-2] == "--invocation-ticket":
|
|
964
|
+
turn_argv = turn_argv[:-2]
|
|
965
|
+
print(json.dumps(turn_cli(get_repo_root(), args, turn_argv), ensure_ascii=False))
|
|
966
|
+
return 0
|
|
959
967
|
if args.command in commands:
|
|
960
968
|
if args.command.startswith("delegate-"):
|
|
961
969
|
from common.worktree_delegation import run, runtime_path
|
|
@@ -968,6 +976,9 @@ def main() -> int:
|
|
|
968
976
|
return run(args)
|
|
969
977
|
show_usage()
|
|
970
978
|
return 1
|
|
979
|
+
except TurnError as error:
|
|
980
|
+
print(str(error), file=sys.stderr)
|
|
981
|
+
return 1
|
|
971
982
|
except TaskWorkflowError as error:
|
|
972
983
|
print(f"{error.code}: {error}", file=sys.stderr)
|
|
973
984
|
return 1
|
|
@@ -60,6 +60,8 @@ python3 ./.trellis/scripts/task.py reopen <task> --reason "<reason>" --evidence-
|
|
|
60
60
|
|
|
61
61
|
新接受的 `implementation_contract`(以及省略设计阶段时新授权的合同)必须包含 `## 验收覆盖` 表,表头固定为 `接受条件 | 工作包 | Owner | 验证入口 | 交付证据 | 停止条件`,至少一行且各单元格非空。CLI 负责结构检查,阶段 Skill 负责逐条核对已接受条件的语义覆盖。既有接受和授权不会因本次升级自动失效;再次接受或授权时执行新检查。
|
|
62
62
|
|
|
63
|
+
新实施合同用 `## 实施步骤` 记录编号复选框,按需分组,每项写清动作、前置、完成证据和停止点;短任务可只有一个工作包。已接受合同保持不变,执行时在 `execution.md` 引用编号并留证。验收通过不等于已获准写入;项目阶段批准不能替代实际写入工具对目标和候选的原生确认。只阻断依赖失败或缺少授权的步骤,不增加复选框格式的 CLI 拒绝门禁。
|
|
64
|
+
|
|
63
65
|
旧布局须先预览 `task.py migrate-layout`,核对后执行 `task.py migrate-layout --apply`;旧 `archive/YYYY-MM` 中已完成的任务保留原月份,其他任务按真实状态放置。迁移会同步 JSON/JSONL 机器引用、会话指针和运行态索引,保留任务身份与父子关系,不重授历史授权。未完成事务会阻止普通任务命令,须用 `task.py migrate-layout --recover` 恢复;输入被外部改动时停止并保留现场。路径或产物内容改变导致接受证据失效时,须经原生阶段接受或 continuity 核对重新收敛。
|
|
64
66
|
|
|
65
67
|
在支持原生实施或检查 agent 的平台上,任务上下文清单(`implement.jsonl`、`check.jsonl`)用于提供相关规范和研究资料。只有这些 agent 会读取清单时才需要维护;清单不能替代任务资产或阶段证据。
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ablation-store.d.ts","sourceRoot":"","sources":["../../src/utils/ablation-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"ablation-store.d.ts","sourceRoot":"","sources":["../../src/utils/ablation-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAuBH,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,wBAAwB,EAAG,cAAuB,CAAC;AAChE,eAAO,MAAM,uBAAuB,gCAAgC,CAAC;AAErE,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;AAEhF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,C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B,GACrC,IAAI,CAEN"}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { createHash, randomUUID } from "node:crypto";
|
|
11
11
|
import fs from "node:fs";
|
|
12
|
+
import { CODEX_CONFIG_PATH, readCodexConfig, splitCodexConfig, stripCodexConfigPrefix, } from "./codex-config-ownership.js";
|
|
12
13
|
import { assertCurrentExecutionAsset } from "./retired-native-assets.js";
|
|
13
14
|
import os from "node:os";
|
|
14
15
|
import path from "node:path";
|
|
@@ -706,7 +707,11 @@ export function restoreTransactionFiles(transaction, options = {}) {
|
|
|
706
707
|
const ordered = [...transaction.state.entries].sort((left, right) => left.relativePath.split("/").length -
|
|
707
708
|
right.relativePath.split("/").length);
|
|
708
709
|
for (const entry of ordered) {
|
|
709
|
-
|
|
710
|
+
if (entry.relativePath === CODEX_CONFIG_PATH &&
|
|
711
|
+
fingerprintsEqual(fingerprintPath(currentPathForEntry(transaction.state.projectRoot, entry)), entry.pre))
|
|
712
|
+
continue;
|
|
713
|
+
restoreEntry(transaction, entry, entry.relativePath === CODEX_CONFIG_PATH ||
|
|
714
|
+
(options.verifyExpectedState ?? false));
|
|
710
715
|
}
|
|
711
716
|
}
|
|
712
717
|
function assertRestorableExecutionAssets(transaction) {
|
|
@@ -726,6 +731,17 @@ function assertRestorableExecutionAssets(transaction) {
|
|
|
726
731
|
}
|
|
727
732
|
}
|
|
728
733
|
for (const entry of transaction.state.entries) {
|
|
734
|
+
if (entry.backupPath && entry.relativePath === CODEX_CONFIG_PATH) {
|
|
735
|
+
const text = readCodexConfig(path.join(transaction.paths.transactionDir, entry.backupPath));
|
|
736
|
+
const parts = typeof text === "string" ? splitCodexConfig(text) : undefined;
|
|
737
|
+
const retained = parts && stripCodexConfigPrefix(parts.suffix);
|
|
738
|
+
if (!parts ||
|
|
739
|
+
entry.pre.kind !== "file" ||
|
|
740
|
+
!fingerprintsEqual(entry.expectedAblated, retained
|
|
741
|
+
? expectedFileFingerprint(retained, entry.pre.mode)
|
|
742
|
+
: { kind: "absent" }))
|
|
743
|
+
throw new Error("Ablation cannot prove ownership of shared Codex configuration; no shared file was restored");
|
|
744
|
+
}
|
|
729
745
|
if (entry.backupPath)
|
|
730
746
|
visit(path.join(transaction.paths.transactionDir, entry.backupPath), entry.relativePath);
|
|
731
747
|
}
|