Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions pc-mate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

An always-on maintainer agent for a GitHub repository and Feishu conversations.
It triages incoming feedback read-only, answers from a public PowerContext
Scope, follows each reported problem as a case, and can create a GitHub issue or
comment only after a configured maintainer approves the exact text.
Scope, follows each reported problem as a case, implements an accepted task
inside its own Git worktree, and can create a GitHub issue or comment only
after a configured maintainer approves the exact text.

This is an independent Rust sub-program at the repository root. It does not
import the Python package, does not connect to PowerContext tables, and is not an
Expand Down Expand Up @@ -33,8 +34,14 @@ fresh installation replies to nothing and writes nothing.
`git status --porcelain` with the pre-run state and treats any change as a
failed run, so "never mutates the repository" is observed rather than only
requested from the CLI.
- An accepted bug/feature becomes a read-only implementation proposal. The bot
never edits code, commits, pushes, opens a pull request or merges.
- Write access exists only inside a case's own Git worktree. The agent's working
directory is that worktree, and the shared checkout is never a write target —
not by the pipeline, not by `pc-mate run --write`.
- An accepted bug/feature becomes a read-only implementation proposal and, when
`executor.enabled` is on, an implementation inside the case's own Git
worktree. The agent never writes to the shared checkout, and the bot never
pushes, opens a pull request or merges: the branch stays local until a person
publishes it.
- A problem is resolved only by an explicit confirmation carrying a version, an
environment, an observation and an evidence reference. A merged PR, a closed
issue or a release is progress and resolves nothing.
Expand Down Expand Up @@ -65,17 +72,23 @@ fresh installation replies to nothing and writes nothing.
6. Observe, reply, or run the accepted path according to `triage.mode`.
7. For an accepted bug/feature, run a second read-only analysis that names the
files to touch, the change and the risks, plus a durable lesson when found.
8. Advance the case the message belongs to (`open → investigating →
8. When `executor.enabled` is on, give the case its own Git worktree under
`stateDir/work/<case>` and a branch off `git.baseBranch` (the checkout's
HEAD when it is unset), then run the agent there with write access. The
shared checkout stays read-only. The controller commits the result, saves
the patch, and records the branch, base and head in
`stateDir/cases/<case>/worktree.json`.
9. Advance the case the message belongs to (`open → investigating →
waiting_reporter → resolved`). A case is keyed by the thread, so a follow-up
continues it instead of opening a second one.
9. On GitHub, a reply or filing becomes a pending action at the current case
10. On GitHub, a reply or filing becomes a pending action at the current case
version. The maintainer chat receives the exact bounded text and a plain
`确认写入 <action-id> <token>` line.
10. A configured maintainer approves; the service rechecks the token, the text
11. A configured maintainer approves; the service rechecks the token, the text
hash and the case version, persists `sending`, then sends once. A 4xx is a
definite failure; a timeout or 5xx is `unknown`, and an interrupted `sending`
action is never re-approved automatically.
11. `确认解决 版本=… 环境=… 结果=… 证据=…` and the approval command are applied
12. `确认解决 版本=… 环境=… 结果=… 证据=…` and the approval command are applied
without a model call. A model deciding whether a problem is resolved is
exactly what the RFC excludes. A command is read from the message the actor
sent — the latest GitHub comment, or the Feishu message with its mention
Expand All @@ -91,6 +104,9 @@ stateDir/
├── triage/<hash>.json # verdict, reply id, mode, ticket id
├── tickets/<id>/ticket.json # ticket, proposal, reply
├── tickets/<id>/log.md # human-readable transition log
├── cases/<case>/worktree.json # branch, base, head, worktree directory
├── cases/<case>/worktree.patch # the committed change as a binary patch
├── work/<case>/ # the case's Git worktree (the agent's own directory)
├── meta/seen.json # recent event dedupe keys
├── logs/main.log # controller log (one previous file kept at 8 MiB)
├── keynotes.md # active operational lessons
Expand Down Expand Up @@ -127,10 +143,14 @@ Useful inspection commands:
./pc-mate/target/release/pc-mate keynotes prune --dry-run
./pc-mate/target/release/pc-mate logs
./pc-mate/target/release/pc-mate logs <ticket-id> --tail 40
./pc-mate/target/release/pc-mate worktree list
./pc-mate/target/release/pc-mate worktree remove <case-id>
```

Manual `triage` keeps its records under `stateDir/manual` and does not send messages or queue external writes. It defaults to `reply` mode. `--mode auto` additionally asks for an
implementation proposal; it still changes nothing in the repository.
implementation proposal, and with `executor.enabled` it also runs the
implementation in a worktree under `stateDir/manual`. It still publishes
nothing and changes nothing in the repository itself.

The scheduled keynotes prune only rewrites state under the state directory. It does
not promote rules into `checkout/promoteTo`; running `keynotes prune` without
Expand All @@ -141,20 +161,32 @@ not promote rules into `checkout/promoteTo`; running `keynotes prune` without
See `settings.example.yaml`. The important switches are:

- `agent.kind`: `claude` or `codex`. `opencode` is only usable for the manual
`run --write` command: every pipeline path is read-only, and this runner
cannot restrict its own tools.
`run --write` command: the unattended paths either run read-only or run with
write access in a worktree, and this runner cannot restrict its own tools.
- `triage.mode`: `observe`, `reply`, or `auto`.
- `triage.autoLabel`: when false, no label action is queued.
- `github.writeMode`: `off` for M1; `approved` for M2.
- `github.maintainers`: GitHub logins allowed to resolve a case.
- `feishu.maintainers`: Feishu `open_id` values allowed to resolve or approve.
- `feishu.botName`: the bot display name, for example `ClawBot`. Some event
transports flatten the callback and drop the structured `mentions` array. When
this is set, a group message that addresses the bot by name is still accepted
as an explicit `@` mention.
- `feishu.approvalChat`: the private chat that receives exact write requests.
Its messages are accepted without an `@` mention, so the approval command is
not lost when the group does not address the bot.
- `powercontext.scopeId`, `powercontext.tokenEnv`: the public read-only Scope
and the Principal token environment variable. Document search uses the knowledge-base plugin. Set
`powercontext.includeDocuments: false` on installations that only provide built-in artifact families.
- `proposal.enabled`: when false the bot stops after triage.
- `executor.enabled`: when true an accepted task is implemented in its own Git
worktree instead of stopping at the proposal. `executor.branchPrefix` names
the branch (`pc-mate/` by default) and `git.baseBranch` the commit the
worktree branches from; `null` uses the checkout's current HEAD.

`pc-mate worktree list` shows every case worktree, and
`pc-mate worktree remove <case-id>` removes one after saving whatever only it
holds. The local branch survives unless `--delete-branch` is given.

`doctor` checks the configured binaries, the GitHub App credentials when
`writeMode: approved`, the Feishu CLI and writable state.
Expand Down
28 changes: 23 additions & 5 deletions pc-mate/docs/rfc-conformance.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,31 @@ says so. Platform behavior that was not exercised is labeled unverified rather t
- M2 adds GitHub writes through a per-repository GitHub App installation token, only after a
configured maintainer approves the exact stored text at the current case version.
- PC content writes, private Memory, group-message Source capture, knowledge ingestion and
automatic code changes remain out of scope.
publishing to GitHub remain out of scope.
- The implementation stage runs the agent with write access inside a per-case Git worktree
(`stateDir/work/<case>`), never in the shared checkout. The controller commits the result on a
local branch; pushing, opening a pull request and merging stay with a person.

## Enforced by code

| Requirement | Where it is enforced | Test |
| --- | --- | --- |
| Triage never mutates the repository | `Workflow::process` runs `AgentRun { read_only: true }`; `claude` gets only `Read,Grep,Glob`, `codex` runs under `--sandbox read-only`, and `finish_run` compares `git status --porcelain` before and after, failing the run if the checkout changed | `a_read_only_run_gets_no_write_tool_and_no_skip_permissions`, `a_read_only_run_is_confined_by_the_sandbox_flag`, `a_read_only_run_must_leave_the_checkout_unchanged` |
| The implementation agent writes only inside its own worktree | `Workflow::implement_in_worktree` creates `stateDir/work/<case>` with `git worktree add -b` and runs the agent with that directory as `cwd`; the shared checkout is never a write target | `an_accepted_task_is_implemented_inside_its_own_worktree`, `two_cases_get_distinct_worktrees_and_the_shared_checkout_stays_clean` |
| The controller, not the agent, records the change | `worktree::commit_all` stages and commits with a fixed identity, saves `stateDir/cases/<case>/worktree.patch`, and stores branch, base and head in `stateDir/cases/<case>/worktree.json` | `the_controller_commits_the_agent_work_and_saves_the_patch` |
| Two cases never share a branch | the branch name combines the configured prefix, a slug of the title and a hash of the case id, and an existing branch without a worktree record is refused | `a_branch_name_is_readable_and_case_specific`, `two_cases_get_distinct_worktrees_and_the_shared_checkout_stays_clean` |
| Cleanup cannot remove anything else | `worktree::remove` refuses a recorded path that is not under this installation's `stateDir/work`, and refuses the shared checkout; uncommitted work is saved as a patch first | `cleanup_refuses_a_recorded_path_outside_the_installation_work_directory`, `cleanup_saves_uncommitted_work_before_removing_the_worktree` |
| No agent writes the shared checkout, not even by hand | `pc-mate run --write` goes through `App::run_agent_in_worktree`; the only remaining write path in the binary is the worktree one | `an_unattended_implementation_refuses_a_runner_that_cannot_confine_its_writes`; no live CLI test |
| The pipeline stops at the proposal when the executor is off | `executor.enabled: false` skips `implement_in_worktree`, so the ticket ends in `Proposed` and no worktree exists | `a_disabled_executor_stops_after_the_read_only_proposal` |
| An implementation reply names the branch and claims no publication | `implementation_reply` prints the branch, the commit and the changed files, and states that nothing was pushed | `an_implementation_reply_names_the_branch_and_claims_no_publication` |
| A flattened group event still requires an explicit address | `parse_event` accepts a group message only when a structured mention matches the bot id/app id, or when `feishu.botName` is set and the rendered text contains `@<botName>`; an unaddressed group message is still rejected, so RFC 2919 L92 full group ingestion stays excluded | `flattened_group_event_with_display_name_only_is_accepted`, `a_group_mention_without_a_bot_identity_is_ignored` |
| A typed command is read from the message, not the assembled context | `Trigger::message` keeps the latest GitHub comment or the Feishu message; `Trigger::command_text` strips a leading bot mention; `App::handle_command` parses only that | `a_command_is_read_from_the_message_not_the_assembled_context`, `a_mention_is_stripped_before_a_strict_command_match` |
| `observe` refuses commands as well as triage | `App::handle_command` logs and returns before `confirm`/`approve`, so a resolution or an approval changes nothing | `observe_mode_declines_a_typed_approval` |
| A failed delivery is retried | `App::process_trigger_result` admits work through `Store::reserve` only; the readable mirror is written for inspection and never decides admission | `a_failed_delivery_is_retried_although_a_mirror_exists` |
| The model cannot reach MCP write tools | Claude is started with `--strict-mcp-config`, an empty MCP config, `--disallowedTools mcp__*`, and no setting sources; Codex uses `--ignore-user-config`, `--ignore-rules` and `--ephemeral` | runner unit tests |
| A read-only run cannot write through the runner | Claude gets only `Read,Grep,Glob`; Codex runs under `--sandbox read-only`; OpenCode cannot remove its own write and shell tools, so a read-only run is refused before the CLI is spawned | `a_read_only_run_gets_no_write_tool_and_no_skip_permissions`, `a_read_only_run_is_confined_by_the_sandbox_flag`, `a_read_only_run_is_refused_rather_than_assumed_safe` |
| Bot credentials do not reach the model or its shell | `AgentConfig::environment` is an allowlist that excludes `GH_TOKEN`, `GITHUB_TOKEN`, `LARK_*`, `FEISHU_*`, `GIT_ASKPASS` and SSH agent variables; only model-provider prefixes pass | `the_environment_is_an_allowlist_not_a_denylist` |
| A reply body reaches Feishu verbatim and lands in the chat timeline | `reply_body`/`chat_body` build the JSON payload and pass it on stdin to `lark-cli api POST ... --data -`, so no untrusted text becomes an argv value and no shortcut flag is relied on for stdin; `reply_in_thread` is not set, so a group reply is visible in the chat itself | `reply_payloads_are_read_from_stdin_not_argv`; no live delivery test |
| The Feishu CLI still gets its own credentials | `FeishuSource::from_settings` uses the process environment, while the agent child gets the restricted allowlist | compile-time separation; no live test |
| M1 reads PowerContext only through `POST /v1/context/prepare` | `PowerContextClient::prepare`; no MCP catalogue is registered and `include_reuse` is `false` | `the_request_asks_for_no_reuse_binding_and_carries_no_receipt` |
| An empty PowerContext result is explicit evidence absence | `Workflow::process_with_case` logs `status: empty` and tells the model not to guess | triage prompt test coverage |
Expand Down Expand Up @@ -66,6 +78,7 @@ says so. Platform behavior that was not exercised is labeled unverified rather t
| Approval channel | a human approval bound to content and version | typed `确认写入 <id> <token>` in a private Feishu chat; GitHub command responses are withheld | M2 does not post to GitHub without approval, including command acknowledgements |
| Label/channel sender | any side effect that needs approval | `GithubIssue`, `GithubComment`, `GithubLabels` use the same pending-action path; `ChannelMessage` is stored but not implemented | three GitHub senders are better than one; the unimplemented target fails explicitly |
| OpenCode runner | an advertised `agent.kind` that can run read-only | writable manual runs only; every read-only run is refused with an error that names the alternative | the CLI exposes no per-run way to remove `edit`, `write` and `bash`, and an empty config only drops user configuration, not built-in tools |
| Implementation boundary | Discussion #2922 separates triage from code execution and gives every implementation task its own Git worktree | exactly that: one worktree and branch per case under `stateDir/work`, the agent runs there with write access, the controller commits the result locally | a shared checkout cannot hold two half-finished implementations, and keeping the branch local keeps the publication decision with a person |

## Gaps

Expand All @@ -92,15 +105,20 @@ These are not implemented. None is papered over by a local substitute.
6. **Real-platform acceptance missing.** No test runs against Feishu, GitHub or a real model.
GitHub App token validation is tested against a synthetic payload; the real installation
response shape is unverified. Local tests do not establish that GitHub grants exactly the
permissions the validator expects.
7. **GitHub command acknowledgements are not public.** On GitHub, `App::reply` withholds command
permissions the validator expects. The implementation stage has not run against a real model
either: the worktree lifecycle is covered by tests, but no real diff has been produced yet.
7. **The agent's test report is not verified.** The controller commits the worktree and saves the
patch, but it does not re-run the tests the agent claims to have run. A reported test result is
the agent's claim, and the reply labels it as such.
8. **GitHub command acknowledgements are not public.** On GitHub, `App::reply` withholds command
responses instead of creating an approval for them. A maintainer who approves from GitHub sees
the result only in the local log or in the Feishu approval chat.

## Out of scope by the discussion

Automatic code changes, merging, arbitrary shell, full group-history import, multi-tenancy, multi-agent
orchestration, PC content writes, private Memory in group chats, and automatic PR creation.
Publishing to GitHub (push, pull request, merge), arbitrary shell, full group-history import,
multi-tenancy, multi-agent orchestration, PC content writes, and private Memory in group chats. The
implementation stage changes code in a local worktree only, and it publishes nothing.

## Verification

Expand Down
15 changes: 13 additions & 2 deletions pc-mate/settings.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ feishu:
directMessages: true
botId: ""
appId: ""
botName: "" # bot display name; used when the event source drops `mentions`
allowed: []
maintainers: [] # Feishu open_id values allowed to resolve or approve
# M2 uses this private chat for approval requests. It carries the exact write text and the
Expand Down Expand Up @@ -119,11 +120,19 @@ triage:
websiteMaxChars: 20000
keynotesSummaryEntries: 20

# A proposal is where the pipeline ends: the bot never edits code, commits, pushes or opens a pull
# request (RFC 2919 excludes those). Set enabled: false to stop after triage instead.
# The read-only proposal stage: the agent analyses the accepted report and names the files to
# touch. Set enabled: false to stop after triage instead.
proposal:
enabled: true

# The code-execution stage. An accepted bug/feature runs the agent with write access inside its own
# Git worktree under `stateDir/work/<case>`; the shared checkout stays read-only. The controller
# commits the result and keeps the branch local — pushing, opening a pull request and merging stay
# manual. Only `triage.mode: auto` reaches this stage.
executor:
enabled: true
branchPrefix: pc-mate/

keynotes:
enabled: true
file: keynotes.md
Expand All @@ -137,4 +146,6 @@ keynotes:

git:
remote: origin
# The commit a case worktree branches from. `null` uses the checkout's current HEAD; a named
# branch uses that local ref as it is now, without fetching.
baseBranch: null
Loading