@pennixrv/trellis 0.7.2-beta.26 → 0.7.2-beta.27
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/migrations/manifests/0.7.2-beta.27.json +8 -0
- package/dist/templates/codex/hooks/turn-guard.py +2 -1
- package/dist/templates/common/bundled-skills/trellis-decision-space-construction-and-merging/workflow.md +4 -2
- package/dist/templates/common/bundled-skills/trellis-delivery-review-and-closeout/workflow.md +11 -9
- package/dist/templates/common/bundled-skills/trellis-goal-exploration-and-requirements/workflow.md +1 -1
- package/dist/templates/common/bundled-skills/trellis-solution-design-and-convergence/workflow.md +7 -1
- package/dist/templates/common/bundled-skills/trellis-task-implementation/workflow.md +1 -1
- package/dist/templates/common/commands/continue.md +2 -2
- package/dist/templates/common/skills/request-intake.md +2 -0
- package/dist/templates/omp/extensions/trellis/index.ts.txt +16 -9
- package/dist/templates/opencode/plugins/inject-workflow-state.js +15 -7
- package/dist/templates/pi/extensions/trellis/index.ts.txt +9 -4
- package/dist/templates/shared-hooks/inject-shell-session-context.py +4 -1
- package/dist/templates/shared-hooks/inject-workflow-state.py +44 -27
- package/dist/templates/trellis/scripts/common/task_turn.py +69 -26
- package/dist/templates/trellis/scripts/common/task_workflow.py +289 -68
- package/dist/templates/trellis/scripts/common/workflow_selection.py +23 -38
- package/dist/templates/trellis/scripts/task.py +14 -4
- package/dist/templates/trellis/workflow.md +12 -2
- package/package.json +2 -2
|
@@ -9,6 +9,7 @@ import os
|
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
import re
|
|
11
11
|
import shlex
|
|
12
|
+
import sys
|
|
12
13
|
import time
|
|
13
14
|
import uuid
|
|
14
15
|
|
|
@@ -16,11 +17,11 @@ from .active_task import _context_path, _write_json, resolve_context_key
|
|
|
16
17
|
from .io import JSON_READ_MISSING, read_json_checked, write_json
|
|
17
18
|
from .task_move import layout_lock, require_settled_layout
|
|
18
19
|
from .task_utils import resolve_task_dir
|
|
19
|
-
from .task_workflow import _artifact_digest, _state
|
|
20
|
+
from .task_workflow import PHASE_IDS, TaskWorkflowError, _artifact_digest, _state, design_preflight
|
|
20
21
|
|
|
21
22
|
KINDS = ("bounded_reply", "task_complete", "waiting_authorization",
|
|
22
23
|
"waiting_input", "external_block", "user_stop")
|
|
23
|
-
SCOPES = ("explanation", "inspection", "handoff_admission")
|
|
24
|
+
SCOPES = ("explanation", "inspection", "handoff_admission", "maintenance")
|
|
24
25
|
TICKET_ID = re.compile(r"[0-9a-f]{32}\Z")
|
|
25
26
|
MAX_CORRECTIONS = 2
|
|
26
27
|
TICKET_SECONDS = 30
|
|
@@ -139,7 +140,9 @@ def _snapshot(root: Path, context: dict, turn: dict) -> dict | None:
|
|
|
139
140
|
"phase_status": state["phases"][phase_id]["status"] if state and phase_id else None,
|
|
140
141
|
"route_revision": state["task_route_revision"] if state else None,
|
|
141
142
|
"input_revision": state["input_revision"] if state else None,
|
|
142
|
-
"closeout": state.get("closeout_disposition") if state else None
|
|
143
|
+
"closeout": state.get("closeout_disposition") if state else None,
|
|
144
|
+
"accepted_contract": (state["phases"][phase_id].get("outcome_kind") == "implementation_contract"
|
|
145
|
+
and state.get("implementation_authorization") is None) if state and phase_id == PHASE_IDS[2] else False}
|
|
143
146
|
|
|
144
147
|
|
|
145
148
|
def begin(root: Path, event: dict) -> dict:
|
|
@@ -164,10 +167,13 @@ def begin(root: Path, event: dict) -> dict:
|
|
|
164
167
|
return turn
|
|
165
168
|
|
|
166
169
|
|
|
167
|
-
def _invocation(root: Path, command: str) -> tuple[list[str], str | None]:
|
|
170
|
+
def _invocation(root: Path, command: str) -> tuple[list[str], str | None, list[str]]:
|
|
168
171
|
if os.name != "posix":
|
|
169
172
|
raise TurnError("TASK_TURN_UNSUPPORTED: invocation rewriting requires a verified POSIX shell")
|
|
170
|
-
|
|
173
|
+
# Only single-quoted literals can contain shell expansion characters.
|
|
174
|
+
outside_literals = re.sub(r"""(?:"(?:\\.|[^"\\])*"|'[^']*'|\\.)""",
|
|
175
|
+
lambda match: "" if match[0].startswith("'") else match[0], command)
|
|
176
|
+
if any(c in command for c in ("\n", "\r", "\0")) or any(c in outside_literals for c in ("$", "`", "#")):
|
|
171
177
|
raise TurnError("TASK_TURN_WITHHELD: expansions and multiline shell commands are unsupported")
|
|
172
178
|
lexer = shlex.shlex(command, posix=True, punctuation_chars=";&|<>()")
|
|
173
179
|
lexer.whitespace_split = True
|
|
@@ -175,7 +181,8 @@ def _invocation(root: Path, command: str) -> tuple[list[str], str | None]:
|
|
|
175
181
|
tokens = list(lexer)
|
|
176
182
|
if any(token and all(c in ";&|<>()" for c in token) for token in tokens):
|
|
177
183
|
raise TurnError("TASK_TURN_WITHHELD: use one direct Python task.py turn command")
|
|
178
|
-
if len(tokens) < 4 or
|
|
184
|
+
if len(tokens) < 4 or (tokens[0] not in {"python", "python3"} and
|
|
185
|
+
(not Path(tokens[0]).is_absolute() or Path(tokens[0]).resolve() != Path(sys.executable).resolve())):
|
|
179
186
|
raise TurnError("TASK_TURN_WITHHELD: use Python directly")
|
|
180
187
|
index = 3 if tokens[1:3] == ["-X", "utf8"] else 1
|
|
181
188
|
if (len(tokens) <= index + 2 or (root / tokens[index]).resolve() != (root / ".trellis/scripts/task.py").resolve()
|
|
@@ -188,7 +195,7 @@ def _invocation(root: Path, command: str) -> tuple[list[str], str | None]:
|
|
|
188
195
|
raise TurnError("TASK_TURN_WITHHELD: invalid invocation ticket argument")
|
|
189
196
|
ticket = argv[-1]
|
|
190
197
|
argv = argv[:-2]
|
|
191
|
-
return argv, ticket
|
|
198
|
+
return argv, ticket, tokens[:index + 2]
|
|
192
199
|
|
|
193
200
|
|
|
194
201
|
def _ticket_path(root: Path, ticket_id: str) -> Path:
|
|
@@ -222,7 +229,7 @@ def ticket_input(root: Path, event: dict) -> dict:
|
|
|
222
229
|
if not isinstance(tool_input, dict):
|
|
223
230
|
raise TurnError("TASK_TURN_WITHHELD: invalid Bash input")
|
|
224
231
|
command = _text(tool_input.get("command"), "Bash command", 16384)
|
|
225
|
-
argv, existing = _invocation(root, command)
|
|
232
|
+
argv, existing, prefix = _invocation(root, command)
|
|
226
233
|
call_id = _text(event.get("tool_use_id"), "tool_use_id")
|
|
227
234
|
cwd = Path(_text(event.get("cwd"), "cwd", 4096)).resolve()
|
|
228
235
|
if cwd != root.resolve():
|
|
@@ -239,7 +246,7 @@ def ticket_input(root: Path, event: dict) -> dict:
|
|
|
239
246
|
_check_ticket(ticket, root, argv, turn)
|
|
240
247
|
if ticket.get("tool_use_id") != call_id:
|
|
241
248
|
raise TurnError("TASK_TURN_WITHHELD: rewritten call identity changed")
|
|
242
|
-
return tool_input
|
|
249
|
+
return {**tool_input, "command": shlex.join([*prefix, *argv, "--invocation-ticket", existing])}
|
|
243
250
|
_expire_tickets(root)
|
|
244
251
|
ticket_id = uuid.uuid4().hex
|
|
245
252
|
ticket = {"schema_version": 1, "context_key": key, "session_id": session,
|
|
@@ -252,7 +259,7 @@ def ticket_input(root: Path, event: dict) -> dict:
|
|
|
252
259
|
raise TurnError("TASK_TURN_WITHHELD: invocation ticket collision")
|
|
253
260
|
if not write_json(ticket_path, ticket):
|
|
254
261
|
raise TurnError("TASK_TURN_WRITE_FAILED: could not issue invocation ticket")
|
|
255
|
-
return {**tool_input, "command":
|
|
262
|
+
return {**tool_input, "command": shlex.join([*prefix, *argv, "--invocation-ticket", ticket_id])}
|
|
256
263
|
|
|
257
264
|
|
|
258
265
|
def _check_ticket(ticket: dict, root: Path, argv: list[str], turn: dict) -> None:
|
|
@@ -265,7 +272,7 @@ def _check_ticket(ticket: dict, root: Path, argv: list[str], turn: dict) -> None
|
|
|
265
272
|
raise TurnError("TASK_TURN_WITHHELD: expired, replayed or mismatched invocation")
|
|
266
273
|
|
|
267
274
|
|
|
268
|
-
def _evidence(args: argparse.Namespace, turn: dict, snapshot: dict | None) -> dict:
|
|
275
|
+
def _evidence(root: Path, args: argparse.Namespace, turn: dict, snapshot: dict | None) -> dict:
|
|
269
276
|
refs = args.evidence_ref or []
|
|
270
277
|
if not refs or any(not re.fullmatch(r"[A-Za-z0-9_.:/@-]{1,512}", ref) for ref in refs):
|
|
271
278
|
raise TurnError("TASK_TURN_INVALID: nonempty evidence references are required")
|
|
@@ -277,9 +284,23 @@ def _evidence(args: argparse.Namespace, turn: dict, snapshot: dict | None) -> di
|
|
|
277
284
|
result["scope"] = args.scope
|
|
278
285
|
elif kind in {"waiting_authorization", "waiting_input", "external_block"}:
|
|
279
286
|
result["no_independent_work"] = args.no_independent_work
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
287
|
+
result["scope"] = args.scope
|
|
288
|
+
text = _text(args.blocker if kind == "external_block" else args.question,
|
|
289
|
+
"explicit final blocker" if kind == "external_block" else "explicit final question")
|
|
290
|
+
result.update(final_text_digest=_digest(text), final_text_length=len(text))
|
|
291
|
+
if any(value is not None for value in (args.approval_result_ref, args.approval_artifact_revision, args.approval_outcome)):
|
|
292
|
+
if kind != "waiting_authorization" or snapshot is None or args.scope is not None:
|
|
293
|
+
raise TurnError("TASK_TURN_WITHHELD: candidate markers require a task-bound authorization question")
|
|
294
|
+
ref = _text(args.approval_result_ref, "approval result reference")
|
|
295
|
+
revision = _text(args.approval_artifact_revision, "approval artifact revision")
|
|
296
|
+
task_dir = root / snapshot["path"]
|
|
297
|
+
try:
|
|
298
|
+
state = _state(_read(task_dir / "task.json")["meta"])
|
|
299
|
+
candidate = design_preflight(task_dir, state, args.approval_outcome, ref, revision)
|
|
300
|
+
except TaskWorkflowError as error:
|
|
301
|
+
raise TurnError(f"{error.code}: {error}") from error
|
|
302
|
+
result["approval_candidate"] = {"digest": _digest(candidate), "result_ref": ref,
|
|
303
|
+
"artifact_revision": revision, "outcome": args.approval_outcome}
|
|
283
304
|
elif kind == "user_stop":
|
|
284
305
|
result["user_prompt_digest"] = _digest(_text(args.user_instruction, "user instruction", 1024 * 1024))
|
|
285
306
|
if not _valid_exit(result, snapshot, turn):
|
|
@@ -297,15 +318,23 @@ def _valid_exit(evidence: object, snapshot: dict | None, turn: dict) -> bool:
|
|
|
297
318
|
if kind == "bounded_reply":
|
|
298
319
|
return evidence.get("scope") in SCOPES
|
|
299
320
|
if kind == "task_complete":
|
|
300
|
-
return snapshot is not None and
|
|
301
|
-
or snapshot["phase_id"] is None and snapshot["closeout"] in {"delivery_ready", "no_go"})
|
|
321
|
+
return snapshot is not None and snapshot["status"] in {"completed", "cancelled"}
|
|
302
322
|
if kind == "user_stop":
|
|
303
323
|
return evidence.get("user_prompt_digest") == turn["prompt_digest"]
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
324
|
+
if evidence.get("no_independent_work") is not True:
|
|
325
|
+
return False
|
|
326
|
+
scope = evidence.get("scope")
|
|
327
|
+
if scope is not None:
|
|
328
|
+
return kind in {"waiting_input", "external_block"} and scope in SCOPES
|
|
329
|
+
if snapshot is None:
|
|
330
|
+
return kind in {"waiting_input", "waiting_authorization", "external_block"}
|
|
331
|
+
if snapshot["status"] in {"completed", "cancelled"}:
|
|
332
|
+
return False
|
|
333
|
+
if kind == "external_block":
|
|
334
|
+
return (snapshot["phase_status"] == "blocked" or
|
|
335
|
+
snapshot["phase_id"] is None and snapshot["closeout"] in {"delivery_ready", "no_go", "cancelled"})
|
|
336
|
+
return (snapshot["phase_status"] == "waiting_user"
|
|
337
|
+
or kind == "waiting_authorization" and snapshot["phase_status"] == "accepted" and snapshot["accepted_contract"])
|
|
309
338
|
|
|
310
339
|
|
|
311
340
|
def cli(root: Path, args: argparse.Namespace, argv: list[str]) -> dict:
|
|
@@ -337,7 +366,7 @@ def cli(root: Path, args: argparse.Namespace, argv: list[str]) -> dict:
|
|
|
337
366
|
snapshot = _snapshot(root, context, turn)
|
|
338
367
|
if ticket.get("snapshot_digest") != _digest(snapshot):
|
|
339
368
|
raise TurnError("TASK_TURN_WITHHELD: task or artifact revision changed")
|
|
340
|
-
evidence = _evidence(args, turn, snapshot) if args.turn_action == "record" else None
|
|
369
|
+
evidence = _evidence(root, args, turn, snapshot) if args.turn_action == "record" else None
|
|
341
370
|
# Burn first: a crash can withhold evidence, never reuse a successful call.
|
|
342
371
|
ticket["used"] = True
|
|
343
372
|
if not write_json(ticket_path, ticket):
|
|
@@ -428,12 +457,22 @@ def stop(root: Path, event: dict) -> dict:
|
|
|
428
457
|
if turn["interrupted"]:
|
|
429
458
|
return {"continue": False, "systemMessage": "Trellis: user interruption preserved; no automatic continuation."}
|
|
430
459
|
evidence = turn.get("evidence")
|
|
431
|
-
|
|
432
|
-
|
|
460
|
+
snapshot = _snapshot(root, context, turn)
|
|
461
|
+
valid = _valid_exit(evidence, snapshot, turn)
|
|
462
|
+
if valid and snapshot is not None and isinstance(evidence, dict) and "approval_candidate" in evidence:
|
|
463
|
+
expected = evidence["approval_candidate"]
|
|
464
|
+
try:
|
|
465
|
+
task_dir = root / snapshot["path"]
|
|
466
|
+
state = _state(_read(task_dir / "task.json")["meta"])
|
|
467
|
+
candidate = design_preflight(task_dir, state, expected["outcome"], expected["result_ref"], expected["artifact_revision"])
|
|
468
|
+
valid = expected["digest"] == _digest(candidate)
|
|
469
|
+
except (TaskWorkflowError, KeyError, TypeError):
|
|
470
|
+
valid = False
|
|
471
|
+
if valid and isinstance(evidence, dict) and evidence.get("kind") in {"waiting_authorization", "waiting_input", "external_block"}:
|
|
433
472
|
message = event.get("last_assistant_message")
|
|
434
|
-
length = evidence.get("
|
|
473
|
+
length = evidence.get("final_text_length")
|
|
435
474
|
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["
|
|
475
|
+
and 0 < length <= 512 and any(_digest(message[i:i + length]) == evidence["final_text_digest"]
|
|
437
476
|
for i in range(len(message) - length + 1)))
|
|
438
477
|
if valid:
|
|
439
478
|
return {}
|
|
@@ -468,4 +507,8 @@ def add_turn_commands(subparsers: argparse._SubParsersAction) -> None:
|
|
|
468
507
|
record.add_argument("--evidence-ref", action="append", required=True)
|
|
469
508
|
record.add_argument("--no-independent-work", action="store_true")
|
|
470
509
|
record.add_argument("--question")
|
|
510
|
+
record.add_argument("--blocker")
|
|
511
|
+
record.add_argument("--approval-result-ref")
|
|
512
|
+
record.add_argument("--approval-artifact-revision")
|
|
513
|
+
record.add_argument("--approval-outcome", choices=("implementation_contract", "analysis_conclusion", "no_go"))
|
|
471
514
|
record.add_argument("--user-instruction")
|