@tothemax/tasking 0.0.0-stage → 0.6.15
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/README.md +119 -2
- package/README.zh-CN.md +120 -0
- package/assets/skills/install-glab/SKILL.md +70 -0
- package/assets/skills/land/SKILL.md +63 -0
- package/assets/skills/land/land_watch.py +312 -0
- package/assets/skills/openspec-archive-change/SKILL.md +114 -0
- package/assets/skills/opsx-grill-with-docs/SKILL.md +193 -0
- package/assets/skills/opsx-implement/SKILL.md +258 -0
- package/assets/skills/opsx-propose-with-tdd/SKILL.md +271 -0
- package/assets/workflows/WORKFLOW.code-mr.en.md.example +345 -0
- package/assets/workflows/WORKFLOW.code-mr.md.example +339 -0
- package/assets/workflows/WORKFLOW.feishu-direct.en.md.example +267 -0
- package/assets/workflows/WORKFLOW.feishu-direct.md.example +258 -0
- package/assets/workflows/WORKFLOW.grill-openspec.en.md.example +362 -0
- package/assets/workflows/WORKFLOW.grill-openspec.md.example +356 -0
- package/assets/workflows/WORKFLOW.minimal.en.md.example +296 -0
- package/assets/workflows/WORKFLOW.minimal.md.example +289 -0
- package/dist/adapters/feishu/events.d.ts +55 -0
- package/dist/adapters/feishu/events.d.ts.map +1 -0
- package/dist/adapters/feishu/events.js +184 -0
- package/dist/adapters/feishu/events.js.map +1 -0
- package/dist/adapters/feishu/index.d.ts +2 -0
- package/dist/adapters/feishu/index.d.ts.map +1 -0
- package/dist/adapters/feishu/index.js +2 -0
- package/dist/adapters/feishu/index.js.map +1 -0
- package/dist/adapters/feishu/probe.d.ts +31 -0
- package/dist/adapters/feishu/probe.d.ts.map +1 -0
- package/dist/adapters/feishu/probe.js +179 -0
- package/dist/adapters/feishu/probe.js.map +1 -0
- package/dist/adapters/feishu/source.d.ts +124 -0
- package/dist/adapters/feishu/source.d.ts.map +1 -0
- package/dist/adapters/feishu/source.js +715 -0
- package/dist/adapters/feishu/source.js.map +1 -0
- package/dist/adapters/jira/index.d.ts +2 -0
- package/dist/adapters/jira/index.d.ts.map +1 -0
- package/dist/adapters/jira/index.js +2 -0
- package/dist/adapters/jira/index.js.map +1 -0
- package/dist/adapters/jira/tracker.d.ts +63 -0
- package/dist/adapters/jira/tracker.d.ts.map +1 -0
- package/dist/adapters/jira/tracker.js +402 -0
- package/dist/adapters/jira/tracker.js.map +1 -0
- package/dist/bridge/binding-store.d.ts +93 -0
- package/dist/bridge/binding-store.d.ts.map +1 -0
- package/dist/bridge/binding-store.js +365 -0
- package/dist/bridge/binding-store.js.map +1 -0
- package/dist/bridge/commands.d.ts +45 -0
- package/dist/bridge/commands.d.ts.map +1 -0
- package/dist/bridge/commands.js +197 -0
- package/dist/bridge/commands.js.map +1 -0
- package/dist/bridge/comment-bridge.d.ts +116 -0
- package/dist/bridge/comment-bridge.d.ts.map +1 -0
- package/dist/bridge/comment-bridge.js +1473 -0
- package/dist/bridge/comment-bridge.js.map +1 -0
- package/dist/cli/daemon-info.d.ts +17 -0
- package/dist/cli/daemon-info.d.ts.map +1 -0
- package/dist/cli/daemon-info.js +64 -0
- package/dist/cli/daemon-info.js.map +1 -0
- package/dist/cli/daemon.d.ts +27 -0
- package/dist/cli/daemon.d.ts.map +1 -0
- package/dist/cli/daemon.js +77 -0
- package/dist/cli/daemon.js.map +1 -0
- package/dist/cli/doctor.d.ts +7 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +156 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/event-channel.d.ts +16 -0
- package/dist/cli/event-channel.d.ts.map +1 -0
- package/dist/cli/event-channel.js +51 -0
- package/dist/cli/event-channel.js.map +1 -0
- package/dist/cli/help.d.ts +3 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/help.js +155 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +774 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +64 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +1296 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/instance-lock.d.ts +13 -0
- package/dist/cli/instance-lock.d.ts.map +1 -0
- package/dist/cli/instance-lock.js +53 -0
- package/dist/cli/instance-lock.js.map +1 -0
- package/dist/cli/prompts.d.ts +13 -0
- package/dist/cli/prompts.d.ts.map +1 -0
- package/dist/cli/prompts.js +26 -0
- package/dist/cli/prompts.js.map +1 -0
- package/dist/cli/style.d.ts +26 -0
- package/dist/cli/style.d.ts.map +1 -0
- package/dist/cli/style.js +58 -0
- package/dist/cli/style.js.map +1 -0
- package/dist/cli/tui-helpers.d.ts +5 -0
- package/dist/cli/tui-helpers.d.ts.map +1 -0
- package/dist/cli/tui-helpers.js +124 -0
- package/dist/cli/tui-helpers.js.map +1 -0
- package/dist/cli/workflow-path.d.ts +12 -0
- package/dist/cli/workflow-path.d.ts.map +1 -0
- package/dist/cli/workflow-path.js +37 -0
- package/dist/cli/workflow-path.js.map +1 -0
- package/dist/config/config-types.d.ts +180 -0
- package/dist/config/config-types.d.ts.map +1 -0
- package/dist/config/config-types.js +71 -0
- package/dist/config/config-types.js.map +1 -0
- package/dist/config/dotenv.d.ts +2 -0
- package/dist/config/dotenv.d.ts.map +1 -0
- package/dist/config/dotenv.js +10 -0
- package/dist/config/dotenv.js.map +1 -0
- package/dist/config/index.d.ts +6 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +6 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +5 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +304 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/manager.d.ts +31 -0
- package/dist/config/manager.d.ts.map +1 -0
- package/dist/config/manager.js +110 -0
- package/dist/config/manager.js.map +1 -0
- package/dist/config/resolver.d.ts +6 -0
- package/dist/config/resolver.d.ts.map +1 -0
- package/dist/config/resolver.js +267 -0
- package/dist/config/resolver.js.map +1 -0
- package/dist/config/validator.d.ts +9 -0
- package/dist/config/validator.d.ts.map +1 -0
- package/dist/config/validator.js +70 -0
- package/dist/config/validator.js.map +1 -0
- package/dist/direct/card.d.ts +49 -0
- package/dist/direct/card.d.ts.map +1 -0
- package/dist/direct/card.js +274 -0
- package/dist/direct/card.js.map +1 -0
- package/dist/direct/command.d.ts +12 -0
- package/dist/direct/command.d.ts.map +1 -0
- package/dist/direct/command.js +23 -0
- package/dist/direct/command.js.map +1 -0
- package/dist/direct/manager.d.ts +159 -0
- package/dist/direct/manager.d.ts.map +1 -0
- package/dist/direct/manager.js +1862 -0
- package/dist/direct/manager.js.map +1 -0
- package/dist/mcp/inject.d.ts +5 -0
- package/dist/mcp/inject.d.ts.map +1 -0
- package/dist/mcp/inject.js +51 -0
- package/dist/mcp/inject.js.map +1 -0
- package/dist/mcp/jira-server.d.ts +29 -0
- package/dist/mcp/jira-server.d.ts.map +1 -0
- package/dist/mcp/jira-server.js +288 -0
- package/dist/mcp/jira-server.js.map +1 -0
- package/dist/observability/activity-store.d.ts +29 -0
- package/dist/observability/activity-store.d.ts.map +1 -0
- package/dist/observability/activity-store.js +32 -0
- package/dist/observability/activity-store.js.map +1 -0
- package/dist/observability/config-view.d.ts +19 -0
- package/dist/observability/config-view.d.ts.map +1 -0
- package/dist/observability/config-view.js +61 -0
- package/dist/observability/config-view.js.map +1 -0
- package/dist/observability/http-dashboard.d.ts +36 -0
- package/dist/observability/http-dashboard.d.ts.map +1 -0
- package/dist/observability/http-dashboard.js +297 -0
- package/dist/observability/http-dashboard.js.map +1 -0
- package/dist/observability/log-buffer.d.ts +21 -0
- package/dist/observability/log-buffer.d.ts.map +1 -0
- package/dist/observability/log-buffer.js +69 -0
- package/dist/observability/log-buffer.js.map +1 -0
- package/dist/observability/logger.d.ts +37 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +114 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/snapshot.d.ts +11 -0
- package/dist/observability/snapshot.d.ts.map +1 -0
- package/dist/observability/snapshot.js +59 -0
- package/dist/observability/snapshot.js.map +1 -0
- package/dist/observability/terminal-dashboard.d.ts +155 -0
- package/dist/observability/terminal-dashboard.d.ts.map +1 -0
- package/dist/observability/terminal-dashboard.js +1598 -0
- package/dist/observability/terminal-dashboard.js.map +1 -0
- package/dist/observability/wrap.d.ts +4 -0
- package/dist/observability/wrap.d.ts.map +1 -0
- package/dist/observability/wrap.js +80 -0
- package/dist/observability/wrap.js.map +1 -0
- package/dist/scheduler/index.d.ts +2 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js +2 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/scheduler/scheduler.d.ts +52 -0
- package/dist/scheduler/scheduler.d.ts.map +1 -0
- package/dist/scheduler/scheduler.js +535 -0
- package/dist/scheduler/scheduler.js.map +1 -0
- package/dist/shared/agent-resolver.d.ts +11 -0
- package/dist/shared/agent-resolver.d.ts.map +1 -0
- package/dist/shared/agent-resolver.js +20 -0
- package/dist/shared/agent-resolver.js.map +1 -0
- package/dist/shared/errors.d.ts +14 -0
- package/dist/shared/errors.d.ts.map +1 -0
- package/dist/shared/errors.js +24 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/index.d.ts +4 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +4 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/info-card.d.ts +24 -0
- package/dist/shared/info-card.d.ts.map +1 -0
- package/dist/shared/info-card.js +46 -0
- package/dist/shared/info-card.js.map +1 -0
- package/dist/shared/types.d.ts +148 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +15 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/translate/card.d.ts +2 -0
- package/dist/translate/card.d.ts.map +1 -0
- package/dist/translate/card.js +17 -0
- package/dist/translate/card.js.map +1 -0
- package/dist/translate/dict.d.ts +7 -0
- package/dist/translate/dict.d.ts.map +1 -0
- package/dist/translate/dict.js +895 -0
- package/dist/translate/dict.js.map +1 -0
- package/dist/translate/locale.d.ts +8 -0
- package/dist/translate/locale.d.ts.map +1 -0
- package/dist/translate/locale.js +75 -0
- package/dist/translate/locale.js.map +1 -0
- package/dist/translate/normalize.d.ts +4 -0
- package/dist/translate/normalize.d.ts.map +1 -0
- package/dist/translate/normalize.js +38 -0
- package/dist/translate/normalize.js.map +1 -0
- package/dist/translate/output.d.ts +3 -0
- package/dist/translate/output.d.ts.map +1 -0
- package/dist/translate/output.js +16 -0
- package/dist/translate/output.js.map +1 -0
- package/dist/worker/prompt.d.ts +11 -0
- package/dist/worker/prompt.d.ts.map +1 -0
- package/dist/worker/prompt.js +153 -0
- package/dist/worker/prompt.js.map +1 -0
- package/dist/worker/runner.d.ts +101 -0
- package/dist/worker/runner.d.ts.map +1 -0
- package/dist/worker/runner.js +448 -0
- package/dist/worker/runner.js.map +1 -0
- package/dist/workspace/index.d.ts +2 -0
- package/dist/workspace/index.d.ts.map +1 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/manager.d.ts +37 -0
- package/dist/workspace/manager.d.ts.map +1 -0
- package/dist/workspace/manager.js +157 -0
- package/dist/workspace/manager.js.map +1 -0
- package/package.json +65 -4
package/README.md
CHANGED
|
@@ -1,3 +1,120 @@
|
|
|
1
|
-
|
|
1
|
+
[简体中文](./README.zh-CN.md) | English
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# tasking
|
|
4
|
+
|
|
5
|
+
A TypeScript CLI daemon that orchestrates [opencode](https://opencode.ai) coding-agent work from Jira and Feishu:
|
|
6
|
+
|
|
7
|
+
- **Structured (Jira):** deterministic poll/dispatch/reconcile/retry scheduler — no LLM in the hot loop.
|
|
8
|
+
- **Feishu:** direct opencode sessions (`/chat` in a group) plus a bidirectional comment bridge to Jira. The LLM `route agent` (inbox triage) is **not implemented**.
|
|
9
|
+
|
|
10
|
+
Both converge on a shared normalized `Task` model, a shared workspace manager, and a shared `opencode run` worker.
|
|
11
|
+
|
|
12
|
+
In terms of scheduling, the `tasking` module extends the coordination model adopted from [Symphony](https://github.com/openai/symphony).
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g @tothemax/tasking
|
|
18
|
+
# or use without installing:
|
|
19
|
+
npx @tothemax/tasking --help
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Requires Node 22+ and the [`opencode`](https://opencode.ai) CLI on your `PATH`.
|
|
23
|
+
|
|
24
|
+
## Quick start
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 1. Scaffold a WORKFLOW.md in the current directory
|
|
28
|
+
tasking init
|
|
29
|
+
|
|
30
|
+
# 2. Edit WORKFLOW.md with your Jira/Feishu credentials (or use $ENV vars)
|
|
31
|
+
|
|
32
|
+
# 3. Start the daemon
|
|
33
|
+
tasking start
|
|
34
|
+
|
|
35
|
+
# In another terminal:
|
|
36
|
+
tasking status # show running tasks, retry queue, token totals
|
|
37
|
+
tasking logs # tail recent structured logs
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
For guided quickstarts, see the [Chinese guide](./docs/zh/getting-started.md) or the [English guide](./docs/en/getting-started.md).
|
|
41
|
+
|
|
42
|
+
## Commands
|
|
43
|
+
|
|
44
|
+
| Command | Description |
|
|
45
|
+
|---------|-------------|
|
|
46
|
+
| `tasking init [workflow-path]` | Scaffold a starter `WORKFLOW.md` |
|
|
47
|
+
| `tasking start [path] [--port N]` | Start the daemon (loads `./WORKFLOW.md` by default) |
|
|
48
|
+
| `tasking status` | Print a runtime snapshot (running, retrying, totals) |
|
|
49
|
+
| `tasking logs` | Print recent structured logs |
|
|
50
|
+
| `tasking doctor [workflow-path]` | Read-only whole-chain health check (WORKFLOW.md, Feishu, Jira, opencode) |
|
|
51
|
+
|
|
52
|
+
## `WORKFLOW.md` contract
|
|
53
|
+
|
|
54
|
+
The repo-owned `WORKFLOW.md` (YAML front matter + prompt body) configures the tracker, polling, workspaces, hooks, the opencode worker, and the Feishu source. `tasking init` writes one of four starter templates — `feishu-direct` is the **default** (bare `tasking init`; Feishu-direct-only — [`assets/workflows/WORKFLOW.feishu-direct.md.example`](./assets/workflows/WORKFLOW.feishu-direct.md.example), `tracker.kind: none`, no Jira needed; the first question picks the task source and enter enters this path). The Jira variants are `minimal` (minimal — [`assets/workflows/WORKFLOW.minimal.md.example`](./assets/workflows/WORKFLOW.minimal.md.example)), `code-mr` (full VCS/MR flow — [`assets/workflows/WORKFLOW.code-mr.md.example`](./assets/workflows/WORKFLOW.code-mr.md.example)), and `grill-openspec` ([`assets/workflows/WORKFLOW.grill-openspec.md.example`](./assets/workflows/WORKFLOW.grill-openspec.md.example)) — via `--workflow <variant>` or the connect-Jira branch. Every variant also ships in English: pass `--lang en` to get the `.en.` editions ([`assets/workflows/WORKFLOW.minimal.en.md.example`](./assets/workflows/WORKFLOW.minimal.en.md.example), [`assets/workflows/WORKFLOW.code-mr.en.md.example`](./assets/workflows/WORKFLOW.code-mr.en.md.example), [`assets/workflows/WORKFLOW.grill-openspec.en.md.example`](./assets/workflows/WORKFLOW.grill-openspec.en.md.example)); interactive init prompts for the language when omitted. For a full config reference, see the `code-mr` or `grill-openspec` template.
|
|
55
|
+
|
|
56
|
+
Key config blocks:
|
|
57
|
+
|
|
58
|
+
- `tracker.*` — Jira endpoint, auth (`$JIRA_API_TOKEN`), project key, active/terminal states, required labels
|
|
59
|
+
- `polling.interval_ms` — poll cadence (default 30000)
|
|
60
|
+
- `workspace.root` — per-task workspace root (default `<tmp>/tasking_workspaces`)
|
|
61
|
+
- `hooks.*` — `after_create` / `before_run` / `after_run` / `before_remove` shell hooks
|
|
62
|
+
- `agent.*` — `max_concurrent_agents`, `max_turns`, `max_retry_backoff_ms`, per-state caps
|
|
63
|
+
- `opencode.*` — worker command (default `opencode run`), agent profile, turn/stall timeouts
|
|
64
|
+
- `router.*` — **not implemented**: parsed by the resolver but no runtime code consumes it (reserved for a future route-agent triage path)
|
|
65
|
+
- `feishu.*` — Feishu source app credentials and `enabled` flag; `feishu.direct` enables `/chat` direct opencode sessions in fixed directories (bypasses Jira; see `docs/configuration.md`)
|
|
66
|
+
- `server.port` — optional HTTP dashboard port
|
|
67
|
+
|
|
68
|
+
The prompt body is a strict Liquid-compatible template with `task` (or `issue`) and `attempt` variables. Unknown variables/filters fail rendering.
|
|
69
|
+
|
|
70
|
+
## Architecture
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
Jira (structured) ──► deterministic scheduler ──┐
|
|
74
|
+
├──► workspace ──► opencode run
|
|
75
|
+
Feishu (direct sessions) ──► direct worker ─────┘
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- **Structured path:** Symphony-style poll tick → state machine → reconcile → retry with exponential backoff. No LLM in the hot loop.
|
|
79
|
+
- **Feishu path:** direct opencode sessions (`/chat` in a group runs opencode in a configured directory; one topic per session), plus a comment bridge mirroring issue threads ↔ Jira comments. A planned LLM route-agent inbox triage is **not implemented**.
|
|
80
|
+
- **Worker:** `opencode run --dir <workspace> --agent <build> "<prompt>"` subprocess, OS-level isolation per task.
|
|
81
|
+
- **State:** orchestrator scheduling state is in-memory (restart = re-poll tracker); direct-session bindings are durable SQLite.
|
|
82
|
+
|
|
83
|
+
See [`openspec/changes/archive/2026-06-23-bootstrap-tasking-runtime/design.md`](./openspec/changes/archive/2026-06-23-bootstrap-tasking-runtime/design.md) for the full design decisions.
|
|
84
|
+
|
|
85
|
+
## Safety posture
|
|
86
|
+
|
|
87
|
+
`tasking` inherits Symphony's three non-negotiable filesystem safety invariants:
|
|
88
|
+
|
|
89
|
+
1. **Agent cwd == workspace path** — the worker's cwd is always the per-task workspace; mismatches abort the attempt.
|
|
90
|
+
2. **Workspace under root** — workspace paths are normalized to absolute and must have the workspace root as a prefix; path escapes are rejected.
|
|
91
|
+
3. **Sanitized workspace keys** — only `[A-Za-z0-9._-]` allowed in workspace directory names; all other characters become `_`.
|
|
92
|
+
|
|
93
|
+
### Trust boundary
|
|
94
|
+
|
|
95
|
+
`tasking` is designed for **trusted environments** with a high-trust configuration:
|
|
96
|
+
|
|
97
|
+
- The `opencode run` worker runs with the daemon's OS privileges. Use opencode's approval/sandbox settings to tighten execution where needed.
|
|
98
|
+
- **Hook scripts are fully trusted** — `WORKFLOW.md` hooks (`after_create`, `before_run`, etc.) run arbitrary shell in the workspace directory with `bash -lc`. Only version hooks from sources you control.
|
|
99
|
+
- Workspace hooks are bounded by `hooks.timeout_ms` (default 60s) to avoid hanging the daemon.
|
|
100
|
+
- The orchestrator performs **no tracker writes** — ticket mutations (state transitions, comments) happen inside the coding agent via its tools, not in orchestrator business logic.
|
|
101
|
+
- API tokens are never logged. `$VAR` indirection keeps secrets out of `WORKFLOW.md`.
|
|
102
|
+
|
|
103
|
+
### Approval & sandbox policy
|
|
104
|
+
|
|
105
|
+
Approval, sandbox, and user-input behavior is delegated to `opencode run`'s own policy. Configure it via the `opencode.*` block. A run that requires user input is treated as a hard failure (it does not stall indefinitely).
|
|
106
|
+
|
|
107
|
+
## Development
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npm install
|
|
111
|
+
npm run lint # biome check
|
|
112
|
+
npm run typecheck # tsc --noEmit
|
|
113
|
+
npm test # vitest run
|
|
114
|
+
npm run build # tsc → dist/
|
|
115
|
+
npm run dev -- start # run via tsx
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
Apache-2.0
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
简体中文 | [English](./README.md)
|
|
2
|
+
|
|
3
|
+
# tasking
|
|
4
|
+
|
|
5
|
+
一个 TypeScript CLI daemon,从两个任务源编排 [opencode](https://opencode.ai) coding-agent 工作:
|
|
6
|
+
|
|
7
|
+
- **结构化(Jira):** 确定性的轮询/派发/对账/重试调度器——热循环中无 LLM。
|
|
8
|
+
- **飞书:** 群内 `/chat` 直接跑 opencode 的直连会话,加上与 Jira 的评论双向镜像桥。LLM `route agent`(inbox 分诊)**未实现**。
|
|
9
|
+
|
|
10
|
+
两者汇聚到共享的 `Task` 模型、共享的工作区管理器与共享的 `opencode run` worker。
|
|
11
|
+
|
|
12
|
+
`tasking` 在调度层面参考了 [Symphony](https://github.com/openai/symphony)的协调模型,在此基础进行扩展。
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g @tothemax/tasking
|
|
18
|
+
# 或免安装使用:
|
|
19
|
+
npx @tothemax/tasking --help
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
需要 Node 22+,且 `PATH` 中有 [`opencode`](https://opencode.ai) CLI。
|
|
23
|
+
|
|
24
|
+
## 快速上手
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 1. 在当前目录脚手架生成 WORKFLOW.md
|
|
28
|
+
tasking init
|
|
29
|
+
|
|
30
|
+
# 2. 用你的 Jira/飞书凭据编辑 WORKFLOW.md(或用 $ENV 变量)
|
|
31
|
+
|
|
32
|
+
# 3. 启动 daemon
|
|
33
|
+
tasking start
|
|
34
|
+
|
|
35
|
+
# 在另一个终端:
|
|
36
|
+
tasking status # 查看运行中任务、重试队列、token 总量
|
|
37
|
+
tasking logs # 查看近期结构化日志
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
引导式上手指引见 [中文快速上手](./docs/zh/getting-started.md) 或 [英文快速上手](./docs/en/getting-started.md)。
|
|
41
|
+
|
|
42
|
+
## 命令
|
|
43
|
+
|
|
44
|
+
| 命令 | 说明 |
|
|
45
|
+
|---------|-------------|
|
|
46
|
+
| `tasking init [workflow-path]` | 脚手架生成一份 `WORKFLOW.md` |
|
|
47
|
+
| `tasking start [path] [--port N]` | 启动 daemon(默认加载 `./WORKFLOW.md`) |
|
|
48
|
+
| `tasking status` | 打印运行时快照(运行中、重试中、总量) |
|
|
49
|
+
| `tasking logs` | 打印近期结构化日志 |
|
|
50
|
+
| `tasking doctor [workflow-path]` | 全链路只读体检(WORKFLOW.md、飞书、Jira、opencode) |
|
|
51
|
+
|
|
52
|
+
## `WORKFLOW.md` 契约
|
|
53
|
+
|
|
54
|
+
仓库自有的 `WORKFLOW.md`(YAML front matter + prompt 正文)配置 tracker、轮询、工作区、hooks、opencode worker 与飞书源。`tasking init` 写入四款 starter 模板之一——默认为 **`feishu-direct`**(裸 `tasking init` 即是;飞书直连专用——[`assets/workflows/WORKFLOW.feishu-direct.md.example`](./assets/workflows/WORKFLOW.feishu-direct.md.example),`tracker.kind: none`,无需 Jira;首问「任务来源」回车即进该路径)。Jira 变体为 `minimal`(最小——[`assets/workflows/WORKFLOW.minimal.md.example`](./assets/workflows/WORKFLOW.minimal.md.example))、`code-mr`(完整 VCS/MR 流程——[`assets/workflows/WORKFLOW.code-mr.md.example`](./assets/workflows/WORKFLOW.code-mr.md.example))与 `grill-openspec`([`assets/workflows/WORKFLOW.grill-openspec.md.example`](./assets/workflows/WORKFLOW.grill-openspec.md.example))——经 `--workflow <variant>` 或「接 Jira」分支选择。每个变体另有英文版:传 `--lang en` 获取 `.en.` 版模板([`assets/workflows/WORKFLOW.minimal.en.md.example`](./assets/workflows/WORKFLOW.minimal.en.md.example)、[`assets/workflows/WORKFLOW.code-mr.en.md.example`](./assets/workflows/WORKFLOW.code-mr.en.md.example)、[`assets/workflows/WORKFLOW.grill-openspec.en.md.example`](./assets/workflows/WORKFLOW.grill-openspec.en.md.example));交互式 init 未指定语言时会引导选择。完整配置参考见 `code-mr` 或 `grill-openspec` 模板。
|
|
55
|
+
|
|
56
|
+
关键配置块:
|
|
57
|
+
|
|
58
|
+
- `tracker.*` — Jira endpoint、鉴权(`$JIRA_API_TOKEN`)、project key、active/terminal 状态、必需 label
|
|
59
|
+
- `polling.interval_ms` — 轮询节奏(默认 30000)
|
|
60
|
+
- `workspace.root` — 每任务工作区根(默认 `<tmp>/tasking_workspaces`)
|
|
61
|
+
- `hooks.*` — `after_create` / `before_run` / `after_run` / `before_remove` shell hooks
|
|
62
|
+
- `agent.*` — `max_concurrent_agents`、`max_turns`、`max_retry_backoff_ms`、按状态上限
|
|
63
|
+
- `opencode.*` — worker 命令(默认 `opencode run`)、agent profile、turn/stall 超时
|
|
64
|
+
- `router.*` — **未实现**:resolver 会解析但无运行时代码消费(预留供将来 route agent 分诊)
|
|
65
|
+
- `feishu.*` — 飞书源应用凭据与 `enabled` 标志;`feishu.direct` 启用 `/chat` 固定目录 opencode 直连会话(绕过 Jira;见 `docs/configuration.md`)
|
|
66
|
+
- `server.port` — 可选 HTTP dashboard 端口
|
|
67
|
+
|
|
68
|
+
prompt 正文是严格 Liquid 兼容模板,带 `task`(或 `issue`)与 `attempt` 变量。未知变量/过滤器会导致渲染失败。
|
|
69
|
+
|
|
70
|
+
## 架构
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
Jira (structured) ──► deterministic scheduler ──┐
|
|
74
|
+
├──► shared Task model ──► workspace ──► opencode run
|
|
75
|
+
Feishu (direct sessions) ──► direct worker ──┘
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- **结构化路径:** Symphony 式轮询 tick → 状态机 → 对账 → 指数退避重试。热循环中无 LLM。
|
|
79
|
+
- **飞书路径:** 群内 `/chat` 直连会话(在配置目录跑 opencode,一个话题一个会话),加上 issue 话题 ↔ Jira 评论的双向镜像桥。规划的 route agent inbox 分诊**未实现**。
|
|
80
|
+
- **Worker:** `opencode run --dir <workspace> --agent <build> "<prompt>"` 子进程,按任务做 OS 级隔离。
|
|
81
|
+
- **状态:** 编排器调度状态在内存中(重启 = 重新轮询 tracker);直连会话绑定是持久 SQLite。
|
|
82
|
+
|
|
83
|
+
完整设计决策见 [`openspec/changes/archive/2026-06-23-bootstrap-tasking-runtime/design.md`](./openspec/changes/archive/2026-06-23-bootstrap-tasking-runtime/design.md)。
|
|
84
|
+
|
|
85
|
+
## 安全姿态
|
|
86
|
+
|
|
87
|
+
`tasking` 继承 Symphony 三条不可妥协的文件系统安全不变式:
|
|
88
|
+
|
|
89
|
+
1. **Agent cwd == 工作区路径** — worker 的 cwd 恒为每任务工作区;不匹配则中止该 attempt。
|
|
90
|
+
2. **工作区位于 root 内** — 工作区路径规范化为绝对路径,且必须以工作区 root 为前缀;路径逃逸被拒绝。
|
|
91
|
+
3. **工作区 key 已清洗** — 工作区目录名仅允许 `[A-Za-z0-9._-]`;其余字符转为 `_`。
|
|
92
|
+
|
|
93
|
+
### 信任边界
|
|
94
|
+
|
|
95
|
+
`tasking` 面向**可信环境**、高信任配置:
|
|
96
|
+
|
|
97
|
+
- `opencode run` worker 以 daemon 的 OS 权限运行。按需用 opencode 的 approval/sandbox 设置收紧执行。
|
|
98
|
+
- **Hook 脚本完全可信** — `WORKFLOW.md` hooks(`after_create`、`before_run` 等)以 `bash -lc` 在工作区目录运行任意 shell。只运行你可控来源的 hook。
|
|
99
|
+
- 工作区 hooks 受 `hooks.timeout_ms`(默认 60s)约束,避免 daemon 挂起。
|
|
100
|
+
- 编排器**不做 tracker 写入** — 工单变更(状态流转、评论)发生在 coding agent 内部经其工具完成,而非编排器业务逻辑。
|
|
101
|
+
- API token 绝不记录。`$VAR` 间接引用让凭据不进 `WORKFLOW.md`。
|
|
102
|
+
|
|
103
|
+
### Approval 与 sandbox 策略
|
|
104
|
+
|
|
105
|
+
Approval、sandbox 与用户输入行为委托给 `opencode run` 自身策略。通过 `opencode.*` 块配置。需要用户输入的运行视为硬失败(不会无限 stall)。
|
|
106
|
+
|
|
107
|
+
## 开发
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npm install
|
|
111
|
+
npm run lint # biome check
|
|
112
|
+
npm run typecheck # tsc --noEmit
|
|
113
|
+
npm test # vitest run
|
|
114
|
+
npm run build # tsc → dist/
|
|
115
|
+
npm run dev -- start # 经 tsx 运行
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## 许可证
|
|
119
|
+
|
|
120
|
+
Apache-2.0
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: install-glab
|
|
3
|
+
description:
|
|
4
|
+
Idempotently ensure the GitLab CLI (glab) is installed and authenticated.
|
|
5
|
+
Run before any glab step when `command -v glab` fails, or when a glab
|
|
6
|
+
command reports "command not found".
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Install glab
|
|
10
|
+
|
|
11
|
+
Ensure `glab` is available before running any MR/gitlab operation. The daemon
|
|
12
|
+
injects `GITLAB_TOKEN`/`GITLAB_HOST` into the workspace environment, so no
|
|
13
|
+
interactive `glab auth login` is needed — `glab` picks the token up itself.
|
|
14
|
+
|
|
15
|
+
## Steps
|
|
16
|
+
|
|
17
|
+
1. Check whether glab is already installed and authenticated:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
command -v glab && glab auth status
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- If it succeeds (exit 0), stop here — glab is ready.
|
|
24
|
+
|
|
25
|
+
2. Otherwise install the official binary. Choose the block for your platform:
|
|
26
|
+
|
|
27
|
+
**Linux (amd64/arm64)** or **macOS (arm64/amd64)** — download the latest
|
|
28
|
+
release from the GitLab CLI releases API into `~/.local/bin`:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
set -e
|
|
32
|
+
mkdir -p ~/.local/bin
|
|
33
|
+
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')"
|
|
34
|
+
OS="$(uname -s | tr '[:upper:]' '[:lower:]')" # darwin for macOS
|
|
35
|
+
URL="$(
|
|
36
|
+
curl -fsSL "https://gitlab.com/api/v4/projects/gitlab-org%2Fcli/releases/permalink/latest/assets/links" \
|
|
37
|
+
| grep -oE "https://[^\"]*glab_[^\"]*_${OS}_${ARCH}\.tar\.gz" | head -n1
|
|
38
|
+
)"
|
|
39
|
+
curl -fsSL "$URL" -o /tmp/glab.tar.gz
|
|
40
|
+
tar -xzf /tmp/glab.tar.gz -C /tmp
|
|
41
|
+
install -m 0755 /tmp/bin/glab ~/.local/bin/glab
|
|
42
|
+
export PATH="$HOME/.local/bin:$PATH"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Package managers (fallback):**
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
brew install glab # macOS
|
|
49
|
+
snap install glab # linux (snap)
|
|
50
|
+
scoop install glab # windows
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
3. Verify it works end-to-end:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
glab auth status
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
A successful run lists the authenticated GitLab host from `GITLAB_HOST`
|
|
60
|
+
without prompting.
|
|
61
|
+
|
|
62
|
+
## Notes
|
|
63
|
+
|
|
64
|
+
- Idempotent: if `command -v glab` already succeeds, step 1 exits early.
|
|
65
|
+
- If the release download fails (network/proxy), do NOT pretend the install
|
|
66
|
+
succeeded — print the package-manager fallback commands and continue; if a
|
|
67
|
+
`glab` step is then still blocked, escalate to a human.
|
|
68
|
+
- `~/.local/bin` must be on PATH; if not, add
|
|
69
|
+
`export PATH="$HOME/.local/bin:$PATH"` to the shell rc or prepend it in the
|
|
70
|
+
same command that runs `glab`.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: land
|
|
3
|
+
description:
|
|
4
|
+
MR landing playbook: CI/review monitoring via land_watch.py, review feedback
|
|
5
|
+
handling via glab api, and squash-merge. Only read this skill when you need
|
|
6
|
+
to land/merge an MR.
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Land
|
|
10
|
+
|
|
11
|
+
## glab 预认证
|
|
12
|
+
|
|
13
|
+
`glab` 已通过 `GITLAB_TOKEN` 环境变量预认证,直接使用 `glab` 命令。无需 `glab auth login`。
|
|
14
|
+
|
|
15
|
+
## 前置条件
|
|
16
|
+
|
|
17
|
+
- 当前分支有已创建的 MR
|
|
18
|
+
- 工作区干净(有未提交改动先 commit + push)
|
|
19
|
+
|
|
20
|
+
## 监控 CI 和 Review
|
|
21
|
+
|
|
22
|
+
运行异步监控脚本,并行等待 CI 和 review:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
python3 .opencode/skills/land/land_watch.py
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
根据 exit code 行动:
|
|
29
|
+
|
|
30
|
+
| Exit 0 | CI green, 无未处理 review | 执行 squash-merge(下方命令) |
|
|
31
|
+
| Exit 2 | 有 review 评论 | 处理 review 反馈(下方步骤),完后重跑脚本 |
|
|
32
|
+
| Exit 3 | CI 失败 | 本地修复,commit + push,重跑脚本 |
|
|
33
|
+
| Exit 4 | MR head 更新(如 CI auto-fix) | pull/amend/force-push 重触发 CI,重跑脚本 |
|
|
34
|
+
| Exit 5 | 合并冲突 | rebase against main,push,重跑脚本 |
|
|
35
|
+
|
|
36
|
+
## 处理 Review 反馈 (exit 2)
|
|
37
|
+
|
|
38
|
+
获取 review 评论:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
glab api "projects/:id/merge_requests/<iid>/discussions"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
回复评论:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
glab api -X POST "projects/:id/merge_requests/<iid>/discussions" \
|
|
48
|
+
-f body="<your response>"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- 每条评论判断:接受、澄清、拒绝
|
|
52
|
+
- 接受的反馈:实现修改,commit + push,重跑监控脚本
|
|
53
|
+
- 拒绝的反馈:给出替代方案或后续计划
|
|
54
|
+
|
|
55
|
+
## Squash-Merge
|
|
56
|
+
|
|
57
|
+
CI green 且 review 处理完后:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
glab mr merge --squash --yes
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
不要在有未处理 review 评论时合并。
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""GitLab MR watch helper for the land skill.
|
|
3
|
+
|
|
4
|
+
Monitors CI pipelines, review discussions, and MR head changes in parallel.
|
|
5
|
+
Exits with a code indicating the action the agent should take.
|
|
6
|
+
|
|
7
|
+
Exit codes:
|
|
8
|
+
0: CI green, no outstanding review → merge
|
|
9
|
+
2: Review comments detected → address feedback
|
|
10
|
+
3: CI checks failed → fix and re-run
|
|
11
|
+
4: MR head updated → pull/amend/force-push to retrigger CI
|
|
12
|
+
5: Merge conflicts → resolve before proceeding
|
|
13
|
+
"""
|
|
14
|
+
import asyncio
|
|
15
|
+
import json
|
|
16
|
+
import random
|
|
17
|
+
import re
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
from datetime import datetime
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
POLL_SECONDS = 10
|
|
23
|
+
CHECKS_APPEAR_TIMEOUT_SECONDS = 120
|
|
24
|
+
MAX_GLAB_RETRIES = 5
|
|
25
|
+
BASE_GLAB_BACKOFF_SECONDS = 2
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class MrInfo:
|
|
30
|
+
number: int
|
|
31
|
+
iid: int
|
|
32
|
+
project_id: int
|
|
33
|
+
head_sha: str
|
|
34
|
+
merge_status: str | None
|
|
35
|
+
has_conflicts: bool
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class RateLimitError(RuntimeError):
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def is_rate_limit_error(error: str) -> bool:
|
|
43
|
+
return "HTTP 429" in error or "rate limit" in error.lower()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
async def run_glab(*args: str) -> str:
|
|
47
|
+
max_delay = BASE_GLAB_BACKOFF_SECONDS * (2 ** (MAX_GLAB_RETRIES - 1))
|
|
48
|
+
delay_seconds = BASE_GLAB_BACKOFF_SECONDS
|
|
49
|
+
last_error = "glab command failed"
|
|
50
|
+
for attempt in range(1, MAX_GLAB_RETRIES + 1):
|
|
51
|
+
proc = await asyncio.create_subprocess_exec(
|
|
52
|
+
"glab",
|
|
53
|
+
*args,
|
|
54
|
+
stdout=asyncio.subprocess.PIPE,
|
|
55
|
+
stderr=asyncio.subprocess.PIPE,
|
|
56
|
+
)
|
|
57
|
+
stdout, stderr = await proc.communicate()
|
|
58
|
+
if proc.returncode == 0:
|
|
59
|
+
return stdout.decode()
|
|
60
|
+
error = stderr.decode().strip() or "glab command failed"
|
|
61
|
+
if not is_rate_limit_error(error):
|
|
62
|
+
raise RuntimeError(error)
|
|
63
|
+
last_error = error
|
|
64
|
+
if attempt >= MAX_GLAB_RETRIES:
|
|
65
|
+
break
|
|
66
|
+
jitter = random.uniform(0, delay_seconds)
|
|
67
|
+
await asyncio.sleep(min(delay_seconds + jitter, max_delay))
|
|
68
|
+
delay_seconds = min(delay_seconds * 2, max_delay)
|
|
69
|
+
raise RateLimitError(last_error)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
async def get_mr_info() -> MrInfo:
|
|
73
|
+
data = await run_glab("mr", "view", "--output", "json")
|
|
74
|
+
parsed = json.loads(data)
|
|
75
|
+
return MrInfo(
|
|
76
|
+
number=parsed.get("id", 0),
|
|
77
|
+
iid=parsed.get("iid", 0),
|
|
78
|
+
project_id=parsed.get("project_id", 0),
|
|
79
|
+
head_sha=parsed.get("sha", ""),
|
|
80
|
+
merge_status=parsed.get("detailed_merge_status") or parsed.get("merge_status"),
|
|
81
|
+
has_conflicts=parsed.get("has_conflicts", False),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
async def get_paginated_list(endpoint: str) -> list[dict[str, Any]]:
|
|
86
|
+
page = 1
|
|
87
|
+
items: list[dict[str, Any]] = []
|
|
88
|
+
while True:
|
|
89
|
+
data = await run_glab("api", endpoint, "-f", f"per_page=100", "-f", f"page={page}")
|
|
90
|
+
batch = json.loads(data)
|
|
91
|
+
if not batch:
|
|
92
|
+
break
|
|
93
|
+
items.extend(batch)
|
|
94
|
+
page += 1
|
|
95
|
+
return items
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
async def get_discussions(mr_iid: int) -> list[dict[str, Any]]:
|
|
99
|
+
return await get_paginated_list(f"projects/:id/merge_requests/{mr_iid}/discussions")
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
async def get_pipelines(mr_iid: int) -> list[dict[str, Any]]:
|
|
103
|
+
return await get_paginated_list(f"projects/:id/merge_requests/{mr_iid}/pipelines")
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
async def get_approvals(mr_iid: int) -> dict[str, Any]:
|
|
107
|
+
data = await run_glab("api", f"projects/:id/merge_requests/{mr_iid}/approvals")
|
|
108
|
+
return json.loads(data)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def parse_time(value: str) -> datetime:
|
|
112
|
+
normalized = value.replace("Z", "+00:00")
|
|
113
|
+
return datetime.fromisoformat(normalized)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
CONTROL_CHARS_RE = re.compile(r"[\x00-\x08\x0b-\x1f\x7f-\x9f]")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def sanitize_terminal_output(value: str) -> str:
|
|
120
|
+
return CONTROL_CHARS_RE.sub("", value)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def pipeline_timestamp(pipeline: dict[str, Any]) -> datetime | None:
|
|
124
|
+
for key in ("finished_at", "started_at", "created_at"):
|
|
125
|
+
value = pipeline.get(key)
|
|
126
|
+
if value:
|
|
127
|
+
return parse_time(value)
|
|
128
|
+
return None
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def dedupe_pipelines(pipelines: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
132
|
+
latest_by_name: dict[str, dict[str, Any]] = {}
|
|
133
|
+
for pipeline in pipelines:
|
|
134
|
+
name = pipeline.get("name", pipeline.get("id", "unknown"))
|
|
135
|
+
timestamp = pipeline_timestamp(pipeline)
|
|
136
|
+
if name not in latest_by_name:
|
|
137
|
+
latest_by_name[name] = pipeline
|
|
138
|
+
continue
|
|
139
|
+
existing = latest_by_name[name]
|
|
140
|
+
existing_timestamp = pipeline_timestamp(existing)
|
|
141
|
+
if timestamp is None:
|
|
142
|
+
continue
|
|
143
|
+
if existing_timestamp is None or timestamp > existing_timestamp:
|
|
144
|
+
latest_by_name[name] = pipeline
|
|
145
|
+
return list(latest_by_name.values())
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def summarize_pipelines(pipelines: list[dict[str, Any]]) -> tuple[bool, bool, list[str]]:
|
|
149
|
+
if not pipelines:
|
|
150
|
+
return True, False, ["no pipelines reported"]
|
|
151
|
+
pipelines = dedupe_pipelines(pipelines)
|
|
152
|
+
pending = False
|
|
153
|
+
failed = False
|
|
154
|
+
failures: list[str] = []
|
|
155
|
+
for pipeline in pipelines:
|
|
156
|
+
status = pipeline.get("status")
|
|
157
|
+
name = pipeline.get("name", pipeline.get("id", "unknown"))
|
|
158
|
+
if status not in ("success", "skipped"):
|
|
159
|
+
pending = True
|
|
160
|
+
if status not in ("success", "skipped", "running", "pending"):
|
|
161
|
+
failed = True
|
|
162
|
+
failures.append(f"{name}: {status}")
|
|
163
|
+
return pending, failed, failures
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def comment_time(comment: dict[str, Any]) -> datetime | None:
|
|
167
|
+
timestamp = comment.get("updated_at") or comment.get("created_at")
|
|
168
|
+
if not timestamp:
|
|
169
|
+
return None
|
|
170
|
+
return parse_time(timestamp)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def is_bot_user(user: dict[str, Any]) -> bool:
|
|
174
|
+
login = user.get("username") or ""
|
|
175
|
+
if user.get("type") == "Bot":
|
|
176
|
+
return True
|
|
177
|
+
return login.endswith("[bot]") or login.endswith("_bot")
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def filter_human_discussions(
|
|
181
|
+
discussions: list[dict[str, Any]],
|
|
182
|
+
latest_agent_reply_at: datetime | None,
|
|
183
|
+
) -> list[dict[str, Any]]:
|
|
184
|
+
filtered: list[dict[str, Any]] = []
|
|
185
|
+
for discussion in discussions:
|
|
186
|
+
notes = discussion.get("notes", [])
|
|
187
|
+
if not notes:
|
|
188
|
+
continue
|
|
189
|
+
for note in notes:
|
|
190
|
+
user = note.get("author", {})
|
|
191
|
+
if is_bot_user(user):
|
|
192
|
+
continue
|
|
193
|
+
body = (note.get("body") or "").strip()
|
|
194
|
+
if not body:
|
|
195
|
+
continue
|
|
196
|
+
created_time = comment_time(note)
|
|
197
|
+
if (
|
|
198
|
+
latest_agent_reply_at is not None
|
|
199
|
+
and created_time is not None
|
|
200
|
+
and created_time <= latest_agent_reply_at
|
|
201
|
+
):
|
|
202
|
+
continue
|
|
203
|
+
filtered.append(note)
|
|
204
|
+
return filtered
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def latest_agent_reply_time(discussions: list[dict[str, Any]]) -> datetime | None:
|
|
208
|
+
latest: datetime | None = None
|
|
209
|
+
for discussion in discussions:
|
|
210
|
+
notes = discussion.get("notes", [])
|
|
211
|
+
for note in notes:
|
|
212
|
+
user = note.get("author", {})
|
|
213
|
+
if is_bot_user(user):
|
|
214
|
+
continue
|
|
215
|
+
body = (note.get("body") or "").strip()
|
|
216
|
+
created_time = comment_time(note)
|
|
217
|
+
if created_time is None:
|
|
218
|
+
continue
|
|
219
|
+
if latest is None or created_time > latest:
|
|
220
|
+
latest = created_time
|
|
221
|
+
return latest
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def is_merge_conflicting(mr: MrInfo) -> bool:
|
|
225
|
+
return mr.has_conflicts or mr.merge_status in ("conflict", "cannot_merge")
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
async def wait_for_review(mr_iid: int, checks_done: asyncio.Event) -> None:
|
|
229
|
+
print("Waiting for review feedback...", flush=True)
|
|
230
|
+
while True:
|
|
231
|
+
discussions = await get_discussions(mr_iid)
|
|
232
|
+
latest_reply = latest_agent_reply_time(discussions)
|
|
233
|
+
human_comments = filter_human_discussions(discussions, latest_reply)
|
|
234
|
+
if human_comments:
|
|
235
|
+
print("Review comments detected. Address before merge.")
|
|
236
|
+
for comment in human_comments:
|
|
237
|
+
body = sanitize_terminal_output(comment.get("body") or "").strip()
|
|
238
|
+
if body:
|
|
239
|
+
print(f"- {body}")
|
|
240
|
+
raise SystemExit(2)
|
|
241
|
+
if checks_done.is_set():
|
|
242
|
+
return
|
|
243
|
+
await asyncio.sleep(POLL_SECONDS)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
async def wait_for_checks(mr_iid: int, checks_done: asyncio.Event) -> None:
|
|
247
|
+
print("Waiting for CI pipelines...", flush=True)
|
|
248
|
+
empty_seconds = 0
|
|
249
|
+
while True:
|
|
250
|
+
pipelines = await get_pipelines(mr_iid)
|
|
251
|
+
if not pipelines:
|
|
252
|
+
empty_seconds += POLL_SECONDS
|
|
253
|
+
if empty_seconds >= CHECKS_APPEAR_TIMEOUT_SECONDS:
|
|
254
|
+
print("No pipelines detected after 120s; check CI configuration")
|
|
255
|
+
raise SystemExit(3)
|
|
256
|
+
await asyncio.sleep(POLL_SECONDS)
|
|
257
|
+
continue
|
|
258
|
+
empty_seconds = 0
|
|
259
|
+
pending, failed, failures = summarize_pipelines(pipelines)
|
|
260
|
+
if failed:
|
|
261
|
+
print("Pipelines failed:")
|
|
262
|
+
for failure in failures:
|
|
263
|
+
print(f"- {failure}")
|
|
264
|
+
raise SystemExit(3)
|
|
265
|
+
if not pending:
|
|
266
|
+
print("Pipelines passed")
|
|
267
|
+
checks_done.set()
|
|
268
|
+
return
|
|
269
|
+
await asyncio.sleep(POLL_SECONDS)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
async def watch_mr() -> None:
|
|
273
|
+
mr = await get_mr_info()
|
|
274
|
+
if is_merge_conflicting(mr):
|
|
275
|
+
print("MR has merge conflicts. Resolve/rebase against main and push before running land_watch again.")
|
|
276
|
+
raise SystemExit(5)
|
|
277
|
+
head_sha = mr.head_sha
|
|
278
|
+
checks_done = asyncio.Event()
|
|
279
|
+
review_task = asyncio.create_task(wait_for_review(mr.iid, checks_done))
|
|
280
|
+
checks_task = asyncio.create_task(wait_for_checks(mr.iid, checks_done))
|
|
281
|
+
|
|
282
|
+
async def head_monitor() -> None:
|
|
283
|
+
while True:
|
|
284
|
+
current = await get_mr_info()
|
|
285
|
+
if is_merge_conflicting(current):
|
|
286
|
+
print("MR has merge conflicts. Resolve/rebase against main and push before running land_watch again.")
|
|
287
|
+
raise SystemExit(5)
|
|
288
|
+
if current.head_sha != head_sha:
|
|
289
|
+
print("MR head updated; pull/amend/force-push to retrigger CI")
|
|
290
|
+
raise SystemExit(4)
|
|
291
|
+
await asyncio.sleep(POLL_SECONDS)
|
|
292
|
+
|
|
293
|
+
monitor_task = asyncio.create_task(head_monitor())
|
|
294
|
+
success_task = asyncio.gather(review_task, checks_task)
|
|
295
|
+
|
|
296
|
+
done, pending = await asyncio.wait(
|
|
297
|
+
[monitor_task, success_task],
|
|
298
|
+
return_when=asyncio.FIRST_COMPLETED,
|
|
299
|
+
)
|
|
300
|
+
for task in pending:
|
|
301
|
+
task.cancel()
|
|
302
|
+
for task in done:
|
|
303
|
+
exc = task.exception()
|
|
304
|
+
if exc:
|
|
305
|
+
raise exc
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
if __name__ == "__main__":
|
|
309
|
+
try:
|
|
310
|
+
asyncio.run(watch_mr())
|
|
311
|
+
except SystemExit as exc:
|
|
312
|
+
raise SystemExit(exc.code) from None
|