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.
Files changed (90) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +102 -23
  3. package/package.json +8 -3
  4. package/src/cli.js +6 -0
  5. package/src/commands/init.js +0 -83
  6. package/src/commands/source-refresh.js +40 -0
  7. package/src/commands/sync.js +6 -0
  8. package/src/commands/update.js +59 -6
  9. package/src/lib/copy-template.js +200 -50
  10. package/src/lib/host-assets.js +367 -64
  11. package/src/lib/plan-applier.js +47 -0
  12. package/template/.claude/hooks/inject-workflow-state.py +7 -0
  13. package/template/.codex/hooks/inject-workflow-state.py +7 -0
  14. package/template/.codex/hooks.json +1 -1
  15. package/template/.cowork-flow/.version +1 -1
  16. package/template/.cowork-flow/config.yaml +0 -11
  17. package/template/.cowork-flow/scripts/adapters/cli/init_developer.py +0 -1
  18. package/template/.cowork-flow/scripts/adapters/cli/subagent.py +7 -4
  19. package/template/.cowork-flow/scripts/adapters/cli/task.py +8 -484
  20. package/template/.cowork-flow/scripts/adapters/cli/task_archive_commands.py +15 -134
  21. package/template/.cowork-flow/scripts/adapters/cli/task_context_commands.py +7 -1
  22. package/template/.cowork-flow/scripts/adapters/cli/task_lifecycle_commands.py +388 -0
  23. package/template/.cowork-flow/scripts/adapters/cli/task_navigation.py +163 -2
  24. package/template/.cowork-flow/scripts/adapters/git/git_context.py +16 -193
  25. package/template/.cowork-flow/scripts/adapters/host/host_manifest.py +170 -84
  26. package/template/.cowork-flow/scripts/infra/config.py +0 -17
  27. package/template/.cowork-flow/scripts/infra/developer_profile.py +0 -95
  28. package/template/.cowork-flow/scripts/infra/paths.py +0 -79
  29. package/template/.cowork-flow/scripts/infra/skill_manifest.py +23 -3
  30. package/template/.cowork-flow/scripts/infra/storage/operation_log.py +40 -0
  31. package/template/.cowork-flow/scripts/infra/storage/state_store.py +356 -1
  32. package/template/.cowork-flow/scripts/kernel/workflow_route.py +15 -15
  33. package/template/.cowork-flow/scripts/run.py +0 -5
  34. package/template/.cowork-flow/scripts/services/context_discovery.py +156 -0
  35. package/template/.cowork-flow/scripts/services/context_jsonl.py +119 -0
  36. package/template/.cowork-flow/scripts/services/context_paths.py +186 -0
  37. package/template/.cowork-flow/scripts/services/lifecycle_checks.py +186 -69
  38. package/template/.cowork-flow/scripts/services/lifecycle_policy.py +128 -0
  39. package/template/.cowork-flow/scripts/services/plan_binding.py +146 -0
  40. package/template/.cowork-flow/scripts/services/readiness.py +3 -170
  41. package/template/.cowork-flow/scripts/services/task_archive.py +115 -24
  42. package/template/.cowork-flow/scripts/services/task_context.py +103 -365
  43. package/template/.cowork-flow/scripts/services/task_creation.py +40 -5
  44. package/template/.cowork-flow/scripts/services/task_lifecycle.py +155 -18
  45. package/template/.cowork-flow/scripts/services/task_routing.py +80 -67
  46. package/template/.cowork-flow/scripts/services/task_utils.py +0 -146
  47. package/template/.cowork-flow/scripts/services/workflow_runtime.py +1 -1
  48. package/template/.cowork-flow/spec/contracts/capabilities.md +23 -0
  49. package/template/.cowork-flow/spec/contracts/decision-anchor.md +2 -2
  50. package/template/.cowork-flow/spec/contracts/error-output-as-data.md +8 -0
  51. package/template/.cowork-flow/spec/contracts/index.md +1 -0
  52. package/template/.cowork-flow/spec/contracts/party-mode-v2-board.md +20 -0
  53. package/template/.cowork-flow/spec/contracts/plan-binding.md +50 -0
  54. package/template/.cowork-flow/spec/contracts/skill-owned-actions.md +31 -7
  55. package/template/.cowork-flow/spec/guides/index.md +3 -1
  56. package/template/.cowork-flow/spec/index.md +5 -4
  57. package/template/.cowork-flow/spec/references/definition-of-done.md +2 -3
  58. package/template/.cowork-flow/spec/references/orchestration-patterns.md +1 -1
  59. package/template/.cowork-flow/spec/runtime/contract-registry.json +14 -0
  60. package/template/.cowork-flow/spec/runtime/host-assets.json +73 -3
  61. package/template/.cowork-flow/spec/runtime/index.md +1 -1
  62. package/template/.cowork-flow/spec/schemas/host-assets.schema.json +150 -8
  63. package/template/.zcode/.zcode-plugin/plugin.json +1 -1
  64. package/template/skills/batch-execution/SKILL.md +37 -3
  65. package/template/skills/batch-execution/scripts/batch_action.py +4 -0
  66. package/template/skills/batch-execution/scripts/batch_execution.py +120 -499
  67. package/template/skills/batch-execution/scripts/batch_recovery.py +94 -0
  68. package/template/skills/batch-execution/scripts/batch_state_machine.py +201 -0
  69. package/template/skills/batch-execution/scripts/batch_verification.py +326 -0
  70. package/template/skills/brainstorming/SKILL.md +8 -7
  71. package/template/skills/cowork-flow/SKILL.md +3 -0
  72. package/template/skills/party-mode/scripts/party_action_contract.py +113 -0
  73. package/template/skills/party-mode/scripts/party_actions.py +95 -0
  74. package/template/skills/party-mode/scripts/party_board_store.py +148 -0
  75. package/template/skills/party-mode/scripts/party_mode_v2.py +345 -317
  76. package/template/skills/party-mode/scripts/party_reports.py +177 -0
  77. package/template/skills/party-mode/scripts/party_state_machine.py +189 -0
  78. package/template/skills/runtime-health/SKILL.md +14 -2
  79. package/template/skills/runtime-health/scripts/doctor.py +278 -41
  80. package/template/skills/task-planning/SKILL.md +105 -61
  81. package/template/skills/task-review/SKILL.md +4 -4
  82. package/template/skills/task-review/scripts/review_check.py +277 -20
  83. package/template/skills/test-first/SKILL.md +18 -3
  84. package/template/skills/test-first/manifest.json +8 -4
  85. package/template/.cowork-flow/changes/archive/.gitkeep +0 -1
  86. package/template/.cowork-flow/scripts/adapters/cli/add_session.py +0 -465
  87. package/template/.cowork-flow/scripts/adapters/cli/change.py +0 -412
  88. package/template/.cowork-flow/workspace/index.md +0 -102
  89. package/template/.zcode/scaffold/AGENTS.md +0 -145
  90. package/template/.zcode/scaffold/CLAUDE.md +0 -5
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """Host-neutral action contract checks for Party Mode V2."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from typing import Any
8
+
9
+ ACTION_TYPES = {
10
+ "dispatch_child",
11
+ "send_control_message",
12
+ "wait_children",
13
+ "list_children",
14
+ "close_child",
15
+ "report_to_user",
16
+ }
17
+
18
+ DOCUMENT_FIELDS = {"schema_version", "discussion_id", "next_actions"}
19
+ ACTION_FIELDS = {
20
+ "action_id",
21
+ "type",
22
+ "agent_id",
23
+ "agent_ids",
24
+ "agent_kind",
25
+ "lens",
26
+ "message_kind",
27
+ "prompt_file",
28
+ "reason",
29
+ }
30
+ REQUIRED_FIELDS_BY_TYPE = {
31
+ "dispatch_child": {
32
+ "action_id",
33
+ "type",
34
+ "agent_id",
35
+ "agent_kind",
36
+ "lens",
37
+ "message_kind",
38
+ "prompt_file",
39
+ },
40
+ "send_control_message": {
41
+ "action_id",
42
+ "type",
43
+ "agent_id",
44
+ "agent_kind",
45
+ "lens",
46
+ "message_kind",
47
+ "prompt_file",
48
+ },
49
+ "wait_children": {"action_id", "type", "agent_ids"},
50
+ "list_children": {"action_id", "type"},
51
+ "close_child": {"action_id", "type", "agent_id", "reason"},
52
+ "report_to_user": {"action_id", "type", "reason"},
53
+ }
54
+
55
+
56
+ class PartyActionContractError(ValueError):
57
+ """Raised when a Party Mode action document violates the schema contract."""
58
+
59
+
60
+ def _require_non_empty_string(value: Any, error: str) -> str:
61
+ if not isinstance(value, str) or not value.strip():
62
+ raise PartyActionContractError(error)
63
+ return value
64
+
65
+
66
+ def _validate_agent_ids(value: Any, index: int) -> None:
67
+ if not isinstance(value, list):
68
+ raise PartyActionContractError(f"invalid_action_field:{index}:agent_ids")
69
+ for agent_index, agent_id in enumerate(value):
70
+ if not isinstance(agent_id, str) or not agent_id.strip():
71
+ raise PartyActionContractError(
72
+ f"invalid_action_field:{index}:agent_ids[{agent_index}]"
73
+ )
74
+
75
+
76
+ def _validate_action(action: Any, index: int) -> None:
77
+ if not isinstance(action, dict):
78
+ raise PartyActionContractError(f"invalid_action:{index}")
79
+ unknown = sorted(set(action) - ACTION_FIELDS)
80
+ if unknown:
81
+ raise PartyActionContractError(f"unexpected_action_field:{index}:{unknown[0]}")
82
+
83
+ action_type = _require_non_empty_string(action.get("type"), f"invalid_action_type:{index}")
84
+ if action_type not in ACTION_TYPES:
85
+ raise PartyActionContractError(f"invalid_action_type:{index}:{action_type}")
86
+
87
+ missing = sorted(REQUIRED_FIELDS_BY_TYPE[action_type] - set(action))
88
+ if missing:
89
+ raise PartyActionContractError(f"missing_action_field:{index}:{missing[0]}")
90
+
91
+ _require_non_empty_string(action.get("action_id"), f"invalid_action_field:{index}:action_id")
92
+ for key in ("agent_id", "agent_kind", "lens", "message_kind", "prompt_file", "reason"):
93
+ if key in action:
94
+ _require_non_empty_string(action.get(key), f"invalid_action_field:{index}:{key}")
95
+ if "agent_ids" in action:
96
+ _validate_agent_ids(action["agent_ids"], index)
97
+
98
+
99
+ def validate_actions_document(document: Any) -> dict[str, Any]:
100
+ if not isinstance(document, dict):
101
+ raise PartyActionContractError("invalid_actions_document")
102
+ unknown = sorted(set(document) - DOCUMENT_FIELDS)
103
+ if unknown:
104
+ raise PartyActionContractError(f"unexpected_actions_field:{unknown[0]}")
105
+ if type(document.get("schema_version")) is not int or document["schema_version"] != 1:
106
+ raise PartyActionContractError("invalid_actions_schema_version")
107
+ _require_non_empty_string(document.get("discussion_id"), "invalid_actions_discussion_id")
108
+ actions = document.get("next_actions")
109
+ if not isinstance(actions, list):
110
+ raise PartyActionContractError("invalid_actions_next_actions")
111
+ for index, action in enumerate(actions):
112
+ _validate_action(action, index)
113
+ return document
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """Host-neutral Party Mode V2 action document builders."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from typing import Any
8
+
9
+ from party_action_contract import validate_actions_document
10
+
11
+ PARTY_BOARD_ACTION_CAPABILITY = "party_board_action"
12
+
13
+
14
+ def child_action(
15
+ *,
16
+ agent: dict[str, str],
17
+ round_number: int,
18
+ phase: str,
19
+ prompt_file: str,
20
+ ) -> dict[str, Any]:
21
+ agent_id = agent["agent_id"]
22
+ return {
23
+ "action_id": f"r{round_number}-{phase}-{agent_id}",
24
+ "type": "dispatch_child" if phase == "publish" else "send_control_message",
25
+ "agent_id": agent_id,
26
+ "agent_kind": "advisory",
27
+ "lens": agent["lens"],
28
+ "message_kind": f"board_{phase}",
29
+ "prompt_file": prompt_file,
30
+ }
31
+
32
+
33
+ def actions_document(
34
+ discussion_id: str,
35
+ *,
36
+ child_actions: list[dict[str, Any]],
37
+ agent_ids: list[str],
38
+ round_number: int,
39
+ phase: str,
40
+ ) -> dict[str, Any]:
41
+ actions = list(child_actions)
42
+ actions.append(
43
+ {
44
+ "action_id": f"r{round_number}-{phase}-wait",
45
+ "type": "wait_children",
46
+ "agent_ids": list(agent_ids),
47
+ }
48
+ )
49
+ return validate_actions_document(
50
+ {"schema_version": 1, "discussion_id": discussion_id, "next_actions": actions}
51
+ )
52
+
53
+
54
+ def fallback_actions_document(
55
+ discussion_id: str,
56
+ *,
57
+ round_number: int,
58
+ phase: str,
59
+ host_id: str,
60
+ fallback: str,
61
+ ) -> dict[str, Any]:
62
+ action = {
63
+ "action_id": f"r{round_number}-{phase}-fallback",
64
+ "type": "report_to_user",
65
+ "reason": (
66
+ f"{PARTY_BOARD_ACTION_CAPABILITY} unsupported for host {host_id}; "
67
+ f"fallback={fallback}; manually deliver prompt files or record unable_to_dispatch"
68
+ ),
69
+ }
70
+ return validate_actions_document(
71
+ {"schema_version": 1, "discussion_id": discussion_id, "next_actions": [action]}
72
+ )
73
+
74
+
75
+ def close_actions(
76
+ agents: list[dict[str, str]],
77
+ *,
78
+ round_number: int,
79
+ reason: str,
80
+ ) -> list[dict[str, Any]]:
81
+ return [
82
+ {
83
+ "action_id": f"r{round_number}-close-{agent['agent_id']}",
84
+ "type": "close_child",
85
+ "agent_id": agent["agent_id"],
86
+ "reason": reason,
87
+ }
88
+ for agent in agents
89
+ ]
90
+
91
+
92
+ def empty_actions_document(discussion_id: str) -> dict[str, Any]:
93
+ return validate_actions_document(
94
+ {"schema_version": 1, "discussion_id": discussion_id, "next_actions": []}
95
+ )
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """Storage helpers for Party Mode V2 runtime-board state."""
4
+
5
+ from __future__ import annotations
6
+
7
+ import json
8
+ import os
9
+ import threading
10
+ from datetime import datetime, timezone
11
+ from pathlib import Path
12
+ from typing import Any
13
+
14
+ _LOCKS_GUARD = threading.Lock()
15
+ _STATE_LOCKS: dict[str, dict[str, Any]] = {}
16
+
17
+ __all__ = [
18
+ "append_action_history",
19
+ "append_audit",
20
+ "load_board",
21
+ "read_json",
22
+ "save_board",
23
+ "state_lock",
24
+ "write_json",
25
+ ]
26
+
27
+
28
+ def _now() -> str:
29
+ return datetime.now(timezone.utc).isoformat()
30
+
31
+
32
+ def _lock_file(handle: Any) -> None:
33
+ if os.name == "nt":
34
+ import msvcrt
35
+
36
+ handle.seek(0)
37
+ msvcrt.locking(handle.fileno(), msvcrt.LK_LOCK, 1)
38
+ return
39
+
40
+ import fcntl
41
+
42
+ fcntl.flock(handle.fileno(), fcntl.LOCK_EX)
43
+
44
+
45
+ def _unlock_file(handle: Any) -> None:
46
+ if os.name == "nt":
47
+ import msvcrt
48
+
49
+ handle.seek(0)
50
+ msvcrt.locking(handle.fileno(), msvcrt.LK_UNLCK, 1)
51
+ return
52
+
53
+ import fcntl
54
+
55
+ fcntl.flock(handle.fileno(), fcntl.LOCK_UN)
56
+
57
+
58
+ class _StateLock:
59
+ def __init__(self, base_dir: Path, state: dict[str, Any]) -> None:
60
+ self.base_dir = base_dir
61
+ self.state = state
62
+
63
+ def __enter__(self) -> "_StateLock":
64
+ thread_lock = self.state["thread_lock"]
65
+ thread_lock.acquire()
66
+ current_thread = threading.get_ident()
67
+ if self.state.get("owner_thread") == current_thread:
68
+ self.state["depth"] += 1
69
+ return self
70
+
71
+ self.base_dir.mkdir(parents=True, exist_ok=True)
72
+ lock_path = self.base_dir / ".state.lock"
73
+ handle = lock_path.open("a+b")
74
+ handle.seek(0)
75
+ handle.write(b"0")
76
+ handle.flush()
77
+ _lock_file(handle)
78
+ self.state["owner_thread"] = current_thread
79
+ self.state["depth"] = 1
80
+ self.state["handle"] = handle
81
+ return self
82
+
83
+ def __exit__(self, exc_type: Any, exc: Any, traceback: Any) -> None:
84
+ thread_lock = self.state["thread_lock"]
85
+ try:
86
+ current_thread = threading.get_ident()
87
+ if self.state.get("owner_thread") == current_thread:
88
+ self.state["depth"] -= 1
89
+ if self.state["depth"] == 0:
90
+ handle = self.state.pop("handle", None)
91
+ self.state["owner_thread"] = None
92
+ if handle is not None:
93
+ try:
94
+ _unlock_file(handle)
95
+ finally:
96
+ handle.close()
97
+ finally:
98
+ thread_lock.release()
99
+
100
+
101
+ def state_lock(base_dir: Path) -> _StateLock:
102
+ key = str(base_dir.resolve())
103
+ with _LOCKS_GUARD:
104
+ state = _STATE_LOCKS.get(key)
105
+ if state is None:
106
+ state = {
107
+ "thread_lock": threading.RLock(),
108
+ "owner_thread": None,
109
+ "depth": 0,
110
+ }
111
+ _STATE_LOCKS[key] = state
112
+ return _StateLock(base_dir, state)
113
+
114
+
115
+ def write_json(path: Path, data: dict[str, Any]) -> None:
116
+ path.parent.mkdir(parents=True, exist_ok=True)
117
+ temp_path = path.with_name(f".{path.name}.{threading.get_ident()}.tmp")
118
+ temp_path.write_text(
119
+ json.dumps(data, ensure_ascii=False, indent=2) + "\n",
120
+ encoding="utf-8",
121
+ )
122
+ os.replace(temp_path, path)
123
+
124
+
125
+ def read_json(path: Path) -> dict[str, Any]:
126
+ return json.loads(path.read_text(encoding="utf-8"))
127
+
128
+
129
+ def load_board(base_dir: Path) -> dict[str, Any]:
130
+ return read_json(base_dir / "board.json")
131
+
132
+
133
+ def save_board(base_dir: Path, board: dict[str, Any]) -> None:
134
+ write_json(base_dir / "board.json", board)
135
+
136
+
137
+ def append_audit(base_dir: Path, event: str, payload: dict[str, Any]) -> None:
138
+ audit_path = base_dir / "audit.jsonl"
139
+ entry = {"timestamp": _now(), "event": event, "payload": payload}
140
+ with audit_path.open("a", encoding="utf-8") as handle:
141
+ handle.write(json.dumps(entry, ensure_ascii=False) + "\n")
142
+
143
+
144
+ def append_action_history(base_dir: Path, event: str, payload: dict[str, Any]) -> None:
145
+ history_path = base_dir / "action_history.jsonl"
146
+ entry = {"timestamp": _now(), "event": event, "payload": payload}
147
+ with history_path.open("a", encoding="utf-8") as handle:
148
+ handle.write(json.dumps(entry, ensure_ascii=False) + "\n")