@mjasnikovs/pi-nop 0.1.0 → 0.1.3
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 +7 -3
- package/package.json +8 -6
- package/src/config/command.ts +46 -4
- package/src/config/config.ts +86 -11
- package/src/plan/track.ts +8 -10
- package/src/search/search.ts +17 -7
- package/src/subagent/answer.ts +41 -16
- 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
|
|
|
@@ -83,7 +85,9 @@ and 1 file written outside the plan. Run `/plan` again to see which steps are do
|
|
|
83
85
|
|
|
84
86
|
`model` is `provider/id`, as pi lists it. `thinkingLevel` is `off`, `minimal`, `low`, `medium`,
|
|
85
87
|
`high`, `xhigh` or `max`. One unknown key or bad value makes pi-nop ignore the whole file, with a
|
|
86
|
-
warning
|
|
88
|
+
warning that names it. The first `/nop-config` change then saves the old file as
|
|
89
|
+
`pi-nop.json.broken`, or `.broken-2` and on when older copies are there. A model pi no longer
|
|
90
|
+
lists falls back to pi's current one, with a warning.
|
|
87
91
|
|
|
88
92
|
`PI_NOP_SEARCH_ENGINE` overrides the engine. `PI_NOP_SEARCH_ENDPOINT` overrides its URL.
|
|
89
93
|
|
|
@@ -106,7 +110,7 @@ A guard that trips kills the run and starts it again with a note. Past `restarts
|
|
|
106
110
|
|
|
107
111
|
```bash
|
|
108
112
|
bun install
|
|
109
|
-
bun test
|
|
113
|
+
bun run test
|
|
110
114
|
npm run lint
|
|
111
115
|
```
|
|
112
116
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mjasnikovs/pi-nop",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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/config/command.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {SettingItem} from '@earendil-works/pi-tui'
|
|
|
4
4
|
import {SelectList, SettingsList} from '@earendil-works/pi-tui'
|
|
5
5
|
import {readFileSync} from 'node:fs'
|
|
6
6
|
|
|
7
|
+
import {describe} from '../subagent/describe'
|
|
7
8
|
import {boxed} from './box'
|
|
8
9
|
import {
|
|
9
10
|
applyChange,
|
|
@@ -11,7 +12,8 @@ import {
|
|
|
11
12
|
modelOf,
|
|
12
13
|
modelSpec,
|
|
13
14
|
read,
|
|
14
|
-
|
|
15
|
+
loadSafely,
|
|
16
|
+
setAsideBroken,
|
|
15
17
|
saveConfig,
|
|
16
18
|
settings,
|
|
17
19
|
tools
|
|
@@ -54,6 +56,9 @@ const row = (config: NopConfig, models: string[], setting: Setting): SettingItem
|
|
|
54
56
|
: {values: offered(setting)})
|
|
55
57
|
})
|
|
56
58
|
|
|
59
|
+
const savedValue = (config: NopConfig, id: string): string =>
|
|
60
|
+
String(read(config, settings.find(setting => setting.id === id) as Setting))
|
|
61
|
+
|
|
57
62
|
const sections = [...new Set(settings.map(setting => setting.section))]
|
|
58
63
|
const same = (text: string): string => text
|
|
59
64
|
|
|
@@ -76,6 +81,30 @@ const dropStaleModels = (config: NopConfig, models: string[]): NopConfig =>
|
|
|
76
81
|
: applyChange(fixed, modelOf(tool).id, inherit)
|
|
77
82
|
}, config)
|
|
78
83
|
|
|
84
|
+
// Another editor may have changed the file since the panel opened.
|
|
85
|
+
const synced = (
|
|
86
|
+
ctx: ExtensionCommandContext,
|
|
87
|
+
config: NopConfig,
|
|
88
|
+
available: string[]
|
|
89
|
+
): NopConfig => {
|
|
90
|
+
const now = loadSafely()
|
|
91
|
+
|
|
92
|
+
if (now.broken) {
|
|
93
|
+
ctx.ui.notify(`Saved the broken pi-nop config as ${setAsideBroken()}`, 'info')
|
|
94
|
+
return config
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const fresh = dropStaleModels(now.config, available)
|
|
98
|
+
|
|
99
|
+
if (JSON.stringify(fresh) !== JSON.stringify(config))
|
|
100
|
+
ctx.ui.notify(
|
|
101
|
+
'pi-nop config changed while the panel was open; this change went into the new one. '
|
|
102
|
+
+ 'Reopen /nop-config to see every value.',
|
|
103
|
+
'info'
|
|
104
|
+
)
|
|
105
|
+
return fresh
|
|
106
|
+
}
|
|
107
|
+
|
|
79
108
|
const availableModels = (ctx: ExtensionCommandContext): string[] =>
|
|
80
109
|
ctx.modelRegistry.getAvailable().map(modelSpec)
|
|
81
110
|
|
|
@@ -94,7 +123,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
94
123
|
handler: async (_args, ctx) => {
|
|
95
124
|
const available = availableModels(ctx)
|
|
96
125
|
const models = offeredModels(ctx, available)
|
|
97
|
-
|
|
126
|
+
const fix =
|
|
127
|
+
ctx.mode === 'tui' ?
|
|
128
|
+
'Change a setting here to copy it aside and start fresh.'
|
|
129
|
+
: undefined
|
|
130
|
+
let config = dropStaleModels(loadSafely(ctx, fix).config, available)
|
|
98
131
|
|
|
99
132
|
if (ctx.mode !== 'tui') {
|
|
100
133
|
ctx.ui.notify(
|
|
@@ -116,8 +149,17 @@ export default function (pi: ExtensionAPI) {
|
|
|
116
149
|
Math.min(items.length, maxVisible),
|
|
117
150
|
getSettingsListTheme(),
|
|
118
151
|
(id, value) => {
|
|
119
|
-
|
|
120
|
-
|
|
152
|
+
try {
|
|
153
|
+
const next = applyChange(synced(ctx, config, available), id, value)
|
|
154
|
+
saveConfig(next)
|
|
155
|
+
config = next
|
|
156
|
+
} catch (failure) {
|
|
157
|
+
list.updateValue(id, savedValue(config, id))
|
|
158
|
+
ctx.ui.notify(
|
|
159
|
+
`pi-nop config not saved: ${describe(failure)}`,
|
|
160
|
+
'error'
|
|
161
|
+
)
|
|
162
|
+
}
|
|
121
163
|
},
|
|
122
164
|
() => done(undefined)
|
|
123
165
|
)
|
package/src/config/config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {existsSync, mkdirSync, readFileSync, writeFileSync} from 'node:fs'
|
|
1
|
+
import {copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync} from 'node:fs'
|
|
2
2
|
import {join} from 'node:path'
|
|
3
3
|
import type {ExtensionContext, ModelRegistry} from '@earendil-works/pi-coding-agent'
|
|
4
4
|
import {getAgentDir} from '@earendil-works/pi-coding-agent'
|
|
@@ -23,8 +23,9 @@ const thinkingLevels = [
|
|
|
23
23
|
const inherit = 'inherit'
|
|
24
24
|
const unlimited = 'unlimited'
|
|
25
25
|
const off = 'off'
|
|
26
|
-
const brokenConfig =
|
|
27
|
-
|
|
26
|
+
const brokenConfig = (path: string, reason: string, fix: string): string =>
|
|
27
|
+
`pi-nop config ${path} is broken: ${reason}. Every pi-nop setting uses its default until it is `
|
|
28
|
+
+ `fixed. ${fix}`
|
|
28
29
|
const missingModel = (spec: string): string =>
|
|
29
30
|
`pi-nop model ${spec} is not available, using the host model. Run /nop-config to pick another.`
|
|
30
31
|
|
|
@@ -157,24 +158,97 @@ const configSchema = fileSchema()
|
|
|
157
158
|
type NopConfig = Static<typeof configSchema>
|
|
158
159
|
|
|
159
160
|
const configPath = (): string => join(getAgentDir(), configFile)
|
|
161
|
+
// Notepad and some Windows editors start the file with a byte order mark, which JSON refuses.
|
|
162
|
+
const configText = (): string => readFileSync(configPath(), 'utf8').replace(/^\uFEFF/, '')
|
|
160
163
|
|
|
161
164
|
const loadConfig = (): NopConfig =>
|
|
162
|
-
existsSync(configPath()) ?
|
|
163
|
-
Value.Parse(configSchema, JSON.parse(readFileSync(configPath(), 'utf8')))
|
|
164
|
-
: {}
|
|
165
|
+
existsSync(configPath()) ? Value.Parse(configSchema, JSON.parse(configText())) : {}
|
|
165
166
|
|
|
166
167
|
const saveConfig = (config: NopConfig): void => {
|
|
167
168
|
mkdirSync(getAgentDir(), {recursive: true})
|
|
168
169
|
writeFileSync(configPath(), JSON.stringify(config, null, 2) + '\n')
|
|
169
170
|
}
|
|
170
171
|
|
|
171
|
-
const
|
|
172
|
+
const valueAt = (value: unknown, keys: string[]): unknown =>
|
|
173
|
+
keys.reduce<unknown>((node, key) => (node as Record<string, unknown> | undefined)?.[key], value)
|
|
174
|
+
|
|
175
|
+
// The panel lists settings as subagent.model, which a user may copy into the file flat.
|
|
176
|
+
const unknownKey = (key: string): string => {
|
|
177
|
+
const [head, tail] = path(key)
|
|
178
|
+
return settings.some(setting => setting.id === key) && tail !== undefined ?
|
|
179
|
+
`${key} goes nested, as {"${head}": {"${tail}": ...}}`
|
|
180
|
+
: `${key} is not a setting`
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// A list or an object could be any size, and the warning is one line.
|
|
184
|
+
const shown = (value: unknown): string => {
|
|
185
|
+
if (Array.isArray(value)) return 'a list'
|
|
186
|
+
return typeof value === 'object' && value !== null ? 'an object' : JSON.stringify(value)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const schemaFault = (value: unknown): string => {
|
|
190
|
+
const errors = Value.Errors(configSchema, value)
|
|
191
|
+
const unknown = errors.find(error => error.keyword === 'additionalProperties')
|
|
192
|
+
const first = unknown ?? errors[0]
|
|
193
|
+
const keys = first?.instancePath.split('/').slice(1) ?? []
|
|
194
|
+
|
|
195
|
+
if (unknown !== undefined) {
|
|
196
|
+
// typebox does not escape / in a path, so the unknown key is read from its own error.
|
|
197
|
+
const [name] = (unknown.params as {additionalProperties: string[]}).additionalProperties
|
|
198
|
+
return unknownKey([...keys, name].join('.'))
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (keys.length === 0) return 'not a JSON object'
|
|
202
|
+
return `${keys.join('.')} is ${shown(valueAt(value, keys))}`
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const brokenReason = (): string => {
|
|
206
|
+
let text: string
|
|
207
|
+
let parsed: unknown
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
text = configText()
|
|
211
|
+
} catch (error) {
|
|
212
|
+
return `not readable (${String((error as NodeJS.ErrnoException).code)})`
|
|
213
|
+
}
|
|
214
|
+
|
|
172
215
|
try {
|
|
173
|
-
|
|
216
|
+
parsed = JSON.parse(text)
|
|
174
217
|
} catch {
|
|
175
|
-
|
|
176
|
-
return {}
|
|
218
|
+
return 'not valid JSON'
|
|
177
219
|
}
|
|
220
|
+
|
|
221
|
+
return schemaFault(parsed)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
type Loaded = {config: NopConfig; broken: boolean}
|
|
225
|
+
|
|
226
|
+
// Outside the tui /nop-config only prints the values.
|
|
227
|
+
const fixHint = (ctx?: ExtensionContext): string =>
|
|
228
|
+
ctx?.mode === 'tui' ? 'Run /nop-config to fix it.' : 'Fix the file by hand.'
|
|
229
|
+
|
|
230
|
+
const loadSafely = (ctx?: ExtensionContext, fix = fixHint(ctx)): Loaded => {
|
|
231
|
+
try {
|
|
232
|
+
return {config: loadConfig(), broken: false}
|
|
233
|
+
} catch {
|
|
234
|
+
ctx?.ui.notify(brokenConfig(configPath(), brokenReason(), fix), 'warning')
|
|
235
|
+
return {config: {}, broken: true}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const safeConfig = (ctx?: ExtensionContext): NopConfig => loadSafely(ctx).config
|
|
240
|
+
|
|
241
|
+
const freeAside = (taken: number): string => {
|
|
242
|
+
const aside = `${configPath()}.broken${taken === 0 ? '' : `-${String(taken + 1)}`}`
|
|
243
|
+
return existsSync(aside) ? freeAside(taken + 1) : aside
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// A save over a broken file would lose what the user wrote, so a copy goes aside, past older
|
|
247
|
+
// ones. A copy, not a move: a symlinked config must stay a link for the save to go through.
|
|
248
|
+
const setAsideBroken = (): string => {
|
|
249
|
+
const aside = freeAside(0)
|
|
250
|
+
copyFileSync(configPath(), aside)
|
|
251
|
+
return aside
|
|
178
252
|
}
|
|
179
253
|
|
|
180
254
|
const stored = (config: NopConfig, id: string): unknown =>
|
|
@@ -212,13 +286,13 @@ const findModel = (registry: ModelRegistry, spec?: string): Model<Api> | undefin
|
|
|
212
286
|
|
|
213
287
|
export {
|
|
214
288
|
applyChange,
|
|
215
|
-
brokenConfig,
|
|
216
289
|
concurrency,
|
|
217
290
|
engine,
|
|
218
291
|
engines,
|
|
219
292
|
findModel,
|
|
220
293
|
inherit,
|
|
221
294
|
loadConfig,
|
|
295
|
+
loadSafely,
|
|
222
296
|
missingModel,
|
|
223
297
|
modelOf,
|
|
224
298
|
modelSpec,
|
|
@@ -226,6 +300,7 @@ export {
|
|
|
226
300
|
read,
|
|
227
301
|
restarts,
|
|
228
302
|
safeConfig,
|
|
303
|
+
setAsideBroken,
|
|
229
304
|
saveConfig,
|
|
230
305
|
searchTool,
|
|
231
306
|
settings,
|
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
|
}
|
package/src/search/search.ts
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
-
import type {ExtensionAPI} from '@earendil-works/pi-coding-agent'
|
|
1
|
+
import type {ExtensionAPI, ExtensionContext} from '@earendil-works/pi-coding-agent'
|
|
2
2
|
import {Type} from 'typebox'
|
|
3
3
|
import Value from 'typebox/value'
|
|
4
4
|
|
|
5
|
-
import {engine, read, safeConfig, searchTool} from '../config/config'
|
|
5
|
+
import {engine, engines as engineNames, read, safeConfig, searchTool} from '../config/config'
|
|
6
6
|
import type {EngineName} from '../config/config'
|
|
7
7
|
import {brave} from './brave'
|
|
8
8
|
import {ddg} from './ddg'
|
|
9
9
|
import {exa} from './exa'
|
|
10
10
|
import type {Engine, SearchResult} from './engines'
|
|
11
|
-
import {httpOnly} from './engines'
|
|
11
|
+
import {httpOnly, SearchErrors} from './engines'
|
|
12
12
|
|
|
13
13
|
const engineOverride = 'PI_NOP_SEARCH_ENGINE'
|
|
14
14
|
const engines: Record<EngineName, Engine> = {exa, brave, ddg}
|
|
15
|
+
const listed = `${engineNames.slice(0, -1).join(', ')} and ${String(engineNames.at(-1))}`
|
|
16
|
+
|
|
17
|
+
// The config was checked as it loaded, so only the environment can name an unknown engine.
|
|
18
|
+
const engineName = (ctx: ExtensionContext): EngineName => {
|
|
19
|
+
const override = process.env[engineOverride]
|
|
20
|
+
|
|
21
|
+
// `export PI_NOP_SEARCH_ENGINE=` unsets it in effect.
|
|
22
|
+
if (override === undefined || override === '') return read(safeConfig(ctx), engine)
|
|
23
|
+
if (Value.Check(engine.schema, override)) return override
|
|
24
|
+
throw new Error(
|
|
25
|
+
`${SearchErrors.Failed}${engineOverride} is "${override}", and the engines are ${listed}`
|
|
26
|
+
)
|
|
27
|
+
}
|
|
15
28
|
|
|
16
29
|
const formatResult = (result: SearchResult, index: number): string => {
|
|
17
30
|
const lead = `${index + 1}. [${result.title}](${result.url})`
|
|
@@ -42,10 +55,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
42
55
|
})
|
|
43
56
|
}),
|
|
44
57
|
async execute(_toolCallId, params, signal, _onUpdate, ctx) {
|
|
45
|
-
const name =
|
|
46
|
-
engine.schema,
|
|
47
|
-
process.env[engineOverride] ?? read(safeConfig(ctx), engine)
|
|
48
|
-
)
|
|
58
|
+
const name = engineName(ctx)
|
|
49
59
|
const results = httpOnly(await engines[name](params.query, signal))
|
|
50
60
|
return {
|
|
51
61
|
content: [{type: 'text', text: formatResults(params.query, results)}],
|
package/src/subagent/answer.ts
CHANGED
|
@@ -50,30 +50,55 @@ type Answer = {
|
|
|
50
50
|
const isCoverage = (value: string): value is Coverage =>
|
|
51
51
|
(coverages as readonly string[]).includes(value)
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
// A markup run after the colon closes a dressed label, as in **COVERED:**, only before a space.
|
|
54
|
+
const labelPattern = (label: string, flags: string): RegExp =>
|
|
55
|
+
new RegExp(`^[*_\`#>\\s-]*${label}[*_\`\\s]*:(?:[*_\`]+(?=\\s|$))?`, flags)
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
const labelled = (line: string | undefined, label: string, flags = 'i'): string | undefined => {
|
|
58
|
+
if (line === undefined) return undefined
|
|
59
|
+
|
|
60
|
+
const found = labelPattern(label, flags).exec(line)
|
|
61
|
+
return found === null ? undefined : line.slice(found[0].length).trim()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// A fence tag is one word, as c#, then attributes, as title="a". Other text is a quote. Each
|
|
65
|
+
// attribute has one parse only, so a looped line cannot backtrack exponentially.
|
|
66
|
+
const fence = /^(?:`{3,}|~{3,})(?:\s*[^\s`~]+)?(?:\s+(?:[\w-]+=(?:"[^"]*"|[^\s"]\S*)|\{[^}]*\}))*$/
|
|
67
|
+
const isContent = (line: string): boolean => line !== '' && !fence.test(line)
|
|
68
|
+
|
|
69
|
+
// Capitals only, so the answer may say Evidence:. The first splits, so no quote hides above it.
|
|
70
|
+
const dividerAt = (trimmed: string[], answerAt: number): number =>
|
|
71
|
+
trimmed.findIndex(
|
|
72
|
+
(line, index) => index > answerAt && labelled(line, 'EVIDENCE', '') !== undefined
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
// `no, partially` is a hedge, and read as no it would need no evidence.
|
|
76
|
+
const coverageOf = (line: string | undefined): Coverage | undefined => {
|
|
77
|
+
const said = labelled(line, 'COVERED')?.replace(/[*_`]/g, '').toLowerCase()
|
|
78
|
+
const word = /^([a-z]+)[.!]?$/.exec(said ?? '')?.[1]
|
|
79
|
+
return word !== undefined && isCoverage(word) ? word : undefined
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The answer keeps raw lines: blank lines and indentation belong to a copied code block.
|
|
58
83
|
const parseAnswer = (text: string): Answer | undefined => {
|
|
59
84
|
const lines = text.replaceAll('\r\n', '\n').split('\n')
|
|
60
85
|
const trimmed = lines.map(line => line.trim())
|
|
61
|
-
const coveredAt = trimmed.findIndex(
|
|
62
|
-
const answerAt = trimmed.findIndex((line, index) => index > coveredAt && line
|
|
63
|
-
const divider = trimmed
|
|
64
|
-
|
|
65
|
-
)
|
|
66
|
-
const covered = labelled(trimmed[coveredAt], 'COVERED:')?.toLowerCase()
|
|
67
|
-
const first = labelled(trimmed[answerAt], 'ANSWER:')
|
|
86
|
+
const coveredAt = trimmed.findIndex(isContent)
|
|
87
|
+
const answerAt = trimmed.findIndex((line, index) => index > coveredAt && isContent(line))
|
|
88
|
+
const divider = dividerAt(trimmed, answerAt)
|
|
89
|
+
const covered = coverageOf(trimmed[coveredAt])
|
|
90
|
+
const first = labelled(trimmed[answerAt], 'ANSWER')
|
|
68
91
|
|
|
69
|
-
if (covered === undefined ||
|
|
70
|
-
if (first === undefined || divider === -1) return undefined
|
|
92
|
+
if (covered === undefined || first === undefined || divider === -1) return undefined
|
|
71
93
|
|
|
72
94
|
const answer = [first, ...lines.slice(answerAt + 1, divider)].join('\n').trim()
|
|
73
95
|
|
|
74
96
|
if (answer === '') return undefined
|
|
75
97
|
|
|
76
|
-
const evidence = [
|
|
98
|
+
const evidence = [
|
|
99
|
+
labelled(trimmed[divider], 'EVIDENCE', '') ?? '',
|
|
100
|
+
...trimmed.slice(divider + 1)
|
|
101
|
+
]
|
|
77
102
|
return {covered, answer, evidence: evidence.filter(line => line !== '')}
|
|
78
103
|
}
|
|
79
104
|
|
|
@@ -127,9 +152,9 @@ const missingFrom = (evidence: string[], sources: Source[]): string[] => {
|
|
|
127
152
|
return pending.map(({line}) => line)
|
|
128
153
|
}
|
|
129
154
|
|
|
130
|
-
// A fence, a lone `}` or an emphasis-only line claims nothing, so it is dropped
|
|
155
|
+
// A fence, even ```ts, a lone `}` or an emphasis-only line claims nothing, so it is dropped.
|
|
131
156
|
const substantive = (evidence: string[]): string[] =>
|
|
132
|
-
evidence.filter(line => /[\p{L}\p{N}]/u.test(normalize(line)))
|
|
157
|
+
evidence.filter(line => isContent(line.trim()) && /[\p{L}\p{N}]/u.test(normalize(line)))
|
|
133
158
|
|
|
134
159
|
// The layout is returned as is, so the caller sees the coverage and the evidence too.
|
|
135
160
|
const verifyAnswer = (text: string, sources: Source[]): string => {
|
|
@@ -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>
|