pendingyou 0.0.0-stage → 0.1.0
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 +204 -0
- package/README.md +63 -2
- package/dist/api.js +111 -0
- package/dist/args.js +168 -0
- package/dist/claude.js +311 -0
- package/dist/cli.js +8 -0
- package/dist/credentials.js +59 -0
- package/dist/errors.js +4 -0
- package/dist/files.js +93 -0
- package/dist/format.js +71 -0
- package/dist/hold.js +105 -0
- package/dist/index.js +7 -0
- package/dist/io.js +103 -0
- package/dist/main.js +159 -0
- package/dist/oauth.js +235 -0
- package/dist/pickup.js +74 -0
- package/dist/state.js +69 -0
- package/dist/version.js +2 -0
- package/package.json +24 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Copyright 2026 RecordPlane
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Apache License
|
|
5
|
+
Version 2.0, January 2004
|
|
6
|
+
http://www.apache.org/licenses/
|
|
7
|
+
|
|
8
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
9
|
+
|
|
10
|
+
1. Definitions.
|
|
11
|
+
|
|
12
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
13
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
14
|
+
|
|
15
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
16
|
+
the copyright owner that is granting the License.
|
|
17
|
+
|
|
18
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
19
|
+
other entities that control, are controlled by, or are under common
|
|
20
|
+
control with that entity. For the purposes of this definition,
|
|
21
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
22
|
+
direction or management of such entity, whether by contract or
|
|
23
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
24
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
25
|
+
|
|
26
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
27
|
+
exercising permissions granted by this License.
|
|
28
|
+
|
|
29
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
30
|
+
including but not limited to software source code, documentation
|
|
31
|
+
source, and configuration files.
|
|
32
|
+
|
|
33
|
+
"Object" form shall mean any form resulting from mechanical
|
|
34
|
+
transformation or translation of a Source form, including but
|
|
35
|
+
not limited to compiled object code, generated documentation,
|
|
36
|
+
and conversions to other media types.
|
|
37
|
+
|
|
38
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
39
|
+
Object form, made available under the License, as indicated by a
|
|
40
|
+
copyright notice that is included in or attached to the work
|
|
41
|
+
(an example is provided in the Appendix below).
|
|
42
|
+
|
|
43
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
44
|
+
form, that is based on (or derived from) the Work and for which the
|
|
45
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
46
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
47
|
+
of this License, Derivative Works shall not include works that remain
|
|
48
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
49
|
+
the Work and Derivative Works thereof.
|
|
50
|
+
|
|
51
|
+
"Contribution" shall mean any work of authorship, including
|
|
52
|
+
the original version of the Work and any modifications or additions
|
|
53
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
54
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
55
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
56
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
57
|
+
means any form of electronic, verbal, or written communication sent
|
|
58
|
+
to the Licensor or its representatives, including but not limited to
|
|
59
|
+
communication on electronic mailing lists, source code control systems,
|
|
60
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
61
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
62
|
+
excluding communication that is conspicuously marked or otherwise
|
|
63
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
64
|
+
|
|
65
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
66
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
67
|
+
subsequently incorporated within the Work.
|
|
68
|
+
|
|
69
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
70
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
71
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
72
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
73
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
74
|
+
Work and such Derivative Works in Source or Object form.
|
|
75
|
+
|
|
76
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
77
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
78
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
79
|
+
(except as stated in this section) patent license to make, have made,
|
|
80
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
81
|
+
where such license applies only to those patent claims licensable
|
|
82
|
+
by such Contributor that are necessarily infringed by their
|
|
83
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
84
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
85
|
+
institute patent litigation against any entity (including a
|
|
86
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
87
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
88
|
+
or contributory patent infringement, then any patent licenses
|
|
89
|
+
granted to You under this License for that Work shall terminate
|
|
90
|
+
as of the date such litigation is filed.
|
|
91
|
+
|
|
92
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
93
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
94
|
+
modifications, and in Source or Object form, provided that You
|
|
95
|
+
meet the following conditions:
|
|
96
|
+
|
|
97
|
+
(a) You must give any other recipients of the Work or
|
|
98
|
+
Derivative Works a copy of this License; and
|
|
99
|
+
|
|
100
|
+
(b) You must cause any modified files to carry prominent notices
|
|
101
|
+
stating that You changed the files; and
|
|
102
|
+
|
|
103
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
104
|
+
that You distribute, all copyright, patent, trademark, and
|
|
105
|
+
attribution notices from the Source form of the Work,
|
|
106
|
+
excluding those notices that do not pertain to any part of
|
|
107
|
+
the Derivative Works; and
|
|
108
|
+
|
|
109
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
110
|
+
distribution, then any Derivative Works that You distribute must
|
|
111
|
+
include a readable copy of the attribution notices contained
|
|
112
|
+
within such NOTICE file, excluding those notices that do not
|
|
113
|
+
pertain to any part of the Derivative Works, in at least one
|
|
114
|
+
of the following places: within a NOTICE text file distributed
|
|
115
|
+
as part of the Derivative Works; within the Source form or
|
|
116
|
+
documentation, if provided along with the Derivative Works; or,
|
|
117
|
+
within a display generated by the Derivative Works, if and
|
|
118
|
+
wherever such third-party notices normally appear. The contents
|
|
119
|
+
of the NOTICE file are for informational purposes only and
|
|
120
|
+
do not modify the License. You may add Your own attribution
|
|
121
|
+
notices within Derivative Works that You distribute, alongside
|
|
122
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
123
|
+
that such additional attribution notices cannot be construed
|
|
124
|
+
as modifying the License.
|
|
125
|
+
|
|
126
|
+
You may add Your own copyright statement to Your modifications and
|
|
127
|
+
may provide additional or different license terms and conditions
|
|
128
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
129
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
130
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
131
|
+
the conditions stated in this License.
|
|
132
|
+
|
|
133
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
134
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
135
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
136
|
+
this License, without any additional terms or conditions.
|
|
137
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
138
|
+
the terms of any separate license agreement you may have executed
|
|
139
|
+
with Licensor regarding such Contributions.
|
|
140
|
+
|
|
141
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
142
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
143
|
+
except as required for reasonable and customary use in describing the
|
|
144
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
145
|
+
|
|
146
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
147
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
148
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
149
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
150
|
+
implied, including, without limitation, any warranties or conditions
|
|
151
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
152
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
153
|
+
appropriateness of using or redistributing the Work and assume any
|
|
154
|
+
risks associated with Your exercise of permissions under this License.
|
|
155
|
+
|
|
156
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
157
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
158
|
+
unless required by applicable law (such as deliberate and grossly
|
|
159
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
160
|
+
liable to You for damages, including any direct, indirect, special,
|
|
161
|
+
incidental, or consequential damages of any character arising as a
|
|
162
|
+
result of this License or out of the use or inability to use the
|
|
163
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
164
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
165
|
+
other commercial damages or losses), even if such Contributor
|
|
166
|
+
has been advised of the possibility of such damages.
|
|
167
|
+
|
|
168
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
169
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
170
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
171
|
+
or other liability obligations and/or rights consistent with this
|
|
172
|
+
License. However, in accepting such obligations, You may act only
|
|
173
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
174
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
175
|
+
defend, and hold each Contributor harmless for any liability
|
|
176
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
177
|
+
of your accepting any such warranty or additional liability.
|
|
178
|
+
|
|
179
|
+
END OF TERMS AND CONDITIONS
|
|
180
|
+
|
|
181
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
182
|
+
|
|
183
|
+
To apply the Apache License to your work, attach the following
|
|
184
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
185
|
+
replaced with your own identifying information. (Don't include
|
|
186
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
187
|
+
comment syntax for the file format. We also recommend that a
|
|
188
|
+
file or class name and description of purpose be included on the
|
|
189
|
+
same "printed page" as the copyright notice for easier
|
|
190
|
+
identification within third-party archives.
|
|
191
|
+
|
|
192
|
+
Copyright [yyyy] [name of copyright owner]
|
|
193
|
+
|
|
194
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
195
|
+
you may not use this file except in compliance with the License.
|
|
196
|
+
You may obtain a copy of the License at
|
|
197
|
+
|
|
198
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
199
|
+
|
|
200
|
+
Unless required by applicable law or agreed to in writing, software
|
|
201
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
202
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
203
|
+
See the License for the specific language governing permissions and
|
|
204
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pendingyou
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Pending You for Claude Code. Your assistants ask you in [Pending You](https://www.pendingyou.com) when you're away;
|
|
4
|
+
this command lets Claude Code hear your answer the moment it's ready, even while it sits idle at the prompt.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npx pendingyou init
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Run it once on each computer. It:
|
|
11
|
+
|
|
12
|
+
- adds the Pending You MCP server to Claude Code for every project (unless it's already there),
|
|
13
|
+
- saves the Pending You skill to `~/.claude/skills/pendingyou/SKILL.md`,
|
|
14
|
+
- signs this computer in (your browser opens once; press Allow),
|
|
15
|
+
- adds two hooks to `~/.claude/settings.json`: a new session picks up answers that arrived while nothing was running,
|
|
16
|
+
and your next message brings a waiting answer with it,
|
|
17
|
+
- lets Claude Code start `npx pendingyou hold` and use Pending You's tools without a permission prompt, so a question
|
|
18
|
+
it asks while you're away doesn't wait on one.
|
|
19
|
+
|
|
20
|
+
Your other settings are kept as they are. `npx pendingyou uninstall` removes exactly what `init` added.
|
|
21
|
+
|
|
22
|
+
## How Claude Code uses it
|
|
23
|
+
|
|
24
|
+
After it posts a question to Pending You, Claude Code runs this in the background and keeps working:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npx pendingyou hold req_0123456789abcdef0123
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
When you answer (after the 5-second window to undo), write back, or the question's fallback comes due, it prints a few
|
|
31
|
+
lines (the question, your answer, the next step) and exits. Claude Code wakes up with them. It stops on its own after
|
|
32
|
+
4 hours (`--timeout`), telling Claude Code the hooks will bring the answer later.
|
|
33
|
+
|
|
34
|
+
When you're at the terminal, Claude Code asks you there and puts the same question in Pending You at once; the
|
|
35
|
+
first answer wins. If you answer in the terminal, it withdraws the card and the hold ends by itself.
|
|
36
|
+
|
|
37
|
+
## Commands
|
|
38
|
+
|
|
39
|
+
| Command | What it does |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `init` | Set up Claude Code on this computer (`--no-login`, `--no-browser`) |
|
|
42
|
+
| `hold <requestId>` | Wait for the answer, print it, exit (`--timeout 4h`) |
|
|
43
|
+
| `status` | What's set up; exits 0 when Claude Code hears answers right away |
|
|
44
|
+
| `login` / `logout` | Sign this computer in or out (`--force`, `--all`) |
|
|
45
|
+
| `pickup` / `handoff` | The session-start and next-message hooks |
|
|
46
|
+
| `uninstall` | Remove what `init` added, and sign out |
|
|
47
|
+
|
|
48
|
+
Every command takes `--origin` (default `https://www.pendingyou.com`, or `$PENDINGYOU_ORIGIN`).
|
|
49
|
+
|
|
50
|
+
## What it can see, and where it keeps things
|
|
51
|
+
|
|
52
|
+
The sign-in only hears answers to your own Claude Code assistants' questions. It isn't an assistant: it can't ask,
|
|
53
|
+
answer or change anything, and it doesn't show up as one. It's stored in `~/.config/pendingyou/credentials.json`
|
|
54
|
+
(readable only by you), refreshes itself, and ends after 30 days or on `logout`. `state.json` beside it remembers
|
|
55
|
+
which answers were already handed over (ids only). Nothing is sent anywhere but Pending You.
|
|
56
|
+
|
|
57
|
+
## Development
|
|
58
|
+
|
|
59
|
+
In the Pending You repo: `pnpm --filter pendingyou test`, `pnpm --filter pendingyou build` (to `dist/`). Try it with a
|
|
60
|
+
throwaway home: `HOME=$(mktemp -d) node dist/cli.js status --origin http://localhost:5202`.
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
Apache-2.0. Copyright 2026 RecordPlane. See [LICENSE](LICENSE).
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Calls to Pending You with the command line's sign-in: a fresh access token (refreshed under the credentials lock,
|
|
2
|
+
// so a hold and a hook never spend the same refresh token), one retry after a 401, and plain errors.
|
|
3
|
+
import { readCredential, updateCredential } from "./credentials.js";
|
|
4
|
+
import { OAuthError, refresh } from "./oauth.js";
|
|
5
|
+
/** Refresh this long before the access token runs out. */
|
|
6
|
+
const EARLY_MS = 60_000;
|
|
7
|
+
/** Not signed in on this computer (for this origin), or the sign-in ended: the person runs `pendingyou login`. */
|
|
8
|
+
export class SignInNeeded extends Error {
|
|
9
|
+
name = 'SignInNeeded';
|
|
10
|
+
ended;
|
|
11
|
+
constructor(ended) {
|
|
12
|
+
super(ended ? 'The sign-in has ended.' : 'Not signed in.');
|
|
13
|
+
this.ended = ended;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Pending You couldn't be reached, or had a problem: worth trying again later. */
|
|
17
|
+
export class Unavailable extends Error {
|
|
18
|
+
name = 'Unavailable';
|
|
19
|
+
/** Seconds the server asked to wait, when it said. */
|
|
20
|
+
retryAfter;
|
|
21
|
+
constructor(message, retryAfter) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.retryAfter = retryAfter;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function freshToken(io, origin, force) {
|
|
27
|
+
const stored = await readCredential(io, origin);
|
|
28
|
+
if (!stored)
|
|
29
|
+
throw new SignInNeeded(false);
|
|
30
|
+
if (!force && stored.expiresAt - EARLY_MS > io.now())
|
|
31
|
+
return stored.accessToken;
|
|
32
|
+
let ended = false;
|
|
33
|
+
const updated = await updateCredential(io, origin, async (current) => {
|
|
34
|
+
if (!current)
|
|
35
|
+
return null;
|
|
36
|
+
// Another process may have refreshed while this one waited for the lock.
|
|
37
|
+
if (current.refreshToken !== stored.refreshToken && current.expiresAt - EARLY_MS > io.now())
|
|
38
|
+
return current;
|
|
39
|
+
try {
|
|
40
|
+
const tokens = await refresh(io, origin, current.clientId, current.refreshToken);
|
|
41
|
+
return { ...current, ...tokens };
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error instanceof OAuthError &&
|
|
45
|
+
(error.code === 'invalid_grant' || error.code === 'invalid_client')) {
|
|
46
|
+
ended = true;
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (!updated)
|
|
53
|
+
throw new SignInNeeded(ended);
|
|
54
|
+
return updated.accessToken;
|
|
55
|
+
}
|
|
56
|
+
/** Aborts on `signal` or after `ms`, whichever comes first (AbortSignal.any needs Node 20.3). */
|
|
57
|
+
function either(signal, ms) {
|
|
58
|
+
const timeout = AbortSignal.timeout(ms);
|
|
59
|
+
if (!signal)
|
|
60
|
+
return timeout;
|
|
61
|
+
const controller = new AbortController();
|
|
62
|
+
const abort = () => controller.abort();
|
|
63
|
+
if (signal.aborted)
|
|
64
|
+
abort();
|
|
65
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
66
|
+
timeout.addEventListener('abort', abort, { once: true });
|
|
67
|
+
return controller.signal;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* GETs `path` on `origin` as the command line, and returns the JSON body with its status. 401 after a refresh means
|
|
71
|
+
* the sign-in is over (revoked, or 30 days passed). Network failures and 5xx are `Unavailable`.
|
|
72
|
+
*/
|
|
73
|
+
export async function getJson(io, origin, path, timeoutMs, signal) {
|
|
74
|
+
for (let attempt = 0;; attempt++) {
|
|
75
|
+
let token;
|
|
76
|
+
try {
|
|
77
|
+
token = await freshToken(io, origin, attempt > 0);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error instanceof SignInNeeded)
|
|
81
|
+
throw error;
|
|
82
|
+
throw new Unavailable('Pending You couldn’t be reached to refresh the sign-in.');
|
|
83
|
+
}
|
|
84
|
+
let response;
|
|
85
|
+
try {
|
|
86
|
+
response = await io.fetch(`${origin}${path}`, {
|
|
87
|
+
headers: { authorization: `Bearer ${token}`, accept: 'application/json' },
|
|
88
|
+
signal: either(signal, timeoutMs),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (signal?.aborted)
|
|
93
|
+
throw error;
|
|
94
|
+
throw new Unavailable('Pending You couldn’t be reached.');
|
|
95
|
+
}
|
|
96
|
+
if (response.status === 401) {
|
|
97
|
+
await response.body?.cancel();
|
|
98
|
+
if (attempt === 0)
|
|
99
|
+
continue;
|
|
100
|
+
await updateCredential(io, origin, () => null);
|
|
101
|
+
throw new SignInNeeded(true);
|
|
102
|
+
}
|
|
103
|
+
if (response.status >= 500 || response.status === 429) {
|
|
104
|
+
await response.body?.cancel();
|
|
105
|
+
const retry = Number(response.headers.get('retry-after'));
|
|
106
|
+
throw new Unavailable(`Pending You had a problem (${response.status}).`, Number.isFinite(retry) && retry > 0 ? retry : undefined);
|
|
107
|
+
}
|
|
108
|
+
const body = (await response.json().catch(() => ({})));
|
|
109
|
+
return { status: response.status, body };
|
|
110
|
+
}
|
|
111
|
+
}
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// The command line's arguments: one command, then its flags. No dependencies, no surprises: an unknown flag or a
|
|
2
|
+
// stray argument is an error, never ignored.
|
|
3
|
+
export const DEFAULT_ORIGIN = 'https://www.pendingyou.com';
|
|
4
|
+
/** How long `hold` waits for an answer before it lets go (4 hours). */
|
|
5
|
+
export const DEFAULT_TIMEOUT_MS = 4 * 60 * 60 * 1000;
|
|
6
|
+
const MAX_TIMEOUT_MS = 24 * 60 * 60 * 1000;
|
|
7
|
+
export class UsageError extends Error {
|
|
8
|
+
name = 'UsageError';
|
|
9
|
+
}
|
|
10
|
+
const REQUEST_ID = /^req_[A-Za-z0-9-]{1,40}$/;
|
|
11
|
+
/**
|
|
12
|
+
* A duration: `90s`, `3m`, `4h`, or a bare number of minutes.
|
|
13
|
+
*/
|
|
14
|
+
export function parseDuration(text) {
|
|
15
|
+
const match = /^(\d+(?:\.\d+)?)(s|m|h)?$/.exec(text.trim());
|
|
16
|
+
if (!match)
|
|
17
|
+
throw new UsageError(`“${text}” isn’t a duration. Use 90s, 3m or 4h.`);
|
|
18
|
+
const amount = Number(match[1]);
|
|
19
|
+
const unit = match[2] ?? 'm';
|
|
20
|
+
return Math.round(amount * (unit === 's' ? 1000 : unit === 'm' ? 60_000 : 3_600_000));
|
|
21
|
+
}
|
|
22
|
+
/** An origin Pending You can live at: https, or http on this computer (the local dev server). */
|
|
23
|
+
export function parseOrigin(text) {
|
|
24
|
+
let url;
|
|
25
|
+
try {
|
|
26
|
+
url = new URL(text);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw new UsageError(`“${text}” isn’t an address. Use one like ${DEFAULT_ORIGIN}.`);
|
|
30
|
+
}
|
|
31
|
+
const local = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
32
|
+
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && local))
|
|
33
|
+
throw new UsageError('Pending You’s address must start with https://.');
|
|
34
|
+
if (url.username || url.password)
|
|
35
|
+
throw new UsageError('The address can’t hold a user name.');
|
|
36
|
+
return url.origin;
|
|
37
|
+
}
|
|
38
|
+
const COMMANDS = new Set([
|
|
39
|
+
'help',
|
|
40
|
+
'version',
|
|
41
|
+
'login',
|
|
42
|
+
'logout',
|
|
43
|
+
'status',
|
|
44
|
+
'hold',
|
|
45
|
+
'pickup',
|
|
46
|
+
'handoff',
|
|
47
|
+
'init',
|
|
48
|
+
'uninstall',
|
|
49
|
+
]);
|
|
50
|
+
/** Flags each command takes; `true` when the flag takes a value. */
|
|
51
|
+
const FLAGS = {
|
|
52
|
+
help: {},
|
|
53
|
+
version: {},
|
|
54
|
+
login: { origin: true, 'no-browser': false, force: false },
|
|
55
|
+
logout: { origin: true, all: false },
|
|
56
|
+
status: { origin: true },
|
|
57
|
+
hold: { origin: true, timeout: true },
|
|
58
|
+
pickup: { origin: true },
|
|
59
|
+
handoff: { origin: true },
|
|
60
|
+
init: { origin: true, 'no-login': false, 'no-browser': false },
|
|
61
|
+
uninstall: { origin: true },
|
|
62
|
+
};
|
|
63
|
+
export function parseArgs(argv, env = {}) {
|
|
64
|
+
const [first, ...rest] = argv;
|
|
65
|
+
if (first === undefined || first === '-h' || first === '--help')
|
|
66
|
+
return { name: 'help' };
|
|
67
|
+
if (first === '-v' || first === '--version')
|
|
68
|
+
return { name: 'version' };
|
|
69
|
+
if (!COMMANDS.has(first))
|
|
70
|
+
throw new UsageError(`There’s no “${first}” command.`);
|
|
71
|
+
const allowed = FLAGS[first] ?? {};
|
|
72
|
+
const flags = new Map();
|
|
73
|
+
const positional = [];
|
|
74
|
+
for (let index = 0; index < rest.length; index++) {
|
|
75
|
+
const arg = rest[index];
|
|
76
|
+
if (arg === '-h' || arg === '--help')
|
|
77
|
+
return { name: 'help' };
|
|
78
|
+
if (!arg.startsWith('--')) {
|
|
79
|
+
positional.push(arg);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const [key, inline] = arg.slice(2).split(/=(.*)/s, 2);
|
|
83
|
+
if (!(key in allowed))
|
|
84
|
+
throw new UsageError(`${first} has no --${key} option.`);
|
|
85
|
+
if (flags.has(key))
|
|
86
|
+
throw new UsageError(`--${key} is given twice.`);
|
|
87
|
+
if (allowed[key]) {
|
|
88
|
+
const value = inline ?? rest[++index];
|
|
89
|
+
if (value === undefined || value === '')
|
|
90
|
+
throw new UsageError(`--${key} needs a value.`);
|
|
91
|
+
flags.set(key, value);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
if (inline !== undefined)
|
|
95
|
+
throw new UsageError(`--${key} takes no value.`);
|
|
96
|
+
flags.set(key, true);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const text = (key) => {
|
|
100
|
+
const value = flags.get(key);
|
|
101
|
+
return typeof value === 'string' ? value : undefined;
|
|
102
|
+
};
|
|
103
|
+
const origin = parseOrigin(text('origin') ?? env.PENDINGYOU_ORIGIN ?? DEFAULT_ORIGIN);
|
|
104
|
+
const none = () => {
|
|
105
|
+
if (positional.length)
|
|
106
|
+
throw new UsageError(`${first} takes no “${positional[0]}”.`);
|
|
107
|
+
};
|
|
108
|
+
switch (first) {
|
|
109
|
+
case 'help':
|
|
110
|
+
return { name: 'help' };
|
|
111
|
+
case 'version':
|
|
112
|
+
return { name: 'version' };
|
|
113
|
+
case 'login':
|
|
114
|
+
none();
|
|
115
|
+
return { name: 'login', origin, browser: !flags.has('no-browser'), force: flags.has('force') };
|
|
116
|
+
case 'logout':
|
|
117
|
+
none();
|
|
118
|
+
return { name: 'logout', origin, all: flags.has('all') };
|
|
119
|
+
case 'status':
|
|
120
|
+
none();
|
|
121
|
+
return { name: 'status', origin };
|
|
122
|
+
case 'pickup':
|
|
123
|
+
none();
|
|
124
|
+
return { name: 'pickup', origin };
|
|
125
|
+
case 'handoff':
|
|
126
|
+
none();
|
|
127
|
+
return { name: 'handoff', origin };
|
|
128
|
+
case 'uninstall':
|
|
129
|
+
none();
|
|
130
|
+
return { name: 'uninstall', origin };
|
|
131
|
+
case 'init':
|
|
132
|
+
none();
|
|
133
|
+
return {
|
|
134
|
+
name: 'init',
|
|
135
|
+
origin,
|
|
136
|
+
login: !flags.has('no-login'),
|
|
137
|
+
browser: !flags.has('no-browser'),
|
|
138
|
+
};
|
|
139
|
+
case 'hold': {
|
|
140
|
+
if (positional.length !== 1)
|
|
141
|
+
throw new UsageError('hold needs one request id, like: pendingyou hold req_0123…');
|
|
142
|
+
const requestId = positional[0];
|
|
143
|
+
if (!REQUEST_ID.test(requestId))
|
|
144
|
+
throw new UsageError(`“${requestId}” isn’t a request id (they start with req_).`);
|
|
145
|
+
const timeout = text('timeout');
|
|
146
|
+
const timeoutMs = timeout === undefined ? DEFAULT_TIMEOUT_MS : parseDuration(timeout);
|
|
147
|
+
if (timeoutMs < 1000 || timeoutMs > MAX_TIMEOUT_MS)
|
|
148
|
+
throw new UsageError('--timeout must be between 1 second and 24 hours.');
|
|
149
|
+
return { name: 'hold', origin, requestId, timeoutMs };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
throw new UsageError(`There’s no “${first}” command.`);
|
|
153
|
+
}
|
|
154
|
+
export const USAGE = `pendingyou: Pending You for Claude Code
|
|
155
|
+
|
|
156
|
+
npx pendingyou init Set up Claude Code on this computer: the MCP server, the skill,
|
|
157
|
+
this command's sign-in, and two hooks that hand answers over
|
|
158
|
+
npx pendingyou hold <req_…> Wait in the background until the answer to a request is ready,
|
|
159
|
+
print it, and exit (which wakes Claude Code)
|
|
160
|
+
npx pendingyou status What's set up, and whether Claude Code hears answers right away
|
|
161
|
+
npx pendingyou login | logout
|
|
162
|
+
npx pendingyou uninstall Remove exactly what init added
|
|
163
|
+
npx pendingyou pickup Answers waiting for this folder (the session-start hook)
|
|
164
|
+
npx pendingyou handoff The same, only while a hold is outstanding (the next-message hook)
|
|
165
|
+
|
|
166
|
+
Options: --origin <url> (default ${DEFAULT_ORIGIN}), --timeout 4h (hold), --no-browser (login, init),
|
|
167
|
+
--no-login (init), --all (logout), --force (login).
|
|
168
|
+
`;
|