@defrex/autobuild 1.15.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +110 -10
  3. package/docs/answering-blocked-builds.md +34 -1
  4. package/docs/architecture.md +41 -7
  5. package/docs/configuration.md +41 -7
  6. package/docs/dispatcher-hosting.md +3 -0
  7. package/docs/operator-api.md +15 -5
  8. package/docs/plugin-authoring.md +1 -0
  9. package/docs/remote-store-protocol.md +13 -3
  10. package/docs/remote-ticket-protocol.md +3 -1
  11. package/docs/restacking.md +41 -1
  12. package/docs/setup.md +15 -6
  13. package/docs/troubleshooting.md +51 -3
  14. package/docs/workspaces.md +4 -1
  15. package/package.json +3 -3
  16. package/packages/core/src/cli/accounts.ts +3 -0
  17. package/packages/core/src/cli/binary-direct.ts +14 -1
  18. package/packages/core/src/cli/binary.ts +10 -7
  19. package/packages/core/src/cli/dispatch.ts +610 -356
  20. package/packages/core/src/cli/secrets.ts +2 -0
  21. package/packages/core/src/config/schema.ts +15 -2
  22. package/packages/core/src/events/payloads.ts +8 -5
  23. package/packages/core/src/events/repository.ts +12 -6
  24. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/e28c68e63cbd265f.json +108 -0
  25. package/packages/core/src/kernel/engine.ts +118 -0
  26. package/packages/core/src/kernel/reconcile-restack.ts +72 -9
  27. package/packages/core/src/kernel/reducer-revisions.ts +1 -0
  28. package/packages/core/src/kernel/tracked-dirt.ts +173 -0
  29. package/packages/core/src/ontology.ts +1 -0
  30. package/packages/core/src/operator/index.ts +10 -0
  31. package/packages/core/src/operator/merged-builds.ts +51 -0
  32. package/packages/core/src/operator/registry.ts +190 -101
  33. package/packages/core/src/operator/repo-argument.ts +43 -0
  34. package/packages/core/src/ports/tickets/grants.ts +2 -0
  35. package/packages/core/src/ports/tickets/remote.ts +2 -0
  36. package/packages/core/src/ports/types.ts +25 -4
  37. package/packages/core/src/ports/workspace/vercel-command-diagnostics.ts +144 -0
  38. package/packages/core/src/ports/workspace/vercel-sandbox.ts +811 -169
  39. package/packages/core/src/processes/build-child.ts +15 -1
  40. package/packages/core/src/processes/build-runner.ts +349 -20
  41. package/packages/core/src/processes/dispatcher.ts +509 -104
  42. package/packages/core/src/processes/harvest-child.ts +21 -1
  43. package/packages/core/src/processes/harvest-runner.ts +82 -35
  44. package/packages/core/src/processes/invocation-budget.ts +6 -0
  45. package/packages/core/src/processes/launch-cut.ts +37 -0
  46. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  47. package/packages/core/src/processes/provisioning-progress.ts +23 -0
  48. package/packages/core/src/processes/repo-view.ts +25 -4
  49. package/packages/core/src/processes/workspace-preparation.ts +1 -0
  50. package/packages/core/src/store/adapter.ts +34 -5
  51. package/packages/core/src/store/build-feed.ts +148 -22
  52. package/packages/core/src/store/build-scope.ts +12 -3
  53. package/packages/core/src/store/caller-attribution.ts +170 -0
  54. package/packages/core/src/store/contract.ts +1038 -165
  55. package/packages/core/src/store/local/schema.ts +12 -1
  56. package/packages/core/src/store/local/store.ts +260 -25
  57. package/packages/core/src/store/memory.ts +156 -9
  58. package/packages/core/src/store/phase-session.ts +23 -3
  59. package/packages/core/src/store/reducer-value-shapes.json +5351 -5338
  60. package/packages/core/src/store/remote/client.ts +90 -11
  61. package/packages/core/src/store/remote/credentials.ts +2 -0
  62. package/packages/core/src/store/remote/index.ts +31 -5
  63. package/packages/core/src/store/remote/protocol.ts +45 -8
  64. package/packages/core/src/store/remote/released-clients.json +22 -0
  65. package/packages/core/src/store/remote/released-reducer-values/1.16.0.json +36358 -0
  66. package/packages/core/src/store/remote/released-reducer-values/1.17.0.json +36367 -0
  67. package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
  68. package/packages/core/src/store/remote/released-value-policy.ts +7 -0
  69. package/packages/core/src/store/session-handle.ts +12 -3
  70. package/packages/core/src/store/types.ts +48 -3
  71. package/packages/core/src/testing/reduced-read-budget.ts +310 -12
  72. package/skills/guide/SKILL.md +58 -9
  73. package/skills/guide/references/operator-api.md +15 -5
  74. package/skills/guide/references/plugin-authoring.md +1 -0
  75. package/skills/guide/references/remote-store-protocol.md +13 -3
  76. package/skills/guide/references/remote-ticket-protocol.md +3 -1
  77. package/skills/guide/references/restacking.md +41 -1
  78. package/skills/guide/references/setup.md +15 -6
  79. package/skills/operate/SKILL.md +31 -7
  80. package/templates/hosted-service/package.json +2 -2
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Pure formatting for failed Vercel sandbox guest commands (#1399): the
3
+ * redacted argv, the stage, and bounded stderr/stdout tails an operator needs
4
+ * to see why a command failed without opening the sandbox. No SDK import, no
5
+ * IO. The first line keeps the `sandbox command <cmd> exited <n>` prefix
6
+ * operators already grep for.
7
+ */
8
+
9
+ export const REDACTED = '[REDACTED]'
10
+
11
+ const SECRET_KEY = /(token|password|passwd|secret|credential|api[_-]?key|auth)/i
12
+ /** A credential-bearing flag name, optionally prefixed (`--github-token`). */
13
+ const SECRET_FLAG_NAME =
14
+ '--?(?:[A-Za-z0-9]+[-_])*(?:token|password|passwd|secret|api[-_]?key|auth|credentials?)'
15
+ const SECRET_FLAG = new RegExp(`^${SECRET_FLAG_NAME}$`, 'i')
16
+ /** One value as a shell command line spells it: double- or single-quoted
17
+ * (spaces included), or a bare word. */
18
+ const VALUE = String.raw`(?:"(?:[^"\\]|\\.)*"|'[^']*'|[^\s"'&;|]+)`
19
+
20
+ /** Redact explicit secret values plus the credential shapes a command line
21
+ * or its output commonly carries. Works on whole shell command strings too
22
+ * (`sh -c "installer --password x"`), so flag and quoted values inside one
23
+ * argv element are covered. */
24
+ export function redactSandboxText(text: string, secrets: readonly string[] = []): string {
25
+ let redacted = text
26
+ for (const secret of [...secrets]
27
+ .filter((value) => value.trim() !== '')
28
+ .sort((left, right) => right.length - left.length)) {
29
+ redacted = redacted.split(secret).join(REDACTED)
30
+ }
31
+ return (
32
+ redacted
33
+ // URL userinfo: scheme://user:pass@host
34
+ .replace(/([a-z][a-z0-9+.-]*:\/\/)[^\s/@]+@/gi, `$1${REDACTED}@`)
35
+ // Authorization headers, including git's http[.<url>].extraheader values.
36
+ .replace(
37
+ new RegExp(`(authorization\\s*[:=]\\s*)(?:(basic|bearer)\\s+)?${VALUE}`, 'gi'),
38
+ (_match, head: string, scheme: string | undefined) =>
39
+ scheme === undefined ? `${head}${REDACTED}` : `${head}${scheme} ${REDACTED}`,
40
+ )
41
+ .replace(/\b(bearer|basic)\s+(?!\[REDACTED\])[A-Za-z0-9._~+/=-]+/gi, `$1 ${REDACTED}`)
42
+ // A credential flag followed by its value, inside one command string.
43
+ .replace(
44
+ new RegExp(`(^|[\\s"'])(${SECRET_FLAG_NAME})(\\s+|=)${VALUE}`, 'gi'),
45
+ (_match, lead: string, flag: string, separator: string) =>
46
+ `${lead}${flag}${separator}${REDACTED}`,
47
+ )
48
+ // key=value where the key names a credential; quoted values whole.
49
+ .replace(
50
+ new RegExp(`([A-Za-z0-9_.-]*)=(${VALUE})`, 'g'),
51
+ (match, key: string, value: string) =>
52
+ SECRET_KEY.test(key) && value !== REDACTED ? `${key}=${REDACTED}` : match,
53
+ )
54
+ )
55
+ }
56
+
57
+ /** Redact each argv element, plus the value following a credential flag. */
58
+ export function redactArgv(argv: readonly string[], secrets: readonly string[] = []): string[] {
59
+ return argv.map((arg, index) =>
60
+ index > 0 && SECRET_FLAG.test(argv[index - 1]!) ? REDACTED : redactSandboxText(arg, secrets),
61
+ )
62
+ }
63
+
64
+ /** The trailing `maxLines` lines of `text`, at most `maxChars` characters,
65
+ * marked when truncated; `(empty)` for whitespace-only output. */
66
+ export function outputTail(
67
+ text: string,
68
+ opts: { maxLines?: number; maxChars?: number } = {},
69
+ ): string {
70
+ const maxLines = opts.maxLines ?? 20
71
+ const maxChars = opts.maxChars ?? 2_000
72
+ const trimmed = text.replace(/\s+$/, '')
73
+ if (trimmed.trim() === '') return '(empty)'
74
+ const lines = trimmed.split(/\r?\n/)
75
+ let kept = lines.slice(-maxLines).join('\n')
76
+ const omitted = lines.length - Math.min(lines.length, maxLines)
77
+ let charsCut = false
78
+ if (kept.length > maxChars) {
79
+ kept = kept.slice(kept.length - maxChars)
80
+ charsCut = true
81
+ }
82
+ if (omitted > 0) return `…(${omitted} earlier lines omitted)\n${charsCut ? '…' : ''}${kept}`
83
+ return charsCut ? `…${kept}` : kept
84
+ }
85
+
86
+ export type SandboxCommandOutcome =
87
+ | { kind: 'exit'; code: number }
88
+ | { kind: 'no-status' }
89
+ | { kind: 'timeout'; timeoutMs: number; elapsedMs: number }
90
+ | { kind: 'error'; message: string }
91
+
92
+ export interface SandboxCommandFailure {
93
+ cmd: string
94
+ args?: readonly string[]
95
+ cwd?: string
96
+ stage?: string
97
+ secrets?: readonly string[]
98
+ outcome: SandboxCommandOutcome
99
+ stdout?: string
100
+ stderr?: string
101
+ /** Why the output could not be read; replaces both tails. */
102
+ outputUnavailable?: string
103
+ }
104
+
105
+ const seconds = (ms: number): string => `${Math.max(0, Math.round(ms / 1000))}s`
106
+
107
+ function quoteArg(arg: string): string {
108
+ return arg === '' || /\s|"/.test(arg) ? JSON.stringify(arg) : arg
109
+ }
110
+
111
+ /** The multi-line diagnostic for one failed sandbox command. A timeout header
112
+ * says `timeout` (and avoids provider-limit vocabulary) so infrastructure
113
+ * classification records it as one. */
114
+ export function formatSandboxCommandFailure(input: SandboxCommandFailure): string {
115
+ const secrets = input.secrets ?? []
116
+ const outcome = input.outcome
117
+ const header =
118
+ outcome.kind === 'exit'
119
+ ? `exited ${outcome.code}`
120
+ : outcome.kind === 'no-status'
121
+ ? 'did not return an exit status'
122
+ : outcome.kind === 'timeout'
123
+ ? `exceeded its ${seconds(outcome.timeoutMs)} provisioning timeout after ${seconds(outcome.elapsedMs)}`
124
+ : `failed: ${redactSandboxText(outcome.message, secrets)}`
125
+ const lines = [`sandbox command ${input.cmd} ${header}`]
126
+ if (input.stage !== undefined) lines.push(`stage: ${input.stage}`)
127
+ lines.push(
128
+ `argv: ${redactArgv([input.cmd, ...(input.args ?? [])], secrets)
129
+ .map(quoteArg)
130
+ .join(' ')}`,
131
+ )
132
+ if (input.cwd !== undefined) lines.push(`cwd: ${input.cwd}`)
133
+ if (input.outputUnavailable !== undefined) {
134
+ lines.push(`output: unavailable (${redactSandboxText(input.outputUnavailable, secrets)})`)
135
+ } else {
136
+ lines.push(
137
+ 'stderr (tail):',
138
+ outputTail(redactSandboxText(input.stderr ?? '', secrets)),
139
+ 'stdout (tail):',
140
+ outputTail(redactSandboxText(input.stdout ?? '', secrets)),
141
+ )
142
+ }
143
+ return lines.join('\n')
144
+ }