@lincyaw/workspace 1.0.0-rc.125 → 1.0.0-rc.127
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/workspace",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.127",
|
|
4
4
|
"description": "Presmium's workspace service (presmium serve): documents, their history, reviews and the workspace site",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"mime-types": "3.0.2",
|
|
36
36
|
"playwright-chromium": "1.64.1",
|
|
37
37
|
"yaml": "^2.9.1",
|
|
38
|
-
"@lincyaw/kernel": "1.0.0-rc.
|
|
39
|
-
"@lincyaw/
|
|
40
|
-
"@lincyaw/server": "1.0.0-rc.
|
|
41
|
-
"@lincyaw/
|
|
38
|
+
"@lincyaw/kernel": "1.0.0-rc.127",
|
|
39
|
+
"@lincyaw/design": "1.0.0-rc.127",
|
|
40
|
+
"@lincyaw/server": "1.0.0-rc.127",
|
|
41
|
+
"@lincyaw/compiler": "1.0.0-rc.127"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/mime-types": "^3.0.1",
|
|
45
|
-
"@lincyaw/mcp": "1.0.0-rc.
|
|
45
|
+
"@lincyaw/mcp": "1.0.0-rc.127"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -66,6 +66,14 @@ export function createDocumentVoiceAuthoring({ editor, services, prepareExecutio
|
|
|
66
66
|
signal.throwIfAborted(); current(document, member, opened.source)
|
|
67
67
|
return { ...opened, ...loaded }
|
|
68
68
|
}
|
|
69
|
+
// A read that names no version follows the document: a save while it loads (the voice just chosen) is read again,
|
|
70
|
+
// not refused; only a document that keeps changing is.
|
|
71
|
+
const loadLatest = async (document: string, member: Member, signal: AbortSignal) => {
|
|
72
|
+
for (let attempt = 1; ; attempt++) {
|
|
73
|
+
try { return await load(document, member, signal) }
|
|
74
|
+
catch (error) { if (attempt >= 3 || !(error instanceof RequestError && error.status === 409 && error.message === 'document-version-changed')) throw error }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
69
77
|
const execution = (document: string, member: Member) => async (expected: CanonicalSource | undefined, signal: AbortSignal) => {
|
|
70
78
|
const loaded = await load(document, member, signal, expected)
|
|
71
79
|
if (!loaded.voiceoverExecution) throw new RequestError(503, 'voiceover-unavailable')
|
|
@@ -160,24 +168,26 @@ export function createDocumentVoiceAuthoring({ editor, services, prepareExecutio
|
|
|
160
168
|
return speech.cloneStatus(engine, query.voice, signal)
|
|
161
169
|
}),
|
|
162
170
|
capabilities: (document, member, signal) => work(signal, async signal => {
|
|
163
|
-
const loaded = await
|
|
171
|
+
const loaded = await loadLatest(document, member, signal)
|
|
164
172
|
const [engines, defaultEngine] = await Promise.all([loaded.speech?.engines() ?? [], loaded.speech?.defaultSynthesisEngine?.()])
|
|
165
|
-
signal.throwIfAborted()
|
|
173
|
+
signal.throwIfAborted()
|
|
166
174
|
const configured = engines.some(engine => engine.tts), unknown = !loaded.speech && loaded.findings?.some(finding => finding.severity === 'error')
|
|
167
175
|
const implemented = Boolean(loaded.voiceoverExecution)
|
|
168
176
|
return { document, source: loaded.source, verification: 'configuration-only', status: configured ? 'configured' : unknown ? 'unknown' : 'unavailable', ...!configured ? { reason: unknown ? 'services-unavailable' : 'not-configured' } as const : {}, voiceover: implemented, preview: implemented, engines, ...defaultEngine ? { defaultEngine } : {}, ...loaded.findings?.length ? { findings: loaded.findings } : {}, actions: { status: implemented, list: true, get: true, start: implemented && configured, cancel: true, quotePreview: implemented, preview: implemented && configured, readPreview: true, clone: hasRole(member, 'owner') && Boolean(loaded.speech?.cloneVoice) && engines.some(engine => engine.clone), cloneStatus: hasRole(member, 'owner') && Boolean(loaded.speech?.cloneStatus) && engines.some(engine => engine.clone) }, tasks: { idempotency: 'process', limits: ownerOf(document, member).limits } }
|
|
169
177
|
}),
|
|
170
178
|
catalog: (document, query, member, signal) => work(signal, async signal => {
|
|
171
179
|
if (!validateDocumentVoiceCatalogQuery(query)) throw new RequestError(400, 'voice-catalog-query-invalid')
|
|
172
|
-
|
|
180
|
+
// The voices do not depend on the document's text: only a read pinned to a version is refused when it moves on.
|
|
181
|
+
const loaded = query.source ? await load(document, member, signal, query.source) : await loadLatest(document, member, signal)
|
|
182
|
+
const pinned = () => { signal.throwIfAborted(); if (query.source) current(document, member, loaded.source) }
|
|
173
183
|
const engines = await loaded.speech?.engines() ?? []
|
|
174
|
-
|
|
184
|
+
pinned()
|
|
175
185
|
const preferred = query.engine ?? await loaded.speech?.defaultSynthesisEngine?.()
|
|
176
|
-
|
|
186
|
+
pinned()
|
|
177
187
|
const chosen = preferred ? engines.find(engine => engine.tts && engine.id === speechEngineId(preferred)) : undefined
|
|
178
188
|
const unknown = !loaded.speech && loaded.findings?.some(finding => finding.severity === 'error')
|
|
179
189
|
const catalog = chosen && loaded.speech ? await loaded.speech.voiceCatalog?.(chosen.id, query.lang ?? loaded.lang, signal) ?? { status: 'unavailable' as const, reason: 'unknown' as const, voices: [] } : { status: 'unavailable' as const, reason: unknown ? 'unknown' as const : 'not-configured' as const, voices: [] }
|
|
180
|
-
|
|
190
|
+
pinned()
|
|
181
191
|
return { document, source: loaded.source, engines, catalog, ...catalog.status === 'available' && chosen ? { engine: chosen.id } : {}, ...loaded.findings?.length ? { findings: loaded.findings } : {} }
|
|
182
192
|
}),
|
|
183
193
|
snapshot: (document, query, member, signal) => ownerOf(document, member).snapshot(query, execution(document, member), signal),
|
package/src/node/git.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { execFile, execFileSync, fork } from 'node:child_process'
|
|
|
2
2
|
import type { ChildProcess } from 'node:child_process'
|
|
3
3
|
import { fileURLToPath } from 'node:url'
|
|
4
4
|
import { existsSync, readdirSync, realpathSync } from 'node:fs'
|
|
5
|
-
import {
|
|
5
|
+
import { appendFile, mkdir, readFile } from 'node:fs/promises'
|
|
6
|
+
import { dirname, join, resolve } from 'node:path'
|
|
6
7
|
import { promisify } from 'node:util'
|
|
7
8
|
import { gitConfigArgs, gitEnvironment } from '@lincyaw/kernel'
|
|
8
9
|
|
|
@@ -84,6 +85,39 @@ function runGit(request: RunRequest): Promise<GitResult> {
|
|
|
84
85
|
})
|
|
85
86
|
}
|
|
86
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Repositories inside the work tree are left out of Presmium's own histories: git cannot add one without a commit
|
|
90
|
+
* (it stops the whole `git add`), and one with a commit would enter only as a reference to it. `ls-files --others`
|
|
91
|
+
* names each as its directory with a trailing slash, and nothing else that way.
|
|
92
|
+
*/
|
|
93
|
+
export const nestedRepositories = (untracked: string): string[] => untracked.split('\0').filter(path => path.endsWith('/'))
|
|
94
|
+
const reported = new Set<string>()
|
|
95
|
+
/** Pathspecs (git's literal-pathspec setting off) that add `paths` except the nested repositories. */
|
|
96
|
+
export function addPathspecs(paths: string[], nested: string[]): string[] {
|
|
97
|
+
for (const path of nested) if (!reported.has(path)) { reported.add(path); console.warn(`presmium: ${path} is a git repository of its own; its files are not part of the workspace history`) }
|
|
98
|
+
return [...paths.map(path => `:(literal)${path}`), ...nested.map(path => `:(exclude,literal)${path}`)]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* DeltaBox keeps a session's state in `.deltabox/` and `.deltabox-lite-state/` of the project root it is given; an
|
|
103
|
+
* earlier Presmium gave it the author's workspace, so these may be left there. A live session may still use them,
|
|
104
|
+
* so they are not removed: the project's local `info/exclude` (never a file the author commits) leaves them out.
|
|
105
|
+
* Answers the lines it added.
|
|
106
|
+
*/
|
|
107
|
+
export async function excludeDeltaboxState(root: string): Promise<string[]> {
|
|
108
|
+
const present = ['.deltabox', '.deltabox-lite-state'].filter(name => existsSync(join(root, name)))
|
|
109
|
+
if (!present.length || !Git.isRepository(root)) return []
|
|
110
|
+
const git = new Git(root)
|
|
111
|
+
const prefix = (await git.output(['rev-parse', '--show-prefix'])).trim()
|
|
112
|
+
const file = resolve(root, (await git.output(['rev-parse', '--git-path', 'info/exclude'])).trim())
|
|
113
|
+
const existing = await readFile(file, 'utf8').catch((error: NodeJS.ErrnoException) => { if (error.code === 'ENOENT') return ''; throw error })
|
|
114
|
+
const lines = present.map(name => `/${prefix}${name}/`).filter(line => !existing.split(/\r?\n/).includes(line))
|
|
115
|
+
if (!lines.length) return lines
|
|
116
|
+
await mkdir(dirname(file), { recursive: true })
|
|
117
|
+
await appendFile(file, `${existing && !existing.endsWith('\n') ? '\n' : ''}${lines.join('\n')}\n`)
|
|
118
|
+
return lines
|
|
119
|
+
}
|
|
120
|
+
|
|
87
121
|
export class Git {
|
|
88
122
|
readonly root: string
|
|
89
123
|
readonly top: string
|
|
@@ -138,6 +172,13 @@ export class Git {
|
|
|
138
172
|
return { ok: result.code === 0, output: result.code === 0 ? result.stdout.toString('utf8') : `${result.stderr}${result.stdout.toString('utf8')}` }
|
|
139
173
|
}
|
|
140
174
|
|
|
175
|
+
/** `git add -A` of `paths` (literal) that skips nested repositories. */
|
|
176
|
+
async addAll(paths: string[], env: Record<string, string> = {}): Promise<void> {
|
|
177
|
+
const literal = { ...env, GIT_LITERAL_PATHSPECS: '1' }
|
|
178
|
+
const nested = nestedRepositories(await this.output(['ls-files', '--others', '--exclude-standard', '-z', '--', ...paths], literal))
|
|
179
|
+
await this.output(['add', '-A', '--', ...addPathspecs(paths, nested)], { ...env, GIT_LITERAL_PATHSPECS: '0' })
|
|
180
|
+
}
|
|
181
|
+
|
|
141
182
|
exclusive<T>(work: () => Promise<T>): Promise<T> {
|
|
142
183
|
const next = this.#queue.then(work, work)
|
|
143
184
|
this.#queue = next.catch(() => undefined)
|
package/src/node/jobs.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createHash, randomBytes } from 'node:crypto'
|
|
2
2
|
import { createReadStream, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
3
3
|
import { join, relative, sep } from 'node:path'
|
|
4
|
-
import { availableRenderers, build, compileTranslations, documentExporters, exportDocument, serveDirectory } from '@lincyaw/compiler'
|
|
4
|
+
import { availableRenderers, build, compileTranslations, documentExporters, exportDocument, missingOutput, serveDirectory } from '@lincyaw/compiler'
|
|
5
5
|
import type { Compilation } from '@lincyaw/compiler'
|
|
6
|
-
import { errorMessage, fnv1a64 } from '@lincyaw/kernel'
|
|
6
|
+
import { errorMessage, fnv1a64, jobFailureCode } from '@lincyaw/kernel'
|
|
7
7
|
import { lookup } from 'mime-types'
|
|
8
8
|
import type { CompileJob, JobFile, JobSource, Logger, OutputJobs, OutputTarget } from '@lincyaw/kernel'
|
|
9
9
|
import { writeArchive } from './archive.ts'
|
|
@@ -205,9 +205,7 @@ export function createJobs(options: JobsOptions): Jobs {
|
|
|
205
205
|
const report = await build(compilation, { outDir: dir, to: [job.target], base: `${outputs}${job.id}/${job.target}/`, log })
|
|
206
206
|
if (controller.signal.aborted) throw new Cancelled()
|
|
207
207
|
job.warnings = report.findings.filter(finding => finding.severity === 'warning').map(finding => finding.message)
|
|
208
|
-
if (!report.outputs.some(output => output.renderer === job.target))
|
|
209
|
-
throw new Error(report.findings.filter(finding => finding.severity === 'error').map(finding => finding.message).join('\n') || `the ${job.target} renderer made nothing`)
|
|
210
|
-
}
|
|
208
|
+
if (!report.outputs.some(output => output.renderer === job.target)) throw await missingOutput(compilation, job.target, report.findings)
|
|
211
209
|
job.files = listFiles(dir, join(dir, job.target))
|
|
212
210
|
job.main = mainFile(job.target, job.files)
|
|
213
211
|
if (job.main?.endsWith('/index.html')) await archiveSite(entry, compilation, log, progress)
|
|
@@ -235,7 +233,7 @@ export function createJobs(options: JobsOptions): Jobs {
|
|
|
235
233
|
const report = await build(compilation, { outDir: work, to: [job.target], log })
|
|
236
234
|
if (controller.signal.aborted) throw new Cancelled()
|
|
237
235
|
const site = report.outputs.find(output => output.renderer === job.target)
|
|
238
|
-
if (!site) throw
|
|
236
|
+
if (!site) throw await missingOutput(compilation, job.target, report.findings)
|
|
239
237
|
const file = `${job.target}.zip`
|
|
240
238
|
await writeArchive(site.outDir, join(dir, file), controller.signal)
|
|
241
239
|
job.archive = file
|
|
@@ -266,6 +264,8 @@ export function createJobs(options: JobsOptions): Jobs {
|
|
|
266
264
|
job.state = controller.signal.aborted ? 'cancelled' : 'failed'
|
|
267
265
|
if (job.state === 'failed') {
|
|
268
266
|
job.error = errorMessage(error)
|
|
267
|
+
const code = jobFailureCode(error)
|
|
268
|
+
if (code) job.code = code
|
|
269
269
|
// The author's Details show why, under the reason the workbench gives in plain words.
|
|
270
270
|
job.log.push(job.error)
|
|
271
271
|
}
|
|
@@ -74,7 +74,7 @@ export async function captureLocalBaseline(git: Git, paths: string[], initial =
|
|
|
74
74
|
if (excluded.code !== 0 && excluded.code !== 1) throw new Error(excluded.stderr)
|
|
75
75
|
const ignored = new Set(excluded.stdout.toString('utf8').split('\0'))
|
|
76
76
|
const selected = paths.filter(path => !ignored.has(path) && (tracked.has(path) || lstatSync(join(git.root, path), { throwIfNoEntry: false })))
|
|
77
|
-
if (selected.length) await git.
|
|
77
|
+
if (selected.length) await git.addAll(selected)
|
|
78
78
|
const tree = (await git.output(['write-tree'])).trim()
|
|
79
79
|
const parent = await git.tryOutput(['rev-parse', '--verify', '--quiet', 'HEAD'])
|
|
80
80
|
if (!initial && parent.ok && tree === (await git.output(['rev-parse', 'HEAD^{tree}'])).trim()) return
|
|
@@ -25,6 +25,13 @@ function stamp(file: string): FileStamp | undefined {
|
|
|
25
25
|
if (!stat.isFile()) throw new RequestError(409, 'agent-source-type-changed')
|
|
26
26
|
return { version: versionOf(readFileSync(file)), ...stat.mode & 0o111 ? { executable: true } : {} }
|
|
27
27
|
}
|
|
28
|
+
const SANDBOX_STATE = new Set(['.deltabox', '.deltabox-lite-state'])
|
|
29
|
+
/**
|
|
30
|
+
* What a candidate copies of the author's listing: not the candidates themselves, not a sandbox's state (its live
|
|
31
|
+
* tree is a repository of its own), and not another repository inside the workspace, which git lists as `dir/`.
|
|
32
|
+
*/
|
|
33
|
+
const isAuthorFile = (path: string) => !!path && !path.endsWith('/') && !path.startsWith('.presmium/agent-workspaces/')
|
|
34
|
+
&& !path.split('/').some(part => SANDBOX_STATE.has(part))
|
|
28
35
|
const same = (a: FileStamp | undefined, b: FileStamp | undefined) => JSON.stringify(a) === JSON.stringify(b)
|
|
29
36
|
async function sourceStamp(file: string): Promise<FileStamp | undefined> {
|
|
30
37
|
let stat
|
|
@@ -63,7 +70,7 @@ export class AgentWorkspace {
|
|
|
63
70
|
async refresh(): Promise<boolean> {
|
|
64
71
|
const listing = ['ls-files', '--cached', '--others', '--exclude-standard', '-z', '--', '.']
|
|
65
72
|
const listed = Git.isRepository(this.#config.root) ? await git(this.#config.root, listing) : await (await openLocalHistory(this.#config.root)).output(listing)
|
|
66
|
-
const paths = listed.split('\0').filter(
|
|
73
|
+
const paths = listed.split('\0').filter(isAuthorFile)
|
|
67
74
|
const next: Record<string, FileStamp> = {}
|
|
68
75
|
for (const path of new Set(paths)) {
|
|
69
76
|
const current = await sourceStamp(join(this.#config.root, path))
|
|
@@ -6,6 +6,7 @@ import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
|
6
6
|
import { gitConfigArgs, gitEnvironment } from '@lincyaw/kernel'
|
|
7
7
|
import type { ChangeReview, DocumentFileChange, DocumentFiles, ReviewChange, ReviewChangeKind, ReviewStep } from '@lincyaw/kernel'
|
|
8
8
|
import { isInside } from '@lincyaw/kernel/node'
|
|
9
|
+
import { addPathspecs, nestedRepositories } from '../git.ts'
|
|
9
10
|
import { snapshotGitDir } from './git-guard.ts'
|
|
10
11
|
import type { SavedGitDir } from './git-guard.ts'
|
|
11
12
|
import { isHolderAlive, readRecord, removeRecord, THIS_PROCESS, writeRecord } from './record.ts'
|
|
@@ -40,7 +41,7 @@ function git(cwd: string, args: string[], env: Record<string, string> = {}): Pro
|
|
|
40
41
|
cwd,
|
|
41
42
|
encoding: 'buffer',
|
|
42
43
|
maxBuffer: 256 << 20,
|
|
43
|
-
env: { ...gitEnvironment(process.env), ...env, GIT_OPTIONAL_LOCKS: '0'
|
|
44
|
+
env: { ...gitEnvironment(process.env), GIT_LITERAL_PATHSPECS: '1', ...env, GIT_OPTIONAL_LOCKS: '0' },
|
|
44
45
|
}, (error, stdout, stderr) => {
|
|
45
46
|
if (error) reject(new Error(`git ${args[0]}: ${stderr.toString('utf8').trim() || error.message}`))
|
|
46
47
|
else resolve(stdout)
|
|
@@ -111,8 +112,8 @@ class ReviewTrees {
|
|
|
111
112
|
this.#files = options.files
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
#git(args: string[], index?: string): Promise<Buffer> {
|
|
115
|
-
return git(this.top, args, { ...this.#env, ...index ? { GIT_INDEX_FILE: index } : {} })
|
|
115
|
+
#git(args: string[], index?: string, env: Record<string, string> = {}): Promise<Buffer> {
|
|
116
|
+
return git(this.top, args, { ...this.#env, ...index ? { GIT_INDEX_FILE: index } : {}, ...env })
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
async #text(args: string[], index?: string): Promise<string> {
|
|
@@ -129,7 +130,8 @@ class ReviewTrees {
|
|
|
129
130
|
async tree(): Promise<string> {
|
|
130
131
|
const index = this.#index()
|
|
131
132
|
try {
|
|
132
|
-
await this.#
|
|
133
|
+
const nested = nestedRepositories(await this.#text(['ls-files', '--others', '--exclude-standard', '-z', '--', this.#pathspec], index))
|
|
134
|
+
await this.#git(['add', '-A', '--', ...addPathspecs([this.#pathspec], nested)], index, { GIT_LITERAL_PATHSPECS: '0' })
|
|
133
135
|
return (await this.#text(['write-tree'], index)).trim()
|
|
134
136
|
} finally {
|
|
135
137
|
rmSync(index, { force: true })
|
package/src/node/serve.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { documentSummaries, listDocuments, readWorkspaceConfig } from './config.
|
|
|
26
26
|
import { DocumentOperations, documentsDiff } from './document-operations.ts'
|
|
27
27
|
import type { DocumentsChange } from './document-operations.ts'
|
|
28
28
|
import { RequestError } from './errors.ts'
|
|
29
|
-
import { Git } from './git.ts'
|
|
29
|
+
import { excludeDeltaboxState, Git } from './git.ts'
|
|
30
30
|
import { captureLocalBaseline, clearStaleHistoryLock, openLocalHistory } from './local-history.ts'
|
|
31
31
|
import { createJobs, OUTPUTS_PATH } from './jobs.ts'
|
|
32
32
|
import { DocumentLocks } from './locks.ts'
|
|
@@ -168,6 +168,8 @@ async function startWorkspace(options: ServeOptions): Promise<WorkspaceServer> {
|
|
|
168
168
|
const unhandled = (reason: unknown) => log.error(`an operation failed unexpectedly: ${errorMessage(reason)}`)
|
|
169
169
|
process.on('unhandledRejection', unhandled)
|
|
170
170
|
if (clearStaleHistoryLock(root, env)) log.warn('removed the local history\'s index lock that an earlier service, ended in the middle of a git command, left behind')
|
|
171
|
+
const excluded = await excludeDeltaboxState(root).catch((error: unknown) => { log.warn(`could not leave DeltaBox's state directories out of the project: ${errorMessage(error)}`); return [] })
|
|
172
|
+
if (excluded.length) log.warn(`left ${excluded.join(', ')} out of the project in its git info/exclude: DeltaBox state an earlier service put in the workspace`)
|
|
171
173
|
const historyGit = await openLocalHistory(root, env)
|
|
172
174
|
await historyGit.exclusive(() => captureLocalBaseline(historyGit, ['.']))
|
|
173
175
|
const operatorDirectory = resolveOperatorDir(root, options.operatorDir ?? env.PRESMIUM_OPERATOR_DIR)
|