physicalvalidation 0.3.0 → 0.4.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/README.md +52 -103
- package/dist/cli.js +72 -47
- package/package.json +3 -7
package/README.md
CHANGED
|
@@ -1,148 +1,97 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Physical Validation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Describe an experiment, review a draft, and send a request to [Physical Validation](https://physicalvalidation.com). Halmos reviews submitted requests before contacting laboratories.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Requires Node.js 18 or newer. Run:
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
```bash
|
|
7
|
+
```sh
|
|
10
8
|
npx physicalvalidation
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## Install and usage
|
|
11
|
+
After the opening animation, answer **What would you like to test?** Press Enter to receive a browser review link. Review your specifications there before submitting. Creating a draft does not place an order. Press Enter on an empty prompt to leave.
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
For a persistent installation, run `npm install --global physicalvalidation`. You can also start with `bunx physicalvalidation` or `pnpm dlx physicalvalidation`.
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
npx physicalvalidation search "peptide bioanalysis" --country US
|
|
21
|
-
npx physicalvalidation company <id> --json
|
|
22
|
-
npx physicalvalidation services
|
|
23
|
-
npx physicalvalidation "GLP bioanalysis for a peptide, US site"
|
|
24
|
-
bunx physicalvalidation "Stability study for an mRNA-LNP, EU site"
|
|
25
|
-
pnpm dlx physicalvalidation "Peptide characterization, GMP, US"
|
|
26
|
-
```
|
|
15
|
+
## Prepare an experiment
|
|
27
16
|
|
|
28
|
-
|
|
17
|
+
Use the guided interview to add missing details or continue from a previous review link:
|
|
29
18
|
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
npm run build
|
|
33
|
-
node dist/cli.js search "peptide bioanalysis" --limit 5
|
|
19
|
+
```sh
|
|
20
|
+
npx physicalvalidation draft "Characterize a synthetic peptide for purity and identity"
|
|
34
21
|
```
|
|
35
22
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Catalogue reads need no account. `--json` prints the API document. Commercial fields are left out of that printout.
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
npx physicalvalidation search "analytical development" --country US --quality GLP
|
|
42
|
-
npx physicalvalidation search --service "Peptide synthesis" --facets
|
|
43
|
-
npx physicalvalidation company listed:org_example
|
|
44
|
-
npx physicalvalidation site <id> --json
|
|
45
|
-
npx physicalvalidation services
|
|
46
|
-
npx physicalvalidation techniques
|
|
47
|
-
npx physicalvalidation countries
|
|
48
|
-
```
|
|
23
|
+
Answer each question, press Enter to leave a detail for later, or type `/done` to receive the updated review link. Preserve that complete link to continue editing. Drafting needs no account.
|
|
49
24
|
|
|
50
|
-
|
|
25
|
+
## Find a laboratory
|
|
51
26
|
|
|
52
|
-
|
|
27
|
+
Search the public catalogue without signing in:
|
|
53
28
|
|
|
54
|
-
```
|
|
55
|
-
npx physicalvalidation
|
|
29
|
+
```sh
|
|
30
|
+
npx physicalvalidation search "peptide bioanalysis" --country US --limit 5
|
|
31
|
+
npx physicalvalidation search "peptide bioanalysis" --json
|
|
32
|
+
npx physicalvalidation services
|
|
56
33
|
```
|
|
57
34
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
## Sending a request
|
|
61
|
-
|
|
62
|
-
On a terminal the command shows the request, asks for an email, then beams it:
|
|
35
|
+
Read a result with `company <id>` or `site <id>`. Use IDs returned by search. `services`, `techniques`, and `countries` list filter values. Pass `--cursor` with `next_cursor` from a JSON search result to read another page.
|
|
63
36
|
|
|
64
|
-
|
|
65
|
-
┌ Physical Validation
|
|
66
|
-
│
|
|
67
|
-
│ GLP bioanalysis for a peptide, US site.
|
|
68
|
-
│
|
|
69
|
-
email: ada@lab.example
|
|
70
|
-
Beaming your request to Physical Validation...
|
|
71
|
-
Code sent.
|
|
72
|
-
code: 123456
|
|
37
|
+
## Send a request
|
|
73
38
|
|
|
74
|
-
|
|
39
|
+
```sh
|
|
40
|
+
npx physicalvalidation "GLP bioanalysis for a peptide, US site"
|
|
75
41
|
```
|
|
76
42
|
|
|
77
|
-
The
|
|
43
|
+
The terminal shows your brief and asks for your email. Enter the six-digit code sent to that address to confirm the request. A person at Physical Validation reviews it; providers are not contacted automatically. The verified email provides access to your request. You have up to five code attempts, and Ctrl-C leaves a pending request you can resume.
|
|
78
44
|
|
|
79
|
-
|
|
45
|
+
The CLI accepts request text from 1 to 4,000 characters. For structured scientific specifications and attachments, use the [request form](https://physicalvalidation.com/request) or [MCP](https://physicalvalidation.com/docs/mcp).
|
|
80
46
|
|
|
81
|
-
|
|
82
|
-
printf '%s\n' "Method transfer for a small molecule" \
|
|
83
|
-
| npx physicalvalidation --email ada@lab.example --code 123456
|
|
84
|
-
```
|
|
47
|
+
## Resume an interrupted request
|
|
85
48
|
|
|
86
|
-
|
|
49
|
+
The code-sent message includes a pending reference. Continue on the same machine:
|
|
87
50
|
|
|
88
|
-
```
|
|
89
|
-
npx physicalvalidation
|
|
51
|
+
```sh
|
|
52
|
+
npx physicalvalidation resume PENDING_REFERENCE
|
|
90
53
|
```
|
|
91
54
|
|
|
92
|
-
|
|
55
|
+
The terminal asks for the code. For a script, pass `--code CODE`. If the code expires, use `resume PENDING_REFERENCE --resend` to email a fresh code for that same brief. Retrying after a network failure keeps the same submission key and cannot create a second request with that key.
|
|
93
56
|
|
|
94
|
-
|
|
57
|
+
After receipt, the CLI prints a request reference and a private account link. Sign in with the verified email to view it. Halmos acts next to review and clarify the brief.
|
|
95
58
|
|
|
96
|
-
|
|
97
|
-
2. `POST /api/v1/unvetted-requests/{id}/verify` with JSON `{"code"}`. The response is `{"status":"received"}`.
|
|
59
|
+
## Connect an agent
|
|
98
60
|
|
|
99
|
-
|
|
61
|
+
Follow the [agent setup guide](https://physicalvalidation.com/agents) and [workflow instructions](https://physicalvalidation.com/SKILL.md). Verify setup with a public catalogue search before reporting a connection as working. MCP account tools require authorization and submission consent; anonymous searches and draft preparation do not.
|
|
100
62
|
|
|
101
|
-
|
|
63
|
+
## Help and troubleshooting
|
|
102
64
|
|
|
103
|
-
|
|
65
|
+
Run `npx physicalvalidation --help` for commands and filters, or `--version` to check the installed version. `--json` prints one JSON result on stdout, disables prompts and animation, and prints structured errors on stderr. This works for search, draft preparation, intake, recovery and diagnostics.
|
|
104
66
|
|
|
105
|
-
|
|
|
67
|
+
| Exit code | Meaning |
|
|
106
68
|
| --- | --- |
|
|
107
|
-
|
|
|
108
|
-
|
|
|
109
|
-
|
|
|
110
|
-
|
|
|
111
|
-
| `-h`, `--help` | Show help and examples |
|
|
112
|
-
| `-V`, `--version` | Show the version |
|
|
69
|
+
| 0 | The command completed |
|
|
70
|
+
| 1 | Network problem, rate limit, expired code, or rejected request |
|
|
71
|
+
| 2 | Correct the command or input |
|
|
72
|
+
| 130 | Cancelled |
|
|
113
73
|
|
|
114
|
-
|
|
74
|
+
If rate limited, wait for the duration in the error before retrying. The CLI stores a cooldown timestamp and private recovery files containing pending briefs, email addresses, and temporary authorization after verification. Recovery files are removed after receipt; they stay local if a command is interrupted. Keep the pending reference private and resume on the same machine. `NO_COLOR` disables color. `--api <url>` overrides `PHYSICALVALIDATION_API`; the default is `https://physicalvalidation.com/api/v1`.
|
|
115
75
|
|
|
116
|
-
|
|
76
|
+
[CLI guide](https://physicalvalidation.com/docs/cli) · [API reference](https://physicalvalidation.com/docs/api) · [Support](https://physicalvalidation.com/support)
|
|
117
77
|
|
|
118
|
-
|
|
119
|
-
| --- | --- |
|
|
120
|
-
| 0 | The search or lookup finished, or the request was received |
|
|
121
|
-
| 1 | Network problem, rate limit, expired code, or a rejected request |
|
|
122
|
-
| 2 | The command line or the typed email/code needs a fix |
|
|
123
|
-
| 130 | Cancelled |
|
|
78
|
+
## Privacy and license
|
|
124
79
|
|
|
125
|
-
|
|
80
|
+
Request intake sends your brief, email, and verification code to Physical Validation. The CLI does not run a model or contact providers. See [Privacy](https://physicalvalidation.com/privacy) and [Terms](https://physicalvalidation.com/terms) for the hosted service.
|
|
126
81
|
|
|
127
|
-
|
|
82
|
+
This CLI is licensed under MIT (see the included LICENSE file), copyright © 2026 Halmos Labs. The license applies to the CLI; the hosted Physical Validation service is proprietary.
|
|
128
83
|
|
|
129
|
-
|
|
84
|
+
### Automation and diagnostics
|
|
130
85
|
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
npm run build
|
|
137
|
-
node dist/cli.js --help
|
|
138
|
-
npm run pack:dry
|
|
139
|
-
npm run bench
|
|
86
|
+
```sh
|
|
87
|
+
npx physicalvalidation doctor --json
|
|
88
|
+
npx physicalvalidation draft "Measure peptide purity" --json
|
|
89
|
+
npx physicalvalidation "Measure peptide purity" --email user@example.com --json
|
|
90
|
+
npx physicalvalidation resume PENDING_REFERENCE --code CODE --json
|
|
140
91
|
```
|
|
141
92
|
|
|
142
|
-
`
|
|
143
|
-
|
|
144
|
-
Publishing is a manual GitHub Actions workflow (`workflow_dispatch` only). It asks you to type the package version, then runs `npm publish --access public` with the `NPM_TOKEN` Actions secret. That works from a private repository. It does not run on push.
|
|
93
|
+
`doctor` checks the required live endpoints and performs a catalogue search. It reports which actions still require email verification; it does not verify an MCP connection.
|
|
145
94
|
|
|
146
|
-
|
|
95
|
+
A draft returns `status: "draft"`, `submitted: false`, the draft, missing fields and `review.url`. Intake returns `status: "code_sent"`, a `pendingReference` and `nextCommand`. Successful recovery returns `status: "received"`, `id`, `versionId`, `nextActor: "halmos"` and a private account `url`. A received request is awaiting Halmos review; it is not a laboratory quote or confirmed order.
|
|
147
96
|
|
|
148
|
-
|
|
97
|
+
Errors contain `error.code`, `message` and `retryable`, plus `retryAfterSeconds` when known. Pending requests include their reference and recovery command. Credentials and verification codes are never included in these results. Keep draft JSON and review links private: they can contain your supplied scientific and contact details.
|
package/dist/cli.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createInterface as
|
|
2
|
+
import{createInterface as Ke}from"readline/promises";var a=class extends Error{exitCode;kind;retryAfterSeconds;constructor(t,r,n,i){super(t),this.name="CliError",this.exitCode=r,this.kind=n,i!==void 0&&(this.retryAfterSeconds=i)}};async function v(e,t){if(e.ask)return e.ask(t);let r=Ke({input:e.stdin,output:e.stdout});try{return await new Promise((n,i)=>{let s=!1,o=f=>{s||(s=!0,f())};r.once("SIGINT",()=>{o(()=>i(new a("Cancelled.",130,"cancelled")))}),r.once("close",()=>o(()=>i(new a("Interview closed.",130,"cancelled")))),r.question(t).then(f=>o(()=>n(f)),f=>o(()=>i(f)))})}finally{r.close()}}var U="https://physicalvalidation.com/api/v1",ne="Received. A person at Physical Validation will review it. Nothing else happens automatically.",re="Beaming your request to Physical Validation...",ie="email: ",se="code: ";function M(e){return`physicalvalidation ${e}
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Describe an experiment, review a draft, or search providers and capabilities.
|
|
5
5
|
Nothing is sent to a provider automatically.
|
|
6
6
|
|
|
7
7
|
Usage:
|
|
8
|
-
physicalvalidation
|
|
8
|
+
physicalvalidation Describe an experiment and get a review link.
|
|
9
9
|
physicalvalidation search [text] [filters]
|
|
10
10
|
physicalvalidation company <id>
|
|
11
11
|
physicalvalidation site <id>
|
|
12
12
|
physicalvalidation services
|
|
13
13
|
physicalvalidation techniques
|
|
14
14
|
physicalvalidation countries
|
|
15
|
+
physicalvalidation doctor [--json]
|
|
15
16
|
physicalvalidation draft [brief or review link]
|
|
16
17
|
physicalvalidation "<request>"
|
|
17
|
-
physicalvalidation --email <email>
|
|
18
|
-
|
|
18
|
+
physicalvalidation --email <email> "<request>"
|
|
19
|
+
physicalvalidation resume <pending-reference> [--code <digits>]
|
|
20
|
+
physicalvalidation resume <pending-reference> --resend
|
|
19
21
|
|
|
20
22
|
Search filters:
|
|
21
23
|
--service <value> Repeatable. A value from \`services\` or the facets.
|
|
@@ -25,18 +27,19 @@ Search filters:
|
|
|
25
27
|
--modality <value> Repeatable.
|
|
26
28
|
--quality <value> Such as GLP or GMP. Repeatable.
|
|
27
29
|
--equipment <value> Repeatable.
|
|
28
|
-
--sort <value> relevance (default)
|
|
30
|
+
--sort <value> relevance (default) or name.
|
|
29
31
|
--limit <n> Page size from 1 to 50. Default 10.
|
|
30
32
|
--cursor <token> next_cursor from the previous page.
|
|
31
33
|
--facets Include filter counts.
|
|
32
|
-
--json
|
|
34
|
+
--json Machine-readable output; no prompts or animation.
|
|
33
35
|
|
|
34
36
|
Request options:
|
|
35
37
|
--email <email> Prompted on a terminal. Required otherwise.
|
|
36
|
-
--code <digits>
|
|
38
|
+
--code <digits> Verify an existing pending request with resume.
|
|
39
|
+
--resend Email a fresh code for the same pending request.
|
|
37
40
|
|
|
38
41
|
Other:
|
|
39
|
-
--api <url> API base URL (default: ${
|
|
42
|
+
--api <url> API base URL (default: ${U})
|
|
40
43
|
-h, --help Show this help
|
|
41
44
|
-V, --version Show the version
|
|
42
45
|
|
|
@@ -55,12 +58,13 @@ Examples:
|
|
|
55
58
|
Use draft to answer one question at a time and get a review link.
|
|
56
59
|
|
|
57
60
|
Passing a quoted request directly shows the text, asks for an email, then asks for the
|
|
58
|
-
6-digit code from that email. Up to five code attempts are allowed. The
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
`).
|
|
61
|
+
6-digit code from that email. Up to five code attempts are allowed. The
|
|
62
|
+
request is sent after verification. Interrupted requests can be continued with resume.
|
|
63
|
+
Private recovery files are kept locally until receipt. The CLI does not run a model.
|
|
64
|
+
Halmos reviews the request and clarifies missing details before contacting laboratories.
|
|
65
|
+
`}function oe(e,t,r){let n=!!t.isTTY;return{color:n&&x(t,r),interactive:!!(e.isTTY&&t.isTTY),show:n,columns:t.columns&&t.columns>20?t.columns:80}}function x(e,t){return t.NO_COLOR||t.TERM==="dumb"?!1:!!e.isTTY}function Qe(e,t){let r=e%18,n="";for(let i=0;i<14;i+=1){let s=i<=r&&i>r-4;t?s?n+="\x1B[36m\u2501\x1B[0m":n+="\x1B[2m\xB7\x1B[0m":n+=s?"=":"."}return n}function R(e,t,r){if(!e.isTTY)return{stop(){}};let n=!1,i=0,s=()=>{e.write(`\r\x1B[2K${t} ${Qe(i,r)}`),i+=1};e.write("\x1B[?25l"),s();let o=setInterval(s,70);return o.unref(),{stop(f="clear"){n||(n=!0,clearInterval(o),f==="keep"?e.write(`\r\x1B[2K${t}
|
|
66
|
+
\x1B[?25h`):e.write("\r\x1B[2K\x1B[?25h"))}}}function ae(e,t){let r=Ze(e,Math.min(t.columns,78)-4);if(t.color){let n="\x1B[2m\u2502\x1B[0m",i=r.split(`
|
|
67
|
+
`).map(s=>`${n} ${s}`);return`
|
|
64
68
|
\x1B[1m\u250C Physical Validation\x1B[0m
|
|
65
69
|
${n}
|
|
66
70
|
${i.join(`
|
|
@@ -71,41 +75,62 @@ ${n}
|
|
|
71
75
|
Request:
|
|
72
76
|
${r}
|
|
73
77
|
|
|
74
|
-
`}function
|
|
78
|
+
`}function $(e,t){return t?`\x1B[31m${e}\x1B[0m
|
|
75
79
|
`:`${e}
|
|
76
|
-
`}function
|
|
77
|
-
`)){let
|
|
78
|
-
`)}var
|
|
79
|
-
|
|
80
|
-
${
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
> `)).trim();
|
|
84
|
-
`)
|
|
85
|
-
${h
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
`)}
|
|
90
|
-
|
|
91
|
-
${d.
|
|
92
|
-
|
|
93
|
-
`}function
|
|
94
|
-
|
|
80
|
+
`}function Ze(e,t){let r=Math.max(20,t),n=[];for(let i of e.split(`
|
|
81
|
+
`)){let s=i;if(s.length<=r){n.push(s);continue}for(;s.length>r;){let o=s.lastIndexOf(" ",r);o<=0&&(o=r),n.push(s.slice(0,o).trimEnd()),s=s.slice(o).trimStart()}n.push(s)}return n.join(`
|
|
82
|
+
`)}var C="\x1B[?1049h",V="\x1B[?1049l",et=new RegExp(String.raw`^(?:[ Oo|/\\\r\n-]+|`+"\x1B"+String.raw`\[(?:H|K|(?:0|34|36|90|94|96)m))+`);async function F(e,t){if(!x(e.stdout,e.env)||(e.stdout.columns??80)<33||(e.stdout.rows??24)<20)return;let r=!1,n=()=>{r&&e.stdout.write(V),r=!1},i;process.once("exit",n);try{let s=await e.fetch(t+"/dna",{headers:{accept:"text/plain"},redirect:"error",signal:AbortSignal.timeout(6e3)});if(!s.ok||!s.headers.get("content-type")?.startsWith("text/plain")||(i=s.body?.getReader(),!i))return;let o="",f=0;for(;;){let{value:c,done:u}=await i.read();if(u||(f+=c.length)>256e3)break;if(o+=Buffer.from(c).toString("latin1"),!r){if(C.startsWith(o)&&o!==C)continue;if(!o.startsWith(C))break;e.stdout.write(C),r=!0,o=o.slice(C.length)}let l=et.exec(o)?.[0]??"";if(l&&(e.stdout.write(l),o=o.slice(l.length)),o.startsWith(V)||o&&(!o.startsWith("\x1B")||o.length>=V.length))break}}catch{return}finally{n(),process.removeListener("exit",n),await i?.cancel().catch(()=>{})}}import{createHash as tt}from"crypto";import{inflateRawSync as nt}from"zlib";function g(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}var ce=14e5,ue=/^#prepared=1\.d\.([A-Za-z0-9_-]+)\.([a-f0-9]{16})$/;function J(e,t){if(typeof e!="string"||e.length>ce+1024)return!1;let r=t+"/request?review=1";return e.startsWith(r)&&ue.test(e.slice(r.length))&&e.trim()===e}function B(e,t){let r=new a("Paste the complete Physical Validation review link, including its #prepared fragment.",2,"usage");if(!J(e,t))throw r;try{let n=ue.exec(new URL(e).hash),i=Buffer.from(n[1],"base64url");if(tt("sha256").update(i).digest("hex").slice(0,16)!==n[2])throw r;let s=JSON.parse(nt(i,{maxOutputLength:ce+1024}).toString("utf8"));if(!g(s)||typeof s.fragment!="string")throw r;let o=new URLSearchParams(s.fragment);if(o.get("v")!=="2")throw r;let f=JSON.parse(o.get("input")??"");if(!g(f)||s.estimate!==void 0&&!g(s.estimate))throw r;return{...f,...s.estimate?{estimate:s.estimate}:{}}}catch{throw r}}var rt=new Set(["json","facets","resend"]),fe=new Set(["service","type","country","region","modality","quality","equipment"]),it=new Set(["api","email","code","sort","limit","cursor"]),st=new Set(["draft","resume","doctor","search","company","site","services","capabilities","techniques","countries"]),ot=new Set(["relevance","name","completeness"]);function le(e){if(e.some(i=>i==="-h"||i==="--help"))return G({help:!0});if(e.some(i=>i==="-V"||i==="--version"))return G({version:!0});let t=G(),r=[],n=!1;for(let i=0;i<e.length;i+=1){let s=e[i];if(s===void 0)continue;if(s==="--"){r.length===0&&(n=!0),r.push(...e.slice(i+1));break}if(!s.startsWith("-")){r.push(s);continue}if(!s.startsWith("--"))throw new a(`Unknown option: ${s}. See --help for usage.`,2,"usage");let o=s.indexOf("="),f=o===-1?s:s.slice(0,o),c=f.slice(2),u=o===-1?void 0:s.slice(o+1);if(rt.has(c)){if(u!==void 0)throw new a(`--${c} does not take a value.`,2,"usage");c==="json"&&(t.json=!0),c==="facets"&&(t.facets=!0),c==="resend"&&(t.resend=!0);continue}if(!fe.has(c)&&!it.has(c))throw new a(`Unknown option: ${f}. See --help for usage.`,2,"usage");let l=u;if(l===void 0){let d=e[i+1];if(d===void 0||d.startsWith("-")&&d!=="-")throw new a(`Missing value for --${c}.`,2,"usage");l=d,i+=1}at(t,c,l)}return ut(t,r,n),dt(t),t}function me(e){let t=(e??U).trim(),r;try{r=new URL(t)}catch{throw new a("Pass an http or https URL to --api.",2,"usage")}if(r.protocol!=="http:"&&r.protocol!=="https:")throw new a("Pass an http or https URL to --api.",2,"usage");if(r.username||r.password)throw new a("The API URL cannot include a username or password.",2,"usage");return r.hash="",r.search="",r.toString().replace(/\/$/,"")}function S(e){return e.length<=254&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function Y(e){return/^\d{6}$/.test(e)}function b(e){let t="";for(let r=0;r<e.length;r+=1){let n=e.charCodeAt(r);if(n===27){r=lt(e,r);continue}n<=8||n===11||n===12||n>=14&&n<=31||n===127||(t+=e[r])}return t.trim()}function G(e={}){return{help:!1,version:!1,json:!1,facets:!1,resend:!1,command:"intake",service:[],type:[],country:[],region:[],modality:[],quality:[],equipment:[],...e}}function at(e,t,r){if(t==="api"&&(e.api=r),t==="email"&&(e.email=r),t==="code"&&(e.code=r),t==="sort"&&(e.sort=r),t==="limit"&&(e.limit=r),t==="cursor"&&(e.cursor=r),!fe.has(t))return;let n=t==="country"||t==="type"?r.split(","):[r],i=ct(e,t);for(let s of n){let o=s.trim();o&&i.push(o)}}function ct(e,t){return t==="service"?e.service:t==="type"?e.type:t==="country"?e.country:t==="region"?e.region:t==="modality"?e.modality:t==="quality"?e.quality:e.equipment}function ut(e,t,r){let n=t[0];if(!r&&n&&st.has(n)){let i=t.slice(1),s=n==="capabilities"?"services":n;if(e.command=s,s==="resume"){if(i.length!==1||!/^pending_[0-9a-f]{32}$/.test(i[0]))throw new a("Pass one pending reference from the code-sent message.",2,"usage");e.id=i[0];return}if(s==="draft"){i.length&&(e.text=i.join(" "));return}if(s==="search"){let o=i.join(" ").trim();o&&(e.query=o);return}if(s==="company"||s==="site"){if(i.length!==1)throw new a(s==="company"?"Pass one company id. See --help for usage.":"Pass one site id. See --help for usage.",2,"usage");e.id=i[0];return}if(i.length>0)throw new a(`${s} does not take extra text. See --help for usage.`,2,"usage");return}e.command="intake",t.length>0&&(e.text=t.join(" "))}function dt(e){if(e.help||e.version)return;let t=ft(e);if(e.command!=="search"&&t)throw new a("Those options are for search. See --help for usage.",2,"usage");if(e.email!==void 0&&e.command!=="intake")throw new a("--email is only for a new request.",2,"usage");if(e.code!==void 0&&e.command!=="resume")throw new a("Use resume PENDING_REFERENCE --code CODE to verify an existing request.",2,"usage");if(e.resend&&(e.command!=="resume"||e.code!==void 0))throw new a("Use resume PENDING_REFERENCE --resend without a code to request a fresh code.",2,"usage");if(e.command!=="search")return;let r=e.query??"";if(r.length>500)throw new a(`Keep the search under ${500} characters.`,2,"usage");if(!r&&!t)throw new a("Pass the search text or a filter such as --country US. See --help for usage.",2,"usage");if(e.sort!==void 0){let n=e.sort.toLowerCase();if(!ot.has(n))throw new a("Pass relevance or name to --sort.",2,"usage");e.sort=n}if(e.limit!==void 0&&(!/^\d+$/.test(e.limit)||Number(e.limit)<1||Number(e.limit)>50))throw new a("Pass a page size from 1 to 50 to --limit.",2,"usage");if(e.cursor!==void 0&&(e.cursor.length>4e3||/\s/.test(e.cursor)))throw new a("That page cursor is not valid. Search again without --cursor.",2,"usage");e.country=e.country.map(n=>{if(!/^[A-Za-z]{2}$/.test(n))throw new a("Country codes are two letters, such as US.",2,"usage");return n.toUpperCase()});for(let n of[...e.service,...e.type,...e.region,...e.modality,...e.quality,...e.equipment])if(n.length>200)throw new a("That filter is too long.",2,"usage")}function ft(e){return e.facets||e.sort!==void 0||e.limit!==void 0||e.cursor!==void 0||e.service.length>0||e.type.length>0||e.country.length>0||e.region.length>0||e.modality.length>0||e.quality.length>0||e.equipment.length>0}function lt(e,t){if(e[t+1]!=="[")return t;let r=t+2;for(;r<e.length;){let n=e.charCodeAt(r);if(n>=64&&n<=126)return r;r+=1}return e.length-1}var pe=new Set(["need.title","need.description","need.services","pricing.min","pricing.max","pricing.currency","pricing.flexibility","contact.name","contact.email","contact.company","contact.role","estimate.customerType","estimate.region"]),he={"need.services":[["Other","other"],["Peptides","peptide-synthesis"],["Rabbits","rabbit-supply"],["Mice","mouse-supply"],["Genes & plasmids","gene-synthesis"],["Proteins & antibodies","protein-production"],["Sequencing","nucleic-acid-sequencing"]],"estimate.customerType":[["Industry","industry"],["Academic / nonprofit","academic_external"]],"estimate.region":[["United States","us"],["Europe","eu"],["United Kingdom","uk"],["China","cn"],["India","in"]],"pricing.flexibility":[["Firm","firm"],["Flexible","flexible"]]};async function N(e,t,r){let{data:n}=await e.prepare(t);if(!g(n)||n.submitted!==!1||!g(n.draft)||!g(n.review)||typeof n.review.url!="string"||!J(n.review.url,r)||!Array.isArray(n.missing)||!n.missing.every(i=>g(i)&&typeof i.path=="string"&&typeof i.ask=="string"))throw new a("Physical Validation returned an unreadable draft.",1,"unexpected");return{url:n.review.url,draft:{...n.draft,...t.estimate?{estimate:t.estimate}:{}},missing:n.missing}}async function ge(e,t,r,n){let i=new URL(n).origin,s=/^https?:\/\/\S+$/i.test(e)?B(e,i):{description:e},o=await N(r,s,i);return t.stdout.write(JSON.stringify({status:"draft",submitted:!1,draft:o.draft,review:{url:o.url},missing:o.missing,nextActor:"user"})+`
|
|
83
|
+
`),0}function mt(e,t,r){let[n,i]=t.split("."),s=r,o=he[t];if(o){let c=o.find(([u,l],d)=>[u.toLowerCase(),l,String(d+1)].includes(r.toLowerCase()));if(c)s=c[1];else if(t!=="need.services")throw new a("Choose one of the listed options.",2,"usage")}if(t==="need.services")return{...e,services:[s]};if(n==="need")return{...e,[i]:s};if(t==="contact.email"&&!S(r))throw new a("Enter a valid email address.",2,"usage");if(t==="pricing.currency"){if(!/^[a-z]{3}$/i.test(r))throw new a("Enter a three-letter currency code, such as USD.",2,"usage");s=r.toUpperCase()}if(t==="pricing.min"||t==="pricing.max"){if(!/^\d+(?:\.\d+)?$/.test(r)||!Number.isFinite(Number(r)))throw new a("Enter a nonnegative amount.",2,"usage");s=Number(r)}let f=e[n];return{...e,[n]:{...g(f)?f:{},[i]:s}}}async function we(e,t,r){let n=new URL(r).origin;await F(e,n);let i=b(await v(e,`What would you like to test?
|
|
84
|
+
> `));if(!i)return 0;if(i.length>4e3)throw new a(`Keep the brief to ${4e3.toLocaleString("en-US")} characters or fewer.`,2,"usage");let s=await N(t,{description:i},n);return e.stdout.write(`Review your draft
|
|
85
|
+
${s.url}
|
|
86
|
+
`),0}async function ye(e,t,r,n,i){if(!i.interactive)throw new a("Run physicalvalidation draft in a terminal to answer the questions.",2,"usage");let s=new URL(n).origin,o=(e??await v(t,`Describe your request or paste its Physical Validation review link
|
|
87
|
+
> `)).trim();for(;!o;)o=(await v(t,`Enter a brief description or paste the review link
|
|
88
|
+
> `)).trim();let f=/^https?:\/\/\S+$/i.test(o);if(!f&&o.length>4e3)throw new a("Keep the initial brief under 4,000 characters.",2,"usage");let c=f?B(o,s):{description:b(o)};f||await F(t,s);let u=await N(r,c,s),l=new Set;try{for(u.missing.some(d=>pe.has(d.path))&&t.stdout.write(`Press Enter to skip a question, or type /done to review now.
|
|
89
|
+
`);;){let d=u.missing.find(h=>pe.has(h.path)&&!l.has(h.path));if(!d)break;let p=he[d.path]?.map(([h],j)=>`${j+1}) ${h}`).join(" "),y=b(d.ask).replace(/[\s\u0080-\u009f]+/g," "),T=b(await v(t,`${y}
|
|
90
|
+
${p?p+`
|
|
91
|
+
`:""}> `));if(T==="/done")break;if(!T){l.add(d.path);continue}try{let h=await N(r,mt(u.draft,d.path,T),s);h.missing.some(j=>j.path===d.path)?t.stderr.write(d.path==="need.services"?`Choose a listed service or enter its Physical Validation catalogue name.
|
|
92
|
+
`:`Physical Validation still needs this field. Try another answer or press Enter to skip.
|
|
93
|
+
`):u=h}catch(h){if(!(h instanceof a)||h.kind!=="usage")throw h;t.stderr.write(h.message+`
|
|
94
|
+
`)}}}finally{let d=u.missing.length;t.stdout.write(`
|
|
95
|
+
${d?`${d} unanswered ${d===1?"field":"fields"} to review. `:""}Draft only. Review your request here:
|
|
96
|
+
${u.url}
|
|
97
|
+
`)}return 0}async function be(e,t,r,n){let i=await t.index(),s=g(i.data)&&Array.isArray(i.data.endpoints)?i.data.endpoints:[];if(["/api/v1/search","/api/v1/requests/prepare","/api/v1/request-auth","/api/v1/request-briefs"].filter(l=>!s.some(d=>g(d)&&d.path===l)).length)throw new a("The service is missing a required CLI endpoint. Update the CLI or contact support.",1,"rejected");let c=await t.search({q:"peptide",limit:"1"});if(!Array.isArray(c.data))throw new a("The catalogue returned an unreadable result.",1,"unexpected");let u={status:"ready",version:e.version,api:r,checks:{endpoints:"ok",catalogue:"ok"},catalogueResults:c.data.length,capabilities:{catalogue:"verified",draft:"available",submission:"requires_email_verification",mcp:"not_checked"}};return e.stdout.write(n?JSON.stringify(u)+`
|
|
98
|
+
`:`Physical Validation ${e.version}
|
|
99
|
+
API: ${r}
|
|
100
|
+
Required endpoints: available
|
|
101
|
+
Catalogue: verified (${c.data.length} result)
|
|
102
|
+
Draft preparation: available
|
|
103
|
+
Submission: requires email verification
|
|
104
|
+
MCP: not checked by the CLI
|
|
105
|
+
`),0}var pt=/^req_[0-9a-f]{32}$/,ht=1440*60,q=class{base;fetchImpl;version;timeoutMs;constructor(t){this.base=t.base.replace(/\/$/,""),this.fetchImpl=t.fetch,this.version=t.version,this.timeoutMs=t.timeoutMs??2e4}async sendCode(t){let r=await this.send("POST","/request-auth",{email:t},"create");if(r.status!=="code_sent"||r.email!==t)throw _()}async authenticate(t,r){let n=await this.send("POST","/request-auth",{email:t,code:r},"verify");if(n.status!=="authenticated"||n.email!==t||typeof n.accountToken!="string"||!/^breq_[A-Za-z0-9_-]{43}$/.test(n.accountToken)||typeof n.expiresAt!="string"||!(Date.parse(n.expiresAt)>Date.now()))throw _();return{token:n.accountToken,expiresAt:n.expiresAt}}async submitBrief(t,r,n){let i=await this.send("POST","/request-briefs",{text:t,consent:!0},"submit",void 0,{authorization:`Bearer ${r}`,"idempotency-key":n});if(typeof i.id!="string"||!pt.test(i.id)||typeof i.versionId!="string"||!/^ver_[0-9a-f]{32}$/.test(i.versionId)||i.status!=="received"||i.nextActor!=="halmos")throw _();return{id:i.id,versionId:i.versionId,status:"received",nextActor:"halmos",url:`${new URL(this.base).origin}/account#${i.id}`}}async search(t){return this.send("GET","/search",void 0,"read",gt(t))}async index(){return this.send("GET","",void 0,"read")}async company(t){return this.send("GET",`/companies/${encodeURIComponent(t)}`,void 0,"read")}async site(t){return this.send("GET",`/sites/${encodeURIComponent(t)}`,void 0,"read")}async prepare(t){return this.send("POST","/requests/prepare",t,"draft")}async services(){return this.send("GET","/services",void 0,"read")}async techniques(){return this.send("GET","/techniques",void 0,"read")}async countries(){return this.send("GET","/countries",void 0,"read")}async send(t,r,n,i,s,o){let f=s&&[...s.keys()].length>0?`${this.base}${r}?${s}`:`${this.base}${r}`,c;try{c=await this.fetchImpl(f,{method:t,redirect:"manual",credentials:"omit",headers:{...o,accept:"application/json","user-agent":`physicalvalidation/${this.version}`,...n?{"content-type":"application/json"}:{}},body:n?JSON.stringify(n):void 0,signal:AbortSignal.timeout(this.timeoutMs)})}catch(l){throw Pt(l)}if(c.status>=300&&c.status<400)throw new a("Physical Validation sent an unexpected redirect. Nothing else was sent.",1,"unexpected");let u=await Et(c);if(c.status===429||xt(c.status,u))throw wt(c,u);if(i==="draft"&&(c.status===400||c.status===422))throw new a(W(xe(u))??"Physical Validation could not use that value.",2,"usage");if(!c.ok)throw vt(c.status,u,i);if(!I(u)||i==="read"&&!("data"in u))throw _();return u}};function gt(e){let t=new URLSearchParams;return e.q&&t.set("q",e.q),k(t,"service",e.service),k(t,"type",e.type),k(t,"country",e.country),k(t,"region",e.region),k(t,"modality",e.modality),k(t,"quality",e.quality),k(t,"equipment",e.equipment),e.sort&&t.set("sort",e.sort),e.limit&&t.set("limit",e.limit),e.cursor&&t.set("cursor",e.cursor),e.facets&&t.set("facets","true"),t}function k(e,t,r){for(let n of r??[])e.append(t,n)}function _(){return new a("Physical Validation returned an unexpected response. Try again in a moment.",1,"unexpected")}function wt(e,t){let r=bt(e.headers.get("retry-after")),n=H(t),i=yt(r),s=n.toUpperCase()==="TOO_MANY_ATTEMPTS"?"Too many tries.":"Physical Validation is receiving too many requests right now.";return new a(`${s}${i}`,1,"rate_limit",r??60)}function yt(e){return e===void 0?" Wait a minute and try again.":e<1?" Try again in a moment.":e===1?" Try again in 1 second.":` Try again in ${e} seconds.`}function bt(e){let t=e?.trim()??"";if(!t)return;if(/^\d+$/.test(t))return ve(Number(t));let r=Date.parse(t);if(!Number.isNaN(r))return ve(Math.ceil((r-Date.now())/1e3))}function ve(e){return Number.isFinite(e)?Math.min(Math.max(0,e),ht):0}function vt(e,t,r){let n=H(t),i=xe(t);if(e===410||n.toUpperCase()==="EXPIRED")return new a("That code has expired. Resume with --resend to request a new one.",1,"expired");if(r==="submit"&&e===401)return new a("Verification expired. Resume with --resend to request a new code.",1,"expired");if(n.toUpperCase()==="IDEMPOTENCY_CONFLICT")return new a("This request reference already belongs to a different brief. Start a new request for changed text.",1,"rejected");if(e===409||n.toUpperCase()==="STALE_CURSOR")return new a("That page cursor is out of date. Search again without --cursor.",1,"rejected");if(e===503||n.toUpperCase()==="UNAVAILABLE")return new a("Physical Validation is not taking requests right now. Try again later.",1,"unavailable");if(e===404){if(r==="read"){let f=W(i);return new a(f??"Nothing matched that id.",1,"rejected")}return new a(r==="verify"?"That code could not be matched. Run the command again to request a new one.":"Physical Validation is not ready to take that request yet. Try again later.",1,"rejected")}if(e===413)return new a("That request is too long.",2,"usage");if(r==="verify"&&(e===400||e===401||e===403||e===422||/code/i.test(n)))return new a("That code does not match.",1,"invalid_code");let s=W(i),o=e>=500?"Physical Validation had a problem on its side. Try again in a moment.":r==="read"?"Physical Validation did not accept that lookup.":"Physical Validation did not accept that request.";return new a(s?`${o} ${s}`:o,1,e>=500?"unavailable":"rejected")}function xt(e,t){if(e===429)return!0;let r=H(t);return/^(rate_limited|too_many_requests|rate_limit|too_many_attempts)$/i.test(r)}function W(e){let t=e.replace(/\s+/g," ").trim();if(!(!t||t.length>180||t.includes("@")||kt(t))&&!St(t))return t}function St(e){return!!(/breq_|bearer|\btoken\b|\bsecret\b|\bpassword\b/i.test(e)||/price|pricing|\bcost\b|\bfees?\b|\$\s?\d|\b(?:usd|eur|gbp|aud|cad)\b/i.test(e)||/\.(?:ts|tsx|js|mjs|cjs):\d+/.test(e)||/\bat\s+\S+\s+\(/.test(e)||/\bstack\s*trace\b/i.test(e)||/node:internal/.test(e))}function H(e){let t=Se(e);return typeof t?.code=="string"?t.code:""}function xe(e){let t=Se(e);return typeof t?.message=="string"?t.message:I(e)&&typeof e.message=="string"?e.message:""}function Se(e){if(I(e))return I(e.error)?e.error:e}function kt(e){for(let t=0;t<e.length;t+=1)if(e.charCodeAt(t)<=31)return!0;return!1}async function Et(e){let t;try{t=await e.text()}catch{return null}if(!t)return null;try{return JSON.parse(t)}catch{return null}}function Pt(e){return e instanceof a?e:At(e)?new a("Physical Validation took too long to respond. Try again in a moment.",1,"network"):new a("Could not reach Physical Validation. Check your connection and try again.",1,"network")}function At(e){let t=Tt(e);if(t==="TimeoutError"||t==="AbortError")return!0;let r=Rt(e);return r==="ETIMEDOUT"||r==="UND_ERR_CONNECT_TIMEOUT"||r==="ABORT_ERR"}function Tt(e){return e&&typeof e=="object"&&"name"in e&&typeof e.name=="string"?e.name:""}function Rt(e){let t=new Set,r=n=>{if(!(!n||typeof n!="object"||t.has(n))){if(t.add(n),"code"in n&&typeof n.code=="string")return n.code;if("errors"in n&&Array.isArray(n.errors))for(let i of n.errors){let s=r(i);if(s)return s}if("cause"in n)return r(n.cause)}};return r(e)}function I(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}import{constants as ke,chmodSync as $t,closeSync as Ct,fstatSync as _t,lstatSync as Nt,mkdirSync as qt,openSync as It,readFileSync as Ot,renameSync as Lt,rmSync as Ee,writeFileSync as Dt}from"fs";import{randomUUID as Pe}from"crypto";import{homedir as jt}from"os";import{join as O}from"path";var Ut=/^pending_[0-9a-f]{32}$/;function Mt(e){let t=O(e.PHYSICALVALIDATION_STATE_DIR||O(e.XDG_STATE_HOME||O(jt(),".local","state"),"physicalvalidation"),"pending");qt(t,{recursive:!0,mode:448});let r=Nt(t);if(!r.isDirectory()||r.isSymbolicLink()||process.getuid&&r.uid!==process.getuid())throw new Error("Unsafe state directory");return $t(t,448),t}function z(e,t){if(!Ut.test(t))throw new a("Pass the pending reference printed when the code was sent.",2,"usage");return O(Mt(e),`${t}.json`)}function L(e,t){try{let r=z(e,t.id),n=`${r}.${Pe()}.tmp`;try{Dt(n,JSON.stringify(t),{mode:384,flag:"wx"}),Lt(n,r)}finally{Ee(n,{force:!0})}}catch{throw new a("Could not save private recovery state. Check the state directory before sending.",1,"unexpected")}}function Ae(e,t){let r={...t,id:`pending_${Pe().replaceAll("-","")}`,stage:"created",createdAt:Date.now()};return L(e,r),r}function Te(e,t){let r=z(e,t);try{let n=It(r,ke.O_RDONLY|(ke.O_NOFOLLOW??0));try{let i=_t(n);if(!i.isFile()||i.size>32768||process.getuid&&(i.uid!==process.getuid()||(i.mode&63)!==0))throw new Error("Unsafe state file");let s=JSON.parse(Ot(n,"utf8"));if(s.id!==t||typeof s.base!="string"||typeof s.email!="string"||typeof s.text!="string"||!S(s.email)||!s.text||s.text.length>4e3||b(s.text)!==s.text||!["created","code_sent","verified"].includes(s.stage)||!Number.isFinite(s.createdAt)||s.auth&&(typeof s.auth.token!="string"||!/^breq_[A-Za-z0-9_-]{43}$/.test(s.auth.token)||!Number.isFinite(Date.parse(s.auth.expiresAt))))throw new Error("Invalid state");return s}finally{Ct(n)}}catch{throw new a("That pending request could not be read securely on this machine. Check its reference or start a new request.",1,"rejected")}}function Re(e,t){Ee(z(e,t),{force:!0})}var Vt=/^(?:price|prices|pricing|cost|costs|fee|fees|budget|budgets|quote|quotes|currency)$/i,Ce=/\$\s?\d|\b\d[\d,.]*\s*(?:usd|eur|gbp|aud|cad)\b/i;function X(e){if(Array.isArray(e))return e.map(X).filter(r=>r!==void 0);if(!w(e))return typeof e=="string"&&Ce.test(e)?void 0:e;let t={};for(let[r,n]of Object.entries(e)){if(Vt.test(r))continue;let i=X(n);i!==void 0&&(t[r]=i)}return t}function _e(e){return`${JSON.stringify(X(e),null,2)}
|
|
106
|
+
`}function Ne(e){let t=P(e),r=A(t.data);if(r.length===0)return`No providers matched that search.
|
|
107
|
+
`;let n=[],i=zt(t);return i!==void 0&&n.push(`${i} ${i===1?"provider":"providers"}`,""),r.forEach((s,o)=>{n.push(`${o+1}. ${m(s.name)||"Provider"}`);let f=[m(s.providerType),m(s.level),Gt(s)].filter(T=>T.length>0);f.length>0&&n.push(` ${f.join(" \xB7 ")}`);let c=m(s.id);c&&n.push(` ${c}`);let u=De(s.countries);u.length>0&&n.push(` ${u.join(", ")}`);let l=K(s.sites);l&&l!=="0"&&n.push(` ${l} ${l==="1"?"site":"sites"}`);let d=m(s.summary);d&&n.push(` ${d}`);let p=Yt(s.matched);p.length>0&&n.push(` ${p.join(", ")}`);let y=m(s.url);y&&n.push(` ${y}`),n.push("")}),Bt(n,t),typeof t.next_cursor=="string"&&t.next_cursor&&n.push("Another page is available. Run again with --json and pass next_cursor to --cursor."),`${n.join(`
|
|
95
108
|
`).replace(/\n+$/,"")}
|
|
96
|
-
`}function
|
|
97
|
-
`;if(t==="countries"){let i=["code name sites"];for(let
|
|
109
|
+
`}function qe(e){let t=P(P(e).data);return Le(t,"company")}function Ie(e){let t=P(P(e).data);return Le(t,"site")}function Oe(e,t){let r=A(P(e).data);if(r.length===0)return`Nothing is listed.
|
|
110
|
+
`;if(t==="countries"){let i=["code name sites"];for(let s of r){let o=m(s.code),f=m(s.name),c=K(s.count)||"0";(o||f)&&i.push(`${o.padEnd(5)}${f} ${c}`)}return`${i.join(`
|
|
98
111
|
`)}
|
|
99
|
-
`}return`${r.map(i=>{let
|
|
112
|
+
`}return`${r.map(i=>{let s=m(i.slug),o=m(i.name);return s&&o?`${s} \u2014 ${o}`:s||o}).filter(i=>i.length>0).join(`
|
|
100
113
|
`)}
|
|
101
|
-
`}function
|
|
114
|
+
`}function Le(e,t){let r=[];r.push(m(e.name)||(t==="company"?"Company":"Site"));let n=m(e.id);n&&r.push(n);let i=[m(e.providerType),m(e.level)].filter(u=>u.length>0);i.length>0&&r.push(i.join(" \xB7 "));let s=m(e.summary)||Wt(e.published);s&&r.push("",s);let o=De(e.websites);if(o.length>0&&r.push("",...o),t==="site"){let u=Ht(e.company);u&&r.push("",u);let l=$e(e.location);l&&r.push(l)}else{let u=A(e.sites);if(u.length===0)r.push("","No sites are listed.");else{r.push("","Sites");for(let l of u.slice(0,20)){let d=m(l.name)||"Site",p=$e(l.location);r.push(` ${p?`${p} \u2014 ${d}`:d}`)}u.length>20&&r.push(` ${u.length-20} more. Use --json for the full record.`)}}Ft(r,e.claims),Jt(r,e.unknowns);let f=m(e.url);f&&r.push("",f);let c=m(e.notice);return c&&r.push("",c),`${r.join(`
|
|
102
115
|
`)}
|
|
103
|
-
`}function
|
|
104
|
-
|
|
105
|
-
`:`
|
|
106
|
-
`),await
|
|
107
|
-
`)
|
|
108
|
-
`)
|
|
116
|
+
`}function Ft(e,t){let r=A(t);if(r.length!==0){e.push("","Claims");for(let n of r.slice(0,15)){let i=m(n.label);if(!i)continue;let s=m(n.scope);e.push(` ${s?`${i} (${s})`:i}`)}r.length>15&&e.push(` ${r.length-15} more. Use --json for the full record.`)}}function Jt(e,t){if(!Array.isArray(t)||t.length===0)return;let r=t.map(n=>typeof n=="string"?n.trim():w(n)?m(n.label)||m(n.name)||m(n.detail):"").filter(n=>n.length>0);r.length!==0&&e.push("","Unknown",...r.slice(0,10).map(n=>` ${n}`))}function Bt(e,t){let r=w(t.meta)?t.meta:void 0,n=r&&w(r.facets)?r.facets:void 0;if(!n)return;let i=[];for(let[s,o]of Object.entries(n)){let c=A(o).slice(0,8).map(u=>{let l=m(u.label)||m(u.value),d=K(u.count);return l?d?`${l} (${d})`:l:""}).filter(u=>u.length>0);c.length>0&&i.push(` ${s}: ${c.join(", ")}`)}i.length>0&&e.push("Filters",...i,"")}function Gt(e){let t=m(e.match),r=m(e.matchedOn);return t&&r?`${t} match on ${r}`:t?`${t} match`:""}function Yt(e){let t=[];for(let r of A(e)){let n=m(r.label);if(n&&!t.includes(n)&&t.push(n),t.length===6)break}return t}function Wt(e){return w(e)?m(e.description):""}function Ht(e){return w(e)?m(e.name):""}function $e(e){return w(e)?[m(e.city),m(e.region),m(e.country)||m(e.countryCode)].filter(t=>t.length>0).join(", "):""}function zt(e){if(!w(e.meta))return;let t=e.meta.total;return typeof t=="number"&&Number.isFinite(t)?t:void 0}function P(e){return w(e)?e:{}}function A(e){return Array.isArray(e)?e.filter(w):[]}function De(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.trim().length>0):[]}function m(e){if(typeof e!="string")return"";let t=e.trim();return!t||Ce.test(t)?"":t}function K(e){return typeof e=="number"&&Number.isFinite(e)?String(e):""}function w(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var Xt=/^(?:provider|archive|listed):[A-Za-z0-9_-]{1,120}$/;async function je(e,t,r,n){e.command==="company"&&Ue(e.id),e.command==="site"&&Me(e.id);let i=e.command==="search"?"Searching Physical Validation...":"Loading from Physical Validation...",s=e.json?{stop(){}}:R(t.stdout,i,n.color);try{let o=await Kt(e,r);return s.stop(),t.stdout.write(Qt(e,o)),0}catch(o){throw s.stop(),o}}async function Kt(e,t){switch(e.command){case"search":return t.search({...e.query?{q:e.query}:{},service:e.service,type:e.type,country:e.country,region:e.region,modality:e.modality,quality:e.quality,equipment:e.equipment,...e.sort?{sort:e.sort}:{},...e.limit?{limit:e.limit}:{},...e.cursor?{cursor:e.cursor}:{},...e.facets?{facets:!0}:{}});case"company":return t.company(Ue(e.id));case"site":return t.site(Me(e.id));case"services":return t.services();case"techniques":return t.techniques();case"countries":return t.countries();default:throw new a("See --help for usage.",2,"usage")}}function Qt(e,t){if(e.json)return _e(t);if(e.command==="search")return Ne(t);if(e.command==="company")return qe(t);if(e.command==="site")return Ie(t);if(e.command==="services"||e.command==="techniques"||e.command==="countries")return Oe(t,e.command);throw new a("See --help for usage.",2,"usage")}function Ue(e){if(!e||!Xt.test(e))throw new a("Pass a company id from search, such as listed:org_example.",2,"usage");return e}function Me(e){if(!e||e.length>200||e.includes("/")||e.includes("\\")||e.includes(".."))throw new a("Pass the site id from a company lookup.",2,"usage");if(e.includes("%")||e.includes("?")||e.includes("#")||/\s/.test(e))throw new a("Pass the site id from a company lookup.",2,"usage");return e}import{mkdirSync as Zt,readFileSync as en,writeFileSync as tn}from"fs";import{tmpdir as nn}from"os";import{join as Z}from"path";var Q=3e4,Ve="cooldown.json";function ee(e){let t=e.PHYSICALVALIDATION_COOLDOWN_MS;if(t===void 0||t.trim()===""||!/^\d+$/.test(t.trim()))return Q;let r=Number(t.trim());return Number.isFinite(r)?r:Q}function Fe(e){let t=e.PHYSICALVALIDATION_STATE_DIR?.trim();return t||Z(nn(),"physicalvalidation")}function Je(e,t=Date.now()){return Math.max(0,Be(Fe(e))-t)}function te(e,t,r=Date.now()){if(t>0)try{let n=Fe(e),i=Math.max(Be(n),r+t);Zt(n,{recursive:!0}),tn(Z(n,Ve),JSON.stringify({nextAt:i}),{mode:384})}catch{}}function Be(e){try{let t=JSON.parse(en(Z(e,Ve),"utf8"));return typeof t.nextAt=="number"&&Number.isFinite(t.nextAt)?t.nextAt:0}catch{return 0}}var rn=350,sn=64*1024;async function We(e,t){let r="intake",n,i=e.slice(0,e.indexOf("--")<0?e.length:e.indexOf("--")).includes("--json");try{let s=i?{color:!1,interactive:!1,show:!1,columns:80}:oe(t.stdin,t.stdout,t.env),o=le(e);if(r=o.command,o.help||e.length===0&&!s.interactive)return t.stdout.write(i?JSON.stringify({version:t.version,help:M(t.version)})+`
|
|
117
|
+
`:M(t.version)),0;if(o.version)return t.stdout.write(i?JSON.stringify({version:t.version})+`
|
|
118
|
+
`:`physicalvalidation ${t.version}
|
|
119
|
+
`),0;o.command==="resume"&&(n=Te(t.env,o.id));let f=o.api??t.env.PHYSICALVALIDATION_API,c=me(f??n?.base);if(n&&c!==n.base)throw new a("Resume with the same API used to create this request.",2,"usage");let u=new q({base:c,fetch:t.fetch,version:t.version});if(e.length===0)return r="draft",await we(t,u,c);if(o.command==="doctor")return await be(t,u,c,i);if(o.command==="draft")return i?await ge(await Ye(o.text,t),t,u,c):await ye(o.text,t,u,c,s);if(o.command!=="intake"&&o.command!=="resume")return await je(o,t,u,s);if(!n){let d=await Ye(o.text,t);Ge(t.env);let p=an(o.email,void 0,s.interactive);s.show&&(t.stdout.write(ae(d,s)),t.stdout.write(`Enter the email code to send this brief for review under ${new URL("/terms",c).href}.
|
|
120
|
+
`));let y=(p.email??await cn(t)).toLowerCase();n=Ae(t.env,{base:c,email:y,text:d})}if(o.command==="intake"||o.resend){Ge(t.env);let d=Date.now(),p=i?{stop(){}}:R(t.stdout,re,s.color);try{await u.sendCode(n.email)}finally{p.stop()}if(te(t.env,ee(t.env)),n.stage="code_sent",delete n.auth,L(t.env,n),s.show){let y=rn-(Date.now()-d);y>0&&await dn(y)}i||t.stdout.write(`Code sent. Resume if interrupted: npx physicalvalidation resume ${n.id}
|
|
121
|
+
`)}if(n.stage==="created")throw new a("Code delivery was not confirmed. Resume with --resend to request a new code.",1,"rejected");if(n.auth&&Date.parse(n.auth.expiresAt)<=Date.now())throw new a("Verification expired. Resume with --resend to request a new code.",1,"expired");if(!n.auth){if(!s.interactive&&!o.code){let d=`npx physicalvalidation resume ${n.id} --code CODE${i?" --json":""}`;return t.stdout.write(i?JSON.stringify({status:"code_sent",submitted:!1,pendingReference:n.id,nextActor:"user",nextCommand:d})+`
|
|
122
|
+
`:`Enter the emailed code with: ${d}
|
|
123
|
+
`),0}n.auth=await un(u,n.email,o.code,t,s,i),n.stage="verified",L(t.env,n)}let l=await u.submitBrief(n.text,n.auth.token,n.id);s.show&&t.stdout.write(`
|
|
124
|
+
`),s.color&&t.stdout.write("\x1B[32m\u2713\x1B[0m "),t.stdout.write(i?JSON.stringify(l)+`
|
|
125
|
+
`:`${ne}
|
|
126
|
+
Reference: ${l.id}
|
|
127
|
+
Next: Halmos reviews your brief and clarifies missing details.
|
|
128
|
+
View your request: ${l.url}
|
|
129
|
+
`);try{Re(t.env,n.id)}catch{let d="Request received, but the private recovery file could not be removed.";t.stderr.write(i?JSON.stringify({warning:{code:"cleanup_failed",message:d}})+`
|
|
130
|
+
`:d+`
|
|
131
|
+
`)}return n=void 0,0}catch(s){(r==="intake"||r==="resume")&&s instanceof a&&s.kind==="rate_limit"&&s.retryAfterSeconds!==void 0&&te(t.env,Math.max(ee(t.env),s.retryAfterSeconds*1e3));let o=s instanceof a?s:new a("Something went wrong. Try again in a moment.",1,"unexpected");return i?t.stderr.write(JSON.stringify({error:{code:o.kind,message:o.message,retryable:["network","rate_limit","unavailable","unexpected"].includes(o.kind),...o.retryAfterSeconds!==void 0?{retryAfterSeconds:o.retryAfterSeconds}:{}},...n?{pendingReference:n.id,nextCommand:`npx physicalvalidation resume ${n.id}${o.kind==="expired"||n.stage==="created"?" --resend":n.auth?"":" --code CODE"} --json`}:{}})+`
|
|
132
|
+
`):(t.stderr.write($(o.message,x(t.stderr,t.env))),n&&t.stderr.write(`Continue this request: npx physicalvalidation resume ${n.id}
|
|
133
|
+
`)),o.exitCode}}function Ge(e){let t=Je(e);if(t<=0)return;let r=Math.max(1,Math.ceil(t/1e3)),n=r===1?"second":"seconds";throw new a(`Wait ${r} ${n} before sending another request.`,1,"rate_limit",r)}async function Ye(e,t){let r=e!==void 0?e:t.stdin.isTTY?void 0:await on(t.stdin);if(r===void 0)throw new a("Pass the request text, or pipe it on stdin. See --help for usage.",2,"usage");let n=b(r);if(!n)throw new a("The request text is empty.",2,"usage");if(n.length>4e3)throw new a(`The request is too long. Keep it under ${4e3} characters.`,2,"usage");return n}async function on(e){let t=[],r=0;for await(let n of e){let i=Buffer.isBuffer(n)?n:Buffer.from(n);if(r+=i.length,r>sn)throw new a("The request is too long.",2,"usage");t.push(i)}return Buffer.concat(t).toString("utf8")}function an(e,t,r){let n=e?.trim(),i=t?.trim();if(e!==void 0&&!S(n??""))throw new a("Enter a valid email address.",2,"usage");if(t!==void 0&&!Y(i??""))throw new a("Enter the 6-digit code from the email.",2,"usage");if(!r&&!n)throw new a("Pass --email when this is not a terminal. See --help for usage.",2,"usage");return{...n?{email:n}:{},...i?{code:i}:{}}}async function cn(e){for(let t=0;t<5;t+=1){let r=(await v(e,ie)).trim();if(S(r))return r;e.stderr.write($("Enter a valid email address.",x(e.stderr,e.env)))}throw new a("Enter a valid email address.",2,"usage")}async function un(e,t,r,n,i,s=!1){let o=r,f=0,c=0;for(;f<5;){let u=o;if(o=void 0,!u){if(!i.interactive)throw new a("Pass --code when this is not a terminal. See --help for usage.",2,"usage");u=(await v(n,se)).trim()}if(!Y(u)){c+=1;let d="Enter the 6-digit code from the email.";if(!i.interactive||c>=5)throw new a(d,2,"usage");n.stderr.write($(d,x(n.stderr,n.env)));continue}f+=1;let l=s?{stop(){}}:R(n.stdout,"Checking code...",i.color);try{return await e.authenticate(t,u)}catch(d){if(!(d instanceof a)||d.kind!=="invalid_code")throw d;if(!i.interactive||f>=5)throw new a(f>=5?"That code does not match. Too many tries. Resume with --resend to request a new code.":"That code does not match.",1,"invalid_code");let p=5-f;n.stderr.write($(`That code does not match. ${p} ${p===1?"try":"tries"} left.`,x(n.stderr,n.env)))}finally{l.stop()}}throw new a("That code does not match. Too many tries. Resume with --resend to request a new code.",1,"invalid_code")}function dn(e){return new Promise(t=>{setTimeout(t,e)})}var He=Number.parseInt(process.versions.node.split(".")[0]??"",10);(!Number.isFinite(He)||He<18)&&(process.stderr.write(`physicalvalidation needs Node.js 18 or newer.
|
|
109
134
|
`),process.exit(1));process.on("SIGINT",()=>{process.stdout.isTTY&&process.stdout.write(`\x1B[?25h
|
|
110
|
-
`),process.exit(130)});var
|
|
111
|
-
`),process.exit(1)};process.on("uncaughtException",
|
|
135
|
+
`),process.exit(130)});var ze=()=>{process.stderr.write(`Something went wrong. Try again in a moment.
|
|
136
|
+
`),process.exit(1)};process.on("uncaughtException",ze);process.on("unhandledRejection",ze);var Xe=await We(process.argv.slice(2),{stdin:process.stdin,stdout:process.stdout,stderr:process.stderr,env:process.env,fetch:globalThis.fetch,version:"0.4.0"});process.exitCode=Xe;setImmediate(()=>{process.exit(Xe)});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "physicalvalidation",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Describe an experiment, review a draft, and send a request to Physical Validation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"physical-validation",
|
|
7
7
|
"cli",
|
|
@@ -27,13 +27,9 @@
|
|
|
27
27
|
"engines": {
|
|
28
28
|
"node": ">=18"
|
|
29
29
|
},
|
|
30
|
-
"repository": {
|
|
31
|
-
"type": "git",
|
|
32
|
-
"url": "git+https://github.com/Halmoslabs/physicalvalidation.git"
|
|
33
|
-
},
|
|
34
30
|
"homepage": "https://physicalvalidation.com",
|
|
35
31
|
"bugs": {
|
|
36
|
-
"url": "https://
|
|
32
|
+
"url": "https://physicalvalidation.com/support"
|
|
37
33
|
},
|
|
38
34
|
"scripts": {
|
|
39
35
|
"build": "tsup && chmod +x dist/cli.js",
|