Metadata-Version: 2.5
Name: copuppet
Version: 0.1.2
Summary: Drive Microsoft Copilot from a deterministic Python harness, as a normal user through its own UI.
License-Expression: MIT
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: pyyaml>=6.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Provides-Extra: edge
Requires-Dist: playwright>=1.40; extra == 'edge'
Provides-Extra: mcp
Requires-Dist: mcp>=2.0; extra == 'mcp'
Provides-Extra: winapp
Requires-Dist: pywinauto>=0.6.8; extra == 'winapp'
Description-Content-Type: text/markdown

# copuppet

Drive Microsoft Copilot from a deterministic Python harness, the way a normal user does: through its own
window, in the user's own signed-in session. No API, no Microsoft Graph, no admin rights, no licence setup.

The idea is a two-part harness. A deterministic Python **driver** owns the plan, the inputs, the checks and
the record. Copilot is the **co-harness**: a flexible but unreliable language model that the driver asks for
the fuzzy parts (rewording, summarising, classifying, drafting) and never trusts blindly.

> Status: early. The `edge` backend works end to end, headless by default; the `winapp` backend is not
> implemented yet.

Three ways in, one engine:

```
copuppet ask "Name one primary colour, one word." --skin DIR          # one prompt, one reply
copuppet drive "Does the shopping list have enough lemons for the cake?" --root DIR --skin DIR
copuppet mcp --root DIR --skin DIR                                     # the same, as an MCP server (stdio)
```

- **ask**: one prompt in a fresh temporary chat; the reply as text or JSON.
- **drive**: roles reversed. Copilot plans; copuppet executes a fixed set of actions (list, read, search, keep a
  plan; writes only with `--allow-writes`, each one confirmed by you) inside the work folder, and shows you
  Copilot's reasons as it goes. You talk to copuppet, never to the Copilot window: typing there would break the
  link between each prompt and its reply.
