copuppet 0.1.0__tar.gz → 0.1.2__tar.gz
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.
- copuppet-0.1.2/.github/workflows/test.yml +24 -0
- copuppet-0.1.2/CHANGELOG.md +51 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/PKG-INFO +53 -1
- {copuppet-0.1.0 → copuppet-0.1.2}/README.md +52 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/config.example/skin.yaml +2 -0
- copuppet-0.1.2/docs/roadmap.md +33 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/pyproject.toml +1 -1
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/__init__.py +1 -1
- copuppet-0.1.2/src/copuppet/__main__.py +7 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/backends/edge.py +56 -74
- copuppet-0.1.2/src/copuppet/backends/edge_common.py +140 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/calibrate.py +1 -2
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/cli.py +28 -0
- copuppet-0.1.0/tools/discover_edge.py → copuppet-0.1.2/src/copuppet/discover.py +43 -54
- copuppet-0.1.2/src/copuppet/example_skin/skin.yaml +45 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/ledger.py +3 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/protocol.py +2 -1
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/relay.py +8 -2
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/skin.py +5 -1
- copuppet-0.1.2/tests/test_edge_codeblocks.py +34 -0
- copuppet-0.1.2/tests/test_first_run.py +38 -0
- copuppet-0.1.2/tests/test_notices.py +50 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/test_redteam_3.py +1 -2
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/test_relay.py +24 -7
- copuppet-0.1.2/tools/discover_edge.py +7 -0
- copuppet-0.1.0/CHANGELOG.md +0 -20
- {copuppet-0.1.0 → copuppet-0.1.2}/.gitattributes +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/.github/workflows/release.yml +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/.gitignore +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/CLAUDE.md +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/LICENSE +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/RELEASING.md +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/docs/model.md +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/actions.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/backend.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/backends/__init__.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/backends/winapp.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/driver.py +1 -1
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/fake.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/mcp_server.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/policy.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/runner.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/session.py +1 -1
- {copuppet-0.1.0 → copuppet-0.1.2}/src/copuppet/tokens.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/README.md +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/recorded.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000001.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000001.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000002.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000002.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000003.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000003.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000004.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000004.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000005.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000005.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000006.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000006.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000007.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000007.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000008.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000008.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000009.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000009.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000010.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000010.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000011.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000011.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000013.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/copilot-000013.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/person-000012.a.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/done/person-000012.q.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/run/run.json +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/work/notes/fridge.md +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/work/pantry.md +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/work/recipes/omelette.md +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/work/recipes/pancakes.md +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/work/recipes/shortbread.md +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/fixtures/pantry/work/recipes/tomato-rice.md +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/test_calibrate.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/test_driver.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/test_ledger_and_fake.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/test_mcp_server.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/test_protocol_and_session.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/test_replay_fixture.py +0 -0
- {copuppet-0.1.0 → copuppet-0.1.2}/tests/test_skin.py +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# copuppet - offline test suite (fake, relay and replay backends; no Edge, no Copilot) on pull requests and main.
|
|
2
|
+
name: test
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
pytest:
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
os: [ubuntu-latest, windows-latest]
|
|
17
|
+
python: ['3.10', '3.13']
|
|
18
|
+
runs-on: ${{ matrix.os }}
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
21
|
+
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
|
|
22
|
+
with: { python-version: '${{ matrix.python }}' }
|
|
23
|
+
- run: python -m pip install -e ".[dev,mcp]"
|
|
24
|
+
- run: python -m pytest -q
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.2 (2026-11-29)
|
|
4
|
+
|
|
5
|
+
First run on a managed PC (#18).
|
|
6
|
+
|
|
7
|
+
- `python -m copuppet` works: neither the Scripts folder on PATH nor the unsigned launcher is needed.
|
|
8
|
+
- The example skin ships in the package; `copuppet init-skin DIR` copies it as the start of your own.
|
|
9
|
+
- The discovery tool is part of the package: `copuppet discover` (including `--probe`, which samples the page while
|
|
10
|
+
a reply is written). `tools/discover_edge.py` remains as a shim.
|
|
11
|
+
- The no-skin error says how to start one.
|
|
12
|
+
- README: installing on a managed PC (`python -m pip`, `python -m copuppet`) and building a skin for your Copilot
|
|
13
|
+
surface (consumer Copilot and Microsoft 365 Copilot Chat are different pages).
|
|
14
|
+
- README: the `signed_in` selector as an account guard; Edge refusing a debugging port does not affect copuppet.
|
|
15
|
+
- Verified on a managed PC against Microsoft 365 Copilot Chat with a work account (a skin built there).
|
|
16
|
+
|
|
17
|
+
## 0.1.1 (2026-11-29)
|
|
18
|
+
|
|
19
|
+
Fixes from the first live runs.
|
|
20
|
+
|
|
21
|
+
- Code blocks are read until two reads agree and every block appears in the reply's own text; a lasting
|
|
22
|
+
difference is noted, never patched (#1).
|
|
23
|
+
- First-token time is measured at the new reply's first visible text, so the latency trigger has a real baseline
|
|
24
|
+
(#2).
|
|
25
|
+
- Page notices (alerts, alert dialogs, assertive live regions) are recorded in the reply notes; throttle or
|
|
26
|
+
challenge wording stops the run; skin option `edge.notices_ignore` mutes known harmless notices, never a
|
|
27
|
+
challenge (#3).
|
|
28
|
+
- The Edge backend and the discovery tool share one helper module; the discovery tool now takes the profile lock
|
|
29
|
+
and refuses a profile a copuppet run is using (#4).
|
|
30
|
+
- README: using copuppet as an MCP server (#5).
|
|
31
|
+
- The relay no longer fails when the drive consumes a question while the stand-in reads it.
|
|
32
|
+
- Test CI on pull requests: Windows and Linux, Python 3.10 and 3.13 (#14).
|
|
33
|
+
|
|
34
|
+
## 0.1.0 (2026-11-29)
|
|
35
|
+
|
|
36
|
+
First release.
|
|
37
|
+
|
|
38
|
+
- `edge` backend: drives Copilot in the installed Microsoft Edge with a persistent profile; headless by default with
|
|
39
|
+
Windows single sign-on, then off-screen, then visible; paste-first input verified by read-back; reply binding
|
|
40
|
+
(each reply tied to its own prompt); stops on challenge and limit markers.
|
|
41
|
+
- `ask`: one prompt in a fresh temporary chat.
|
|
42
|
+
- Sessions: memory checks with labelled codes, chat rotation on measured limits, a hand-over brief from Python's
|
|
43
|
+
own state, suspect taint after a failed check.
|
|
44
|
+
- `calibrate`: measures the longest accepted prompt and recall depth; sessions use the measured limits after
|
|
45
|
+
three runs of the current method.
|
|
46
|
+
- `drive`: driver mode, Copilot plans and copuppet executes a fixed catalog (list, read, search, plan, ask, finish,
|
|
47
|
+
confirmed writes to an output folder) under a policy that confines paths, hides credentials and redacts secrets.
|
|
48
|
+
- `mcp`: the same as an MCP server over stdio (`copilot_ask`, `copilot_turn`, `copilot_drive`); run settings fixed
|
|
49
|
+
at start.
|
|
50
|
+
- Hash-chained ledger of every step; relay and replay backends for development and regression tests.
|
|
51
|
+
- Verified live: a read-only drive, a drive with one confirmed write, an MCP call, three calibration runs.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: copuppet
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Drive Microsoft Copilot from a deterministic Python harness, as a normal user through its own UI.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -89,6 +89,58 @@ Everything installs in your own user account: no admin rights, no system-wide in
|
|
|
89
89
|
If your PC blocks access to PyPI, download the wheels elsewhere (`pip download "copuppet[edge]" -d wheels`) and
|
|
90
90
|
install them with `pip install --user --no-index --find-links wheels "copuppet[edge]"`.
|
|
91
91
|
|
|
92
|
+
### On a managed PC
|
|
93
|
+
|
|
94
|
+
- Use `python -m pip install --user "copuppet[edge]"` when `pip.exe` is blocked, and `python -m copuppet ...` for
|
|
95
|
+
every command: a `--user` install puts `copuppet.exe` in a Scripts folder that is usually not on PATH, and an
|
|
96
|
+
unsigned launcher may be blocked. `python -m copuppet` needs neither.
|
|
97
|
+
- If Edge refuses automation (remote debugging disabled by policy), the `edge` backend cannot run on that PC.
|
|
98
|
+
|
|
99
|
+
## First run: a skin for your Copilot
|
|
100
|
+
|
|
101
|
+
copuppet ships no working skin: selectors depend on which Copilot you use (consumer Copilot, or Microsoft 365
|
|
102
|
+
Copilot Chat with a work account, which is a different page) and change with its updates. Build your own:
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
python -m copuppet init-skin MYSKIN # a copy of the example, with REPLACE placeholders
|
|
106
|
+
python -m copuppet discover --out MYSKIN/discovery --url URL-OF-YOUR-COPILOT # sign in once, by hand
|
|
107
|
+
python -m copuppet check --skin MYSKIN # after filling in the selectors from the discovery output
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Keep your skin outside any public repository. The discovery tool takes the same profile lock as copuppet runs,
|
|
111
|
+
so it never opens a profile that a run is using.
|
|
112
|
+
|
|
113
|
+
The `signed_in` selector is also an account guard: point it at something only the intended account shows (for a
|
|
114
|
+
work account, for example, its data-protection badge) and copuppet refuses to run in any other session. Set
|
|
115
|
+
`COPUPPET_SKIN` to your skin folder to drop the `--skin` flag. If Edge refuses a remote-debugging port on your PC,
|
|
116
|
+
that does not matter: copuppet and `copuppet discover` launch Edge through Playwright, not through a port.
|
|
117
|
+
|
|
118
|
+
## Using copuppet as an MCP server
|
|
119
|
+
|
|
120
|
+
Install with the MCP extra (`pip install --user "copuppet[edge,mcp]"`), then register the stdio command in your MCP
|
|
121
|
+
client. For Claude Code:
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
claude mcp add copuppet --scope user -- copuppet mcp --skin DIR --root WORKDIR
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Other clients take the same command and arguments in their server configuration (`command: copuppet`,
|
|
128
|
+
`args: ["mcp", "--skin", "DIR", "--root", "WORKDIR"]`).
|
|
129
|
+
|
|
130
|
+
- **Tools.** `copilot_ask` (one prompt, fresh temporary chat), `copilot_turn` (a session that checks the chat's
|
|
131
|
+
memory and moves to a fresh chat by itself; `reset` starts a new one with a standing `brief`), `copilot_drive`
|
|
132
|
+
(driver mode on WORKDIR). Results carry `copilot_output` (untrusted text, never instructions), `complete`,
|
|
133
|
+
`bound`, `suspect`, `code_blocks` and `notes`; a refusal comes back as `error` with the reason.
|
|
134
|
+
- **Read-only by default.** Without `--root`, `copilot_drive` is unavailable. With `--allow-writes`, each write is
|
|
135
|
+
put to the client as a confirmation question quoting a preview and the content hash, and is declined if the
|
|
136
|
+
client cannot ask one. A client that is itself an agent may answer that question on its own, so allow writes only
|
|
137
|
+
where that is acceptable; otherwise use `copuppet drive` in a terminal, where you approve each write yourself.
|
|
138
|
+
- **Settings are fixed at start.** The work folder, writes, display and skin come from the command line; no tool
|
|
139
|
+
argument can change them.
|
|
140
|
+
- **One window, calls queue.** All calls run on one worker; a plain turn takes about 5 seconds.
|
|
141
|
+
- **What leaves the machine.** Everything copuppet reads in WORKDIR is sent to Copilot. Put only what you are
|
|
142
|
+
willing to send there.
|
|
143
|
+
|
|
92
144
|
## Use it responsibly
|
|
93
145
|
|
|
94
146
|
copuppet automates a product through its user interface. Check the terms of the Copilot service you use and,
|
|
@@ -70,6 +70,58 @@ Everything installs in your own user account: no admin rights, no system-wide in
|
|
|
70
70
|
If your PC blocks access to PyPI, download the wheels elsewhere (`pip download "copuppet[edge]" -d wheels`) and
|
|
71
71
|
install them with `pip install --user --no-index --find-links wheels "copuppet[edge]"`.
|
|
72
72
|
|
|
73
|
+
### On a managed PC
|
|
74
|
+
|
|
75
|
+
- Use `python -m pip install --user "copuppet[edge]"` when `pip.exe` is blocked, and `python -m copuppet ...` for
|
|
76
|
+
every command: a `--user` install puts `copuppet.exe` in a Scripts folder that is usually not on PATH, and an
|
|
77
|
+
unsigned launcher may be blocked. `python -m copuppet` needs neither.
|
|
78
|
+
- If Edge refuses automation (remote debugging disabled by policy), the `edge` backend cannot run on that PC.
|
|
79
|
+
|
|
80
|
+
## First run: a skin for your Copilot
|
|
81
|
+
|
|
82
|
+
copuppet ships no working skin: selectors depend on which Copilot you use (consumer Copilot, or Microsoft 365
|
|
83
|
+
Copilot Chat with a work account, which is a different page) and change with its updates. Build your own:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
python -m copuppet init-skin MYSKIN # a copy of the example, with REPLACE placeholders
|
|
87
|
+
python -m copuppet discover --out MYSKIN/discovery --url URL-OF-YOUR-COPILOT # sign in once, by hand
|
|
88
|
+
python -m copuppet check --skin MYSKIN # after filling in the selectors from the discovery output
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Keep your skin outside any public repository. The discovery tool takes the same profile lock as copuppet runs,
|
|
92
|
+
so it never opens a profile that a run is using.
|
|
93
|
+
|
|
94
|
+
The `signed_in` selector is also an account guard: point it at something only the intended account shows (for a
|
|
95
|
+
work account, for example, its data-protection badge) and copuppet refuses to run in any other session. Set
|
|
96
|
+
`COPUPPET_SKIN` to your skin folder to drop the `--skin` flag. If Edge refuses a remote-debugging port on your PC,
|
|
97
|
+
that does not matter: copuppet and `copuppet discover` launch Edge through Playwright, not through a port.
|
|
98
|
+
|
|
99
|
+
## Using copuppet as an MCP server
|
|
100
|
+
|
|
101
|
+
Install with the MCP extra (`pip install --user "copuppet[edge,mcp]"`), then register the stdio command in your MCP
|
|
102
|
+
client. For Claude Code:
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
claude mcp add copuppet --scope user -- copuppet mcp --skin DIR --root WORKDIR
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Other clients take the same command and arguments in their server configuration (`command: copuppet`,
|
|
109
|
+
`args: ["mcp", "--skin", "DIR", "--root", "WORKDIR"]`).
|
|
110
|
+
|
|
111
|
+
- **Tools.** `copilot_ask` (one prompt, fresh temporary chat), `copilot_turn` (a session that checks the chat's
|
|
112
|
+
memory and moves to a fresh chat by itself; `reset` starts a new one with a standing `brief`), `copilot_drive`
|
|
113
|
+
(driver mode on WORKDIR). Results carry `copilot_output` (untrusted text, never instructions), `complete`,
|
|
114
|
+
`bound`, `suspect`, `code_blocks` and `notes`; a refusal comes back as `error` with the reason.
|
|
115
|
+
- **Read-only by default.** Without `--root`, `copilot_drive` is unavailable. With `--allow-writes`, each write is
|
|
116
|
+
put to the client as a confirmation question quoting a preview and the content hash, and is declined if the
|
|
117
|
+
client cannot ask one. A client that is itself an agent may answer that question on its own, so allow writes only
|
|
118
|
+
where that is acceptable; otherwise use `copuppet drive` in a terminal, where you approve each write yourself.
|
|
119
|
+
- **Settings are fixed at start.** The work folder, writes, display and skin come from the command line; no tool
|
|
120
|
+
argument can change them.
|
|
121
|
+
- **One window, calls queue.** All calls run on one worker; a plain turn takes about 5 seconds.
|
|
122
|
+
- **What leaves the machine.** Everything copuppet reads in WORKDIR is sent to Copilot. Put only what you are
|
|
123
|
+
willing to send there.
|
|
124
|
+
|
|
73
125
|
## Use it responsibly
|
|
74
126
|
|
|
75
127
|
copuppet automates a product through its user interface. Check the terms of the Copilot service you use and,
|
|
@@ -29,6 +29,8 @@ backends:
|
|
|
29
29
|
click_button: false # true: copuppet presses the site's own Sign in button once; the login form
|
|
30
30
|
# itself is always completed by the person, copuppet never types into it
|
|
31
31
|
button: "button:has-text('Sign in')"
|
|
32
|
+
notices_ignore: # page notices (alerts, live regions) known to be harmless: not reported in the notes.
|
|
33
|
+
- "REPLACE: part of a harmless notice's text" # a throttle or challenge notice is never muted by this
|
|
32
34
|
dismiss: # page modals copuppet may close; unknown modals are only reported, never clicked
|
|
33
35
|
- when: "[role='dialog']:has-text('cookies')"
|
|
34
36
|
click: "button:has-text('Reject')" # prefer the button that declines optional cookies
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Roadmap
|
|
2
|
+
|
|
3
|
+
Tracked as GitHub milestones and issues; this page says why each release contains what it does.
|
|
4
|
+
|
|
5
|
+
## 0.1.0 (released 2026-11-29)
|
|
6
|
+
Edge backend (headless with single sign-on), `ask`, sessions with memory checks and rotation, `calibrate`,
|
|
7
|
+
`drive` (driver mode under a policy), `mcp`, the hash-chained ledger, relay and replay backends. Verified live: a
|
|
8
|
+
read-only drive, a drive with one confirmed write, an MCP call, three calibration runs.
|
|
9
|
+
|
|
10
|
+
## 0.1.1 (released 2026-11-29)
|
|
11
|
+
What the first live runs found: #1 stable code-block read-back, #2 first-token timing, #3 page notices,
|
|
12
|
+
#4 shared helpers, #5 MCP docs, #14 CI.
|
|
13
|
+
|
|
14
|
+
## 0.1.2 (released 2026-11-29): first run on a managed PC
|
|
15
|
+
Brought forward after a first install on a managed PC: #18 `python -m copuppet`, the packaged example skin with
|
|
16
|
+
`init-skin`, and discovery in the package.
|
|
17
|
+
|
|
18
|
+
## 0.1.3: real runs become tests
|
|
19
|
+
Builds on 0.1.1: once read-back and timing are right, real runs are worth recording.
|
|
20
|
+
- #6 Record real runs in the relay format, so they replay as regression tests.
|
|
21
|
+
- #7 Resume a stopped drive from its ledger, never repeating a recorded step.
|
|
22
|
+
- #8 Find the real recall ceiling (today only a lower bound of 378,000 characters).
|
|
23
|
+
- #9 Calibrate the off-screen and visible display modes.
|
|
24
|
+
- #10 Progress and cancel for `copilot_drive` over MCP.
|
|
25
|
+
- #19 Copilot surfaces without a temporary chat (an explicit skin capability instead of failing closed).
|
|
26
|
+
|
|
27
|
+
## Later
|
|
28
|
+
- #11 winapp backend: parked until a PC blocks Edge automation.
|
|
29
|
+
- #12 Edge on macOS and Linux.
|
|
30
|
+
|
|
31
|
+
## Release rule
|
|
32
|
+
A release is a tag plus a GitHub Release; the release workflow publishes to PyPI through Trusted Publishing
|
|
33
|
+
(RELEASING.md). Every release passes the full test suite, including the replay fixtures.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""copuppet: drive Microsoft Copilot from a deterministic Python harness, as a normal user through its own UI."""
|
|
2
|
-
__version__ = "0.1.
|
|
2
|
+
__version__ = "0.1.2"
|
|
@@ -7,70 +7,31 @@ model label. Everything page-specific comes from the skin.
|
|
|
7
7
|
"""
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
|
-
import json
|
|
11
|
-
import os
|
|
12
|
-
import re
|
|
13
10
|
import sys
|
|
14
11
|
import time
|
|
15
12
|
from pathlib import Path
|
|
16
13
|
|
|
17
14
|
from ..backend import BackendError, ChatHandle, Probe, Reply
|
|
18
|
-
|
|
19
|
-
BROWSER_ARGS
|
|
20
|
-
DIALOG_SELECTOR
|
|
21
|
-
LOGIN_HOSTS
|
|
22
|
-
|
|
15
|
+
from .edge_common import (
|
|
16
|
+
BROWSER_ARGS,
|
|
17
|
+
DIALOG_SELECTOR,
|
|
18
|
+
LOGIN_HOSTS,
|
|
19
|
+
ZERO_WIDTH,
|
|
20
|
+
ProfileBusy,
|
|
21
|
+
acquire_lock,
|
|
22
|
+
classify_notices,
|
|
23
|
+
first_visible,
|
|
24
|
+
mark_clean_exit,
|
|
25
|
+
normalise,
|
|
26
|
+
release_lock,
|
|
27
|
+
visible_notices,
|
|
28
|
+
)
|
|
23
29
|
|
|
24
30
|
|
|
25
31
|
class ChallengeError(BackendError):
|
|
26
32
|
"""A challenge or throttle marker: stop; no display fallback, no retry (I12)."""
|
|
27
33
|
|
|
28
34
|
|
|
29
|
-
def mark_clean_exit(profile: Path) -> None:
|
|
30
|
-
"""Prevent Edge's 'Restore pages' bubble (browser UI, unclickable from Playwright) after an unclean exit."""
|
|
31
|
-
pref = profile / "Default" / "Preferences"
|
|
32
|
-
try:
|
|
33
|
-
data = json.loads(pref.read_text(encoding="utf-8"))
|
|
34
|
-
except (OSError, ValueError):
|
|
35
|
-
return
|
|
36
|
-
prof = data.setdefault("profile", {})
|
|
37
|
-
if prof.get("exit_type") != "Normal" or prof.get("exited_cleanly") is not True:
|
|
38
|
-
prof["exit_type"], prof["exited_cleanly"] = "Normal", True
|
|
39
|
-
pref.write_text(json.dumps(data), encoding="utf-8")
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def first_visible(locator, limit: int = 10):
|
|
43
|
-
for i in range(min(locator.count(), limit)):
|
|
44
|
-
if locator.nth(i).is_visible():
|
|
45
|
-
return locator.nth(i)
|
|
46
|
-
return None
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
ZERO_WIDTH = re.compile("[\u200b\u200c\u200d\u2060\ufeff]")
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def normalise(text: str) -> str:
|
|
53
|
-
"""Whitespace collapsed and zero-width characters removed: the chat editor inserts U+200B U+200C at line ends."""
|
|
54
|
-
return re.sub(r"\s+", " ", ZERO_WIDTH.sub("", text or "")).strip()
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def _pid_alive(pid: int) -> bool:
|
|
58
|
-
if pid <= 0:
|
|
59
|
-
return False
|
|
60
|
-
try:
|
|
61
|
-
if os.name == "nt":
|
|
62
|
-
import ctypes
|
|
63
|
-
h = ctypes.windll.kernel32.OpenProcess(0x1000, False, pid) # PROCESS_QUERY_LIMITED_INFORMATION
|
|
64
|
-
if not h:
|
|
65
|
-
return False
|
|
66
|
-
ctypes.windll.kernel32.CloseHandle(h)
|
|
67
|
-
return True
|
|
68
|
-
os.kill(pid, 0)
|
|
69
|
-
return True
|
|
70
|
-
except OSError:
|
|
71
|
-
return False
|
|
72
|
-
|
|
73
|
-
|
|
74
35
|
class EdgeBackend:
|
|
75
36
|
name = "edge"
|
|
76
37
|
|
|
@@ -84,6 +45,7 @@ class EdgeBackend:
|
|
|
84
45
|
self.rerender = float(t.get("rerender_seconds", 2.5))
|
|
85
46
|
self.signin = config.get("signin") or {}
|
|
86
47
|
self.dismiss = config.get("dismiss") or []
|
|
48
|
+
self.notices_ignore = [s.lower() for s in config.get("notices_ignore") or []] # #3: known harmless notices
|
|
87
49
|
self.profile = Path(str(config.get("profile_dir") or "~/.copuppet/edge-profile")).expanduser()
|
|
88
50
|
self.type_delay = int(config.get("type_delay_ms", 5))
|
|
89
51
|
self.display = str(config.get("display", "auto")) # auto | headless | offscreen | visible
|
|
@@ -93,7 +55,8 @@ class EdgeBackend:
|
|
|
93
55
|
self._lock = None
|
|
94
56
|
self._chat_seq = 0
|
|
95
57
|
self.notes: list[str] = []
|
|
96
|
-
self.chat_notes: list[str] = []
|
|
58
|
+
self.chat_notes: list[str] = []
|
|
59
|
+
self._notices_seen: set = set() # page notices already reported (#3) # notes from new_chat, carried into the next send's Reply
|
|
97
60
|
self.verbose = bool(config.get("_verbose"))
|
|
98
61
|
|
|
99
62
|
def log(self, msg: str) -> None:
|
|
@@ -117,17 +80,10 @@ class EdgeBackend:
|
|
|
117
80
|
|
|
118
81
|
# ---------- lock + browser lifecycle ----------
|
|
119
82
|
def _acquire_lock(self) -> None:
|
|
120
|
-
self.profile.mkdir(parents=True, exist_ok=True)
|
|
121
|
-
lock = self.profile / LOCK_NAME
|
|
122
83
|
try:
|
|
123
|
-
|
|
124
|
-
except
|
|
125
|
-
|
|
126
|
-
if holder and holder != os.getpid() and _pid_alive(holder):
|
|
127
|
-
raise BackendError(f"another copuppet run (pid {holder}) is using {self.profile}; next: wait for it or "
|
|
128
|
-
"stop it")
|
|
129
|
-
lock.write_text(str(os.getpid()), encoding="utf-8")
|
|
130
|
-
self._lock = lock
|
|
84
|
+
self._lock = acquire_lock(self.profile)
|
|
85
|
+
except ProfileBusy as err:
|
|
86
|
+
raise BackendError(str(err)) from None
|
|
131
87
|
|
|
132
88
|
DISPLAY_ARGS = {
|
|
133
89
|
"headless": [],
|
|
@@ -178,11 +134,7 @@ class EdgeBackend:
|
|
|
178
134
|
finally:
|
|
179
135
|
if self._pw is not None:
|
|
180
136
|
self._pw.stop()
|
|
181
|
-
|
|
182
|
-
try:
|
|
183
|
-
self._lock.unlink()
|
|
184
|
-
except OSError:
|
|
185
|
-
pass
|
|
137
|
+
release_lock(self._lock)
|
|
186
138
|
self._pw = self._ctx = self.page = self._lock = None
|
|
187
139
|
|
|
188
140
|
# ---------- page state ----------
|
|
@@ -203,6 +155,13 @@ class EdgeBackend:
|
|
|
203
155
|
markers = [k for k in ("limit_marker", "error_marker", "challenge_marker") if self._visible(k)]
|
|
204
156
|
if any(h in self._host() for h in LOGIN_HOSTS):
|
|
205
157
|
markers.append("login_page")
|
|
158
|
+
try:
|
|
159
|
+
found, notes = classify_notices(visible_notices(self.page), self._notices_seen, # #3
|
|
160
|
+
ignore=self.notices_ignore)
|
|
161
|
+
except Exception: # a notice scan must never break a probe
|
|
162
|
+
found, notes = [], []
|
|
163
|
+
markers += [m for m in found if m not in markers]
|
|
164
|
+
self.notes += notes
|
|
206
165
|
return Probe(temporary=self._visible("temporary_on"), signed_in=self._visible("signed_in"),
|
|
207
166
|
model_label=self._text_of("model"), markers=markers,
|
|
208
167
|
reply_count=self.page.locator(self.sel["reply"]).count(), url=self.page.url[:120])
|
|
@@ -423,6 +382,23 @@ class EdgeBackend:
|
|
|
423
382
|
out.append(ZERO_WIDTH.sub("", part.inner_text() if part.count() else "").strip("\n"))
|
|
424
383
|
return out
|
|
425
384
|
|
|
385
|
+
def _stable_code_blocks(self, reply, reply_text: str) -> list[str]:
|
|
386
|
+
"""Read the code blocks until two reads agree and every block appears in the reply's own text (issue #1:
|
|
387
|
+
live, a block was once read with an extra line the reply text did not contain, during the editor's last
|
|
388
|
+
re-render). After the retries the last read is returned with a note, never silently patched."""
|
|
389
|
+
flat = " ".join(normalise(reply_text).split())
|
|
390
|
+
prev = None
|
|
391
|
+
for _ in range(6):
|
|
392
|
+
cur = self._code_blocks(reply)
|
|
393
|
+
contained = all(" ".join(normalise(b).split()) in flat for b in cur)
|
|
394
|
+
if cur == prev and contained:
|
|
395
|
+
return cur
|
|
396
|
+
prev = cur
|
|
397
|
+
time.sleep(0.25)
|
|
398
|
+
if not all(" ".join(normalise(b).split()) in flat for b in prev or []):
|
|
399
|
+
self.notes.append("a code block read back differs from the reply text (issue #1)")
|
|
400
|
+
return prev or []
|
|
401
|
+
|
|
426
402
|
def _mark_seen(self, mark: str) -> list:
|
|
427
403
|
"""Give every existing reply and user-message node its own id mark; returns [id, text] of the reply nodes
|
|
428
404
|
that held text (I11)."""
|
|
@@ -491,7 +467,9 @@ class EdgeBackend:
|
|
|
491
467
|
kept = self._mark_seen(mark)
|
|
492
468
|
fresh_sel = f"{self.sel['reply']}:not([data-copuppet-seen])"
|
|
493
469
|
user_sel = f"{self.sel['user_message']}:not([data-copuppet-seen])" if self.sel.get("user_message") else ""
|
|
494
|
-
|
|
470
|
+
# `started` = the service took the prompt (busy marker or a new reply node); `first_token` = the new reply
|
|
471
|
+
# first shows text (#2: the busy marker appears at once, so it says nothing about latency)
|
|
472
|
+
started, first_token, t_sent, busy_seen = None, None, time.time(), False
|
|
495
473
|
for attempt in (1, 2):
|
|
496
474
|
self.page.keyboard.press("Enter")
|
|
497
475
|
t_sent = time.time()
|
|
@@ -500,10 +478,10 @@ class EdgeBackend:
|
|
|
500
478
|
busy = self._visible("busy")
|
|
501
479
|
busy_seen = busy_seen or busy
|
|
502
480
|
if busy or self.page.locator(fresh_sel).count() > 0:
|
|
503
|
-
|
|
481
|
+
started = time.time()
|
|
504
482
|
break
|
|
505
483
|
time.sleep(0.2)
|
|
506
|
-
if
|
|
484
|
+
if started is not None:
|
|
507
485
|
break
|
|
508
486
|
# I10: resubmit only with proof that nothing was sent (no new user message, no new reply)
|
|
509
487
|
sent_evidence = (self.page.locator(user_sel).count() > 0) if user_sel else True
|
|
@@ -515,7 +493,7 @@ class EdgeBackend:
|
|
|
515
493
|
break
|
|
516
494
|
continue
|
|
517
495
|
break
|
|
518
|
-
if
|
|
496
|
+
if started is None:
|
|
519
497
|
raise BackendError("no answer started after submitting; next: re-run tools/discover_edge.py --probe")
|
|
520
498
|
complete, last_text, stable_since = False, None, None
|
|
521
499
|
done_sel = f"{fresh_sel} {self.sel['done']}" if self.sel.get("done") else ""
|
|
@@ -524,6 +502,8 @@ class EdgeBackend:
|
|
|
524
502
|
busy = self._visible("busy")
|
|
525
503
|
busy_seen = busy_seen or busy
|
|
526
504
|
fresh = self.page.locator(fresh_sel)
|
|
505
|
+
if first_token is None and fresh.count() > 0 and normalise(fresh.nth(fresh.count() - 1).inner_text()):
|
|
506
|
+
first_token = time.time()
|
|
527
507
|
if not busy and fresh.count() > 0:
|
|
528
508
|
if done_sel and first_visible(self.page.locator(done_sel)) is not None:
|
|
529
509
|
complete = True # done marker scoped to the new reply
|
|
@@ -539,6 +519,8 @@ class EdgeBackend:
|
|
|
539
519
|
last_text, stable_since = None, None
|
|
540
520
|
time.sleep(0.3)
|
|
541
521
|
t_done = time.time()
|
|
522
|
+
if first_token is None:
|
|
523
|
+
first_token = t_done # no text was ever seen: generation time 0, the reply is empty
|
|
542
524
|
after = self.probe()
|
|
543
525
|
b = self._bind(kept)
|
|
544
526
|
bound = b["fresh"] == 1 and b["before_anchor"] == 0 and b["anchored"] # I8 + I11
|
|
@@ -557,7 +539,7 @@ class EdgeBackend:
|
|
|
557
539
|
new_nodes = self.page.locator(f"{self.sel['reply']}[data-copuppet-fresh]")
|
|
558
540
|
last = new_nodes.nth(new_nodes.count() - 1) if new_nodes.count() else None
|
|
559
541
|
text = ZERO_WIDTH.sub("", last.inner_text()).strip() if last is not None else ""
|
|
560
|
-
code = self.
|
|
542
|
+
code = self._stable_code_blocks(last, text) if last is not None else []
|
|
561
543
|
if not complete:
|
|
562
544
|
self.notes.append(f"stopped waiting after {timeout:g}s; the reply may be partial")
|
|
563
545
|
self.log(("reply complete" if complete else "reply incomplete") + ("" if bound else ", UNBOUND") +
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"""What the Edge backend and tools/discover_edge.py share, so a fix lands once (#4): browser arguments, login hosts,
|
|
2
|
+
the clean-exit mark, text normalisation, visible-dialog reading and the profile lock. No Playwright import here."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
BROWSER_ARGS = ["--hide-crash-restore-bubble", "--no-first-run", "--no-default-browser-check"]
|
|
11
|
+
DIALOG_SELECTOR = "[role='dialog'], [role='alertdialog'], [aria-modal='true']"
|
|
12
|
+
LOGIN_HOSTS = ("login.live.com", "login.microsoftonline.com", "login.microsoft.com", "account.microsoft.com")
|
|
13
|
+
LOCK_NAME = "copuppet.lock"
|
|
14
|
+
ZERO_WIDTH = re.compile("[\u200b\u200c\u200d\u2060\ufeff]")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ProfileBusy(RuntimeError):
|
|
18
|
+
"""Another copuppet process holds the Edge profile."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def mark_clean_exit(profile: Path) -> None:
|
|
22
|
+
"""Prevent Edge's 'Restore pages' bubble (browser UI, unclickable from Playwright) after an unclean exit."""
|
|
23
|
+
pref = profile / "Default" / "Preferences"
|
|
24
|
+
try:
|
|
25
|
+
data = json.loads(pref.read_text(encoding="utf-8"))
|
|
26
|
+
except (OSError, ValueError):
|
|
27
|
+
return
|
|
28
|
+
prof = data.setdefault("profile", {})
|
|
29
|
+
if prof.get("exit_type") != "Normal" or prof.get("exited_cleanly") is not True:
|
|
30
|
+
prof["exit_type"], prof["exited_cleanly"] = "Normal", True
|
|
31
|
+
pref.write_text(json.dumps(data), encoding="utf-8")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def first_visible(locator, limit: int = 10):
|
|
35
|
+
for i in range(min(locator.count(), limit)):
|
|
36
|
+
if locator.nth(i).is_visible():
|
|
37
|
+
return locator.nth(i)
|
|
38
|
+
return None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def normalise(text: str) -> str:
|
|
42
|
+
"""Whitespace collapsed and zero-width characters removed: the chat editor inserts U+200B U+200C at line ends."""
|
|
43
|
+
return re.sub(r"\s+", " ", ZERO_WIDTH.sub("", text or "")).strip()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def pid_alive(pid: int) -> bool:
|
|
47
|
+
if pid <= 0:
|
|
48
|
+
return False
|
|
49
|
+
try:
|
|
50
|
+
if os.name == "nt":
|
|
51
|
+
import ctypes
|
|
52
|
+
h = ctypes.windll.kernel32.OpenProcess(0x1000, False, pid) # PROCESS_QUERY_LIMITED_INFORMATION
|
|
53
|
+
if not h:
|
|
54
|
+
return False
|
|
55
|
+
ctypes.windll.kernel32.CloseHandle(h)
|
|
56
|
+
return True
|
|
57
|
+
os.kill(pid, 0)
|
|
58
|
+
return True
|
|
59
|
+
except OSError:
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def acquire_lock(profile: Path) -> Path:
|
|
64
|
+
"""Take the profile lock (one copuppet process per Edge profile); returns the lock file to release."""
|
|
65
|
+
profile.mkdir(parents=True, exist_ok=True)
|
|
66
|
+
lock = profile / LOCK_NAME
|
|
67
|
+
try:
|
|
68
|
+
holder = int(lock.read_text(encoding="utf-8").strip() or 0)
|
|
69
|
+
except (OSError, ValueError):
|
|
70
|
+
holder = 0
|
|
71
|
+
if holder and holder != os.getpid() and pid_alive(holder):
|
|
72
|
+
raise ProfileBusy(f"another copuppet run (pid {holder}) is using {profile}; next: wait for it or stop it")
|
|
73
|
+
lock.write_text(str(os.getpid()), encoding="utf-8")
|
|
74
|
+
return lock
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def release_lock(lock: Path | None) -> None:
|
|
78
|
+
if lock is None:
|
|
79
|
+
return
|
|
80
|
+
try:
|
|
81
|
+
if lock.read_text(encoding="utf-8").strip() == str(os.getpid()):
|
|
82
|
+
lock.unlink()
|
|
83
|
+
except OSError:
|
|
84
|
+
pass
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
VISIBLE_DIALOGS_JS = r"""
|
|
88
|
+
(sel) => [...document.querySelectorAll(sel)].filter(el => {
|
|
89
|
+
const r = el.getBoundingClientRect(); return r.width > 0 && r.height > 0 && getComputedStyle(el).visibility !== 'hidden';
|
|
90
|
+
}).map(el => ({
|
|
91
|
+
role: el.getAttribute('role') || '', aria_label: (el.getAttribute('aria-label') || '').slice(0, 80),
|
|
92
|
+
testid: el.getAttribute('data-testid') || '', id: el.id || '',
|
|
93
|
+
buttons: [...el.querySelectorAll("button, [role='button'], a")].map(b =>
|
|
94
|
+
((b.getAttribute('aria-label') || b.innerText || '').trim().replace(/\s+/g, ' ')).slice(0, 40)).filter(Boolean).slice(0, 8),
|
|
95
|
+
}))
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def visible_dialogs(page) -> list:
|
|
100
|
+
"""Visible page modals, each with its role, label and the labels of its buttons (structure only)."""
|
|
101
|
+
return page.evaluate(VISIBLE_DIALOGS_JS, DIALOG_SELECTOR)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# ---------- notices (#3) ----------
|
|
105
|
+
THROTTLE = re.compile(r"(?i)(too many (requests|messages)|try again later|reached (the|your) (daily |message )?limit|"
|
|
106
|
+
r"slow down|unusual activity|verify (that )?you are (a )?human|are you a robot|captcha)")
|
|
107
|
+
NOTICE_SELECTOR = "[role='alert'], [role='alertdialog'], [aria-live='assertive']"
|
|
108
|
+
NOTICES_JS = r"""
|
|
109
|
+
(sel) => [...document.querySelectorAll(sel)].filter(el => {
|
|
110
|
+
const r = el.getBoundingClientRect(); return r.width > 0 && r.height > 0 && getComputedStyle(el).visibility !== 'hidden';
|
|
111
|
+
}).map(el => ({
|
|
112
|
+
role: el.getAttribute('role') || ('live:' + (el.getAttribute('aria-live') || '')),
|
|
113
|
+
testid: el.getAttribute('data-testid') || '', aria_label: (el.getAttribute('aria-label') || '').slice(0, 80),
|
|
114
|
+
text: (el.innerText || '').trim().replace(/\s+/g, ' ').slice(0, 160),
|
|
115
|
+
})).filter(n => n.text || n.aria_label)
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def visible_notices(page) -> list:
|
|
120
|
+
"""Visible alerts, alert dialogs and assertive live regions (where challenge and limit notices would appear)."""
|
|
121
|
+
return page.evaluate(NOTICES_JS, NOTICE_SELECTOR)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def classify_notices(notices: list, seen: set, ignore=()) -> tuple[list, list]:
|
|
125
|
+
"""(markers, notes) for a list of notices. Throttle or challenge wording becomes `challenge_marker` (fail closed:
|
|
126
|
+
the run stops); every notice not seen before becomes a note with its structure, so the skin can get a real
|
|
127
|
+
selector once one has been observed. `seen` is updated."""
|
|
128
|
+
markers, notes = [], []
|
|
129
|
+
for n in notices:
|
|
130
|
+
text = n.get("text") or n.get("aria_label") or ""
|
|
131
|
+
if THROTTLE.search(text) and "challenge_marker" not in markers: # checked before `ignore`: never muted
|
|
132
|
+
markers.append("challenge_marker")
|
|
133
|
+
if any(s in text.lower() for s in ignore): # skin edge.notices_ignore
|
|
134
|
+
continue
|
|
135
|
+
key = (n.get("role"), n.get("testid"), text)
|
|
136
|
+
if key not in seen:
|
|
137
|
+
seen.add(key)
|
|
138
|
+
notes.append(f"page notice ({n.get('role')}{', testid ' + n['testid'] if n.get('testid') else ''}): "
|
|
139
|
+
f"{text[:120]}")
|
|
140
|
+
return markers, notes
|
|
@@ -25,11 +25,10 @@ from pathlib import Path
|
|
|
25
25
|
import yaml
|
|
26
26
|
|
|
27
27
|
from .backend import BackendError
|
|
28
|
+
from .backends.edge_common import THROTTLE # one throttle pattern for calibration and the backend
|
|
28
29
|
|
|
29
30
|
STORE = Path.home() / ".copuppet" / "limits.yaml"
|
|
30
31
|
METHOD = 2 # 2: prompt cap by doubling and bisection, recall filler at 80% of the cap
|
|
31
|
-
THROTTLE = re.compile(r"(?i)(too many (requests|messages)|try again later|reached (the|your) (daily |message )?limit|"
|
|
32
|
-
r"slow down|unusual activity|verify (that )?you are (a )?human)")
|
|
33
32
|
WORDS = ["ledger", "amount", "invoice", "north", "river", "column", "status", "pending", "review", "folder", "branch", "archive", "meter", "client", "record", "field", "window", "value", "report", "export", "label", "budget", "sample", "margin", "vendor", "ticket", "batch"]
|
|
34
33
|
|
|
35
34
|
|