@defrex/autobuild 0.10.1 → 0.12.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.
- package/README.md +3 -1
- package/SPEC.md +237 -23
- package/bin/ab-dispatch-kernel.ts +1 -1
- package/docs/architecture.md +66 -4
- package/docs/configuration.md +137 -19
- package/docs/hosted-dispatcher.md +17 -2
- package/docs/hosted-service.md +214 -0
- package/docs/mcp.md +8 -2
- package/docs/operator-api.md +107 -7
- package/docs/remote-store-protocol.md +189 -144
- package/docs/remote-ticket-protocol.md +111 -18
- package/docs/setup.md +173 -16
- package/docs/ticket-dependencies.md +1 -1
- package/package.json +7 -6
- package/packages/core/src/cli/attention.ts +209 -0
- package/packages/core/src/cli/binary.ts +3 -3
- package/packages/core/src/cli/configured-store.ts +17 -0
- package/packages/core/src/cli/connect.ts +261 -0
- package/packages/core/src/cli/dashboard/model.ts +8 -5
- package/packages/core/src/cli/dashboard/render.ts +37 -7
- package/packages/core/src/cli/dispatch-frontend.ts +16 -1
- package/packages/core/src/cli/dispatch-process.ts +25 -7
- package/packages/core/src/cli/dispatch.ts +247 -47
- package/packages/core/src/cli/dispatcher-liveness.ts +91 -0
- package/packages/core/src/cli/help.ts +45 -13
- package/packages/core/src/cli/init-validation.ts +27 -2
- package/packages/core/src/cli/main.ts +41 -15
- package/packages/core/src/cli/mcp.ts +7 -1
- package/packages/core/src/cli/pr-summary-publication.ts +220 -0
- package/packages/core/src/cli/pr-summary.ts +2 -0
- package/packages/core/src/cli/project-credentials.ts +132 -0
- package/packages/core/src/cli/repo-state.ts +15 -2
- package/packages/core/src/cli/repository-status.ts +45 -5
- package/packages/core/src/cli/self-update.ts +10 -0
- package/packages/core/src/cli/store-opening.ts +22 -14
- package/packages/core/src/cli/terminals.ts +0 -10
- package/packages/core/src/cli/ticket.ts +8 -1
- package/packages/core/src/cli/upgrade-compatibility.ts +80 -0
- package/packages/core/src/cli/wait.ts +84 -17
- package/packages/core/src/cli/watch.ts +350 -68
- package/packages/core/src/config/live.ts +4 -0
- package/packages/core/src/config/schema.ts +65 -11
- package/packages/core/src/connection.ts +86 -0
- package/packages/core/src/events/catalog.ts +10 -2
- package/packages/core/src/events/globs.ts +8 -3
- package/packages/core/src/events/payloads.ts +44 -0
- package/packages/core/src/events/repository.ts +64 -2
- package/packages/core/src/integration/harness.ts +2 -1
- package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +148 -83
- package/packages/core/src/kernel/dispatch-status.ts +9 -1
- package/packages/core/src/kernel/dispatcher-liveness.ts +70 -0
- package/packages/core/src/kernel/engine.ts +24 -0
- package/packages/core/src/kernel/generators/build-log.ts +10 -0
- package/packages/core/src/kernel/log-index.ts +17 -0
- package/packages/core/src/kernel/pr-summary.ts +89 -0
- package/packages/core/src/kernel/reducer-registry.ts +12 -0
- package/packages/core/src/kernel/reducer.ts +8 -0
- package/packages/core/src/kernel/ticket-source-health.ts +30 -0
- package/packages/core/src/ontology.ts +1 -0
- package/packages/core/src/operator/index.ts +7 -0
- package/packages/core/src/operator/query.ts +44 -19
- package/packages/core/src/operator/ticket-source-backend.ts +1 -0
- package/packages/core/src/operator/tickets.ts +6 -8
- package/packages/core/src/plugin-sdk/index.ts +1 -0
- package/packages/core/src/plugins/manifest.ts +5 -3
- package/packages/core/src/plugins/runtimes.ts +3 -1
- package/packages/core/src/ports/forge/fake.ts +13 -1
- package/packages/core/src/ports/forge/github-transport.ts +36 -1
- package/packages/core/src/ports/forge/github.ts +29 -5
- package/packages/core/src/ports/forge/local-git.ts +12 -4
- package/packages/core/src/ports/forge/summary-marker.ts +8 -0
- package/packages/core/src/ports/runner/session-env.ts +1 -0
- package/packages/core/src/ports/tickets/contract.ts +25 -0
- package/packages/core/src/ports/tickets/create.ts +11 -3
- package/packages/core/src/ports/tickets/fake.ts +10 -8
- package/packages/core/src/ports/tickets/file.ts +1 -0
- package/packages/core/src/ports/tickets/hosted-index.ts +0 -3
- package/packages/core/src/ports/tickets/linear.ts +241 -49
- package/packages/core/src/ports/tickets/remote-protocol.ts +3 -0
- package/packages/core/src/ports/tickets/remote.ts +1 -0
- package/packages/core/src/ports/types.ts +17 -0
- package/packages/core/src/ports/workspace/build-execution.ts +5 -1
- package/packages/core/src/ports/workspace/create.ts +11 -2
- package/packages/core/src/ports/workspace/distribution-archive.ts +3 -5
- package/packages/core/src/ports/workspace/harvest-execution.ts +3 -1
- package/packages/core/src/ports/workspace/local-build-execution.ts +8 -1
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +47 -19
- package/packages/core/src/processes/build-execution-state.ts +1 -1
- package/packages/core/src/processes/build-runner.ts +87 -26
- package/packages/core/src/processes/dispatch-failure-budget.ts +83 -0
- package/packages/core/src/processes/dispatcher.ts +336 -83
- package/packages/core/src/processes/harvest-child.ts +1 -0
- package/packages/core/src/processes/harvest-execution-state.ts +19 -2
- package/packages/core/src/processes/harvest-runner.ts +142 -100
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/publication-loss.ts +18 -1
- package/packages/core/src/processes/repo-view.ts +2 -1
- package/packages/core/src/store/adapter.ts +1 -0
- package/packages/core/src/store/contract.ts +109 -0
- package/packages/core/src/store/digest.ts +14 -2
- package/packages/core/src/store/local/store.ts +18 -5
- package/packages/core/src/store/remote/client.ts +1 -1
- package/packages/core/src/store/remote/compatibility.ts +90 -0
- package/packages/core/src/store/remote/credentials.ts +28 -0
- package/packages/core/src/store/remote/index.ts +14 -1
- package/packages/core/src/store/remote/protocol.ts +26 -0
- package/packages/core/src/store/remote/token.ts +74 -13
- package/packages/core/src/store/repo-state-events.ts +49 -59
- package/packages/core/src/store/types.ts +5 -1
- package/packages/core/src/testing/index.ts +7 -0
- package/skills/guide/SKILL.md +175 -26
- package/skills/guide/references/operator-api.md +135 -13
- package/skills/guide/references/plugin-authoring.md +10 -2
- package/skills/guide/references/remote-store-protocol.md +189 -144
- package/skills/guide/references/remote-ticket-protocol.md +111 -18
- package/skills/guide/references/setup.md +173 -16
- package/skills/guide/references/ticket-dependencies.md +1 -1
- package/skills/operate/SKILL.md +159 -34
- package/templates/hosted-service/package.json +13 -0
- package/templates/hosted-service/vercel.json +7 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto'
|
|
2
|
+
import {
|
|
3
|
+
constants,
|
|
4
|
+
fstatSync,
|
|
5
|
+
chmodSync,
|
|
6
|
+
lstatSync,
|
|
7
|
+
mkdirSync,
|
|
8
|
+
openSync,
|
|
9
|
+
closeSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
writeFileSync,
|
|
12
|
+
renameSync,
|
|
13
|
+
unlinkSync,
|
|
14
|
+
} from 'node:fs'
|
|
15
|
+
import { homedir } from 'node:os'
|
|
16
|
+
import { isAbsolute, join } from 'node:path'
|
|
17
|
+
import { normalizeServiceURL } from '../connection'
|
|
18
|
+
import { normalizeGitRemoteUrl } from '../kernel/origin'
|
|
19
|
+
|
|
20
|
+
export interface ProjectCredential {
|
|
21
|
+
service: string
|
|
22
|
+
repo: string
|
|
23
|
+
id: string
|
|
24
|
+
token: string
|
|
25
|
+
}
|
|
26
|
+
export class ProjectCredentials {
|
|
27
|
+
readonly directory: string
|
|
28
|
+
constructor(env: Record<string, string | undefined> = process.env) {
|
|
29
|
+
const root = env.XDG_CONFIG_HOME
|
|
30
|
+
if (root && !isAbsolute(root))
|
|
31
|
+
throw new Error('XDG_CONFIG_HOME must be absolute for project credentials')
|
|
32
|
+
this.directory = join(
|
|
33
|
+
root ||
|
|
34
|
+
(env.HOME && isAbsolute(env.HOME) ? join(env.HOME, '.config') : join(homedir(), '.config')),
|
|
35
|
+
'autobuild',
|
|
36
|
+
'credentials',
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
private path(service: string, repo: string): string {
|
|
40
|
+
return join(
|
|
41
|
+
this.directory,
|
|
42
|
+
`${createHash('sha256')
|
|
43
|
+
.update(JSON.stringify([normalizeServiceURL(service), normalizeGitRemoteUrl(repo)]))
|
|
44
|
+
.digest('hex')}.json`,
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
private guard(path: string): boolean {
|
|
48
|
+
try {
|
|
49
|
+
const info = lstatSync(path)
|
|
50
|
+
if (!info.isFile() || info.isSymbolicLink()) throw new Error('unsafe credential file')
|
|
51
|
+
return true
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return false
|
|
54
|
+
throw error
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
load(service: string, repo: string): ProjectCredential | undefined {
|
|
58
|
+
try {
|
|
59
|
+
const path = this.path(service, repo)
|
|
60
|
+
if (!this.guard(path)) return undefined
|
|
61
|
+
const directory = lstatSync(this.directory)
|
|
62
|
+
if (directory.isSymbolicLink() || (directory.mode & 0o777) !== 0o700) throw new Error()
|
|
63
|
+
const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW)
|
|
64
|
+
let entry: ProjectCredential
|
|
65
|
+
try {
|
|
66
|
+
if ((fstatSync(fd).mode & 0o777) !== 0o600) throw new Error()
|
|
67
|
+
entry = JSON.parse(readFileSync(fd, 'utf8'))
|
|
68
|
+
} finally {
|
|
69
|
+
closeSync(fd)
|
|
70
|
+
}
|
|
71
|
+
if (
|
|
72
|
+
entry.service !== normalizeServiceURL(service) ||
|
|
73
|
+
entry.repo !== normalizeGitRemoteUrl(repo) ||
|
|
74
|
+
typeof entry.id !== 'string' ||
|
|
75
|
+
typeof entry.token !== 'string' ||
|
|
76
|
+
!/^[a-f0-9]{32}$/.test(entry.id) ||
|
|
77
|
+
!new RegExp(`^abp_1_${entry.id}_[a-f0-9]{64}$`).test(entry.token)
|
|
78
|
+
)
|
|
79
|
+
throw new Error()
|
|
80
|
+
return entry
|
|
81
|
+
} catch {
|
|
82
|
+
throw new Error(
|
|
83
|
+
'Cannot read project credential; repair user credential storage and run ab connect',
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
save(entry: ProjectCredential): void {
|
|
88
|
+
const path = this.path(entry.service, entry.repo)
|
|
89
|
+
let temporary: string | undefined
|
|
90
|
+
try {
|
|
91
|
+
mkdirSync(this.directory, { recursive: true, mode: 0o700 })
|
|
92
|
+
if (lstatSync(this.directory).isSymbolicLink()) throw new Error()
|
|
93
|
+
chmodSync(this.directory, 0o700)
|
|
94
|
+
this.guard(path)
|
|
95
|
+
temporary = `${path}.${randomUUID()}`
|
|
96
|
+
const fd = openSync(temporary, 'wx', 0o600)
|
|
97
|
+
try {
|
|
98
|
+
writeFileSync(fd, `${JSON.stringify(entry)}\n`)
|
|
99
|
+
} finally {
|
|
100
|
+
closeSync(fd)
|
|
101
|
+
}
|
|
102
|
+
renameSync(temporary, path)
|
|
103
|
+
} catch {
|
|
104
|
+
throw new Error('Cannot save project credential; check user credential directory permissions')
|
|
105
|
+
} finally {
|
|
106
|
+
if (temporary) {
|
|
107
|
+
try {
|
|
108
|
+
unlinkSync(temporary)
|
|
109
|
+
} catch {
|
|
110
|
+
/* renamed or absent */
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
remove(service: string, repo: string): void {
|
|
116
|
+
const path = this.path(service, repo)
|
|
117
|
+
if (this.guard(path)) unlinkSync(path)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export function projectToken(
|
|
121
|
+
service: string,
|
|
122
|
+
repo: string,
|
|
123
|
+
env: Record<string, string | undefined>,
|
|
124
|
+
): string | undefined {
|
|
125
|
+
if (env.AB_TOKEN !== undefined && env.AB_TOKEN !== '') return env.AB_TOKEN
|
|
126
|
+
try {
|
|
127
|
+
normalizeServiceURL(service)
|
|
128
|
+
} catch {
|
|
129
|
+
return undefined
|
|
130
|
+
}
|
|
131
|
+
return new ProjectCredentials(env).load(service, repo)?.token
|
|
132
|
+
}
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* normalized against that checkout so the dispatcher and agents cannot
|
|
21
21
|
* interpret a relative path from different working directories.
|
|
22
22
|
*/
|
|
23
|
+
import { configuredStore } from './configured-store'
|
|
23
24
|
import { basename, dirname, isAbsolute, join, resolve } from 'node:path'
|
|
24
25
|
import type { Exec } from '../ports/workspace/git-worktree'
|
|
25
26
|
import type { BuildRecord } from '../store/types'
|
|
@@ -92,6 +93,8 @@ export async function resolveMainRepo(targetRepo: string, exec: Exec): Promise<s
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
export interface RepoStatePaths {
|
|
96
|
+
/** Validated repository setting used for this selection, when present. */
|
|
97
|
+
configStore?: string
|
|
95
98
|
/** Repository identity in BuildStore records/journals: the checkout's
|
|
96
99
|
* normalized origin URL, falling back to the resolved checkout path only
|
|
97
100
|
* when the checkout has no origin remote. Opaque to the store schema. */
|
|
@@ -116,7 +119,7 @@ function nonBlank(value: string | undefined): string | undefined {
|
|
|
116
119
|
|
|
117
120
|
/**
|
|
118
121
|
* Select state with one precedence rule for every sessionless command:
|
|
119
|
-
* non-blank explicit `--store` > non-blank `AB_STORE` >
|
|
122
|
+
* non-blank explicit `--store` > non-blank `AB_STORE` > `[store] url` > local default.
|
|
120
123
|
*
|
|
121
124
|
* A local selection relocates the whole local tree, including worktrees. A
|
|
122
125
|
* remote store has no filesystem root, so its worktrees remain local beneath
|
|
@@ -130,14 +133,20 @@ export function resolveRepoStatePaths(opts: {
|
|
|
130
133
|
checkout?: string
|
|
131
134
|
storeRef?: string
|
|
132
135
|
envStore?: string
|
|
136
|
+
configStore?: string
|
|
133
137
|
}): RepoStatePaths {
|
|
134
138
|
const checkout = resolve(opts.checkout ?? opts.repo)
|
|
135
139
|
const defaultLocalRoot = join(checkout, LOCAL_STATE_DIR)
|
|
136
|
-
const selected =
|
|
140
|
+
const selected =
|
|
141
|
+
nonBlank(opts.storeRef) ??
|
|
142
|
+
nonBlank(opts.envStore) ??
|
|
143
|
+
nonBlank(opts.configStore) ??
|
|
144
|
+
defaultLocalRoot
|
|
137
145
|
const remote = isRemoteStoreRef(selected)
|
|
138
146
|
const storeRef = remote ? selected : resolve(checkout, selected)
|
|
139
147
|
const localStateRoot = remote ? defaultLocalRoot : storeRef
|
|
140
148
|
return {
|
|
149
|
+
...(opts.configStore !== undefined ? { configStore: opts.configStore } : {}),
|
|
141
150
|
repo: opts.repo,
|
|
142
151
|
checkout,
|
|
143
152
|
defaultLocalRoot,
|
|
@@ -223,10 +232,14 @@ export async function resolveRepoState(opts: {
|
|
|
223
232
|
exec: Exec
|
|
224
233
|
storeRef?: string
|
|
225
234
|
envStore?: string
|
|
235
|
+
configStore?: string
|
|
226
236
|
}): Promise<RepoStatePaths> {
|
|
227
237
|
const checkout = await resolveMainRepo(opts.targetRepo, opts.exec)
|
|
228
238
|
const origin = await resolveRepoOrigin(checkout, opts.exec)
|
|
229
239
|
return resolveRepoStatePaths({
|
|
240
|
+
configStore:
|
|
241
|
+
opts.configStore ??
|
|
242
|
+
(nonBlank(opts.storeRef) || nonBlank(opts.envStore) ? undefined : configuredStore(checkout)),
|
|
230
243
|
repo: origin ?? checkout,
|
|
231
244
|
checkout,
|
|
232
245
|
...(opts.storeRef !== undefined ? { storeRef: opts.storeRef } : {}),
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatDispatcherIdentity,
|
|
3
|
+
projectDispatcherLiveness,
|
|
4
|
+
type DispatcherLiveness,
|
|
5
|
+
} from '../kernel/dispatcher-liveness'
|
|
6
|
+
import { readDispatcherLiveness } from './dispatcher-liveness'
|
|
7
|
+
import {
|
|
8
|
+
reduceTicketSourceHealth,
|
|
9
|
+
type TicketSourceDegradation,
|
|
10
|
+
} from '../kernel/ticket-source-health'
|
|
1
11
|
import type { RepositoryEvent } from '../events/repository'
|
|
2
12
|
import { reduceDispatchSettings, type DispatchSettings } from '../kernel/dispatch-settings'
|
|
3
13
|
import { sandboxStates } from '../processes/sandbox-state'
|
|
@@ -7,6 +17,8 @@ import { withSessionlessStore, type StoreOpener } from './store-opening'
|
|
|
7
17
|
/** Script-facing projection returned by `ab repository status`. */
|
|
8
18
|
export interface RepositoryStatus extends DispatchSettings {
|
|
9
19
|
repo: string
|
|
20
|
+
dispatcher: DispatcherLiveness
|
|
21
|
+
ticketSourceDegradation?: TicketSourceDegradation
|
|
10
22
|
/** Live operator sandboxes (AUT-340); released environments are omitted. */
|
|
11
23
|
sandboxes: Array<{
|
|
12
24
|
operator: string
|
|
@@ -38,10 +50,15 @@ export interface RepositoryStatusOpts {
|
|
|
38
50
|
json?: boolean
|
|
39
51
|
/** Explicit --store reference; precedence is owned by repo-state.ts. */
|
|
40
52
|
storeRef?: string
|
|
53
|
+
now?: () => Date
|
|
41
54
|
openStore?: StoreOpener
|
|
42
55
|
}
|
|
43
56
|
|
|
44
|
-
export function projectRepositoryStatus(
|
|
57
|
+
export function projectRepositoryStatus(
|
|
58
|
+
repo: string,
|
|
59
|
+
events: RepositoryEvent[],
|
|
60
|
+
dispatcher = projectDispatcherLiveness(null, [], new Date()),
|
|
61
|
+
): RepositoryStatus {
|
|
45
62
|
const publications: RepositoryStatus['publications'] = []
|
|
46
63
|
for (const event of events) {
|
|
47
64
|
if (event.type !== 'orchestrator.sandbox.published') continue
|
|
@@ -63,8 +80,11 @@ export function projectRepositoryStatus(repo: string, events: RepositoryEvent[])
|
|
|
63
80
|
})
|
|
64
81
|
}
|
|
65
82
|
publications.reverse()
|
|
83
|
+
const active = reduceTicketSourceHealth(events)
|
|
66
84
|
return {
|
|
85
|
+
...(active === undefined ? {} : { ticketSourceDegradation: active }),
|
|
67
86
|
repo,
|
|
87
|
+
dispatcher,
|
|
68
88
|
...reduceDispatchSettings(events),
|
|
69
89
|
sandboxes: sandboxStates(events)
|
|
70
90
|
.filter((state) => state.state !== 'released')
|
|
@@ -81,8 +101,30 @@ export function projectRepositoryStatus(repo: string, events: RepositoryEvent[])
|
|
|
81
101
|
|
|
82
102
|
export function renderRepositoryStatus(status: RepositoryStatus): string[] {
|
|
83
103
|
const setting = (enabled: boolean): string => (enabled ? 'ON' : 'OFF')
|
|
104
|
+
const active = status.ticketSourceDegradation
|
|
84
105
|
return [
|
|
106
|
+
...(active === undefined
|
|
107
|
+
? []
|
|
108
|
+
: [
|
|
109
|
+
`ticket source ${active.source}: ${active.cause} (${active.operation}) — ${active.message}${'resetAt' in active ? `; reset ${active.resetAt}` : ''}`,
|
|
110
|
+
]),
|
|
85
111
|
`repository: ${status.repo}`,
|
|
112
|
+
`dispatcher: ${status.dispatcher.state}${status.dispatcher.holder ? ` — ${formatDispatcherIdentity(status.dispatcher.holder)}` : ' — no dispatcher holds the repository'}`,
|
|
113
|
+
...(status.dispatcher.expiredHolder
|
|
114
|
+
? [`expired dispatcher: ${formatDispatcherIdentity(status.dispatcher.expiredHolder)}`]
|
|
115
|
+
: []),
|
|
116
|
+
...[status.dispatcher.holder ?? status.dispatcher.expiredHolder].flatMap((run) =>
|
|
117
|
+
run
|
|
118
|
+
? [
|
|
119
|
+
`last tick: ${run.lastTickAt ?? 'unknown'} (${run.lastTickAgeMs ?? 'unknown'}ms ago); ${JSON.stringify(run.lastTick)}`,
|
|
120
|
+
]
|
|
121
|
+
: [],
|
|
122
|
+
),
|
|
123
|
+
...(status.dispatcher.latestStoppedRun
|
|
124
|
+
? [
|
|
125
|
+
`last dispatcher stop: ${status.dispatcher.latestStoppedRun.stoppedAt}; ${status.dispatcher.latestStoppedRun.stop?.outcome}; signal ${status.dispatcher.latestStoppedRun.stop?.signal ?? 'none'}`,
|
|
126
|
+
]
|
|
127
|
+
: []),
|
|
86
128
|
`intake: ${setting(status.intake)}`,
|
|
87
129
|
`repository pause: ${setting(status.paused)}`,
|
|
88
130
|
`default auto-merge: ${setting(status.defaultAutoMerge)}`,
|
|
@@ -105,10 +147,8 @@ export async function abRepositoryStatus(opts: RepositoryStatusOpts): Promise<vo
|
|
|
105
147
|
await withSessionlessStore(opts, async ({ store, repo }) => {
|
|
106
148
|
// A fresh store has no repository row. Do not call ensureRepo: this query's
|
|
107
149
|
// empty-stream defaults must remain a genuinely read-only operation.
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
const events = record === null ? [] : await store.getRepoStateEvents(repo)
|
|
111
|
-
const status = projectRepositoryStatus(repo, events)
|
|
150
|
+
const { events, dispatcher } = await readDispatcherLiveness(store, repo, opts.now?.())
|
|
151
|
+
const status = projectRepositoryStatus(repo, events, dispatcher)
|
|
112
152
|
if (opts.json === true) {
|
|
113
153
|
opts.stdout(JSON.stringify(status, null, 2))
|
|
114
154
|
return
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkUpgradeCompatibility, type CompatibilityFetch } from './upgrade-compatibility'
|
|
1
2
|
import { readFile, writeFile } from 'node:fs/promises'
|
|
2
3
|
import semver from 'semver'
|
|
3
4
|
import type { ExecResult } from '../ports/workspace/git-worktree'
|
|
@@ -71,6 +72,7 @@ export function registryVersion(response: { status: number; body: string }): str
|
|
|
71
72
|
|
|
72
73
|
export interface SelfUpdateOptions {
|
|
73
74
|
targetRepo: string
|
|
75
|
+
compatibilityFetch?: CompatibilityFetch
|
|
74
76
|
version?: string
|
|
75
77
|
distRoot?: string
|
|
76
78
|
env?: Record<string, string | undefined>
|
|
@@ -393,6 +395,14 @@ export async function selfUpdate(options: SelfUpdateOptions): Promise<SelfUpdate
|
|
|
393
395
|
return { kind: 'continue' }
|
|
394
396
|
}
|
|
395
397
|
|
|
398
|
+
await checkUpgradeCompatibility({
|
|
399
|
+
targetRepo: options.targetRepo,
|
|
400
|
+
version: resolved,
|
|
401
|
+
env: options.env,
|
|
402
|
+
stderr: options.stderr,
|
|
403
|
+
fetch: options.compatibilityFetch,
|
|
404
|
+
})
|
|
405
|
+
|
|
396
406
|
const dependency = updateDependency(install, resolved)
|
|
397
407
|
let updateCommand: string[]
|
|
398
408
|
if (install.scope === 'global') {
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* joins those seams to the production remote adapter and owns finite-command
|
|
7
7
|
* store lifecycle.
|
|
8
8
|
*/
|
|
9
|
+
import { projectToken } from './project-credentials'
|
|
10
|
+
import { isRemoteStoreRef } from './repo-state'
|
|
9
11
|
import type { Exec } from '../ports/workspace/git-worktree'
|
|
10
12
|
import { RemoteBuildStore } from '../store/remote/client'
|
|
11
13
|
import { scopeLocalStoreToPhaseSession } from '../store/phase-session'
|
|
@@ -16,7 +18,7 @@ import {
|
|
|
16
18
|
type CliEnv,
|
|
17
19
|
type HarvestCliEnv,
|
|
18
20
|
} from './env'
|
|
19
|
-
import {
|
|
21
|
+
import { resolveRepoState, type RepoStatePaths } from './repo-state'
|
|
20
22
|
import { resolveStore } from './store-ref'
|
|
21
23
|
|
|
22
24
|
/** Shared injection seam used by every command that opens a BuildStore. */
|
|
@@ -39,15 +41,14 @@ export const openProductionStore: StoreOpener = (ref, token) => {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/** Apply validated ambient authority to a selected Store handle. Remote
|
|
42
|
-
* handles retain
|
|
43
|
-
* the
|
|
44
|
+
* handles retain server-side project authorization; every handle receives
|
|
45
|
+
* the same in-process build/session scope. Keeping this primitive shared prevents
|
|
44
46
|
* phase commands and ambient-aware query commands from drifting. */
|
|
45
47
|
function scopeSelectedStoreToPhaseSession(
|
|
46
48
|
store: BuildStore,
|
|
47
|
-
|
|
49
|
+
_ref: string,
|
|
48
50
|
env: AmbientReadSession,
|
|
49
51
|
): BuildStore {
|
|
50
|
-
if (isRemoteStoreRef(ref)) return store
|
|
51
52
|
return scopeLocalStoreToPhaseSession(
|
|
52
53
|
store,
|
|
53
54
|
'build' in env
|
|
@@ -65,15 +66,15 @@ export interface OpenedStoreContext extends RepoStatePaths {
|
|
|
65
66
|
store: BuildStore
|
|
66
67
|
token?: string
|
|
67
68
|
/** The validated ambient phase/Harvest identity this invocation carries, if
|
|
68
|
-
* any — the same value that scoped `store
|
|
69
|
-
*
|
|
70
|
-
* where no session wrapper exists. */
|
|
69
|
+
* any — the same value that scoped `store`. Exposed for commands whose
|
|
70
|
+
* repository selection also depends on ambient own-build authority. */
|
|
71
71
|
ambient?: AmbientReadSession
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export interface OpenStoreForRepoStateOpts {
|
|
75
75
|
env: Record<string, string | undefined>
|
|
76
76
|
openStore?: StoreOpener
|
|
77
|
+
useProjectCredential?: boolean
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
/** Open from an already canonicalized state selection. Dispatch uses this form
|
|
@@ -82,7 +83,13 @@ export function openStoreForRepoState(
|
|
|
82
83
|
state: RepoStatePaths,
|
|
83
84
|
opts: OpenStoreForRepoStateOpts,
|
|
84
85
|
): OpenedStoreContext {
|
|
85
|
-
const token =
|
|
86
|
+
const token =
|
|
87
|
+
opts.useProjectCredential !== false && isRemoteStoreRef(state.storeRef)
|
|
88
|
+
? projectToken(state.storeRef, state.repo, opts.env)
|
|
89
|
+
: optionalToken(opts.env.AB_TOKEN)
|
|
90
|
+
if (!token && isRemoteStoreRef(state.storeRef) && state.configStore === state.storeRef) {
|
|
91
|
+
throw new Error('No project credential for this service; run ab connect')
|
|
92
|
+
}
|
|
86
93
|
const store = (opts.openStore ?? openProductionStore)(state.storeRef, token)
|
|
87
94
|
return {
|
|
88
95
|
...state,
|
|
@@ -115,10 +122,8 @@ export async function openSessionlessStore(
|
|
|
115
122
|
/** Finite command ownership boundary. Opening failures occur before the
|
|
116
123
|
* try/finally, so only a successfully returned handle is ever closed.
|
|
117
124
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* consume `ambient` from the context directly rather than rely on the handle
|
|
121
|
-
* enforcing a scope. */
|
|
125
|
+
* Ambient query openers apply in-process build/session scope to both local
|
|
126
|
+
* and remote handles; the server additionally enforces project authority. */
|
|
122
127
|
export async function withSessionlessStore<T>(
|
|
123
128
|
opts: SessionlessStoreOpts,
|
|
124
129
|
use: (context: OpenedStoreContext) => Promise<T> | T,
|
|
@@ -145,7 +150,10 @@ export async function openAmbientReadStore(
|
|
|
145
150
|
...(opts.storeRef !== undefined ? { storeRef: opts.storeRef } : {}),
|
|
146
151
|
...(opts.env.AB_STORE !== undefined ? { envStore: opts.env.AB_STORE } : {}),
|
|
147
152
|
})
|
|
148
|
-
const context = openStoreForRepoState(state,
|
|
153
|
+
const context = openStoreForRepoState(state, {
|
|
154
|
+
...opts,
|
|
155
|
+
useProjectCredential: ambient === undefined,
|
|
156
|
+
})
|
|
149
157
|
if (ambient === undefined) return context
|
|
150
158
|
return {
|
|
151
159
|
...context,
|
|
@@ -50,7 +50,6 @@ import type { ArtifactMeta, BuildStore } from '../store/types'
|
|
|
50
50
|
import { textContent } from '../store/types'
|
|
51
51
|
import { expandIssues } from '../zod-issues'
|
|
52
52
|
import { preparePrAttachments } from './pr-attachments'
|
|
53
|
-
import { renderPrSummary } from './pr-summary'
|
|
54
53
|
import type { CliEnv } from './env'
|
|
55
54
|
|
|
56
55
|
/** Structural subset of CliDeps (src/cli/main.ts) — what terminals need. */
|
|
@@ -441,15 +440,6 @@ export async function completeFinalizePr(
|
|
|
441
440
|
}
|
|
442
441
|
}
|
|
443
442
|
|
|
444
|
-
try {
|
|
445
|
-
await deps.forge.commentOnPr(
|
|
446
|
-
deps.workspacePath,
|
|
447
|
-
pr.number,
|
|
448
|
-
renderPrSummary(env, await store.getEvents(env.build)),
|
|
449
|
-
)
|
|
450
|
-
} catch {
|
|
451
|
-
// The durable audit trail remains authoritative.
|
|
452
|
-
}
|
|
453
443
|
return event
|
|
454
444
|
}
|
|
455
445
|
|
|
@@ -199,13 +199,20 @@ export async function openTicketSource(
|
|
|
199
199
|
const plugins = await loadPlugins(config.plugins, targetRepo)
|
|
200
200
|
const repoState = resolveRepoStatePaths({
|
|
201
201
|
repo: targetRepo,
|
|
202
|
+
configStore: config.store?.url,
|
|
202
203
|
...(opts.storeRef !== undefined ? { storeRef: opts.storeRef } : {}),
|
|
203
204
|
...(opts.env.AB_STORE !== undefined ? { envStore: opts.env.AB_STORE } : {}),
|
|
204
205
|
})
|
|
205
206
|
const factory = opts.sourceFactory ?? createTicketSource
|
|
206
207
|
return {
|
|
207
208
|
config,
|
|
208
|
-
source: await factory(
|
|
209
|
+
source: await factory(
|
|
210
|
+
config.tickets,
|
|
211
|
+
config.tickets.source === 'hosted' ? { ...opts.env, AB_STORE: repoState.storeRef } : opts.env,
|
|
212
|
+
targetRepo,
|
|
213
|
+
repoState.localStateRoot,
|
|
214
|
+
plugins,
|
|
215
|
+
),
|
|
209
216
|
}
|
|
210
217
|
}
|
|
211
218
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { spawnExec } from '../ports/workspace/git-worktree'
|
|
2
|
+
import { readDistributionIdentity } from './installation'
|
|
3
|
+
import { isRemoteStoreRef, resolveRepoState } from './repo-state'
|
|
4
|
+
import {
|
|
5
|
+
classifyClient,
|
|
6
|
+
compatibilityAdvice,
|
|
7
|
+
stableVersion,
|
|
8
|
+
supportedClientRangeSchema,
|
|
9
|
+
} from '../store/remote/compatibility'
|
|
10
|
+
|
|
11
|
+
export type CompatibilityFetch = (url: string, init: RequestInit) => Promise<Response>
|
|
12
|
+
|
|
13
|
+
/** Read-only, advisory, and deliberately credential-free. Never expose a store URL. */
|
|
14
|
+
export async function checkUpgradeCompatibility(options: {
|
|
15
|
+
targetRepo: string
|
|
16
|
+
version?: string
|
|
17
|
+
distRoot?: string
|
|
18
|
+
env?: Record<string, string | undefined>
|
|
19
|
+
stderr: (line: string) => void
|
|
20
|
+
fetch?: CompatibilityFetch
|
|
21
|
+
timeoutMs?: number
|
|
22
|
+
}): Promise<void> {
|
|
23
|
+
const paths = await resolveRepoState({
|
|
24
|
+
targetRepo: options.targetRepo,
|
|
25
|
+
exec: spawnExec,
|
|
26
|
+
envStore: (options.env ?? process.env).AB_STORE,
|
|
27
|
+
})
|
|
28
|
+
if (!isRemoteStoreRef(paths.storeRef)) return
|
|
29
|
+
const unknown = () =>
|
|
30
|
+
options.stderr(
|
|
31
|
+
'warning: hosted service compatibility could not be verified; the upgraded project may fail to connect',
|
|
32
|
+
)
|
|
33
|
+
try {
|
|
34
|
+
const targetVersion =
|
|
35
|
+
options.version ?? (await readDistributionIdentity(options.distRoot)).version
|
|
36
|
+
const url = new URL(paths.storeRef)
|
|
37
|
+
url.username = ''
|
|
38
|
+
url.password = ''
|
|
39
|
+
url.search = ''
|
|
40
|
+
url.hash = ''
|
|
41
|
+
url.pathname = `${url.pathname.replace(/\/$/, '')}/health`
|
|
42
|
+
const controller = new AbortController()
|
|
43
|
+
let timeout: ReturnType<typeof setTimeout> | undefined
|
|
44
|
+
const expired = new Promise<never>((_, reject) => {
|
|
45
|
+
timeout = setTimeout(() => {
|
|
46
|
+
controller.abort()
|
|
47
|
+
reject(new Error('timeout'))
|
|
48
|
+
}, options.timeoutMs ?? 3000)
|
|
49
|
+
})
|
|
50
|
+
const response = await Promise.race([
|
|
51
|
+
(async () => {
|
|
52
|
+
const response = await (options.fetch ?? fetch)(url.toString(), {
|
|
53
|
+
signal: controller.signal,
|
|
54
|
+
redirect: 'error',
|
|
55
|
+
})
|
|
56
|
+
if (response.status !== 200) throw new Error('health failed')
|
|
57
|
+
return (await response.json()) as Record<string, unknown>
|
|
58
|
+
})(),
|
|
59
|
+
expired,
|
|
60
|
+
]).finally(() => clearTimeout(timeout))
|
|
61
|
+
if (!response || !stableVersion(response.autobuildVersion)) return unknown()
|
|
62
|
+
const serviceVersion = response.autobuildVersion as string
|
|
63
|
+
if (!Object.hasOwn(response, 'supportedClientRange')) {
|
|
64
|
+
if (targetVersion !== serviceVersion)
|
|
65
|
+
options.stderr(
|
|
66
|
+
`warning: service Autobuild ${serviceVersion} requires an exact client version; target ${targetVersion} differs. Upgrade the service to the compatibility-window release first to publish a supported client range; the upgraded project may fail to connect`,
|
|
67
|
+
)
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
const range = supportedClientRangeSchema.safeParse(response.supportedClientRange)
|
|
71
|
+
if (!range.success || classifyClient(targetVersion, range.data) === 'invalid') return unknown()
|
|
72
|
+
const advice = compatibilityAdvice(targetVersion, serviceVersion, range.data)
|
|
73
|
+
if (advice)
|
|
74
|
+
options.stderr(
|
|
75
|
+
`warning: target Autobuild ${targetVersion}: ${advice}; the upgraded project may fail to connect`,
|
|
76
|
+
)
|
|
77
|
+
} catch {
|
|
78
|
+
unknown()
|
|
79
|
+
}
|
|
80
|
+
}
|