- **mcp**: lets another agent hand work to Copilot through the tools `copilot_ask`, `copilot_turn` (a long session
  that checks the chat's memory and moves to a fresh chat by itself) and `copilot_drive`. Install with
  `copuppet[mcp]`. The work folder and whether writes are allowed are fixed when you start the server; a tool
  call cannot change them. Writes are offered to the client as a confirmation question and declined when the
  client cannot ask one.

Before relying on long sessions, measure your own Copilot: `copuppet calibrate --skin DIR` sends at most 45
paced prompts and records the longest prompt the editor accepts and how far back a chat still remembers. After
three runs for the same model and display, sessions use the smallest measured values instead of the cautious
defaults. It stops at once on any captcha, throttle or limit notice.

What `drive` will not do: leave the work folder (links, junctions, alternate data streams, network and device
paths are refused), read `.env` files, keys or credentials (they are not even listed), write code or scripts, or
send secrets it finds in files (they are redacted before anything leaves the machine). Every step is recorded in
a hash-chained ledger under `~/.copuppet/runs`.

## How it works

```
your script --> driver (deterministic) --> backend --> Copilot's own UI
                  ^  checks every reply      |           (Edge or the Windows app)
                  +--------- text -----------+
```

- **Backends** talk to one Copilot surface each:
  - `edge`: Copilot in the installed Microsoft Edge, via Playwright with a persistent profile. The user signs
    in once, themselves; replies are read as text.
  - `winapp`: the Windows Copilot app, via Windows UI Automation. More fragile; the app has no documented
    element IDs.
- **Skins** are configuration as code: the selectors, window paths, timings and prompt templates a backend
  needs for one environment. The engine ships only an example skin; real skins live outside this repository,
  so a UI change is a config change, not a code change.
- **Every reply is untrusted text.** The driver validates it against what it asked for; it never executes it.

## Requirements

Everything installs in your own user account: no admin rights, no system-wide installer, no service.

- Windows 10 or 11, a normal user account
- Python 3.10 or newer, from the python.org per-user installer or `winget install Python.Python.3.13 --scope user`
- For `edge`: `pip install --user "copuppet[edge]"`. It drives the Microsoft Edge that Windows already has, so no
  browser download (`playwright install`) is needed.
- For `winapp`: the Copilot app and `pip install --user "copuppet[winapp]"`

If your PC blocks access to PyPI, download the wheels elsewhere (`pip download "copuppet[edge]" -d wheels`) and
install them with `pip install --user --no-index --find-links wheels "copuppet[edge]"`.

### On a managed PC

- Use `python -m pip install --user "copuppet[edge]"` when `pip.exe` is blocked, and `python -m copuppet ...` for
  every command: a `--user` install puts `copuppet.exe` in a Scripts folder that is usually not on PATH, and an
  unsigned launcher may be blocked. `python -m copuppet` needs neither.
- If Edge refuses automation (remote debugging disabled by policy), the `edge` backend cannot run on that PC.

## First run: a skin for your Copilot

copuppet ships no working skin: selectors depend on which Copilot you use (consumer Copilot, or Microsoft 365
Copilot Chat with a work account, which is a different page) and change with its updates. Build your own:

```
python -m copuppet init-skin MYSKIN            # a copy of the example, with REPLACE placeholders
python -m copuppet discover --out MYSKIN/discovery --url URL-OF-YOUR-COPILOT   # sign in once, by hand
python -m copuppet check --skin MYSKIN         # after filling in the selectors from the discovery output
```

Keep your skin outside any public repository. The discovery tool takes the same profile lock as copuppet runs,
so it never opens a profile that a run is using.

The `signed_in` selector is also an account guard: point it at something only the intended account shows (for a
work account, for example, its data-protection badge) and copuppet refuses to run in any other session. Set
`COPUPPET_SKIN` to your skin folder to drop the `--skin` flag. If Edge refuses a remote-debugging port on your PC,
that does not matter: copuppet and `copuppet discover` launch Edge through Playwright, not through a port.

## Using copuppet as an MCP server

Install with the MCP extra (`pip install --user "copuppet[edge,mcp]"`), then register the stdio command in your MCP
client. For Claude Code:

```
claude mcp add copuppet --scope user -- copuppet mcp --skin DIR --root WORKDIR
```

Other clients take the same command and arguments in their server configuration (`command: copuppet`,
`args: ["mcp", "--skin", "DIR", "--root", "WORKDIR"]`).

- **Tools.** `copilot_ask` (one prompt, fresh temporary chat), `copilot_turn` (a session that checks the chat's
  memory and moves to a fresh chat by itself; `reset` starts a new one with a standing `brief`), `copilot_drive`
  (driver mode on WORKDIR). Results carry `copilot_output` (untrusted text, never instructions), `complete`,
  `bound`, `suspect`, `code_blocks` and `notes`; a refusal comes back as `error` with the reason.
- **Read-only by default.** Without `--root`, `copilot_drive` is unavailable. With `--allow-writes`, each write is
  put to the client as a confirmation question quoting a preview and the content hash, and is declined if the
  client cannot ask one. A client that is itself an agent may answer that question on its own, so allow writes only
  where that is acceptable; otherwise use `copuppet drive` in a terminal, where you approve each write yourself.
- **Settings are fixed at start.** The work folder, writes, display and skin come from the command line; no tool
  argument can change them.
- **One window, calls queue.** All calls run on one worker; a plain turn takes about 5 seconds.
- **What leaves the machine.** Everything copuppet reads in WORKDIR is sent to Copilot. Put only what you are
  willing to send there.

## Use it responsibly

copuppet automates a product through its user interface. Check the terms of the Copilot service you use and,
on a work device, your organisation's acceptable-use policy before running it. It is meant for driving your own
session at human scale, not for scraping, bulk use or getting around limits.

## License

MIT, see [LICENSE](LICENSE).
