@mjasnikovs/pi-nop 0.1.0 → 0.1.2
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 +4 -2
- package/package.json +8 -6
- package/src/plan/track.ts +8 -10
- package/src/subagent/docs/files.ts +3 -2
- package/src/subagent/docs/locate.ts +8 -7
- package/src/subagent/docs/npm.ts +58 -18
- package/src/subagent/fetch/pdf.ts +8 -3
- package/src/subagent/platform.ts +81 -0
- package/assets/hero.png +0 -0
- package/assets/hero.svg +0 -1
package/README.md
CHANGED
|
@@ -29,7 +29,9 @@ Gemma 12B and Qwen 3.8.
|
|
|
29
29
|
pi install npm:@mjasnikovs/pi-nop
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
Needs pi 1.6.0 or later. `subagent-docs` needs `npm` and `tar`
|
|
32
|
+
Needs pi 1.6.0 or later. `subagent-docs` needs `npm` on PATH, and `tar` too outside Windows.
|
|
33
|
+
Windows 10 1803 and Server 2019 or later ship the `tar.exe` it uses. `subagent-fetch` needs
|
|
34
|
+
`pdftotext` from poppler 26.05.0 or later on PATH for PDF pages.
|
|
33
35
|
|
|
34
36
|
## Tools
|
|
35
37
|
|
|
@@ -106,7 +108,7 @@ A guard that trips kills the run and starts it again with a note. Past `restarts
|
|
|
106
108
|
|
|
107
109
|
```bash
|
|
108
110
|
bun install
|
|
109
|
-
bun test
|
|
111
|
+
bun run test
|
|
110
112
|
npm run lint
|
|
111
113
|
```
|
|
112
114
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mjasnikovs/pi-nop",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Read-only subagents for pi: repo search, web fetch, npm package docs, web search, and a /plan panel.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
"files": [
|
|
37
37
|
"src",
|
|
38
38
|
"README.md",
|
|
39
|
-
"LICENSE"
|
|
40
|
-
"assets"
|
|
39
|
+
"LICENSE"
|
|
41
40
|
],
|
|
42
41
|
"scripts": {
|
|
43
|
-
"test": "bun test",
|
|
44
|
-
"lint": "prettier --log-level warn --write
|
|
45
|
-
"lint:check": "prettier --check
|
|
42
|
+
"test": "bun test --isolate",
|
|
43
|
+
"lint": "prettier --log-level warn --write \"{src,test,eval}/**/*.ts\" && eslint --fix . && tsc --noEmit",
|
|
44
|
+
"lint:check": "prettier --check \"{src,test,eval}/**/*.ts\" && eslint . --max-warnings 0 && tsc --noEmit",
|
|
46
45
|
"eval": "bun eval/fetch.eval.ts",
|
|
47
46
|
"eval:search": "bun eval/search.eval.ts",
|
|
48
47
|
"eval:docs": "bun eval/docs.eval.ts"
|
|
49
48
|
},
|
|
50
49
|
"dependencies": {
|
|
51
50
|
"@mozilla/readability": "0.6.0",
|
|
51
|
+
"cross-spawn": "7.0.6",
|
|
52
52
|
"linkedom": "0.18.13",
|
|
53
53
|
"turndown": "7.2.4",
|
|
54
54
|
"turndown-plugin-gfm": "1.0.2",
|
|
@@ -62,10 +62,12 @@
|
|
|
62
62
|
"@eslint/js": "10.0.1",
|
|
63
63
|
"@stylistic/eslint-plugin": "5.10.0",
|
|
64
64
|
"@types/bun": "1.4.2",
|
|
65
|
+
"@types/cross-spawn": "6.0.6",
|
|
65
66
|
"@types/turndown": "5.0.6",
|
|
66
67
|
"eslint": "10.11.0",
|
|
67
68
|
"eslint-config-prettier": "10.1.8",
|
|
68
69
|
"globals": "17.12.0",
|
|
70
|
+
"jiti": "2.7.0",
|
|
69
71
|
"prettier": "3.9.8",
|
|
70
72
|
"typebox": "1.3.27",
|
|
71
73
|
"typescript-eslint": "8.70.0"
|
package/src/plan/track.ts
CHANGED
|
@@ -39,15 +39,13 @@ const writes = (entries: SessionEntry[]): string[] => [
|
|
|
39
39
|
// pi exports no path resolver. Its read tool hands the resolved path to access.
|
|
40
40
|
const resolved = async (cwd: string, path: string): Promise<string> => {
|
|
41
41
|
const found = {path}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
})
|
|
42
|
+
|
|
43
|
+
const stop = (at: string): Promise<never> => {
|
|
44
|
+
found.path = at
|
|
45
|
+
return Promise.reject(new Error(at))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const read = createReadTool(cwd, {operations: {access: stop, readFile: stop}})
|
|
51
49
|
await read.execute(resolveLabel, {path}, undefined).catch(() => undefined)
|
|
52
50
|
return found.path
|
|
53
51
|
}
|
|
@@ -117,7 +115,7 @@ const progress = async (
|
|
|
117
115
|
),
|
|
118
116
|
outside: written
|
|
119
117
|
.filter(path => !wanted.some(row => holds(row, path)))
|
|
120
|
-
.map(path => relative(cwd, path)),
|
|
118
|
+
.map(path => relative(cwd, path).split(sep).join('/')),
|
|
121
119
|
written: wanted.filter(done).length,
|
|
122
120
|
total: wanted.length
|
|
123
121
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {readdirSync, readFileSync} from 'node:fs'
|
|
2
|
-
import {join, relative} from 'node:path'
|
|
2
|
+
import {join, relative, sep} from 'node:path'
|
|
3
3
|
|
|
4
4
|
import type {TextSource} from '../answer'
|
|
5
5
|
import {packages} from './locate'
|
|
@@ -76,7 +76,8 @@ const readAll = (pkg: Package, paths: string[]): CorpusFile[] => {
|
|
|
76
76
|
// What the model is handed, and what its quotes are checked against.
|
|
77
77
|
const corpusOf = (located: Located): Corpus => {
|
|
78
78
|
const entry = located.entry
|
|
79
|
-
const entryPath =
|
|
79
|
+
const entryPath =
|
|
80
|
+
entry === undefined ? undefined : relative(located.pkg.dir, entry).split(sep).join('/')
|
|
80
81
|
const keepFolder = entryPath === undefined ? undefined : majorFolder(entryPath)
|
|
81
82
|
const files = packages(located).flatMap(pkg => readAll(pkg, packageFiles(pkg, keepFolder)))
|
|
82
83
|
const declared = files.some(file => isDeclaration(file.label))
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {existsSync
|
|
1
|
+
import {existsSync} from 'node:fs'
|
|
2
2
|
import {isBuiltin} from 'node:module'
|
|
3
3
|
import {dirname, join, sep} from 'node:path'
|
|
4
4
|
import ts from 'typescript'
|
|
5
5
|
|
|
6
|
+
import {realpath} from '../platform'
|
|
6
7
|
import {isNamed, readManifest} from './manifest'
|
|
7
8
|
import type {Named} from './manifest'
|
|
8
9
|
import {download, packTarget, resolveVersion, versionPattern} from './npm'
|
|
@@ -41,7 +42,7 @@ type Project = {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
const resolveOptions: ts.CompilerOptions = {moduleResolution: ts.ModuleResolutionKind.Bundler}
|
|
44
|
-
const packageNamePattern = /^(@[
|
|
45
|
+
const packageNamePattern = /^(@[^/\\\s@:]+\/)?[^./\\\s@:-][^/\\\s@:]*$/
|
|
45
46
|
const runtimePrefix = /^(node|bun):/
|
|
46
47
|
|
|
47
48
|
const packageName = (module: string): string => {
|
|
@@ -56,7 +57,7 @@ const typesModule = (module: string): string | undefined => {
|
|
|
56
57
|
|
|
57
58
|
// A subpath segment of `.` or `..` would resolve into another package.
|
|
58
59
|
const assertPackage = (module: string): void => {
|
|
59
|
-
const dotted = module.split(
|
|
60
|
+
const dotted = module.split(/[\\/]/).some(segment => segment === '.' || segment === '..')
|
|
60
61
|
|
|
61
62
|
if (dotted || !packageNamePattern.test(packageName(module)))
|
|
62
63
|
throw new Error(LocateErrors.BadName + module)
|
|
@@ -96,7 +97,7 @@ const projectOf = (name: string, cwd: string): Project => {
|
|
|
96
97
|
|
|
97
98
|
const findPackageDir = (name: string, cwd: string): string | undefined => {
|
|
98
99
|
const dir = findUp(cwd, here => hasManifest(join(here, 'node_modules', name)))
|
|
99
|
-
return dir === undefined ? undefined :
|
|
100
|
+
return dir === undefined ? undefined : realpath(join(dir, 'node_modules', name))
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
const packageRootOf = (file: string, name: string): string => {
|
|
@@ -121,7 +122,7 @@ const stubTargets = (entry: string): Package[] => {
|
|
|
121
122
|
const name = resolved?.packageId?.name
|
|
122
123
|
|
|
123
124
|
if (name === undefined || resolved?.resolvedFileName === undefined) return []
|
|
124
|
-
return [readPackage(packageRootOf(
|
|
125
|
+
return [readPackage(packageRootOf(realpath(resolved.resolvedFileName), name))]
|
|
125
126
|
})
|
|
126
127
|
}
|
|
127
128
|
|
|
@@ -135,7 +136,7 @@ const resolveEntry = (module: string, cwd: string): ts.ResolvedModuleFull | unde
|
|
|
135
136
|
).resolvedModule
|
|
136
137
|
|
|
137
138
|
if (resolved === undefined) return undefined
|
|
138
|
-
return {...resolved, resolvedFileName:
|
|
139
|
+
return {...resolved, resolvedFileName: realpath(resolved.resolvedFileName)}
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
// The package a resolved entry belongs to: the asked one, or @types/x when that answered.
|
|
@@ -190,7 +191,7 @@ const locateIn = (module: string, cwd: string): Found | undefined =>
|
|
|
190
191
|
|
|
191
192
|
// A tree unpacked into the cache must not pick up a stray @types from an ancestor node_modules.
|
|
192
193
|
const locateDownloaded = (module: string, root: string): Found | undefined => {
|
|
193
|
-
const fence =
|
|
194
|
+
const fence = realpath(root) + sep
|
|
194
195
|
const resolved = resolveEntry(module, root)
|
|
195
196
|
const inside = resolved?.resolvedFileName.startsWith(fence) === true
|
|
196
197
|
const found = packageAt(module, root, inside ? resolved : undefined)
|
package/src/subagent/docs/npm.ts
CHANGED
|
@@ -1,16 +1,53 @@
|
|
|
1
|
-
import {execFile} from 'node:child_process'
|
|
2
1
|
import {existsSync, mkdirSync, mkdtempSync, renameSync, rmSync} from 'node:fs'
|
|
3
2
|
import {join} from 'node:path'
|
|
4
|
-
import {promisify} from 'node:util'
|
|
5
3
|
import {getAgentDir} from '@earendil-works/pi-coding-agent'
|
|
6
4
|
import {Type} from 'typebox'
|
|
7
5
|
import Value from 'typebox/value'
|
|
6
|
+
import spawn from 'cross-spawn'
|
|
8
7
|
|
|
9
8
|
import {describe} from '../describe'
|
|
10
9
|
import {unlessAborted} from '../subagent'
|
|
11
10
|
import {readManifest} from './manifest'
|
|
11
|
+
import {childEnv, missing, onPath, stop, tar} from '../platform'
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
// A silent npm prints its --json error on stdout, and any stderr line must not hide it.
|
|
14
|
+
const said = (...streams: string[]): string => streams.filter(text => text !== '').join('\n')
|
|
15
|
+
|
|
16
|
+
// Not execFile: it cannot start Windows' npm.cmd. cross-spawn escapes each argument for cmd.exe.
|
|
17
|
+
const run = (
|
|
18
|
+
command: string,
|
|
19
|
+
args: string[],
|
|
20
|
+
cwd?: string,
|
|
21
|
+
signal?: AbortSignal
|
|
22
|
+
): Promise<string> =>
|
|
23
|
+
new Promise<string>((resolve, reject) => {
|
|
24
|
+
signal?.throwIfAborted()
|
|
25
|
+
const child = spawn(onPath(command), args, {
|
|
26
|
+
cwd,
|
|
27
|
+
env: childEnv(),
|
|
28
|
+
stdio: ['ignore', 'pipe', 'pipe']
|
|
29
|
+
})
|
|
30
|
+
const abort = () => stop(child)
|
|
31
|
+
let stdout = ''
|
|
32
|
+
let stderr = ''
|
|
33
|
+
const settle = () => signal?.removeEventListener('abort', abort)
|
|
34
|
+
signal?.addEventListener('abort', abort, {once: true})
|
|
35
|
+
child.stdout?.setEncoding('utf8').on('data', (chunk: string) => (stdout += chunk))
|
|
36
|
+
child.stderr?.setEncoding('utf8').on('data', (chunk: string) => (stderr += chunk))
|
|
37
|
+
// A failed spawn still ends in close, so settle there covers it.
|
|
38
|
+
child.on('error', reject)
|
|
39
|
+
child.on('close', (code, killedBy) => {
|
|
40
|
+
settle()
|
|
41
|
+
if (code === 0) return resolve(stdout)
|
|
42
|
+
reject(
|
|
43
|
+
new Error(
|
|
44
|
+
said(stderr, stdout) || `${command} ended with ${String(killedBy ?? code)}`
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
})
|
|
48
|
+
}).catch((error: unknown) => {
|
|
49
|
+
throw missing(command, error, cwd)
|
|
50
|
+
})
|
|
14
51
|
|
|
15
52
|
enum NpmErrors {
|
|
16
53
|
Missing = 'not on npm: ',
|
|
@@ -32,16 +69,17 @@ type Target = {
|
|
|
32
69
|
type View = {
|
|
33
70
|
version: string
|
|
34
71
|
deprecated?: string
|
|
35
|
-
latest
|
|
72
|
+
latest?: string
|
|
36
73
|
}
|
|
37
74
|
|
|
38
75
|
// npm's codes for "no such package or version". Anything else is npm or the network failing.
|
|
39
76
|
const missingCodes = ['E404', 'ETARGET', 'EINVALIDTAGNAME', 'EINVALIDPACKAGENAME']
|
|
40
77
|
|
|
41
|
-
// npm 10 prints `npm error code X
|
|
78
|
+
// npm 10 prints `npm error code X`, npm 9 `npm ERR! code X`. A silent npm prints only its --json error.
|
|
42
79
|
const npmCode = (error: unknown): string => {
|
|
43
80
|
const text = describe(error)
|
|
44
|
-
|
|
81
|
+
const found = /^npm (?:error|ERR!) code (\S+)|"code": "([^"]+)"/m.exec(text)
|
|
82
|
+
return found?.[1] ?? found?.[2] ?? text
|
|
45
83
|
}
|
|
46
84
|
|
|
47
85
|
// npm runs in the project, so .npmrc scopes, mirrors and auth hold, the same as an install would.
|
|
@@ -51,21 +89,20 @@ const npm = async (
|
|
|
51
89
|
cwd: string,
|
|
52
90
|
signal?: AbortSignal
|
|
53
91
|
): Promise<string> =>
|
|
54
|
-
run('npm', args,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
throw new Error(`${lead}${target.name}@${target.spec} (${code})`, {cause: error})
|
|
61
|
-
})
|
|
92
|
+
run('npm', args, cwd, signal).catch((error: unknown) => {
|
|
93
|
+
unlessAborted(signal, error)
|
|
94
|
+
const code = npmCode(error)
|
|
95
|
+
const lead = missingCodes.includes(code) ? NpmErrors.Missing : NpmErrors.Failed
|
|
96
|
+
throw new Error(`${lead}${target.name}@${target.spec} (${code})`, {cause: error})
|
|
97
|
+
})
|
|
62
98
|
|
|
63
99
|
const viewed = Type.Object({
|
|
64
100
|
version: Type.String(),
|
|
65
101
|
deprecated: Type.Optional(Type.String()),
|
|
66
|
-
'dist-tags.latest': Type.String()
|
|
102
|
+
'dist-tags.latest': Type.Optional(Type.String())
|
|
67
103
|
})
|
|
68
104
|
const viewedShape = Type.Union([viewed, Type.Array(viewed)])
|
|
105
|
+
const packed = Type.Array(Type.Object({filename: Type.String()}))
|
|
69
106
|
|
|
70
107
|
// `name` and `version` always exist, so the answer is an object, or an array of them for a range.
|
|
71
108
|
const view = async (target: Target, cwd: string, signal?: AbortSignal): Promise<View> => {
|
|
@@ -76,7 +113,8 @@ const view = async (target: Target, cwd: string, signal?: AbortSignal): Promise<
|
|
|
76
113
|
cwd,
|
|
77
114
|
signal
|
|
78
115
|
)
|
|
79
|
-
|
|
116
|
+
// npm prints nothing, with exit 0, for a package with no latest tag.
|
|
117
|
+
const parsed = stdout.trim() === '' ? [] : Value.Parse(viewedShape, JSON.parse(stdout))
|
|
80
118
|
const last = Array.isArray(parsed) ? parsed.at(-1) : parsed
|
|
81
119
|
|
|
82
120
|
if (last === undefined)
|
|
@@ -140,6 +178,8 @@ const unpack = async (
|
|
|
140
178
|
target,
|
|
141
179
|
[
|
|
142
180
|
'pack',
|
|
181
|
+
// A silent npm prints its error code only with --json.
|
|
182
|
+
'--json',
|
|
143
183
|
'--ignore-scripts',
|
|
144
184
|
'--pack-destination',
|
|
145
185
|
scratch,
|
|
@@ -149,10 +189,10 @@ const unpack = async (
|
|
|
149
189
|
cwd,
|
|
150
190
|
signal
|
|
151
191
|
)
|
|
152
|
-
const tarball = join(scratch,
|
|
192
|
+
const tarball = join(scratch, Value.Parse(packed, JSON.parse(stdout))[0]?.filename ?? '')
|
|
153
193
|
const dir = join(scratch, 'tree', 'node_modules', asked)
|
|
154
194
|
mkdirSync(dir, {recursive: true})
|
|
155
|
-
await run(
|
|
195
|
+
await run(tar, ['-xzf', tarball, '-C', dir, '--strip-components=1'], undefined, signal).catch(
|
|
156
196
|
(error: unknown) => {
|
|
157
197
|
unlessAborted(signal, error)
|
|
158
198
|
throw error
|
|
@@ -3,6 +3,7 @@ import {spawn} from 'node:child_process'
|
|
|
3
3
|
import {normalize} from '../answer'
|
|
4
4
|
import type {Source} from '../answer'
|
|
5
5
|
import {createLineReader} from '../guards/lines'
|
|
6
|
+
import {onPath} from '../platform'
|
|
6
7
|
import {FetchErrors} from './errors'
|
|
7
8
|
|
|
8
9
|
// `soft` keeps a hyphen that ends a line: the default joins `VX-` / `4471` into `VX4471`.
|
|
@@ -29,8 +30,9 @@ const exitFailure = (
|
|
|
29
30
|
|
|
30
31
|
// Not execFile: its maxBuffer caps stderr too, and a damaged PDF can warn past the page cap.
|
|
31
32
|
const convert = (bytes: Uint8Array, maxBuffer: number, signal?: AbortSignal): Promise<string> =>
|
|
32
|
-
new Promise((resolve, reject) => {
|
|
33
|
-
|
|
33
|
+
new Promise<string>((resolve, reject) => {
|
|
34
|
+
// A plain spawn runs only an .exe or .com; a .cmd needs cmd.exe.
|
|
35
|
+
const child = spawn(onPath('pdftotext', '.EXE;.COM'), args, {signal})
|
|
34
36
|
const chunks: Buffer[] = []
|
|
35
37
|
const lines = createLineReader()
|
|
36
38
|
let size = 0
|
|
@@ -54,7 +56,7 @@ const convert = (bytes: Uint8Array, maxBuffer: number, signal?: AbortSignal): Pr
|
|
|
54
56
|
})
|
|
55
57
|
child.stderr.setEncoding('utf8')
|
|
56
58
|
child.stderr.on('data', hear)
|
|
57
|
-
child.on('error',
|
|
59
|
+
child.on('error', reject)
|
|
58
60
|
child.on('close', (code, killedBy) => {
|
|
59
61
|
if (code === 0) return resolve(Buffer.concat(chunks).toString())
|
|
60
62
|
hear('\n')
|
|
@@ -63,6 +65,9 @@ const convert = (bytes: Uint8Array, maxBuffer: number, signal?: AbortSignal): Pr
|
|
|
63
65
|
// A child that exits or is aborted before reading its input closes stdin; the EPIPE kills pi.
|
|
64
66
|
child.stdin.on('error', () => undefined)
|
|
65
67
|
child.stdin.end(bytes)
|
|
68
|
+
}).catch((error: Error & {code?: string}) => {
|
|
69
|
+
// Our own failures carry no code; a failed spawn, or onPath finding nothing, does.
|
|
70
|
+
throw error.code === undefined ? error : startFailure(error)
|
|
66
71
|
})
|
|
67
72
|
|
|
68
73
|
const pageBreak = '\f'
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {spawn} from 'node:child_process'
|
|
2
|
+
import type {ChildProcess} from 'node:child_process'
|
|
3
|
+
import {existsSync, realpathSync, statSync} from 'node:fs'
|
|
4
|
+
import {delimiter, isAbsolute, join} from 'node:path'
|
|
5
|
+
|
|
6
|
+
// pi falls back the same way when SystemRoot is unset.
|
|
7
|
+
const system32 = join(process.env.SystemRoot ?? 'C:\\Windows', 'System32')
|
|
8
|
+
// Git for Windows puts GNU tar on PATH, which reads C:\ as a remote host. System32 has bsdtar.
|
|
9
|
+
const tar = process.platform === 'win32' ? join(system32, 'tar.exe') : 'tar'
|
|
10
|
+
const notFound = (command: string): string => `${command} was not found`
|
|
11
|
+
|
|
12
|
+
// A spawn in a folder that is gone fails with ENOENT too, and that is not a missing command.
|
|
13
|
+
const missing = (command: string, error: unknown, cwd?: string): unknown =>
|
|
14
|
+
isNotFound(error) && (cwd === undefined || existsSync(cwd)) ?
|
|
15
|
+
new Error(notFound(command))
|
|
16
|
+
: error
|
|
17
|
+
|
|
18
|
+
const isNotFound = (error: unknown): boolean =>
|
|
19
|
+
error instanceof Error && 'code' in error && error.code === 'ENOENT'
|
|
20
|
+
|
|
21
|
+
// An offline share or a folder the user may not list throws; Windows skips it, so this does too.
|
|
22
|
+
const isFile = (path: string): boolean => {
|
|
23
|
+
try {
|
|
24
|
+
return statSync(path, {throwIfNoEntry: false})?.isFile() === true
|
|
25
|
+
} catch {
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// On Windows which, libuv and cmd.exe search the current folder first, so a repo's own copy would run.
|
|
31
|
+
const onPath = (name: string, runnable = process.env.PATHEXT ?? '.COM;.EXE;.BAT;.CMD'): string => {
|
|
32
|
+
if (process.platform !== 'win32' || isAbsolute(name)) return name
|
|
33
|
+
|
|
34
|
+
// Windows allows a quoted PATH entry, and which reads it the same way.
|
|
35
|
+
const dirs = (process.env.PATH ?? '')
|
|
36
|
+
.split(delimiter)
|
|
37
|
+
.map(dir => dir.replace(/^"(.*)"$/, '$1'))
|
|
38
|
+
.filter(dir => isAbsolute(dir))
|
|
39
|
+
// An empty PATHEXT entry would match Node's extensionless npm shell script.
|
|
40
|
+
const extensions = runnable.split(delimiter).filter(extension => extension !== '')
|
|
41
|
+
const found = dirs
|
|
42
|
+
.flatMap(dir => extensions.map(extension => join(dir, name + extension)))
|
|
43
|
+
.find(isFile)
|
|
44
|
+
|
|
45
|
+
if (found === undefined) throw Object.assign(new Error(notFound(name)), {code: 'ENOENT'})
|
|
46
|
+
return found
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// cmd.exe looks for a bare command, like the node an upgraded npm.cmd calls, in the current folder first.
|
|
50
|
+
const childEnv = (): NodeJS.ProcessEnv => ({
|
|
51
|
+
...process.env,
|
|
52
|
+
NoDefaultCurrentDirectoryInExePath: '1'
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// cross-spawn runs npm.cmd under cmd.exe, and killing cmd.exe alone leaves npm running.
|
|
56
|
+
const stop = (child: ChildProcess): void => {
|
|
57
|
+
// An exited child's PID may already belong to another process tree.
|
|
58
|
+
if (child.exitCode !== null || child.signalCode !== null) return
|
|
59
|
+
|
|
60
|
+
if (process.platform !== 'win32' || child.pid === undefined) {
|
|
61
|
+
child.kill()
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
spawn(join(system32, 'taskkill.exe'), ['/F', '/T', '/PID', String(child.pid)], {
|
|
66
|
+
stdio: 'ignore'
|
|
67
|
+
})
|
|
68
|
+
.once('error', () => child.kill())
|
|
69
|
+
.once('exit', code => code === 0 || child.kill())
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Native, as TypeScript resolves on Windows, falling back where native throws, as TypeScript does.
|
|
73
|
+
const realpath = (path: string): string => {
|
|
74
|
+
try {
|
|
75
|
+
return realpathSync.native(path)
|
|
76
|
+
} catch {
|
|
77
|
+
return realpathSync(path)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export {childEnv, missing, onPath, realpath, stop, tar}
|
package/assets/hero.png
DELETED
|
Binary file
|
package/assets/hero.svg
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 600" width="960" height="600" role="img" aria-label="pi-nop. Your daily driver. Minimal, read-only, guarded. Files, a web page and npm docs go into a guarded subagent. One answer goes back to pi."><rect width="960" height="600" fill="#111312"/><text x="54" y="112" font-family="ui-monospace, Menlo, Consolas, 'DejaVu Sans Mono', monospace" font-size="76" font-weight="700" fill="#e9ecea" letter-spacing="-1">pi-nop</text><text x="58" y="162" font-family="ui-monospace, Menlo, Consolas, 'DejaVu Sans Mono', monospace" font-size="28" fill="#8a918e">Your daily driver.</text><text x="58" y="198" font-family="ui-monospace, Menlo, Consolas, 'DejaVu Sans Mono', monospace" font-size="28" fill="#8a918e">Minimal, read-only, guarded.</text><g transform="translate(0,50)"><rect x="70" y="250" width="150" height="100" fill="none" stroke="#e9ecea" stroke-width="2.5"/><text x="145" y="312" text-anchor="middle" font-family="ui-monospace, Menlo, Consolas, 'DejaVu Sans Mono', monospace" font-size="34" font-weight="700" fill="#e9ecea">pi</text><rect x="380" y="250" width="200" height="100" fill="none" stroke="#e9ecea" stroke-width="2.5"/><text x="480" y="308" text-anchor="middle" font-family="ui-monospace, Menlo, Consolas, 'DejaVu Sans Mono', monospace" font-size="24" font-weight="700" fill="#e9ecea">subagent</text><rect x="364" y="234" width="232" height="132" fill="none" stroke="#8a918e" stroke-width="1.6" stroke-dasharray="6 5"/><g transform="translate(465.0,219.0) scale(1.25)"><path d="M12 2 4 5v6c0 5 3.4 9.4 8 11 4.6-1.6 8-6 8-11V5z" fill="#111312" stroke="#e9ecea" stroke-width="1.60" stroke-linejoin="round"/><path d="m8.5 12 2.5 2.5 4.5-5" fill="none" stroke="#e9ecea" stroke-width="1.60" stroke-linecap="round" stroke-linejoin="round"/></g><rect x="750" y="110" width="150" height="90" fill="none" stroke="#e9ecea" stroke-width="2"/><path d="M764 128H849" stroke="#8a918e" stroke-width="3"/><path d="M764 142H825" stroke="#8a918e" stroke-width="3"/><path d="M764 156H862" stroke="#8a918e" stroke-width="3"/><path d="M764 170H813" stroke="#8a918e" stroke-width="3"/><path d="M764 184H843" stroke="#8a918e" stroke-width="3"/><text x="825.0" y="226" text-anchor="middle" font-family="ui-monospace, Menlo, Consolas, 'DejaVu Sans Mono', monospace" font-size="17" font-weight="400" fill="#8a918e">files</text><path d="M750 120.0C640 120.0 666 262.0 596 262.0" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 128.8C640 128.8 666 264.8 596 264.8" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 137.5C640 137.5 666 267.5 596 267.5" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 146.2C640 146.2 666 270.2 596 270.2" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 155.0C640 155.0 666 273.0 596 273.0" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 163.8C640 163.8 666 275.8 596 275.8" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 172.5C640 172.5 666 278.5 596 278.5" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 181.2C640 181.2 666 281.2 596 281.2" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 190.0C640 190.0 666 284.0 596 284.0" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><rect x="750" y="255" width="150" height="90" fill="none" stroke="#e9ecea" stroke-width="2"/><path d="M750 275H900" stroke="#e9ecea" stroke-width="2"/><circle cx="762" cy="265" r="2.5" fill="#e9ecea"/><circle cx="772" cy="265" r="2.5" fill="#e9ecea"/><circle cx="782" cy="265" r="2.5" fill="#e9ecea"/><path d="M764 291H862" stroke="#8a918e" stroke-width="3"/><path d="M764 304H837" stroke="#8a918e" stroke-width="3"/><path d="M764 317H856" stroke="#8a918e" stroke-width="3"/><path d="M764 330H819" stroke="#8a918e" stroke-width="3"/><text x="825.0" y="371" text-anchor="middle" font-family="ui-monospace, Menlo, Consolas, 'DejaVu Sans Mono', monospace" font-size="17" font-weight="400" fill="#8a918e">web page</text><path d="M750 265.0C640 265.0 666 288.0 596 288.0" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 273.8C640 273.8 666 290.8 596 290.8" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 282.5C640 282.5 666 293.5 596 293.5" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 291.2C640 291.2 666 296.2 596 296.2" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 300.0C640 300.0 666 299.0 596 299.0" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 308.8C640 308.8 666 301.8 596 301.8" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 317.5C640 317.5 666 304.5 596 304.5" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 326.2C640 326.2 666 307.2 596 307.2" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 335.0C640 335.0 666 310.0 596 310.0" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><rect x="750" y="400" width="150" height="90" fill="none" stroke="#e9ecea" stroke-width="2"/><path d="M825.0 421.0L849.0 433.0V457.0L825.0 469.0L801.0 457.0V433.0ZM801.0 433.0L825.0 445.0L849.0 433.0M825.0 445.0V469.0" fill="none" stroke="#e9ecea" stroke-width="2" stroke-linejoin="round"/><text x="825.0" y="516" text-anchor="middle" font-family="ui-monospace, Menlo, Consolas, 'DejaVu Sans Mono', monospace" font-size="17" font-weight="400" fill="#8a918e">npm docs</text><path d="M750 410.0C640 410.0 666 314.0 596 314.0" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 418.8C640 418.8 666 316.8 596 316.8" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 427.5C640 427.5 666 319.5 596 319.5" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 436.2C640 436.2 666 322.2 596 322.2" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 445.0C640 445.0 666 325.0 596 325.0" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 453.8C640 453.8 666 327.8 596 327.8" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 462.5C640 462.5 666 330.5 596 330.5" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 471.2C640 471.2 666 333.2 596 333.2" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M750 480.0C640 480.0 666 336.0 596 336.0" fill="none" stroke="#e9ecea" stroke-width="1.3" opacity=".45"/><path d="M354 300H231.5" stroke="#ff8a3d" stroke-width="3"/><path d="M243 290.5L230 300L243 309.5" fill="none" stroke="#ff8a3d" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/><text x="292.0" y="286" text-anchor="middle" font-family="ui-monospace, Menlo, Consolas, 'DejaVu Sans Mono', monospace" font-size="17" font-weight="400" fill="#ff8a3d">answer</text></g></svg>
|