Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
gstack/scripts/preflight-agent-sdk.ts at main · garrytan/gstack · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
garrytan
gstack
Repository navigation
Code
Issues
153
(153)
Pull requests
28
(28)
Actions
Projects
Security and quality
1
(1)
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
gstack
/
scripts
/
preflight-agent-sdk.ts
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
161 lines (147 loc) · 5.56 KB
main
Breadcrumbs
gstack
/
scripts
/
preflight-agent-sdk.ts
Copy path
Top
File metadata and controls
Code
Blame
161 lines (147 loc) · 5.56 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
* Preflight for the overlay efficacy harness.
*
* Confirms, before any paid eval runs:
* 1. `@anthropic-ai/claude-agent-sdk` loads and `query()` is the expected shape.
* 2. `claude-opus-4-7` is a live API model ID (not a Claude Code alias).
* 3. The SDK event stream contains the types we assume (system init, assistant,
* result) with the fields we destructure.
* 4. `scripts/resolvers/model-overlay.ts` resolves `{{INHERIT:claude}}` against
* `opus-4-7.md` with no unresolved inheritance directives.
* 5. A local `claude` binary exists at `which claude` so binary pinning is possible.
*
* Run: bun run scripts/preflight-agent-sdk.ts [--live]
*
* Checks 1-2 and 4-5 are free. Check 3 (the live SDK query, ~15 tokens of API
* spend) runs only with --live. Exit 0 on success, 1 on any failed check,
* 2 on a bad argument.
*/
import
'../lib/conductor-env-shim'
;
import
{
query
,
type
SDKMessage
}
from
'@anthropic-ai/claude-agent-sdk'
;
import
{
readOverlay
}
from
'./resolvers/model-overlay'
;
import
{
resolveClaudeBinary
}
from
'../lib/claude-bin'
;
const
USAGE
=
`Usage: bun run scripts/preflight-agent-sdk.ts [--live]
Free checks: overlay resolution and local claude binary pinning.
--live also runs one end-to-end SDK query against claude-opus-4-7
(~15 tokens of API spend; needs ANTHROPIC_API_KEY).`
;
function
parsePreflightArgs
(
argv
:
string
[
]
)
:
{
help
:
boolean
;
live
:
boolean
}
{
const
parsed
=
{
help
:
false
,
live
:
false
}
;
for
(
const
arg
of
argv
)
{
if
(
arg
===
'--help'
||
arg
===
'-h'
)
parsed
.
help
=
true
;
else
if
(
arg
===
'--live'
)
parsed
.
live
=
true
;
else
throw
new
Error
(
`unknown argument "
${
arg
}
"`
)
;
}
return
parsed
;
}
async
function
main
(
)
{
let
args
:
{
help
:
boolean
;
live
:
boolean
}
;
try
{
args
=
parsePreflightArgs
(
process
.
argv
.
slice
(
2
)
)
;
}
catch
(
err
)
{
console
.
error
(
`preflight-agent-sdk:
${
(
err
as
Error
)
.
message
}
\n\n
${
USAGE
}
`
)
;
process
.
exit
(
2
)
;
}
if
(
args
.
help
)
{
console
.
log
(
USAGE
)
;
return
;
}
const
failures
:
string
[
]
=
[
]
;
const
pass
=
(
msg
:
string
)
=>
console
.
log
(
` ok
${
msg
}
`
)
;
const
fail
=
(
msg
:
string
)
=>
{
console
.
log
(
` FAIL
${
msg
}
`
)
;
failures
.
push
(
msg
)
;
}
;
// 1. Overlay resolver
console
.
log
(
'1. Overlay resolver'
)
;
const
resolved
=
readOverlay
(
'opus-4-7'
)
;
if
(
!
resolved
)
{
fail
(
"readOverlay('opus-4-7') returned empty"
)
;
}
else
{
pass
(
`resolved overlay length:
${
resolved
.
length
}
chars`
)
;
if
(
resolved
.
includes
(
'{{INHERIT:'
)
)
{
fail
(
'resolved overlay still contains {{INHERIT:...}} directive'
)
;
}
else
{
pass
(
'no unresolved INHERIT directives'
)
;
}
}
// 2. Local claude binary exists
console
.
log
(
'\n2. Binary pinning'
)
;
let
claudePath
:
string
|
null
=
resolveClaudeBinary
(
)
;
if
(
claudePath
)
{
pass
(
`local claude binary:
${
claudePath
}
`
)
;
}
else
{
fail
(
'`Bun.which("claude")` failed — cannot pin binary (set GSTACK_CLAUDE_BIN to override)'
)
;
}
// 3. SDK query end-to-end
console
.
log
(
'\n3. SDK query end-to-end'
)
;
if
(
!
args
.
live
)
{
console
.
log
(
' skip live query not requested — rerun with --live to spend ~15 tokens on it'
)
;
}
else
if
(
!
process
.
env
.
ANTHROPIC_API_KEY
)
{
console
.
log
(
' skip ANTHROPIC_API_KEY not set — cannot test live query'
)
;
}
else
{
try
{
const
events
:
SDKMessage
[
]
=
[
]
;
const
q
=
query
(
{
prompt
:
'say pong'
,
options
:
{
model
:
'claude-opus-4-7'
,
systemPrompt
:
''
,
tools
:
[
]
,
permissionMode
:
'bypassPermissions'
,
allowDangerouslySkipPermissions
:
true
,
settingSources
:
[
]
,
maxTurns
:
1
,
pathToClaudeCodeExecutable
:
claudePath
??
undefined
,
env
:
{
ANTHROPIC_API_KEY
:
process
.
env
.
ANTHROPIC_API_KEY
}
,
}
,
}
)
;
for
await
(
const
ev
of
q
)
events
.
push
(
ev
)
;
pass
(
`received
${
events
.
length
}
events`
)
;
const
init
=
events
.
find
(
(
e
)
=>
e
.
type
===
'system'
&&
(
e
as
{
subtype
?:
string
}
)
.
subtype
===
'init'
,
)
as
{
claude_code_version
?:
string
;
model
?:
string
}
|
undefined
;
if
(
!
init
)
{
fail
(
'no system/init event received'
)
;
}
else
{
pass
(
`system init: claude_code_version=
${
init
.
claude_code_version
}
, model=
${
init
.
model
}
`
)
;
}
const
assistantEvents
=
events
.
filter
(
(
e
)
=>
e
.
type
===
'assistant'
)
;
if
(
assistantEvents
.
length
===
0
)
{
fail
(
'no assistant events received — model ID may be rejected'
)
;
}
else
{
pass
(
`received
${
assistantEvents
.
length
}
assistant event(s)`
)
;
const
first
=
assistantEvents
[
0
]
as
{
message
?:
{
content
?:
unknown
[
]
}
}
;
const
content
=
first
.
message
?.
content
;
if
(
!
Array
.
isArray
(
content
)
)
{
fail
(
'first assistant event has no content[] array'
)
;
}
else
{
pass
(
`first assistant content[] has
${
content
.
length
}
block(s)`
)
;
}
}
const
result
=
events
.
find
(
(
e
)
=>
e
.
type
===
'result'
)
as
|
{
subtype
?:
string
;
total_cost_usd
?:
number
;
num_turns
?:
number
}
|
undefined
;
if
(
!
result
)
{
fail
(
'no result event received'
)
;
}
else
{
pass
(
`result: subtype=
${
result
.
subtype
}
, cost=$
${
result
.
total_cost_usd
?.
toFixed
(
4
)
}
, turns=
${
result
.
num_turns
}
`
,
)
;
}
}
catch
(
err
)
{
fail
(
`SDK query threw:
${
err
instanceof
Error
?
err
.
message
:
String
(
err
)
}
`
)
;
}
}
console
.
log
(
)
;
if
(
failures
.
length
>
0
)
{
console
.
log
(
`PREFLIGHT FAILED:
${
failures
.
length
}
check(s) failed`
)
;
process
.
exit
(
1
)
;
}
console
.
log
(
'PREFLIGHT OK'
)
;
}
if
(
import
.
meta
.
main
)
{
main
(
)
.
catch
(
(
err
)
=>
{
console
.
error
(
err
)
;
process
.
exit
(
1
)
;
}
)
;
}
You can’t perform that action at this time.