cowork-flow 0.0.47 → 0.0.49
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/CHANGELOG.md +41 -0
- package/README.md +102 -23
- package/package.json +8 -3
- package/src/cli.js +6 -0
- package/src/commands/init.js +0 -83
- package/src/commands/source-refresh.js +40 -0
- package/src/commands/sync.js +6 -0
- package/src/commands/update.js +59 -6
- package/src/lib/copy-template.js +200 -50
- package/src/lib/host-assets.js +367 -64
- package/src/lib/plan-applier.js +47 -0
- package/template/.claude/hooks/inject-workflow-state.py +7 -0
- package/template/.codex/hooks/inject-workflow-state.py +7 -0
- package/template/.codex/hooks.json +1 -1
- package/template/.cowork-flow/.version +1 -1
- package/template/.cowork-flow/config.yaml +0 -11
- package/template/.cowork-flow/scripts/adapters/cli/init_developer.py +0 -1
- package/template/.cowork-flow/scripts/adapters/cli/subagent.py +7 -4
- package/template/.cowork-flow/scripts/adapters/cli/task.py +8 -484
- package/template/.cowork-flow/scripts/adapters/cli/task_archive_commands.py +15 -134
- package/template/.cowork-flow/scripts/adapters/cli/task_context_commands.py +7 -1
- package/template/.cowork-flow/scripts/adapters/cli/task_lifecycle_commands.py +388 -0
- package/template/.cowork-flow/scripts/adapters/cli/task_navigation.py +163 -2
- package/template/.cowork-flow/scripts/adapters/git/git_context.py +16 -193
- package/template/.cowork-flow/scripts/adapters/host/host_manifest.py +170 -84
- package/template/.cowork-flow/scripts/infra/config.py +0 -17
- package/template/.cowork-flow/scripts/infra/developer_profile.py +0 -95
- package/template/.cowork-flow/scripts/infra/paths.py +0 -79
- package/template/.cowork-flow/scripts/infra/skill_manifest.py +23 -3
- package/template/.cowork-flow/scripts/infra/storage/operation_log.py +40 -0
- package/template/.cowork-flow/scripts/infra/storage/state_store.py +356 -1
- package/template/.cowork-flow/scripts/kernel/workflow_route.py +15 -15
- package/template/.cowork-flow/scripts/run.py +0 -5
- package/template/.cowork-flow/scripts/services/context_discovery.py +156 -0
- package/template/.cowork-flow/scripts/services/context_jsonl.py +119 -0
- package/template/.cowork-flow/scripts/services/context_paths.py +186 -0
- package/template/.cowork-flow/scripts/services/lifecycle_checks.py +186 -69
- package/template/.cowork-flow/scripts/services/lifecycle_policy.py +128 -0
- package/template/.cowork-flow/scripts/services/plan_binding.py +146 -0
- package/template/.cowork-flow/scripts/services/readiness.py +3 -170
- package/template/.cowork-flow/scripts/services/task_archive.py +115 -24
- package/template/.cowork-flow/scripts/services/task_context.py +103 -365
- package/template/.cowork-flow/scripts/services/task_creation.py +40 -5
- package/template/.cowork-flow/scripts/services/task_lifecycle.py +155 -18
- package/template/.cowork-flow/scripts/services/task_routing.py +80 -67
- package/template/.cowork-flow/scripts/services/task_utils.py +0 -146
- package/template/.cowork-flow/scripts/services/workflow_runtime.py +1 -1
- package/template/.cowork-flow/spec/contracts/capabilities.md +23 -0
- package/template/.cowork-flow/spec/contracts/decision-anchor.md +2 -2
- package/template/.cowork-flow/spec/contracts/error-output-as-data.md +8 -0
- package/template/.cowork-flow/spec/contracts/index.md +1 -0
- package/template/.cowork-flow/spec/contracts/party-mode-v2-board.md +20 -0
- package/template/.cowork-flow/spec/contracts/plan-binding.md +50 -0
- package/template/.cowork-flow/spec/contracts/skill-owned-actions.md +31 -7
- package/template/.cowork-flow/spec/guides/index.md +3 -1
- package/template/.cowork-flow/spec/index.md +5 -4
- package/template/.cowork-flow/spec/references/definition-of-done.md +2 -3
- package/template/.cowork-flow/spec/references/orchestration-patterns.md +1 -1
- package/template/.cowork-flow/spec/runtime/contract-registry.json +14 -0
- package/template/.cowork-flow/spec/runtime/host-assets.json +73 -3
- package/template/.cowork-flow/spec/runtime/index.md +1 -1
- package/template/.cowork-flow/spec/schemas/host-assets.schema.json +150 -8
- package/template/.zcode/.zcode-plugin/plugin.json +1 -1
- package/template/skills/batch-execution/SKILL.md +37 -3
- package/template/skills/batch-execution/scripts/batch_action.py +4 -0
- package/template/skills/batch-execution/scripts/batch_execution.py +120 -499
- package/template/skills/batch-execution/scripts/batch_recovery.py +94 -0
- package/template/skills/batch-execution/scripts/batch_state_machine.py +201 -0
- package/template/skills/batch-execution/scripts/batch_verification.py +326 -0
- package/template/skills/brainstorming/SKILL.md +8 -7
- package/template/skills/cowork-flow/SKILL.md +3 -0
- package/template/skills/party-mode/scripts/party_action_contract.py +113 -0
- package/template/skills/party-mode/scripts/party_actions.py +95 -0
- package/template/skills/party-mode/scripts/party_board_store.py +148 -0
- package/template/skills/party-mode/scripts/party_mode_v2.py +345 -317
- package/template/skills/party-mode/scripts/party_reports.py +177 -0
- package/template/skills/party-mode/scripts/party_state_machine.py +189 -0
- package/template/skills/runtime-health/SKILL.md +14 -2
- package/template/skills/runtime-health/scripts/doctor.py +278 -41
- package/template/skills/task-planning/SKILL.md +105 -61
- package/template/skills/task-review/SKILL.md +4 -4
- package/template/skills/task-review/scripts/review_check.py +277 -20
- package/template/skills/test-first/SKILL.md +18 -3
- package/template/skills/test-first/manifest.json +8 -4
- package/template/.cowork-flow/changes/archive/.gitkeep +0 -1
- package/template/.cowork-flow/scripts/adapters/cli/add_session.py +0 -465
- package/template/.cowork-flow/scripts/adapters/cli/change.py +0 -412
- package/template/.cowork-flow/workspace/index.md +0 -102
- package/template/.zcode/scaffold/AGENTS.md +0 -145
- package/template/.zcode/scaffold/CLAUDE.md +0 -5
|
@@ -4,167 +4,67 @@
|
|
|
4
4
|
from __future__ import annotations
|
|
5
5
|
|
|
6
6
|
import json
|
|
7
|
-
import re
|
|
8
7
|
from dataclasses import dataclass
|
|
9
8
|
from pathlib import Path
|
|
10
9
|
|
|
11
10
|
from infra.files import read_text_utf8
|
|
12
|
-
from infra.
|
|
13
|
-
from
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
from infra.paths import FILE_TASK_JSON
|
|
12
|
+
from services.context_discovery import (
|
|
13
|
+
detect_installed_platforms,
|
|
14
|
+
discover_spec_files,
|
|
15
|
+
get_check_context,
|
|
16
|
+
get_debug_context,
|
|
17
|
+
get_domain_skill_context,
|
|
18
|
+
get_implement_backend,
|
|
19
|
+
get_implement_base,
|
|
20
|
+
get_implement_frontend,
|
|
21
|
+
get_implement_spec,
|
|
22
|
+
is_skill_path,
|
|
23
|
+
skill_path,
|
|
24
|
+
use_claude_skill_context,
|
|
20
25
|
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
'"type": "deleted-file" before running `task next --run`.'
|
|
26
|
+
from services.context_jsonl import (
|
|
27
|
+
ContextJsonlEntry,
|
|
28
|
+
ContextJsonlReadResult,
|
|
29
|
+
ContextValidationIssue,
|
|
30
|
+
iter_jsonl_lines,
|
|
31
|
+
read_context_jsonl_entries,
|
|
32
|
+
write_jsonl,
|
|
29
33
|
)
|
|
34
|
+
from services.context_paths import (
|
|
35
|
+
CONTEXT_ENTRY_TYPES,
|
|
36
|
+
TaskContextError,
|
|
37
|
+
normalize_context_file_scope_entry,
|
|
38
|
+
normalize_context_path,
|
|
39
|
+
prepare_context_entry,
|
|
40
|
+
)
|
|
41
|
+
from services.plan_binding import normalize_plan_file, plan_file_blockers
|
|
30
42
|
|
|
31
43
|
|
|
32
|
-
|
|
33
|
-
"""Raised when a context mutation cannot be performed."""
|
|
34
|
-
|
|
35
|
-
def __init__(self, code: str, path: Path, detail: str) -> None:
|
|
36
|
-
self.code = code
|
|
37
|
-
self.path = path
|
|
38
|
-
self.detail = detail
|
|
39
|
-
super().__init__(f"{code}: {detail}: {path}")
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def normalize_context_path(
|
|
43
|
-
repo_root: Path,
|
|
44
|
-
path: str,
|
|
45
|
-
entry_type: str,
|
|
46
|
-
) -> tuple[str, Path]:
|
|
47
|
-
"""Return a canonical repo-relative context path and its absolute target."""
|
|
48
|
-
candidate = Path(repo_root) / str(path)
|
|
49
|
-
_validate_context_entry_type(candidate, entry_type)
|
|
50
|
-
normalized = _normalized_context_path(path, entry_type)
|
|
51
|
-
segments = normalized.split("/")
|
|
52
|
-
_validate_context_path(candidate, normalized, segments, path, entry_type)
|
|
53
|
-
repo_root, full_path = _resolved_context_target(repo_root, segments)
|
|
54
|
-
return _typed_context_path(normalized, full_path, repo_root, entry_type)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def _validate_context_entry_type(candidate: Path, entry_type: str) -> None:
|
|
58
|
-
if entry_type not in CONTEXT_ENTRY_TYPES:
|
|
59
|
-
raise TaskContextError(
|
|
60
|
-
"TASK-CONTEXT-TYPE-001",
|
|
61
|
-
candidate,
|
|
62
|
-
f"unsupported context entry type: {entry_type}",
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def _normalized_context_path(path: str, entry_type: str) -> str:
|
|
67
|
-
normalized = str(path).replace("\\", "/")
|
|
68
|
-
while normalized.startswith("./"):
|
|
69
|
-
normalized = normalized[2:]
|
|
70
|
-
if entry_type == "directory" and normalized.endswith("/"):
|
|
71
|
-
normalized = normalized[:-1]
|
|
72
|
-
return normalized
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def _validate_context_path(
|
|
76
|
-
candidate: Path,
|
|
77
|
-
normalized: str,
|
|
78
|
-
segments: list[str],
|
|
79
|
-
path: str,
|
|
80
|
-
entry_type: str,
|
|
81
|
-
) -> None:
|
|
82
|
-
if not _is_valid_context_path(normalized, segments, path, entry_type):
|
|
83
|
-
raise TaskContextError(
|
|
84
|
-
"TASK-CONTEXT-PATH-002",
|
|
85
|
-
candidate,
|
|
86
|
-
"context path must be a canonical repository-relative path",
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def _is_valid_context_path(
|
|
91
|
-
normalized: str,
|
|
92
|
-
segments: list[str],
|
|
93
|
-
path: str,
|
|
94
|
-
entry_type: str,
|
|
95
|
-
) -> bool:
|
|
96
|
-
return not (
|
|
97
|
-
not normalized
|
|
98
|
-
or normalized.startswith("/")
|
|
99
|
-
or re.match(r"^[A-Za-z]:", normalized) is not None
|
|
100
|
-
or any(segment in ("", ".", "..") for segment in segments)
|
|
101
|
-
or any(character in normalized for character in "*?[]")
|
|
102
|
-
or (entry_type in {"planned-file", "deleted-file"} and str(path).endswith(("/", "\\")))
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
def _resolved_context_target(
|
|
107
|
-
repo_root: Path,
|
|
108
|
-
segments: list[str],
|
|
109
|
-
) -> tuple[Path, Path]:
|
|
110
|
-
resolved_root = Path(repo_root).resolve()
|
|
111
|
-
return resolved_root, resolved_root.joinpath(*segments).resolve(strict=False)
|
|
44
|
+
CONTEXT_JSONL_FILES = ("implement.jsonl", "check.jsonl", "debug.jsonl")
|
|
112
45
|
|
|
113
46
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
) -> tuple[str, Path]:
|
|
120
|
-
try:
|
|
121
|
-
full_path.relative_to(repo_root)
|
|
122
|
-
except ValueError as error:
|
|
123
|
-
raise TaskContextError(
|
|
124
|
-
"TASK-CONTEXT-PATH-002",
|
|
125
|
-
full_path,
|
|
126
|
-
"context path resolves outside the repository",
|
|
127
|
-
) from error
|
|
47
|
+
@dataclass(frozen=True)
|
|
48
|
+
class ContextInitializationResult:
|
|
49
|
+
created: tuple[str, ...]
|
|
50
|
+
skipped: tuple[str, ...]
|
|
51
|
+
entry_counts: dict[str, int]
|
|
128
52
|
|
|
129
|
-
if entry_type == "directory":
|
|
130
|
-
normalized = f"{normalized}/"
|
|
131
|
-
return normalized, full_path
|
|
132
53
|
|
|
54
|
+
@dataclass(frozen=True)
|
|
55
|
+
class ContextAddResult:
|
|
56
|
+
added: bool
|
|
57
|
+
entry_type: str
|
|
58
|
+
path: str
|
|
59
|
+
entry: dict
|
|
133
60
|
|
|
134
|
-
def prepare_context_entry(
|
|
135
|
-
repo_root: Path,
|
|
136
|
-
path: str,
|
|
137
|
-
reason: str,
|
|
138
|
-
requested_type: str | None,
|
|
139
|
-
) -> tuple[str, str, dict]:
|
|
140
|
-
"""Build one validated context entry without writing it."""
|
|
141
|
-
entry_type = requested_type
|
|
142
|
-
if entry_type is None:
|
|
143
|
-
candidate = Path(repo_root) / path
|
|
144
|
-
entry_type = "directory" if candidate.is_dir() else "file"
|
|
145
|
-
|
|
146
|
-
normalized_path, full_path = normalize_context_path(
|
|
147
|
-
repo_root,
|
|
148
|
-
path,
|
|
149
|
-
entry_type,
|
|
150
|
-
)
|
|
151
|
-
valid_target = {
|
|
152
|
-
"directory": full_path.is_dir(),
|
|
153
|
-
"planned-file": not full_path.is_dir(),
|
|
154
|
-
"deleted-file": not full_path.is_dir(),
|
|
155
|
-
"file": full_path.is_file(),
|
|
156
|
-
}[entry_type]
|
|
157
|
-
if not valid_target:
|
|
158
|
-
raise TaskContextError(
|
|
159
|
-
"TASK-CONTEXT-PATH-001",
|
|
160
|
-
full_path,
|
|
161
|
-
f"context {entry_type} path does not exist or has the wrong type",
|
|
162
|
-
)
|
|
163
61
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
62
|
+
@dataclass(frozen=True)
|
|
63
|
+
class ContextFileValidation:
|
|
64
|
+
context_file: str
|
|
65
|
+
exists: bool
|
|
66
|
+
entry_count: int
|
|
67
|
+
issues: tuple[ContextValidationIssue, ...]
|
|
168
68
|
|
|
169
69
|
|
|
170
70
|
def _context_issue(
|
|
@@ -248,7 +148,7 @@ def _validate_context_entry_target(
|
|
|
248
148
|
context_file,
|
|
249
149
|
line,
|
|
250
150
|
"file_not_found",
|
|
251
|
-
f"File not found: {normalized_path}
|
|
151
|
+
f"File not found: {normalized_path}",
|
|
252
152
|
)
|
|
253
153
|
return None
|
|
254
154
|
|
|
@@ -285,189 +185,6 @@ def _deleted_file_issue(
|
|
|
285
185
|
)
|
|
286
186
|
|
|
287
187
|
|
|
288
|
-
@dataclass(frozen=True)
|
|
289
|
-
class ContextInitializationResult:
|
|
290
|
-
created: tuple[str, ...]
|
|
291
|
-
skipped: tuple[str, ...]
|
|
292
|
-
entry_counts: dict[str, int]
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
@dataclass(frozen=True)
|
|
296
|
-
class ContextAddResult:
|
|
297
|
-
added: bool
|
|
298
|
-
entry_type: str
|
|
299
|
-
path: str
|
|
300
|
-
entry: dict
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
@dataclass(frozen=True)
|
|
304
|
-
class ContextValidationIssue:
|
|
305
|
-
context_file: str
|
|
306
|
-
line: int
|
|
307
|
-
code: str
|
|
308
|
-
message: str
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
@dataclass(frozen=True)
|
|
312
|
-
class ContextFileValidation:
|
|
313
|
-
context_file: str
|
|
314
|
-
exists: bool
|
|
315
|
-
entry_count: int
|
|
316
|
-
issues: tuple[ContextValidationIssue, ...]
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
def get_implement_base(repo_root: Path | None = None) -> list[dict]:
|
|
320
|
-
root = Path(repo_root) if repo_root is not None else get_repo_root()
|
|
321
|
-
entries = [
|
|
322
|
-
{
|
|
323
|
-
"file": "AGENTS.md",
|
|
324
|
-
"reason": "Project collaboration rules and workflow checks",
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
"file": f"{DIR_WORKFLOW}/{DIR_SPEC}/guides/index.md",
|
|
328
|
-
"reason": "Pre-implementation thinking guides",
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
"file": (
|
|
332
|
-
f"{DIR_WORKFLOW}/{DIR_SPEC}/guides/"
|
|
333
|
-
"pre-implementation-checklist.md"
|
|
334
|
-
),
|
|
335
|
-
"reason": "Mandatory pre-coding checklist",
|
|
336
|
-
},
|
|
337
|
-
]
|
|
338
|
-
entries.extend(context_entries(root, context="implement"))
|
|
339
|
-
return entries
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
def get_implement_backend() -> list[dict]:
|
|
343
|
-
return [
|
|
344
|
-
{
|
|
345
|
-
"file": f"{DIR_WORKFLOW}/{DIR_SPEC}/backend/index.md",
|
|
346
|
-
"reason": "Backend development guide",
|
|
347
|
-
}
|
|
348
|
-
]
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
def get_implement_frontend() -> list[dict]:
|
|
352
|
-
return [
|
|
353
|
-
{
|
|
354
|
-
"file": f"{DIR_WORKFLOW}/{DIR_SPEC}/frontend/index.md",
|
|
355
|
-
"reason": "Frontend development guide",
|
|
356
|
-
}
|
|
357
|
-
]
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
def get_implement_spec() -> list[dict]:
|
|
361
|
-
return [
|
|
362
|
-
{
|
|
363
|
-
"file": f"{DIR_WORKFLOW}/{DIR_SPEC}/index.md",
|
|
364
|
-
"reason": "Spec index — read before modifying spec/",
|
|
365
|
-
},
|
|
366
|
-
{
|
|
367
|
-
"file": f"{DIR_WORKFLOW}/{DIR_SPEC}/contracts/index.md",
|
|
368
|
-
"reason": "Contract definitions",
|
|
369
|
-
},
|
|
370
|
-
{
|
|
371
|
-
"file": f"{DIR_WORKFLOW}/{DIR_SPEC}/schemas/index.md",
|
|
372
|
-
"reason": "Schema definitions",
|
|
373
|
-
},
|
|
374
|
-
]
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
def detect_installed_platforms(repo_root: Path | None = None) -> list[str]:
|
|
378
|
-
repo_root = Path(repo_root) if repo_root is not None else get_repo_root()
|
|
379
|
-
platforms: list[str] = []
|
|
380
|
-
if (repo_root / ".codex").is_dir():
|
|
381
|
-
platforms.append("codex")
|
|
382
|
-
if (repo_root / ".opencode").is_dir():
|
|
383
|
-
platforms.append("opencode")
|
|
384
|
-
if (repo_root / ".claude").is_dir() or (repo_root / "CLAUDE.md").is_file():
|
|
385
|
-
platforms.append("claude-code")
|
|
386
|
-
return platforms
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
def use_claude_skill_context(repo_root: Path | None = None) -> bool:
|
|
390
|
-
return detect_installed_platforms(repo_root) == ["claude-code"]
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
def skill_path(name: str, repo_root: Path | None = None) -> str:
|
|
394
|
-
if use_claude_skill_context(repo_root):
|
|
395
|
-
return f".claude/skills/{name}/SKILL.md"
|
|
396
|
-
return f"{DIR_AGENTS}/skills/{name}/SKILL.md"
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
def get_domain_skill_context(
|
|
400
|
-
repo_root: Path,
|
|
401
|
-
*,
|
|
402
|
-
dev_type: str | None = None,
|
|
403
|
-
paths: tuple[str, ...] = (),
|
|
404
|
-
) -> list[dict]:
|
|
405
|
-
return context_entries(
|
|
406
|
-
repo_root,
|
|
407
|
-
context="implement",
|
|
408
|
-
dev_type=dev_type,
|
|
409
|
-
paths=paths,
|
|
410
|
-
include_wildcard=False,
|
|
411
|
-
)
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
def is_skill_path(file_path: str) -> bool:
|
|
415
|
-
return (
|
|
416
|
-
file_path.startswith(f"{DIR_AGENTS}/skills/")
|
|
417
|
-
or file_path.startswith(".claude/skills/")
|
|
418
|
-
or ".skills/" in file_path
|
|
419
|
-
or "/skills/" in file_path
|
|
420
|
-
)
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
def discover_spec_files(repo_root: Path, dev_type: str) -> list[str]:
|
|
424
|
-
if dev_type == "spec":
|
|
425
|
-
return [f"{DIR_WORKFLOW}/{DIR_SPEC}/index.md"]
|
|
426
|
-
|
|
427
|
-
spec_dir = repo_root / DIR_WORKFLOW / DIR_SPEC / dev_type
|
|
428
|
-
if not spec_dir.is_dir():
|
|
429
|
-
return []
|
|
430
|
-
return sorted(
|
|
431
|
-
f"{DIR_WORKFLOW}/{DIR_SPEC}/{dev_type}/{path.name}"
|
|
432
|
-
for path in spec_dir.glob("*.md")
|
|
433
|
-
if path.is_file()
|
|
434
|
-
)
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
def get_check_context(repo_root: Path, dev_type: str) -> list[dict]:
|
|
438
|
-
entries = context_entries(repo_root, context="check", dev_type=dev_type)
|
|
439
|
-
entries.sort(key=lambda entry: entry["file"])
|
|
440
|
-
if dev_type == "spec":
|
|
441
|
-
entries.extend(
|
|
442
|
-
{
|
|
443
|
-
"file": spec_file,
|
|
444
|
-
"reason": f"Verify {Path(spec_file).name} compliance",
|
|
445
|
-
}
|
|
446
|
-
for spec_file in discover_spec_files(repo_root, dev_type)
|
|
447
|
-
)
|
|
448
|
-
entries.extend(quality_source_entries(repo_root, dev_type))
|
|
449
|
-
return entries
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
def get_debug_context(
|
|
453
|
-
dev_type: str,
|
|
454
|
-
repo_root: Path | None = None,
|
|
455
|
-
) -> list[dict]:
|
|
456
|
-
root = Path(repo_root) if repo_root is not None else get_repo_root()
|
|
457
|
-
return context_entries(root, context="debug", dev_type=dev_type)
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
def write_jsonl(path: Path, entries: list[dict]) -> None:
|
|
461
|
-
lines = [json.dumps(entry, ensure_ascii=False) for entry in entries]
|
|
462
|
-
path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
def iter_jsonl_lines(path: Path):
|
|
466
|
-
with path.open("r", encoding="utf-8") as stream:
|
|
467
|
-
for line_number, line in enumerate(stream, start=1):
|
|
468
|
-
yield line_number, line.rstrip("\n")
|
|
469
|
-
|
|
470
|
-
|
|
471
188
|
class TaskContextService:
|
|
472
189
|
"""Manage task JSONL context without CLI rendering."""
|
|
473
190
|
|
|
@@ -561,17 +278,10 @@ class TaskContextService:
|
|
|
561
278
|
|
|
562
279
|
def entries(self, task_dir: Path, context_name: str) -> list[dict]:
|
|
563
280
|
context_file = Path(task_dir) / self._context_file_name(context_name)
|
|
564
|
-
if not context_file.is_file():
|
|
565
|
-
return []
|
|
566
281
|
|
|
567
282
|
entries: list[dict] = []
|
|
568
|
-
for
|
|
569
|
-
|
|
570
|
-
continue
|
|
571
|
-
try:
|
|
572
|
-
data = json.loads(line)
|
|
573
|
-
except json.JSONDecodeError:
|
|
574
|
-
continue
|
|
283
|
+
for entry in read_context_jsonl_entries(context_file).entries:
|
|
284
|
+
data = entry.data
|
|
575
285
|
if isinstance(data, dict):
|
|
576
286
|
entries.append(data)
|
|
577
287
|
return entries
|
|
@@ -588,7 +298,8 @@ class TaskContextService:
|
|
|
588
298
|
context_name: str,
|
|
589
299
|
) -> ContextFileValidation:
|
|
590
300
|
context_file = Path(task_dir) / self._context_file_name(context_name)
|
|
591
|
-
|
|
301
|
+
parsed = read_context_jsonl_entries(context_file)
|
|
302
|
+
if not parsed.exists:
|
|
592
303
|
return ContextFileValidation(
|
|
593
304
|
context_file=context_file.name,
|
|
594
305
|
exists=False,
|
|
@@ -596,30 +307,13 @@ class TaskContextService:
|
|
|
596
307
|
issues=(),
|
|
597
308
|
)
|
|
598
309
|
|
|
599
|
-
issues: list[ContextValidationIssue] =
|
|
600
|
-
|
|
601
|
-
for line_number, line in iter_jsonl_lines(context_file):
|
|
602
|
-
if not line.strip():
|
|
603
|
-
continue
|
|
604
|
-
entry_count += 1
|
|
605
|
-
try:
|
|
606
|
-
data = json.loads(line)
|
|
607
|
-
except json.JSONDecodeError:
|
|
608
|
-
issues.append(
|
|
609
|
-
ContextValidationIssue(
|
|
610
|
-
context_file=context_file.name,
|
|
611
|
-
line=line_number,
|
|
612
|
-
code="invalid_json",
|
|
613
|
-
message="Invalid JSON",
|
|
614
|
-
)
|
|
615
|
-
)
|
|
616
|
-
continue
|
|
617
|
-
|
|
310
|
+
issues: list[ContextValidationIssue] = list(parsed.issues)
|
|
311
|
+
for entry in parsed.entries:
|
|
618
312
|
issue = validate_context_entry(
|
|
619
313
|
self.repo_root,
|
|
620
|
-
context_file
|
|
621
|
-
|
|
622
|
-
data,
|
|
314
|
+
entry.context_file,
|
|
315
|
+
entry.line,
|
|
316
|
+
entry.data,
|
|
623
317
|
)
|
|
624
318
|
if issue is not None:
|
|
625
319
|
issues.append(issue)
|
|
@@ -627,22 +321,66 @@ class TaskContextService:
|
|
|
627
321
|
return ContextFileValidation(
|
|
628
322
|
context_file=context_file.name,
|
|
629
323
|
exists=True,
|
|
630
|
-
entry_count=entry_count,
|
|
324
|
+
entry_count=parsed.entry_count,
|
|
631
325
|
issues=tuple(issues),
|
|
632
326
|
)
|
|
633
327
|
|
|
634
328
|
def start_blockers(self, task_dir: Path) -> tuple[str, ...]:
|
|
635
329
|
task_dir = Path(task_dir)
|
|
636
330
|
blockers: list[str] = []
|
|
331
|
+
task_data = self._task_data(task_dir)
|
|
637
332
|
if not (task_dir / FILE_TASK_JSON).is_file():
|
|
638
333
|
blockers.append("task.json is missing")
|
|
639
|
-
|
|
334
|
+
anchor_text = read_text_utf8(task_dir / "decision-anchor.md")
|
|
335
|
+
if not anchor_text:
|
|
640
336
|
blockers.append("decision-anchor.md is missing or empty")
|
|
337
|
+
else:
|
|
338
|
+
blockers.extend(self._decision_anchor_section_blockers(anchor_text))
|
|
641
339
|
for context_file in ("implement.jsonl",):
|
|
642
340
|
if not read_text_utf8(task_dir / context_file):
|
|
643
341
|
blockers.append(f"{context_file} is missing or empty")
|
|
342
|
+
if (task_dir / FILE_TASK_JSON).is_file() and not self._is_tiny_task(task_data):
|
|
343
|
+
blockers.extend(self._plan_file_blockers(task_data))
|
|
644
344
|
return tuple(blockers)
|
|
645
345
|
|
|
346
|
+
def _task_data(self, task_dir: Path) -> dict:
|
|
347
|
+
text = read_text_utf8(Path(task_dir) / FILE_TASK_JSON)
|
|
348
|
+
if not text:
|
|
349
|
+
return {}
|
|
350
|
+
try:
|
|
351
|
+
data = json.loads(text)
|
|
352
|
+
except json.JSONDecodeError:
|
|
353
|
+
return {}
|
|
354
|
+
return data if isinstance(data, dict) else {}
|
|
355
|
+
|
|
356
|
+
@staticmethod
|
|
357
|
+
def _decision_anchor_section_blockers(anchor_text: str) -> list[str]:
|
|
358
|
+
blockers: list[str] = []
|
|
359
|
+
for section in ("## 目标", "## 验收标准"):
|
|
360
|
+
if section not in anchor_text:
|
|
361
|
+
blockers.append(
|
|
362
|
+
f"decision-anchor.md missing required section: {section}"
|
|
363
|
+
)
|
|
364
|
+
return blockers
|
|
365
|
+
|
|
366
|
+
@staticmethod
|
|
367
|
+
def _is_tiny_task(task_data: dict) -> bool:
|
|
368
|
+
meta = task_data.get("meta")
|
|
369
|
+
candidates = [
|
|
370
|
+
task_data.get("taskType"),
|
|
371
|
+
task_data.get("task_type"),
|
|
372
|
+
meta.get("taskType") if isinstance(meta, dict) else None,
|
|
373
|
+
meta.get("task_type") if isinstance(meta, dict) else None,
|
|
374
|
+
]
|
|
375
|
+
return any(str(candidate).lower() == "tiny" for candidate in candidates)
|
|
376
|
+
|
|
377
|
+
def _plan_file_blockers(self, task_data: dict) -> list[str]:
|
|
378
|
+
return plan_file_blockers(self.repo_root, task_data)
|
|
379
|
+
|
|
380
|
+
@staticmethod
|
|
381
|
+
def _normalize_plan_file(plan_file: str) -> str | None:
|
|
382
|
+
return normalize_plan_file(plan_file)
|
|
383
|
+
|
|
646
384
|
def validation_issue_summaries(self, task_dir: Path) -> tuple[str, ...]:
|
|
647
385
|
summaries: list[str] = []
|
|
648
386
|
for context_file in CONTEXT_JSONL_FILES:
|
|
@@ -14,6 +14,7 @@ from infra.paths import (
|
|
|
14
14
|
ensure_task_date_prefix,
|
|
15
15
|
get_tasks_dir,
|
|
16
16
|
)
|
|
17
|
+
from services.plan_binding import PlanBindingError, bind_plan_file
|
|
17
18
|
from services.task_repository import TaskRepository, TaskRepositoryError
|
|
18
19
|
|
|
19
20
|
|
|
@@ -82,6 +83,7 @@ class TaskCreationService:
|
|
|
82
83
|
tasks_dir = ensure_tasks_dir(self.repo_root)
|
|
83
84
|
task_name = self._task_name(request)
|
|
84
85
|
task_dir = tasks_dir / task_name
|
|
86
|
+
plan_metadata, bound_plan_path = self._plan_metadata(request.from_plan)
|
|
85
87
|
directory_existed = task_dir.exists()
|
|
86
88
|
task_dir.mkdir(parents=True, exist_ok=True)
|
|
87
89
|
|
|
@@ -107,7 +109,7 @@ class TaskCreationService:
|
|
|
107
109
|
"parent": None,
|
|
108
110
|
"relatedFiles": [],
|
|
109
111
|
"notes": "",
|
|
110
|
-
"meta":
|
|
112
|
+
"meta": plan_metadata,
|
|
111
113
|
}
|
|
112
114
|
try:
|
|
113
115
|
self.repository.replace(task_dir, task_data)
|
|
@@ -137,7 +139,7 @@ class TaskCreationService:
|
|
|
137
139
|
|
|
138
140
|
generated_anchor = self._generate_anchor(
|
|
139
141
|
task_dir,
|
|
140
|
-
|
|
142
|
+
bound_plan_path,
|
|
141
143
|
)
|
|
142
144
|
return TaskCreationResult(
|
|
143
145
|
task_dir=task_dir,
|
|
@@ -155,14 +157,47 @@ class TaskCreationService:
|
|
|
155
157
|
return f"{request.date_prefix}-{request.slug}"
|
|
156
158
|
return ensure_task_date_prefix(request.slug)
|
|
157
159
|
|
|
160
|
+
def _plan_metadata(self, from_plan: str | Path | None) -> tuple[dict, Path | None]:
|
|
161
|
+
if not from_plan:
|
|
162
|
+
return {}, None
|
|
163
|
+
try:
|
|
164
|
+
bound = bind_plan_file(
|
|
165
|
+
self.repo_root,
|
|
166
|
+
from_plan,
|
|
167
|
+
allow_absolute=True,
|
|
168
|
+
require_exists=True,
|
|
169
|
+
)
|
|
170
|
+
except PlanBindingError as error:
|
|
171
|
+
raise self._plan_creation_error(error) from error
|
|
172
|
+
return {"planFile": bound.normalized}, bound.path
|
|
173
|
+
|
|
174
|
+
@staticmethod
|
|
175
|
+
def _plan_creation_error(error: PlanBindingError) -> TaskCreationError:
|
|
176
|
+
if error.code == "missing":
|
|
177
|
+
return TaskCreationError(
|
|
178
|
+
"TASK-CREATE-PLAN-003",
|
|
179
|
+
error.path,
|
|
180
|
+
"plan file does not exist",
|
|
181
|
+
)
|
|
182
|
+
if error.code == "outside_repository":
|
|
183
|
+
return TaskCreationError(
|
|
184
|
+
"TASK-CREATE-PLAN-004",
|
|
185
|
+
error.path,
|
|
186
|
+
"plan file must be inside the repository",
|
|
187
|
+
)
|
|
188
|
+
return TaskCreationError(
|
|
189
|
+
"TASK-CREATE-PLAN-005",
|
|
190
|
+
error.path,
|
|
191
|
+
"plan file must live under .cowork-flow/plans",
|
|
192
|
+
)
|
|
193
|
+
|
|
158
194
|
@staticmethod
|
|
159
195
|
def _generate_anchor(
|
|
160
196
|
task_dir: Path,
|
|
161
|
-
|
|
197
|
+
plan_path: Path | None,
|
|
162
198
|
) -> bool:
|
|
163
|
-
if
|
|
199
|
+
if plan_path is None:
|
|
164
200
|
return False
|
|
165
|
-
plan_path = Path(from_plan)
|
|
166
201
|
if not plan_path.is_file():
|
|
167
202
|
return False
|
|
168
203
|
|