@oked/copilot 0.0.0-stage → 0.6.23
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/LICENSE +201 -0
- package/README.md +157 -2
- package/bin/oked-copilot-hook.js +2 -0
- package/bin/oked-copilot.js +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +124 -0
- package/dist/hook.d.ts +2 -0
- package/dist/hook.js +66 -0
- package/dist/install.d.ts +36 -0
- package/dist/install.js +162 -0
- package/dist/map.d.ts +17 -0
- package/dist/map.js +67 -0
- package/dist/output.d.ts +8 -0
- package/dist/output.js +15 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +15 -0
- package/package.json +54 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,158 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @oked/copilot
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@oked/copilot)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
|
|
6
|
+
GitHub Copilot hook for the CLI and for VS Code. Sensitive actions wait for a person in Telegram or on the [web dashboard](https://oked.ai/dashboard) before Copilot continues. The iPhone app is coming soon. Questions: [contact@oked.ai](mailto:contact@oked.ai).
|
|
7
|
+
|
|
8
|
+
Safe actions are allowed by the hook, with no notification. Warning actions are allowed and logged. OKed asks only for `review` and `high_stakes`.
|
|
9
|
+
|
|
10
|
+
VS Code hooks are Preview. The cloud coding agent can run the same project file, with the limits below.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install -g @oked/copilot
|
|
16
|
+
oked-copilot init
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`oked-copilot init` writes `.github/hooks/oked.json` in the current project and stores the API key in `~/.oked/config.json`. The file it writes:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"version": 1,
|
|
24
|
+
"hooks": {
|
|
25
|
+
"preToolUse": [
|
|
26
|
+
{
|
|
27
|
+
"type": "command",
|
|
28
|
+
"command": "oked-copilot-hook",
|
|
29
|
+
"timeoutSec": 690
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
There is no matcher, so every tool is included. Other hooks already in that file are kept. A second init does not add a second copy. It raises a `timeoutSec` below 690 and drops a conflicting `timeout` alias. The binary is `oked-copilot`, not `oked`, so it can sit next to `@oked/claude-code`. The cloud agent loads this same file.
|
|
37
|
+
|
|
38
|
+
Open a new Copilot CLI session, or a new Copilot chat in VS Code, in that project.
|
|
39
|
+
|
|
40
|
+
The approval window is 10 minutes. The hook is configured for 690 seconds, and the SDK client waits 630 seconds. Copilot's own default is 30 seconds. Read the timeout section: a timeout fails open even when the hook is a policy hook.
|
|
41
|
+
|
|
42
|
+
## Commands
|
|
43
|
+
|
|
44
|
+
| Command | What it does |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `oked-copilot init` | Install or update the project hook and pair this device. If this project's Claude settings already have `oked-hook`, this does not add a second hook. |
|
|
47
|
+
| `oked-copilot init --native` | Install the Copilot hook even when a project Claude Code `oked-hook` is present. You will get two prompts until you remove that entry. |
|
|
48
|
+
| `oked-copilot init --no-browser` | Print the pairing link. Do not open a browser, and do not touch the clipboard. |
|
|
49
|
+
| `oked-copilot init --yes` (or `-y`) | Skip the "press Enter to open the browser" prompt. For a non-interactive shell. |
|
|
50
|
+
| `oked-copilot status` | Show install state and ping `GET /health` on the backend. |
|
|
51
|
+
| `oked-copilot uninstall` | Remove the Copilot hook entry. Other hooks in the file are kept. A Claude Code hook is not removed. |
|
|
52
|
+
|
|
53
|
+
## What gets intercepted
|
|
54
|
+
|
|
55
|
+
The hook uses the same four-tier classifier as `@oked/claude-code`. There is no matcher, so every tool is included. Unknown tools are `review` and wait for approval.
|
|
56
|
+
|
|
57
|
+
Copilot sends runtime names on `preToolUse` (`toolName`, `toolArgs`). A PascalCase `PreToolUse` payload uses Claude names (`tool_name`, `tool_input`). This hook accepts both.
|
|
58
|
+
|
|
59
|
+
| Copilot tool | OKed sees | Notes |
|
|
60
|
+
|---|---|---|
|
|
61
|
+
| `bash`, `powershell`, `Bash` | `Bash` | `ls` is safe. `rm` of a real file, a force push, network writes, and a production deploy wait. |
|
|
62
|
+
| `view`, `grep`, `glob`, `web_search` | `Read`, `Grep`, `Glob`, `WebSearch` | Safe. No prompt. |
|
|
63
|
+
| `web_fetch` | `WebFetch` | Warning. Allowed and logged. |
|
|
64
|
+
| `create` | `Write` | A project file is `warning`. A sensitive path is `review`. |
|
|
65
|
+
| `edit`, `str_replace_editor` | `Edit` | Same path rules as a write. |
|
|
66
|
+
| `apply_patch` | `Write` or `rm` | A delete in the patch is `rm`. |
|
|
67
|
+
| `ask_user`, `update_todo`, `task` | session tools | Safe, or `Agent` for `task`. The sub-agent's own tool calls are gated on their own. |
|
|
68
|
+
| `mcp__server__tool`, `MCP:server:tool` | the same MCP name | `list_*` and `get_*` are safe. `create_*` and `send_*` are `review`. `delete_*` is `high_stakes`. |
|
|
69
|
+
| anything else | the same name | Unknown tools wait for approval. |
|
|
70
|
+
|
|
71
|
+
The hooks reference does not list MCP tool names. A name this package does not recognize requires approval rather than passing through.
|
|
72
|
+
|
|
73
|
+
## How it works
|
|
74
|
+
|
|
75
|
+
1. Copilot runs `oked-copilot-hook` before the tool call. The hook is a separate process.
|
|
76
|
+
2. The hook classifies the action locally. `safe` and `warning` do not wait on the network, unless a cached user rule matches.
|
|
77
|
+
3. For `review` and `high_stakes`, it sends an approval request.
|
|
78
|
+
4. You decide in Telegram or on the web dashboard. Web push is optional.
|
|
79
|
+
5. Approve, and the hook prints `{"permissionDecision":"allow"}`. Deny or time out, and it prints `permissionDecision: "deny"` with `permissionDecisionReason`.
|
|
80
|
+
|
|
81
|
+
Empty output uses Copilot's normal permission flow, which can still prompt. A safe call therefore prints an explicit allow, so it runs with no prompt.
|
|
82
|
+
|
|
83
|
+
`ask` is turned into deny in the cloud agent and in CLI autopilot. This hook never prints `ask`. If this device is not paired, the hook denies. The reason is `Pair first: run oked-copilot init`.
|
|
84
|
+
|
|
85
|
+
The hook exits 0. A non-zero exit on `preToolUse` denies the tool, even if stdout says allow. A timeout does the opposite: the tool continues. See below.
|
|
86
|
+
|
|
87
|
+
## Timeout
|
|
88
|
+
|
|
89
|
+
`timeoutSec` is seconds. The default is 30. `timeout` is an alias used only when `timeoutSec` is absent. The docs do not state a maximum. Checked on 2026-10-28 at [the hooks reference](https://docs.github.com/en/copilot/reference/hooks-reference).
|
|
90
|
+
|
|
91
|
+
`oked-copilot init` sets `timeoutSec` to 690 and removes a `timeout` alias so the two cannot disagree. It raises a lower value. A higher `timeoutSec` you set yourself is left alone.
|
|
92
|
+
|
|
93
|
+
Command `preToolUse` hooks fail closed on a crash or any non-zero exit. Timeouts always fail open, including for admin policy hooks. Copilot logs a warning and lets the tool continue through the normal permission flow. There is no `failClosed` field to change that.
|
|
94
|
+
|
|
95
|
+
If Copilot honors 690, the SDK's deny (at 630 seconds) is written before the process is killed. If a build caps the wait below that, the kill fails open. Confirm `timeoutSec: 690` once in Copilot CLI and once in VS Code before you rely on a 10 minute approval.
|
|
96
|
+
|
|
97
|
+
## Claude Code hooks, and asking twice
|
|
98
|
+
|
|
99
|
+
Copilot CLI and VS Code read repository `.claude/settings.json` and `.claude/settings.local.json`, in addition to `.github/hooks/*.json`. Docs: [hooks reference](https://docs.github.com/en/copilot/reference/hooks-reference) and [VS Code hooks](https://code.visualstudio.com/docs/copilot/customization/hooks). They do not read `~/.claude/settings.json`. A user-level Claude hook does not gate Copilot, so init still installs the native hook in that case.
|
|
100
|
+
|
|
101
|
+
A project `oked-hook` plus `.github/hooks/oked.json` would ask twice. `oked-copilot init` looks for that project entry. If it finds one, and the native hook is not already installed, it does not write `oked.json`. Pairing still runs. Both hooks read `~/.oked/config.json`.
|
|
102
|
+
|
|
103
|
+
The imported hook is the Claude Code one. It returns `ask` when the device is not paired. Copilot cloud agent and CLI autopilot turn `ask` into deny. An interactive CLI may still prompt. The native hook denies with a pairing message instead.
|
|
104
|
+
|
|
105
|
+
`oked-copilot init --native` installs even when the project Claude hook is present, and it says that you will be asked twice. Init never deletes the Claude hook. `oked uninstall` from `@oked/claude-code` removes it, and that also removes it from Claude Code.
|
|
106
|
+
|
|
107
|
+
## Cloud coding agent
|
|
108
|
+
|
|
109
|
+
The cloud agent loads only `.github/hooks/*.json` from the repository. It does not load user hooks, `settings.json`, or Claude settings. Putting this file in the repo is what reaches a cloud job.
|
|
110
|
+
|
|
111
|
+
The job's network is limited to GitHub hosts unless an org admin allows the OKed API (`api.oked.ai`). Without that allow rule the hook cannot reach the backend. `high_stakes` is then denied. Lower tiers follow the usual outage rule unless `OKED_STRICT_FAIL_CLOSED` is set.
|
|
112
|
+
|
|
113
|
+
`permissionRequest` does not decide tools in the cloud. `preToolUse` does, and `ask` is deny. The whole wait counts against the job timeout. A 10 minute approval can outlive the job. For a cloud job, prefer a person who can answer quickly, or keep the hook for the CLI and VS Code only.
|
|
114
|
+
|
|
115
|
+
## Environment
|
|
116
|
+
|
|
117
|
+
| Var | Required | Description |
|
|
118
|
+
|---|---|---|
|
|
119
|
+
| `OKED_API_KEY` | no, after pairing | Optional override. `oked-copilot init` stores the paired key in `~/.oked/config.json`. |
|
|
120
|
+
| `OKED_STRICT_FAIL_CLOSED` | no | `1` or `true` denies every sensitive action when the backend is unreachable. |
|
|
121
|
+
| `OKED_REQUIRE_RECEIPT` | no | `0` allows an approval with no receipt. On by default since 0.6.0. |
|
|
122
|
+
| `OKED_HOOK_LOG` | no | Decision log path. Default `~/.oked/hook.log`. |
|
|
123
|
+
|
|
124
|
+
## Receipts
|
|
125
|
+
|
|
126
|
+
Every decision comes with a receipt signed by OKed. The hook verifies it before allowing the action and keeps a copy in `~/.oked/receipts.jsonl`. Since 0.6.0 the hook denies an approval that has no valid receipt. Set `OKED_REQUIRE_RECEIPT=0` only for a backend that does not sign receipts.
|
|
127
|
+
|
|
128
|
+
You can paste one receipt at [oked.ai/docs/#verify](https://oked.ai/docs#verify), or check an export with `npx @oked/verify`. See [docs/receipts.md](../../docs/receipts.md).
|
|
129
|
+
|
|
130
|
+
## Degraded-mode behavior
|
|
131
|
+
|
|
132
|
+
Explicit denials, invalid API keys, and receipts that do not verify deny the action. If the backend is unreachable, OKed denies `high_stakes` and, by default, allows lower tiers. Set `OKED_STRICT_FAIL_CLOSED=1` to deny every sensitive action during an outage.
|
|
133
|
+
|
|
134
|
+
HTTP 429 (too many approvals already waiting) is not an outage: the action is denied until those are decided in Telegram or on the dashboard.
|
|
135
|
+
|
|
136
|
+
If the hook cannot parse its stdin, it denies. A bad payload must not become a silent allow.
|
|
137
|
+
|
|
138
|
+
## Decision log
|
|
139
|
+
|
|
140
|
+
The hook writes one JSON line to `~/.oked/hook.log` (mode 600) for each deny, and for each degraded allow. The log never holds the tool input or the command.
|
|
141
|
+
|
|
142
|
+
## Uninstall
|
|
143
|
+
|
|
144
|
+
`oked-copilot uninstall` removes only the `oked-copilot-hook` entry from `.github/hooks/oked.json`. Other hooks in that file stay. If that was the only hook, the file is deleted. A Claude Code `oked-hook` entry is left in place. The API key in `~/.oked/config.json` stays.
|
|
145
|
+
|
|
146
|
+
## Troubleshooting
|
|
147
|
+
|
|
148
|
+
- Hook never runs: open a new Copilot CLI session or a new VS Code chat. `oked-copilot-hook` must be on `PATH`. VS Code hooks are Preview.
|
|
149
|
+
- The tool ran anyway after a long wait: Copilot kills the hook at `timeoutSec` and fails open, including for policy hooks. There is no `failClosed` switch. Confirm the file says 690. A live check is still required, because the docs state no maximum.
|
|
150
|
+
- Two cards for one action: this project's `.claude/settings.json` or `.claude/settings.local.json` also has `oked-hook`. Copilot CLI and VS Code read those files. `oked-copilot init` skips the native file when it finds one. `--native` installs anyway and warns. A user-level `~/.claude/settings.json` hook does not run in Copilot, so it does not block init.
|
|
151
|
+
- `Pair first: run oked-copilot init`: no API key. The hook denies. It does not print `ask`.
|
|
152
|
+
- Backend down: `high_stakes` is denied. Lower tiers are allowed unless `OKED_STRICT_FAIL_CLOSED=1`. Nobody answering within 10 minutes is a deny.
|
|
153
|
+
- Cloud agent: only `.github/hooks/oked.json` from the repo is loaded. An org admin must allow `api.oked.ai`. The wait counts against the job timeout. `ask` is deny there.
|
|
154
|
+
- Still stuck: [contact@oked.ai](mailto:contact@oked.ai).
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
[Apache-2.0](./LICENSE)
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import { maskKey, pairDevice, writeOkedConfig } from "@oked/hook-core";
|
|
4
|
+
import { OKedClient, OKED_CONFIG_PATH } from "@oked/sdk";
|
|
5
|
+
import { copilotHookInstalled, hooksPath, installCopilotHook, uninstallCopilotHook } from "./install.js";
|
|
6
|
+
import { CLIENT_VERSION, PAIR_COMMAND } from "./version.js";
|
|
7
|
+
const BACKEND = process.env.OKED_BACKEND_URL || "https://api.oked.ai";
|
|
8
|
+
const NO_BROWSER = process.argv.includes("--no-browser");
|
|
9
|
+
const NATIVE = process.argv.includes("--native");
|
|
10
|
+
function footer(uri) {
|
|
11
|
+
return [` (Or visit ${uri} and enter the code above.)`, " The iPhone app is coming soon."];
|
|
12
|
+
}
|
|
13
|
+
function printClaudeHits(hits) {
|
|
14
|
+
for (const hit of hits)
|
|
15
|
+
console.log(` ${hit.scope}: ${hit.path}`);
|
|
16
|
+
}
|
|
17
|
+
async function init() {
|
|
18
|
+
const cwd = process.cwd();
|
|
19
|
+
const result = installCopilotHook(cwd, { native: NATIVE });
|
|
20
|
+
if (result.action === "unreadable") {
|
|
21
|
+
console.log(`OKed could not read ${result.path}. It was not changed.`);
|
|
22
|
+
}
|
|
23
|
+
else if (result.action === "skipped-claude-hook") {
|
|
24
|
+
console.log("Copilot CLI and VS Code already run an @oked/claude-code hook from this project's Claude settings.");
|
|
25
|
+
console.log("A native hook as well would ask twice, so .github/hooks/oked.json was not added.");
|
|
26
|
+
printClaudeHits(result.claudeHooks);
|
|
27
|
+
console.log("Copilot reads .claude/settings.json and .claude/settings.local.json in the repository. It does not read ~/.claude/settings.json.");
|
|
28
|
+
console.log("To install the native hook anyway, run `oked-copilot init --native`. You will get two prompts until you remove the project oked-hook entry.");
|
|
29
|
+
console.log("This command does not remove the Claude Code hook.");
|
|
30
|
+
}
|
|
31
|
+
else if (result.action === "installed") {
|
|
32
|
+
console.log("OKed hook installed.");
|
|
33
|
+
console.log(` Config: ${result.path}`);
|
|
34
|
+
}
|
|
35
|
+
else if (result.action === "updated") {
|
|
36
|
+
console.log("OKed hook updated.");
|
|
37
|
+
console.log(` Config: ${result.path}`);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.log("OKed hook already configured.");
|
|
41
|
+
console.log(` Config: ${result.path}`);
|
|
42
|
+
}
|
|
43
|
+
if (result.claudeHooks.length > 0 && result.action !== "skipped-claude-hook" && result.action !== "unreadable") {
|
|
44
|
+
console.log("A project Claude Code oked-hook is also installed. Copilot runs both, so you will be asked twice.");
|
|
45
|
+
printClaudeHits(result.claudeHooks);
|
|
46
|
+
console.log("Remove the oked-hook entry from the project Claude settings to keep a single prompt.");
|
|
47
|
+
}
|
|
48
|
+
const existing = new OKedClient();
|
|
49
|
+
if (existing.apiKey) {
|
|
50
|
+
const ok = await existing.ping();
|
|
51
|
+
console.log("");
|
|
52
|
+
console.log(` API key: ${maskKey(existing.apiKey)} (already paired)`);
|
|
53
|
+
console.log(` Backend: ${existing.backendUrl} (${ok ? "connected" : "not reachable"})`);
|
|
54
|
+
console.log("");
|
|
55
|
+
console.log("Copilot CLI and VS Code in this project now ask before a risky tool call.");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const apiKey = await pairDevice({
|
|
59
|
+
backendUrl: BACKEND,
|
|
60
|
+
clientType: "copilot",
|
|
61
|
+
clientVersion: CLIENT_VERSION,
|
|
62
|
+
noBrowser: NO_BROWSER,
|
|
63
|
+
retryCommand: PAIR_COMMAND,
|
|
64
|
+
scanLine: " Or scan this with your phone camera. It opens the pairing page in the browser.",
|
|
65
|
+
footerLines: footer,
|
|
66
|
+
});
|
|
67
|
+
if (!apiKey)
|
|
68
|
+
return;
|
|
69
|
+
writeOkedConfig(apiKey, BACKEND);
|
|
70
|
+
console.log("");
|
|
71
|
+
console.log(` Paired. Key saved to ${OKED_CONFIG_PATH}`);
|
|
72
|
+
console.log("");
|
|
73
|
+
console.log("Copilot CLI and VS Code in this project now ask before a risky tool call.");
|
|
74
|
+
console.log("Open a new session to load the hook.");
|
|
75
|
+
}
|
|
76
|
+
async function status() {
|
|
77
|
+
const path = hooksPath(process.cwd());
|
|
78
|
+
const client = new OKedClient();
|
|
79
|
+
console.log("OKed status:");
|
|
80
|
+
console.log(` Hook: ${copilotHookInstalled(process.cwd()) ? "installed" : "not installed"}`);
|
|
81
|
+
console.log(` Project config: ${existsSync(path) ? path : "not found"}`);
|
|
82
|
+
console.log(` API key: ${client.apiKey ? maskKey(client.apiKey) : "not paired"}`);
|
|
83
|
+
console.log(` User config: ${existsSync(OKED_CONFIG_PATH) ? OKED_CONFIG_PATH : "not found"}`);
|
|
84
|
+
if (client.apiKey) {
|
|
85
|
+
const ok = await client.ping();
|
|
86
|
+
console.log(` Backend: ${client.backendUrl} (${ok ? "connected" : "not reachable"})`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function uninstall() {
|
|
90
|
+
const result = uninstallCopilotHook(process.cwd());
|
|
91
|
+
if (result.action === "unreadable") {
|
|
92
|
+
console.log(`OKed could not read ${result.path}. It was not changed.`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (result.action === "absent") {
|
|
96
|
+
console.log("OKed hook was not installed in this project.");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
console.log("OKed hook removed from this project.");
|
|
100
|
+
console.log(` Config: ${result.path}`);
|
|
101
|
+
console.log("A Claude Code hook, if you have one, was left in place.");
|
|
102
|
+
}
|
|
103
|
+
const command = process.argv[2];
|
|
104
|
+
switch (command) {
|
|
105
|
+
case "init":
|
|
106
|
+
init().catch(console.error);
|
|
107
|
+
break;
|
|
108
|
+
case "status":
|
|
109
|
+
status().catch(console.error);
|
|
110
|
+
break;
|
|
111
|
+
case "uninstall":
|
|
112
|
+
uninstall();
|
|
113
|
+
break;
|
|
114
|
+
default:
|
|
115
|
+
console.log("Usage: oked-copilot <command>");
|
|
116
|
+
console.log("");
|
|
117
|
+
console.log("Commands:");
|
|
118
|
+
console.log(" init Install the Copilot preToolUse hook and pair this device");
|
|
119
|
+
console.log(" --native Install even when a project Claude Code oked-hook is present");
|
|
120
|
+
console.log(" --no-browser Print the pairing link. Open no browser, use no clipboard.");
|
|
121
|
+
console.log(" status Show the hook and the connection");
|
|
122
|
+
console.log(" uninstall Remove the OKed Copilot hook from this project");
|
|
123
|
+
break;
|
|
124
|
+
}
|
package/dist/hook.d.ts
ADDED
package/dist/hook.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { asToolInput, decide, errorInfo, logDecision } from "@oked/hook-core";
|
|
3
|
+
import { mapCopilotTool } from "./map.js";
|
|
4
|
+
import { writeDecision } from "./output.js";
|
|
5
|
+
import { CLIENT_ID, PAIR_COMMAND, UNINSTALL_COMMAND } from "./version.js";
|
|
6
|
+
function invalidKeyReason(status) {
|
|
7
|
+
return `OKed: invalid API key (HTTP ${status}). Pair first: run \`${PAIR_COMMAND}\` to pair again, or \`${UNINSTALL_COMMAND}\` to remove OKed.`;
|
|
8
|
+
}
|
|
9
|
+
const UNPAIRED = `OKed: this device is not paired. Pair first: run ${PAIR_COMMAND}`;
|
|
10
|
+
function denyUnreadable(reason) {
|
|
11
|
+
writeDecision({ decision: "deny", reason });
|
|
12
|
+
logDecision({ decision: "deny", reason, tool: "unknown", tier: null, client: CLIENT_ID });
|
|
13
|
+
}
|
|
14
|
+
function stringField(input, keys) {
|
|
15
|
+
for (const key of keys) {
|
|
16
|
+
if (typeof input[key] === "string")
|
|
17
|
+
return input[key];
|
|
18
|
+
}
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
async function main() {
|
|
22
|
+
let raw = "";
|
|
23
|
+
for await (const chunk of process.stdin)
|
|
24
|
+
raw += chunk;
|
|
25
|
+
let input;
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(raw);
|
|
28
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
29
|
+
throw new Error("not an object");
|
|
30
|
+
input = parsed;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
denyUnreadable(`OKed: the hook input could not be read. Pair first: run ${PAIR_COMMAND}`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const toolName = stringField(input, ["toolName", "tool_name"]);
|
|
37
|
+
if (!toolName) {
|
|
38
|
+
denyUnreadable(`OKed: the hook input had no tool name. Pair first: run ${PAIR_COMMAND}`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const rawArgs = input.toolArgs !== undefined ? input.toolArgs : (input.tool_input ?? input.toolInput);
|
|
42
|
+
const mapped = mapCopilotTool(toolName, rawArgs === undefined ? {} : asToolInput(rawArgs));
|
|
43
|
+
const session = stringField(input, ["sessionId", "session_id"]);
|
|
44
|
+
const decision = await decide({
|
|
45
|
+
toolName: mapped.toolName,
|
|
46
|
+
toolInput: mapped.toolInput,
|
|
47
|
+
cwd: typeof input.cwd === "string" ? input.cwd : undefined,
|
|
48
|
+
sessionId: session || undefined,
|
|
49
|
+
}, {
|
|
50
|
+
clientId: CLIENT_ID,
|
|
51
|
+
source: "copilot",
|
|
52
|
+
unpaired: "deny",
|
|
53
|
+
unpairedReason: UNPAIRED,
|
|
54
|
+
unpairedLog: `not paired - pair first: run ${PAIR_COMMAND}`,
|
|
55
|
+
invalidKeyReason,
|
|
56
|
+
});
|
|
57
|
+
writeDecision(decision);
|
|
58
|
+
}
|
|
59
|
+
main().catch((err) => {
|
|
60
|
+
const info = errorInfo(err);
|
|
61
|
+
const reason = `OKed: internal error (fail-safe): ${info.name}: ${info.message}`;
|
|
62
|
+
process.stderr.write(`[OKed] Fatal: ${err}\n`);
|
|
63
|
+
writeDecision({ decision: "deny", reason });
|
|
64
|
+
logDecision({ decision: "deny", reason, tool: "unknown", tier: null, client: CLIENT_ID, error: info });
|
|
65
|
+
process.exit(0);
|
|
66
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ClaudeHookHit } from "@oked/hook-core";
|
|
2
|
+
export declare const HOOK_COMMAND = "oked-copilot-hook";
|
|
3
|
+
export type InstallAction = "installed" | "updated" | "unchanged" | "skipped-claude-hook" | "unreadable";
|
|
4
|
+
export interface InstallResult {
|
|
5
|
+
action: InstallAction;
|
|
6
|
+
path: string;
|
|
7
|
+
claudeHooks: ClaudeHookHit[];
|
|
8
|
+
}
|
|
9
|
+
export declare function hooksPath(cwd: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Add the OKed preToolUse hook, or raise a short timeoutSec. A longer value
|
|
12
|
+
* is kept. The `timeout` alias is removed so it cannot disagree with
|
|
13
|
+
* timeoutSec. Other hooks stay.
|
|
14
|
+
*/
|
|
15
|
+
export declare function upsertCopilotHooks(doc: Record<string, unknown>): {
|
|
16
|
+
doc: Record<string, unknown>;
|
|
17
|
+
changed: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare function removeCopilotHooks(doc: Record<string, unknown>): {
|
|
20
|
+
doc: Record<string, unknown>;
|
|
21
|
+
changed: boolean;
|
|
22
|
+
};
|
|
23
|
+
export declare function copilotHookInstalled(cwd: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Install the project hook. Copilot CLI and VS Code read repository
|
|
26
|
+
* `.claude/settings.json` and `.claude/settings.local.json`, not the user
|
|
27
|
+
* file. A project `oked-hook` plus this file would ask twice, so init skips
|
|
28
|
+
* unless `native` is set. A hook that is already installed is updated in place.
|
|
29
|
+
*/
|
|
30
|
+
export declare function installCopilotHook(cwd: string, opts?: {
|
|
31
|
+
native?: boolean;
|
|
32
|
+
}): InstallResult;
|
|
33
|
+
export declare function uninstallCopilotHook(cwd: string): {
|
|
34
|
+
action: "removed" | "absent" | "unreadable";
|
|
35
|
+
path: string;
|
|
36
|
+
};
|
package/dist/install.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
|
|
2
|
+
import { dirname, join } from "path";
|
|
3
|
+
import { findClaudeOkedHooks, HOOK_TIMEOUT_SECONDS } from "@oked/hook-core";
|
|
4
|
+
export const HOOK_COMMAND = "oked-copilot-hook";
|
|
5
|
+
export function hooksPath(cwd) {
|
|
6
|
+
return join(cwd, ".github", "hooks", "oked.json");
|
|
7
|
+
}
|
|
8
|
+
const COMMAND_KEYS = ["command", "bash", "powershell", "exec"];
|
|
9
|
+
function commandOf(hook) {
|
|
10
|
+
for (const key of COMMAND_KEYS) {
|
|
11
|
+
if (typeof hook[key] === "string")
|
|
12
|
+
return hook[key];
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
function isOurs(hook) {
|
|
17
|
+
return !!hook && typeof hook === "object" && commandOf(hook) === HOOK_COMMAND;
|
|
18
|
+
}
|
|
19
|
+
function readDoc(path) {
|
|
20
|
+
if (!existsSync(path))
|
|
21
|
+
return { doc: {}, state: "absent" };
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
24
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
25
|
+
return { doc: {}, state: "unreadable" };
|
|
26
|
+
return { doc: parsed, state: "ok" };
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return { doc: {}, state: "unreadable" };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function preList(doc) {
|
|
33
|
+
const hooks = doc.hooks;
|
|
34
|
+
if (!hooks || typeof hooks !== "object")
|
|
35
|
+
return [];
|
|
36
|
+
const pre = hooks.preToolUse;
|
|
37
|
+
if (!Array.isArray(pre))
|
|
38
|
+
return [];
|
|
39
|
+
return pre.filter((hook) => hook && typeof hook === "object");
|
|
40
|
+
}
|
|
41
|
+
function documentHasOurs(doc) {
|
|
42
|
+
return preList(doc).some(isOurs);
|
|
43
|
+
}
|
|
44
|
+
function raiseTimeout(hook) {
|
|
45
|
+
const current = typeof hook.timeoutSec === "number" ? hook.timeoutSec : typeof hook.timeout === "number" ? hook.timeout : 0;
|
|
46
|
+
let changed = false;
|
|
47
|
+
if (current < HOOK_TIMEOUT_SECONDS) {
|
|
48
|
+
hook.timeoutSec = HOOK_TIMEOUT_SECONDS;
|
|
49
|
+
changed = true;
|
|
50
|
+
}
|
|
51
|
+
else if (typeof hook.timeoutSec !== "number") {
|
|
52
|
+
hook.timeoutSec = current;
|
|
53
|
+
changed = true;
|
|
54
|
+
}
|
|
55
|
+
// `timeout` is only an alias, and `timeoutSec` wins when both are set.
|
|
56
|
+
if (typeof hook.timeout === "number") {
|
|
57
|
+
delete hook.timeout;
|
|
58
|
+
changed = true;
|
|
59
|
+
}
|
|
60
|
+
return changed;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Add the OKed preToolUse hook, or raise a short timeoutSec. A longer value
|
|
64
|
+
* is kept. The `timeout` alias is removed so it cannot disagree with
|
|
65
|
+
* timeoutSec. Other hooks stay.
|
|
66
|
+
*/
|
|
67
|
+
export function upsertCopilotHooks(doc) {
|
|
68
|
+
const next = structuredClone(doc);
|
|
69
|
+
const hooks = (next.hooks && typeof next.hooks === "object" ? next.hooks : {});
|
|
70
|
+
const list = preList(next);
|
|
71
|
+
let changed = false;
|
|
72
|
+
let found = false;
|
|
73
|
+
for (const hook of list) {
|
|
74
|
+
if (!isOurs(hook))
|
|
75
|
+
continue;
|
|
76
|
+
found = true;
|
|
77
|
+
if (hook.type !== "command") {
|
|
78
|
+
hook.type = "command";
|
|
79
|
+
changed = true;
|
|
80
|
+
}
|
|
81
|
+
if (raiseTimeout(hook))
|
|
82
|
+
changed = true;
|
|
83
|
+
}
|
|
84
|
+
if (!found) {
|
|
85
|
+
list.push({ type: "command", command: HOOK_COMMAND, timeoutSec: HOOK_TIMEOUT_SECONDS });
|
|
86
|
+
changed = true;
|
|
87
|
+
}
|
|
88
|
+
if (next.version === undefined) {
|
|
89
|
+
next.version = 1;
|
|
90
|
+
changed = true;
|
|
91
|
+
}
|
|
92
|
+
if (!changed)
|
|
93
|
+
return { doc, changed: false };
|
|
94
|
+
hooks.preToolUse = list;
|
|
95
|
+
next.hooks = hooks;
|
|
96
|
+
return { doc: next, changed: true };
|
|
97
|
+
}
|
|
98
|
+
export function removeCopilotHooks(doc) {
|
|
99
|
+
const next = structuredClone(doc);
|
|
100
|
+
const hooks = next.hooks;
|
|
101
|
+
if (!hooks || typeof hooks !== "object" || !Array.isArray(hooks.preToolUse)) {
|
|
102
|
+
return { doc: next, changed: false };
|
|
103
|
+
}
|
|
104
|
+
const record = hooks;
|
|
105
|
+
const kept = record.preToolUse.filter((hook) => !isOurs(hook));
|
|
106
|
+
if (kept.length === record.preToolUse.length)
|
|
107
|
+
return { doc: next, changed: false };
|
|
108
|
+
if (kept.length > 0)
|
|
109
|
+
record.preToolUse = kept;
|
|
110
|
+
else
|
|
111
|
+
delete hooks.preToolUse;
|
|
112
|
+
if (Object.keys(hooks).length === 0)
|
|
113
|
+
delete next.hooks;
|
|
114
|
+
return { doc: next, changed: true };
|
|
115
|
+
}
|
|
116
|
+
function writeDoc(path, doc) {
|
|
117
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
118
|
+
writeFileSync(path, JSON.stringify(doc, null, 2) + "\n");
|
|
119
|
+
}
|
|
120
|
+
export function copilotHookInstalled(cwd) {
|
|
121
|
+
const { doc, state } = readDoc(hooksPath(cwd));
|
|
122
|
+
return state === "ok" && documentHasOurs(doc);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Install the project hook. Copilot CLI and VS Code read repository
|
|
126
|
+
* `.claude/settings.json` and `.claude/settings.local.json`, not the user
|
|
127
|
+
* file. A project `oked-hook` plus this file would ask twice, so init skips
|
|
128
|
+
* unless `native` is set. A hook that is already installed is updated in place.
|
|
129
|
+
*/
|
|
130
|
+
export function installCopilotHook(cwd, opts) {
|
|
131
|
+
const path = hooksPath(cwd);
|
|
132
|
+
const claudeHooks = findClaudeOkedHooks(cwd, { includeUser: false });
|
|
133
|
+
const { doc, state } = readDoc(path);
|
|
134
|
+
if (state === "unreadable")
|
|
135
|
+
return { action: "unreadable", path, claudeHooks };
|
|
136
|
+
const had = documentHasOurs(doc);
|
|
137
|
+
if (claudeHooks.length > 0 && !opts?.native && !had) {
|
|
138
|
+
return { action: "skipped-claude-hook", path, claudeHooks };
|
|
139
|
+
}
|
|
140
|
+
const next = upsertCopilotHooks(doc);
|
|
141
|
+
if (!next.changed)
|
|
142
|
+
return { action: "unchanged", path, claudeHooks };
|
|
143
|
+
writeDoc(path, next.doc);
|
|
144
|
+
return { action: had ? "updated" : "installed", path, claudeHooks };
|
|
145
|
+
}
|
|
146
|
+
export function uninstallCopilotHook(cwd) {
|
|
147
|
+
const path = hooksPath(cwd);
|
|
148
|
+
const { doc, state } = readDoc(path);
|
|
149
|
+
if (state === "absent")
|
|
150
|
+
return { action: "absent", path };
|
|
151
|
+
if (state === "unreadable")
|
|
152
|
+
return { action: "unreadable", path };
|
|
153
|
+
const next = removeCopilotHooks(doc);
|
|
154
|
+
if (!next.changed)
|
|
155
|
+
return { action: "absent", path };
|
|
156
|
+
const leftover = Object.keys(next.doc).filter((key) => key !== "version");
|
|
157
|
+
if (leftover.length === 0)
|
|
158
|
+
unlinkSync(path);
|
|
159
|
+
else
|
|
160
|
+
writeDoc(path, next.doc);
|
|
161
|
+
return { action: "removed", path };
|
|
162
|
+
}
|
package/dist/map.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface MappedCall {
|
|
2
|
+
toolName: string;
|
|
3
|
+
toolInput: Record<string, unknown>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Copilot MCP names are not listed in the hooks reference. `mcp__server__tool`
|
|
7
|
+
* and `MCP:server:tool` map straight across. A single `mcp_` prefix keeps the
|
|
8
|
+
* rest as the tool name, so `mcp_list_files` is a read and an unrecognized
|
|
9
|
+
* name still requires approval.
|
|
10
|
+
*/
|
|
11
|
+
export declare function toMcpToolName(name: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Map a Copilot preToolUse call onto a name and input `classify()` understands.
|
|
14
|
+
* Runtime names (`bash`, `create`) and Claude names from a PascalCase payload
|
|
15
|
+
* (`Bash`, `Write`) both work. Unknown tools stay unknown and require approval.
|
|
16
|
+
*/
|
|
17
|
+
export declare function mapCopilotTool(toolName: string, rawInput: unknown): MappedCall;
|
package/dist/map.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { asToolInput, mapPatch, stringField, withNormalizedFields } from "@oked/hook-core";
|
|
2
|
+
const RENAME = {
|
|
3
|
+
bash: "Bash",
|
|
4
|
+
powershell: "Bash",
|
|
5
|
+
view: "Read",
|
|
6
|
+
create: "Write",
|
|
7
|
+
edit: "Edit",
|
|
8
|
+
str_replace_editor: "Edit",
|
|
9
|
+
grep: "Grep",
|
|
10
|
+
rg: "Grep",
|
|
11
|
+
glob: "Glob",
|
|
12
|
+
web_fetch: "WebFetch",
|
|
13
|
+
web_search: "WebSearch",
|
|
14
|
+
ask_user: "AskUserQuestion",
|
|
15
|
+
update_todo: "TodoWrite",
|
|
16
|
+
task: "Agent",
|
|
17
|
+
Task: "Agent",
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Copilot MCP names are not listed in the hooks reference. `mcp__server__tool`
|
|
21
|
+
* and `MCP:server:tool` map straight across. A single `mcp_` prefix keeps the
|
|
22
|
+
* rest as the tool name, so `mcp_list_files` is a read and an unrecognized
|
|
23
|
+
* name still requires approval.
|
|
24
|
+
*/
|
|
25
|
+
export function toMcpToolName(name) {
|
|
26
|
+
if (name.startsWith("mcp__"))
|
|
27
|
+
return name;
|
|
28
|
+
if (/^(?:MCP|mcp):/.test(name)) {
|
|
29
|
+
const parts = name.replace(/^(?:MCP|mcp):/, "").split(":").filter(Boolean);
|
|
30
|
+
if (parts.length >= 2)
|
|
31
|
+
return `mcp__${parts[0]}__${parts.slice(1).join("__")}`;
|
|
32
|
+
return `mcp__mcp__${parts[0] || "tool"}`;
|
|
33
|
+
}
|
|
34
|
+
if (name.startsWith("mcp_"))
|
|
35
|
+
return `mcp__mcp__${name.slice(4)}`;
|
|
36
|
+
return name;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Map a Copilot preToolUse call onto a name and input `classify()` understands.
|
|
40
|
+
* Runtime names (`bash`, `create`) and Claude names from a PascalCase payload
|
|
41
|
+
* (`Bash`, `Write`) both work. Unknown tools stay unknown and require approval.
|
|
42
|
+
*/
|
|
43
|
+
export function mapCopilotTool(toolName, rawInput) {
|
|
44
|
+
const input = withNormalizedFields(asToolInput(rawInput));
|
|
45
|
+
if (toolName === "apply_patch" || toolName === "ApplyPatch") {
|
|
46
|
+
const patch = stringField(input, ["command", "patch", "input"]) ?? "";
|
|
47
|
+
return mapPatch(patch);
|
|
48
|
+
}
|
|
49
|
+
const renamed = RENAME[toolName];
|
|
50
|
+
if (renamed === "Bash" || toolName === "Bash" || toolName === "Shell") {
|
|
51
|
+
return { toolName: "Bash", toolInput: input };
|
|
52
|
+
}
|
|
53
|
+
if (renamed === "Write" || renamed === "Edit" || toolName === "Write" || toolName === "Edit") {
|
|
54
|
+
return { toolName: renamed === "Write" || renamed === "Edit" ? renamed : toolName, toolInput: input };
|
|
55
|
+
}
|
|
56
|
+
if (renamed)
|
|
57
|
+
return { toolName: renamed, toolInput: input };
|
|
58
|
+
if (/^(?:MCP|mcp):/.test(toolName) || toolName.startsWith("mcp__") || toolName.startsWith("mcp_")) {
|
|
59
|
+
return { toolName: toMcpToolName(toolName), toolInput: input };
|
|
60
|
+
}
|
|
61
|
+
const server = stringField(input, ["server", "serverName", "mcp_server"]);
|
|
62
|
+
const tool = stringField(input, ["tool", "name"]);
|
|
63
|
+
if ((toolName === "mcp" || toolName === "MCP") && server && tool) {
|
|
64
|
+
return { toolName: `mcp__${server}__${tool}`, toolInput: input };
|
|
65
|
+
}
|
|
66
|
+
return { toolName, toolInput: input };
|
|
67
|
+
}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GateDecision } from "@oked/hook-core";
|
|
2
|
+
/**
|
|
3
|
+
* Copilot reads a top-level `permissionDecision`. Empty output uses the
|
|
4
|
+
* host's normal permission flow, which can still prompt, so an allow is
|
|
5
|
+
* explicit. `ask` becomes deny in cloud agent and in CLI autopilot, so a
|
|
6
|
+
* non-allow is deny here too.
|
|
7
|
+
*/
|
|
8
|
+
export declare function writeDecision(decision: GateDecision): void;
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copilot reads a top-level `permissionDecision`. Empty output uses the
|
|
3
|
+
* host's normal permission flow, which can still prompt, so an allow is
|
|
4
|
+
* explicit. `ask` becomes deny in cloud agent and in CLI autopilot, so a
|
|
5
|
+
* non-allow is deny here too.
|
|
6
|
+
*/
|
|
7
|
+
export function writeDecision(decision) {
|
|
8
|
+
const permissionDecision = decision.decision === "allow" ? "allow" : "deny";
|
|
9
|
+
const out = { permissionDecision };
|
|
10
|
+
if (decision.reason)
|
|
11
|
+
out.permissionDecisionReason = decision.reason;
|
|
12
|
+
else if (permissionDecision === "deny")
|
|
13
|
+
out.permissionDecisionReason = "OKed denied this action.";
|
|
14
|
+
process.stdout.write(JSON.stringify(out));
|
|
15
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { dirname, join } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
export const CLIENT_VERSION = (() => {
|
|
5
|
+
try {
|
|
6
|
+
const pkgPath = join(dirname(fileURLToPath(import.meta.url)), "..", "package.json");
|
|
7
|
+
return JSON.parse(readFileSync(pkgPath, "utf-8")).version ?? "0.0.0";
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return "0.0.0";
|
|
11
|
+
}
|
|
12
|
+
})();
|
|
13
|
+
export const CLIENT_ID = `@oked/copilot@${CLIENT_VERSION}`;
|
|
14
|
+
export const PAIR_COMMAND = "oked-copilot init";
|
|
15
|
+
export const UNINSTALL_COMMAND = "oked-copilot uninstall";
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oked/copilot",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.6.23",
|
|
4
|
+
"description": "OKed for GitHub Copilot CLI and VS Code. A preToolUse hook that holds risky agent tool calls for a human decision.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"oked-copilot": "./bin/oked-copilot.js",
|
|
8
|
+
"oked-copilot-hook": "./bin/oked-copilot-hook.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"prebuild": "npm run build --workspace=@oked/hook-core",
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"test": "npm run build && node src/map.test.mjs && node src/install.test.mjs && node src/hook.test.mjs && node src/fixture.test.mjs",
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"bin",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"oked",
|
|
24
|
+
"copilot",
|
|
25
|
+
"github-copilot",
|
|
26
|
+
"ai-agent",
|
|
27
|
+
"approval",
|
|
28
|
+
"human-in-the-loop",
|
|
29
|
+
"hooks",
|
|
30
|
+
"vscode"
|
|
31
|
+
],
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/oked-ai/oked-sdk.git",
|
|
35
|
+
"directory": "packages/copilot"
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/oked-ai/oked-sdk/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://oked.ai",
|
|
41
|
+
"license": "Apache-2.0",
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@oked/hook-core": "0.6.23",
|
|
50
|
+
"@oked/sdk": "0.6.23"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^26.6.5",
|
|
54
|
+
"typescript": "^7.0.2"
|
|
55
|
+
}
|
|
56
|
+
}
|