@@ -14,6 +14,7 @@ function usage() {
1414Usage:
1515 agent-memory-workflow init [--target <path>] [--force] [--dry-run] [--backup-root <path>] [--no-backup] [--overwrite-machine-facts] [--skip-verify]
1616 agent-memory-workflow upgrade [--target <path>] [--dry-run] [--backup-root <path>] [--no-backup] [--overwrite-machine-facts] [--skip-verify]
17+ agent-memory-workflow preflight [--target <path>]
1718 agent-memory-workflow verify [--root <path>]
1819 agent-memory-workflow status [--root <path>]
1920 agent-memory-workflow show-paths [--root <path>]
2223Examples:
2324 agent-memory-workflow init --target "$HOME/.agents"
2425 agent-memory-workflow init --target "$HOME/.agents" --dry-run
26+ agent-memory-workflow preflight --target "$HOME/.agents"
2527 agent-memory-workflow upgrade --target "$HOME/.agents"
2628 agent-memory-workflow verify --root "$HOME/.agents"
2729 agent-memory-workflow status --root "$HOME/.agents"
@@ -165,6 +167,75 @@ function printPaths(root) {
165167 console . log ( `initializer=${ paths . initializer } ` ) ;
166168}
167169
170+ function sourcePaths ( ) {
171+ return {
172+ templates : path . join ( repoRoot , "templates" ) ,
173+ bootstrapTemplate : path . join ( repoRoot , "templates" , "AGENT_BOOTSTRAP.md" ) ,
174+ initializer : path . join ( repoRoot , "tools" , "init-agent-memory-workflow.ps1" ) ,
175+ verifier : path . join ( repoRoot , "tools" , "verify-agent-memory-workflow.ps1" ) ,
176+ } ;
177+ }
178+
179+ function runPreflight ( target ) {
180+ const resolvedTarget = path . resolve ( target ) ;
181+ const paths = workflowPaths ( resolvedTarget ) ;
182+ const sources = sourcePaths ( ) ;
183+ const failures = [ ] ;
184+
185+ console . log ( "Agent memory workflow preflight" ) ;
186+ console . log ( `CLI version: ${ packageJson . version } ` ) ;
187+ console . log ( `Node: ${ process . version } ` ) ;
188+
189+ const pwshVersion = spawnSync ( "pwsh" , [ "--version" ] , { encoding : "utf8" } ) ;
190+ if ( pwshVersion . error && pwshVersion . error . code === "ENOENT" ) {
191+ failures . push ( "PowerShell 7 executable `pwsh` was not found on PATH." ) ;
192+ console . log ( "PowerShell: missing" ) ;
193+ } else if ( pwshVersion . error ) {
194+ failures . push ( pwshVersion . error . message ) ;
195+ console . log ( "PowerShell: error" ) ;
196+ } else {
197+ console . log ( `PowerShell: ${ pwshVersion . stdout . trim ( ) || "available" } ` ) ;
198+ }
199+
200+ console . log ( `Source templates: ${ formatPresent ( sources . templates ) } ` ) ;
201+ console . log ( `Bootstrap template: ${ formatPresent ( sources . bootstrapTemplate ) } ` ) ;
202+ console . log ( `Source initializer: ${ formatPresent ( sources . initializer ) } ` ) ;
203+ console . log ( `Source verifier: ${ formatPresent ( sources . verifier ) } ` ) ;
204+
205+ if ( ! exists ( sources . templates ) ) failures . push ( `Missing source templates: ${ sources . templates } ` ) ;
206+ if ( ! exists ( sources . bootstrapTemplate ) ) failures . push ( `Missing bootstrap template: ${ sources . bootstrapTemplate } ` ) ;
207+ if ( ! exists ( sources . initializer ) ) failures . push ( `Missing source initializer: ${ sources . initializer } ` ) ;
208+ if ( ! exists ( sources . verifier ) ) failures . push ( `Missing source verifier: ${ sources . verifier } ` ) ;
209+
210+ const manifest = readManifest ( paths . manifest ) ;
211+ console . log ( `Target: ${ resolvedTarget } ` ) ;
212+ console . log ( `Target exists: ${ exists ( resolvedTarget ) ? "yes" : "no" } ` ) ;
213+ console . log ( `Target manifest: ${ formatPresent ( paths . manifest ) } ` ) ;
214+ if ( manifest ?. parseError ) {
215+ console . log ( `Target manifest parse: failed (${ manifest . parseError } )` ) ;
216+ } else if ( manifest ) {
217+ console . log ( `Target workflow version: ${ manifest . version ?? "unknown" } ` ) ;
218+ }
219+
220+ if ( ! exists ( resolvedTarget ) ) {
221+ console . log ( "Target mode: fresh install" ) ;
222+ } else if ( manifest ) {
223+ console . log ( "Target mode: existing workflow" ) ;
224+ } else {
225+ console . log ( "Target mode: existing non-workflow directory" ) ;
226+ }
227+
228+ if ( failures . length > 0 ) {
229+ console . log ( "Result: FAIL" ) ;
230+ for ( const failure of failures ) {
231+ console . log ( `- ${ failure } ` ) ;
232+ }
233+ process . exit ( 1 ) ;
234+ }
235+
236+ console . log ( "Result: PASS" ) ;
237+ }
238+
168239function runDoctor ( root ) {
169240 const resolvedRoot = path . resolve ( root ) ;
170241 const paths = workflowPaths ( resolvedRoot ) ;
@@ -241,6 +312,13 @@ function main() {
241312 return ;
242313 }
243314
315+ if ( command === "preflight" ) {
316+ validateOptions ( args , { valueOptions : [ "--target" ] } ) ;
317+ const target = readOption ( args , "--target" , path . join ( os . homedir ( ) , ".agents" ) ) ;
318+ runPreflight ( target ) ;
319+ return ;
320+ }
321+
244322 if ( command === "upgrade" ) {
245323 runInit ( args , { force : true } ) ;
246324 return ;
0 commit comments