@lincyaw/workspace 1.0.0-rc.125 → 1.0.0-rc.126

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.125",
3
+ "version": "1.0.0-rc.126",
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.125",
39
- "@lincyaw/compiler": "1.0.0-rc.125",
40
- "@lincyaw/server": "1.0.0-rc.125",
41
- "@lincyaw/design": "1.0.0-rc.125"
38
+ "@lincyaw/kernel": "1.0.0-rc.126",
39
+ "@lincyaw/server": "1.0.0-rc.126",
40
+ "@lincyaw/design": "1.0.0-rc.126",
41
+ "@lincyaw/compiler": "1.0.0-rc.126"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/mime-types": "^3.0.1",
45
- "@lincyaw/mcp": "1.0.0-rc.125"
45
+ "@lincyaw/mcp": "1.0.0-rc.126"
46
46
  }
47
47
  }
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 new Error(report.findings.filter(finding => finding.severity === 'error').map(finding => finding.message).join('\n') || `the ${job.target} renderer made nothing`)
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
  }
@@ -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(path => path && !path.startsWith('.presmium/agent-workspaces/'))
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))