@wildo-ai/wildo-cli 1.1.15 → 1.1.16

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 (102) hide show
  1. package/dist/src/commands/context/journey.command.d.ts.map +1 -1
  2. package/dist/src/commands/context/journey.command.js +12 -0
  3. package/dist/src/commands/context/journey.command.js.map +1 -1
  4. package/dist/src/commands/creation/drive.command.d.ts.map +1 -1
  5. package/dist/src/commands/creation/drive.command.js +2 -1
  6. package/dist/src/commands/creation/drive.command.js.map +1 -1
  7. package/dist/src/commands/local/dev.command.d.ts +44 -0
  8. package/dist/src/commands/local/dev.command.d.ts.map +1 -1
  9. package/dist/src/commands/local/dev.command.js +74 -3
  10. package/dist/src/commands/local/dev.command.js.map +1 -1
  11. package/dist/src/commands/providers/grant-export.command.d.ts +16 -0
  12. package/dist/src/commands/providers/grant-export.command.d.ts.map +1 -0
  13. package/dist/src/commands/providers/grant-export.command.js +78 -0
  14. package/dist/src/commands/providers/grant-export.command.js.map +1 -0
  15. package/dist/src/commands/providers/grant-import.command.d.ts +15 -0
  16. package/dist/src/commands/providers/grant-import.command.d.ts.map +1 -0
  17. package/dist/src/commands/providers/grant-import.command.js +78 -0
  18. package/dist/src/commands/providers/grant-import.command.js.map +1 -0
  19. package/dist/src/kernel/command-runner.d.ts.map +1 -1
  20. package/dist/src/kernel/command-runner.js +4 -6
  21. package/dist/src/kernel/command-runner.js.map +1 -1
  22. package/dist/src/kernel/hooks.d.ts.map +1 -1
  23. package/dist/src/kernel/hooks.js +2 -1
  24. package/dist/src/kernel/hooks.js.map +1 -1
  25. package/dist/src/kernel/json-document-output.d.ts +7 -0
  26. package/dist/src/kernel/json-document-output.d.ts.map +1 -1
  27. package/dist/src/kernel/json-document-output.js +8 -0
  28. package/dist/src/kernel/json-document-output.js.map +1 -1
  29. package/dist/src/kernel/types.d.ts +8 -0
  30. package/dist/src/kernel/types.d.ts.map +1 -1
  31. package/dist/src/kernel/types.js.map +1 -1
  32. package/dist/src/services/application/app-bootstrap.service.d.ts +24 -6
  33. package/dist/src/services/application/app-bootstrap.service.d.ts.map +1 -1
  34. package/dist/src/services/application/app-bootstrap.service.js +46 -13
  35. package/dist/src/services/application/app-bootstrap.service.js.map +1 -1
  36. package/dist/src/services/application/app-local-runtime-addresses.service.d.ts +1 -1
  37. package/dist/src/services/application/app-local-runtime-addresses.service.d.ts.map +1 -1
  38. package/dist/src/services/application/app-local-runtime-addresses.service.js.map +1 -1
  39. package/dist/src/services/application/app-runtime-targets.service.d.ts.map +1 -1
  40. package/dist/src/services/application/app-runtime-targets.service.js +7 -1
  41. package/dist/src/services/application/app-runtime-targets.service.js.map +1 -1
  42. package/dist/src/services/application/application-runtime-bootstrap.service.d.ts +13 -0
  43. package/dist/src/services/application/application-runtime-bootstrap.service.d.ts.map +1 -1
  44. package/dist/src/services/application/application-runtime-bootstrap.service.js +32 -0
  45. package/dist/src/services/application/application-runtime-bootstrap.service.js.map +1 -1
  46. package/dist/src/services/application/environment-provider-configurations.service.d.ts +7 -0
  47. package/dist/src/services/application/environment-provider-configurations.service.d.ts.map +1 -1
  48. package/dist/src/services/application/environment-provider-configurations.service.js +1 -1
  49. package/dist/src/services/application/environment-provider-configurations.service.js.map +1 -1
  50. package/dist/src/services/application/local-tunnel.service.d.ts.map +1 -1
  51. package/dist/src/services/application/local-tunnel.service.js +2 -1
  52. package/dist/src/services/application/local-tunnel.service.js.map +1 -1
  53. package/dist/src/services/companion/companion-client.service.d.ts +17 -0
  54. package/dist/src/services/companion/companion-client.service.d.ts.map +1 -1
  55. package/dist/src/services/companion/companion-client.service.js +21 -0
  56. package/dist/src/services/companion/companion-client.service.js.map +1 -1
  57. package/dist/src/services/companion/creation-drive.service.d.ts +18 -0
  58. package/dist/src/services/companion/creation-drive.service.d.ts.map +1 -1
  59. package/dist/src/services/companion/creation-drive.service.js +70 -1
  60. package/dist/src/services/companion/creation-drive.service.js.map +1 -1
  61. package/dist/src/services/deployment/docker/docker-compose-generator.service.d.ts +10 -1
  62. package/dist/src/services/deployment/docker/docker-compose-generator.service.d.ts.map +1 -1
  63. package/dist/src/services/deployment/docker/docker-compose-generator.service.js +24 -10
  64. package/dist/src/services/deployment/docker/docker-compose-generator.service.js.map +1 -1
  65. package/dist/src/services/deployment/framework-pod-network-membership.d.ts.map +1 -1
  66. package/dist/src/services/deployment/framework-pod-network-membership.js +5 -0
  67. package/dist/src/services/deployment/framework-pod-network-membership.js.map +1 -1
  68. package/dist/src/services/deployment/local-dev-late-workspace-members.service.d.ts +43 -4
  69. package/dist/src/services/deployment/local-dev-late-workspace-members.service.d.ts.map +1 -1
  70. package/dist/src/services/deployment/local-dev-late-workspace-members.service.js +116 -9
  71. package/dist/src/services/deployment/local-dev-late-workspace-members.service.js.map +1 -1
  72. package/dist/src/services/environment/authored-infra-config.utils.d.ts +4 -3
  73. package/dist/src/services/environment/authored-infra-config.utils.d.ts.map +1 -1
  74. package/dist/src/services/environment/authored-infra-config.utils.js +4 -3
  75. package/dist/src/services/environment/authored-infra-config.utils.js.map +1 -1
  76. package/dist/src/services/framework/package-install.service.d.ts +7 -0
  77. package/dist/src/services/framework/package-install.service.d.ts.map +1 -1
  78. package/dist/src/services/framework/package-install.service.js +8 -1
  79. package/dist/src/services/framework/package-install.service.js.map +1 -1
  80. package/dist/src/services/registry/application-provider-connection.service.d.ts +16 -1
  81. package/dist/src/services/registry/application-provider-connection.service.d.ts.map +1 -1
  82. package/dist/src/services/registry/application-provider-connection.service.js +23 -0
  83. package/dist/src/services/registry/application-provider-connection.service.js.map +1 -1
  84. package/dist/src/services/registry/provider-grant-transfer.service.d.ts +48 -0
  85. package/dist/src/services/registry/provider-grant-transfer.service.d.ts.map +1 -0
  86. package/dist/src/services/registry/provider-grant-transfer.service.js +144 -0
  87. package/dist/src/services/registry/provider-grant-transfer.service.js.map +1 -0
  88. package/dist/src/services/registry/provider-module-scaffold.service.d.ts.map +1 -1
  89. package/dist/src/services/registry/provider-module-scaffold.service.js +10 -3
  90. package/dist/src/services/registry/provider-module-scaffold.service.js.map +1 -1
  91. package/dist/tsconfig.build.tsbuildinfo +1 -1
  92. package/package.json +19 -19
  93. package/templates/infra/docker-compose/docker-compose.wildo-platform.yml.hbs +2 -0
  94. package/templates/saas/i18n/email/system/remote-agent-task-updated/labels.en.ts +11 -0
  95. package/templates/saas/i18n/email/system/remote-agent-task-updated/template.tsx +56 -0
  96. package/templates/saas/i18n/engine/components/APP_LAYOUTS_AGENT_ACTIVITY_SETTINGS.en.ts +61 -0
  97. package/templates/saas/i18n/engine/components/APP_LAYOUTS_AGENT_ACTIVITY_SETTINGS.fr.ts +61 -0
  98. package/templates/saas/scenarios/add-technical-doc/files/technical-doc/docusaurus.config.ts.hbs +5 -4
  99. package/templates/saas/scenarios/add-technical-doc/files/technical-doc/package.json.hbs +1 -1
  100. package/templates/saas/scenarios/add-technical-doc/files/technical-doc/scripts/substitute-api-origin.mjs +97 -32
  101. package/templates/saas/scenarios/add-technical-doc/files/technical-doc/src/plugins/api-reference-pages.ts +7 -6
  102. package/wildo-framework.info.json +1 -1
@@ -0,0 +1,78 @@
1
+ import { BaseCommand } from '../../kernel/base-command.js';
2
+ import { CommandCategory } from '../../kernel/types.js';
3
+ import { ErrorUtils } from '../../infrastructure/errors/error.utils.js';
4
+ import { ApplicationConnectionRequestRefusedError, openApplicationConnectionSession, resolveApplicationApiTarget, } from '../../services/registry/application-provider-connection.service.js';
5
+ import { assertLocalGrantTransferTarget, describeGrantTransferOwner, grantTransferRefusalHint, parseGrantTransferOwner, writeGrantTransferDocument, } from '../../services/registry/provider-grant-transfer.service.js';
6
+ const FLAG_CONNECTION = 'connection';
7
+ const FLAG_OWNER = 'owner';
8
+ const FLAG_SLOT = 'slot';
9
+ const FLAG_OUT = 'out';
10
+ const FLAG_TO_TERMINAL = 'to-terminal';
11
+ const FLAGS = {
12
+ [FLAG_CONNECTION]: { type: 'string', description: 'The connection whose grant to export (`asana`).', required: true },
13
+ [FLAG_OWNER]: { type: 'string', description: 'Whose grant: `user:<email>`, `organization:<id or slug>` or `application`.', required: true },
14
+ [FLAG_SLOT]: { type: 'string', description: 'The credential slot, when the connection holds several for that owner.' },
15
+ [FLAG_OUT]: { type: 'string', description: 'Write the document to this file, created with mode 0600. `-` or absent: stdout, refused when stdout is a terminal.' },
16
+ [FLAG_TO_TERMINAL]: { type: 'boolean', description: 'Allow printing the document (which holds tokens) on a terminal.', default: false },
17
+ };
18
+ /**
19
+ * Export one stored OAuth2 grant of the LOCAL running application in its portable form (grant seeding, development and
20
+ * test only), so another development or test stack can import it with `wildo providers grant import`.
21
+ *
22
+ * The application opens the sealed grant (only it holds the key), refuses unless it runs as `development` or `test`,
23
+ * admits only a super-administrator, and records `provider_grant_exported` by owner and connection, never the token.
24
+ * This command signs in as the local administrator, refuses an application that does not answer on this machine, and
25
+ * writes the document only where it was told.
26
+ */
27
+ export default class ProvidersGrantExportCommand extends BaseCommand {
28
+ meta = {
29
+ name: 'providers grant export',
30
+ description: 'Development and test only: export one OAuth2 grant the local running application holds (a person\'s, an organization\'s or its own) '
31
+ + 'as a portable document, so another local or QA stack can import it instead of repeating the vendor\'s consent. The document holds '
32
+ + 'tokens: it is written to a 0600 file or piped, never printed on a terminal unless --to-terminal. Recorded as provider_grant_exported.',
33
+ category: CommandCategory.Core,
34
+ flags: FLAGS,
35
+ // The document on stdout must be the only thing there: the seed script parses it.
36
+ emitsDocumentOnStdout: (flags) => flags[FLAG_OUT] === undefined || flags[FLAG_OUT] === '-',
37
+ };
38
+ async run(ctx) {
39
+ let session;
40
+ try {
41
+ const owner = parseGrantTransferOwner(String(ctx.flags[FLAG_OWNER] ?? ''));
42
+ const connectionRef = String(ctx.flags[FLAG_CONNECTION] ?? '').trim();
43
+ if (connectionRef.length === 0)
44
+ throw new Error('Name the connection: --connection <ref>.');
45
+ const out = ctx.flags[FLAG_OUT];
46
+ const toTerminal = ctx.flags[FLAG_TO_TERMINAL] === true;
47
+ // Refused before signing in: a document that would land on the screen is not asked for.
48
+ if ((out === undefined || out === '-') && process.stdout.isTTY === true && !toTerminal) {
49
+ throw new Error('The grant document holds tokens and stdout is a terminal: pass --out <file> (created 0600), pipe the output, or --to-terminal.');
50
+ }
51
+ // Only the LOCAL stack of an application root: there is no --api-url here, by design.
52
+ if (!ctx.cliContext.resolvedHomes.app.declarationRoot)
53
+ throw new Error('Run it from the application root of a local stack (where wildo.saas.config.ts is): a grant moves only between local development stacks.');
54
+ // The fence BEFORE signing in: the local administrator's password goes nowhere but this machine.
55
+ assertLocalGrantTransferTarget((await resolveApplicationApiTarget(ctx.cliContext.resolvedHomes.app.declarationRoot)).apiBaseUrl);
56
+ session = await openApplicationConnectionSession({
57
+ appRoot: ctx.cliContext.resolvedHomes.app.declarationRoot ?? null,
58
+ frameworkRoot: ctx.cliContext.resolvedHomes.framework.repositoryRoot ?? null,
59
+ });
60
+ const secretSlug = ctx.flags[FLAG_SLOT];
61
+ const document = await session.exportGrant({ owner, connectionRef, ...(secretSlug === undefined ? {} : { secretSlug }) });
62
+ const where = writeGrantTransferDocument(document, { ...(out === undefined ? {} : { out }), stdoutIsTerminal: process.stdout.isTTY === true, toTerminal });
63
+ // On stderr, so a piped document stays the only thing on stdout.
64
+ process.stderr.write(`Exported ${describeGrantTransferOwner(owner)}'s '${document.connectionRef}' grant (slot ${document.secretSlug}, transfer ${document.transferId}) to ${where}. `
65
+ + `${document.grant.refreshToken === undefined ? 'It carries no refresh token: it stops working when its access token expires.' : 'It shares its authorization with this stack: a disconnect on either side may end it on both.'}\n`);
66
+ return { success: true };
67
+ }
68
+ catch (error) {
69
+ const hint = error instanceof ApplicationConnectionRequestRefusedError ? grantTransferRefusalHint(error.code) : undefined;
70
+ ctx.log.error(`${ErrorUtils.extractErrorMessage(error)}${hint === undefined ? '' : ` ${hint}`}`);
71
+ return { success: false };
72
+ }
73
+ finally {
74
+ await session?.signOut();
75
+ }
76
+ }
77
+ }
78
+ //# sourceMappingURL=grant-export.command.js.map
@@ -0,0 +1 @@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CACrO,CAAC;YACF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,GAAG,KAAK,YAAY,wCAAwC,CAAC,CAAC,CAAC,wBAAwB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAC1H,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,mBAAmB,CAAC,KAAK,CAAC,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;YACjG,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC5B,CAAC;gBAAS,CAAC;YACT,MAAM,OAAO,EAAE,OAAO,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { BaseCommand } from '~wildo-cli/kernel/base-command';\nimport { CommandCategory } from '~wildo-cli/kernel/types';\nimport { ErrorUtils } from '~wildo-cli/infrastructure/errors/error.utils';\nimport type { CommandMeta, CommandContext, CommandResult, FlagDefinition } from '~wildo-cli/kernel/types';\nimport {\n ApplicationConnectionRequestRefusedError,\n openApplicationConnectionSession,\n resolveApplicationApiTarget,\n type ApplicationProviderConnectionClient,\n} from '~wildo-cli/services/registry/application-provider-connection.service';\nimport {\n assertLocalGrantTransferTarget,\n describeGrantTransferOwner,\n grantTransferRefusalHint,\n parseGrantTransferOwner,\n writeGrantTransferDocument,\n} from '~wildo-cli/services/registry/provider-grant-transfer.service';\n\nconst FLAG_CONNECTION = 'connection';\nconst FLAG_OWNER = 'owner';\nconst FLAG_SLOT = 'slot';\nconst FLAG_OUT = 'out';\nconst FLAG_TO_TERMINAL = 'to-terminal';\n\nconst FLAGS: Record<string, FlagDefinition> = {\n [FLAG_CONNECTION]: { type: 'string', description: 'The connection whose grant to export (`asana`).', required: true },\n [FLAG_OWNER]: { type: 'string', description: 'Whose grant: `user:<email>`, `organization:<id or slug>` or `application`.', required: true },\n [FLAG_SLOT]: { type: 'string', description: 'The credential slot, when the connection holds several for that owner.' },\n [FLAG_OUT]: { type: 'string', description: 'Write the document to this file, created with mode 0600. `-` or absent: stdout, refused when stdout is a terminal.' },\n [FLAG_TO_TERMINAL]: { type: 'boolean', description: 'Allow printing the document (which holds tokens) on a terminal.', default: false },\n};\n\n/**\n * Export one stored OAuth2 grant of the LOCAL running application in its portable form (grant seeding, development and\n * test only), so another development or test stack can import it with `wildo providers grant import`.\n *\n * The application opens the sealed grant (only it holds the key), refuses unless it runs as `development` or `test`,\n * admits only a super-administrator, and records `provider_grant_exported` by owner and connection, never the token.\n * This command signs in as the local administrator, refuses an application that does not answer on this machine, and\n * writes the document only where it was told.\n */\nexport default class ProvidersGrantExportCommand extends BaseCommand {\n readonly meta: CommandMeta = {\n name: 'providers grant export',\n description:\n 'Development and test only: export one OAuth2 grant the local running application holds (a person\\'s, an organization\\'s or its own) '\n + 'as a portable document, so another local or QA stack can import it instead of repeating the vendor\\'s consent. The document holds '\n + 'tokens: it is written to a 0600 file or piped, never printed on a terminal unless --to-terminal. Recorded as provider_grant_exported.',\n category: CommandCategory.Core,\n flags: FLAGS,\n // The document on stdout must be the only thing there: the seed script parses it.\n emitsDocumentOnStdout: (flags) => flags[FLAG_OUT] === undefined || flags[FLAG_OUT] === '-',\n };\n\n async run(ctx: CommandContext): Promise<CommandResult> {\n let session: ApplicationProviderConnectionClient | undefined;\n try {\n const owner = parseGrantTransferOwner(String(ctx.flags[FLAG_OWNER] ?? ''));\n const connectionRef = String(ctx.flags[FLAG_CONNECTION] ?? '').trim();\n if (connectionRef.length === 0) throw new Error('Name the connection: --connection <ref>.');\n const out = ctx.flags[FLAG_OUT] as string | undefined;\n const toTerminal = ctx.flags[FLAG_TO_TERMINAL] === true;\n // Refused before signing in: a document that would land on the screen is not asked for.\n if ((out === undefined || out === '-') && process.stdout.isTTY === true && !toTerminal) {\n throw new Error('The grant document holds tokens and stdout is a terminal: pass --out <file> (created 0600), pipe the output, or --to-terminal.');\n }\n\n // Only the LOCAL stack of an application root: there is no --api-url here, by design.\n if (!ctx.cliContext.resolvedHomes.app.declarationRoot) throw new Error('Run it from the application root of a local stack (where wildo.saas.config.ts is): a grant moves only between local development stacks.');\n // The fence BEFORE signing in: the local administrator's password goes nowhere but this machine.\n assertLocalGrantTransferTarget((await resolveApplicationApiTarget(ctx.cliContext.resolvedHomes.app.declarationRoot)).apiBaseUrl);\n session = await openApplicationConnectionSession({\n appRoot: ctx.cliContext.resolvedHomes.app.declarationRoot ?? null,\n frameworkRoot: ctx.cliContext.resolvedHomes.framework.repositoryRoot ?? null,\n });\n const secretSlug = ctx.flags[FLAG_SLOT] as string | undefined;\n const document = await session.exportGrant({ owner, connectionRef, ...(secretSlug === undefined ? {} : { secretSlug }) });\n const where = writeGrantTransferDocument(document, { ...(out === undefined ? {} : { out }), stdoutIsTerminal: process.stdout.isTTY === true, toTerminal });\n // On stderr, so a piped document stays the only thing on stdout.\n process.stderr.write(\n `Exported ${describeGrantTransferOwner(owner)}'s '${document.connectionRef}' grant (slot ${document.secretSlug}, transfer ${document.transferId}) to ${where}. `\n + `${document.grant.refreshToken === undefined ? 'It carries no refresh token: it stops working when its access token expires.' : 'It shares its authorization with this stack: a disconnect on either side may end it on both.'}\\n`,\n );\n return { success: true };\n } catch (error) {\n const hint = error instanceof ApplicationConnectionRequestRefusedError ? grantTransferRefusalHint(error.code) : undefined;\n ctx.log.error(`${ErrorUtils.extractErrorMessage(error)}${hint === undefined ? '' : ` ${hint}`}`);\n return { success: false };\n } finally {\n await session?.signOut();\n }\n }\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from '../../kernel/base-command';
2
+ import type { CommandMeta, CommandContext, CommandResult } from '../../kernel/types';
3
+ /**
4
+ * Import a grant another development or test stack exported (grant seeding) into the LOCAL running application, for an
5
+ * owner named here.
6
+ *
7
+ * The application renews the grant at the vendor for its own client before storing it (a revoked or aged-out refresh
8
+ * token is refused here, by name), stores it through the door a completed connect writes into, and records the ordinary
9
+ * GRANTED event marked `grantImport`. A disconnect afterwards revokes it like any connected account.
10
+ */
11
+ export default class ProvidersGrantImportCommand extends BaseCommand {
12
+ readonly meta: CommandMeta;
13
+ run(ctx: CommandContext): Promise<CommandResult>;
14
+ }
15
+ //# sourceMappingURL=grant-import.command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grant-import.command.d.ts","sourceRoot":"","sources":["../../../../src/commands/providers/grant-import.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAI7D,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAkB,MAAM,yBAAyB,CAAC;AA6B1G;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,2BAA4B,SAAQ,WAAW;IAClE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAOxB;IAEI,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;CAyCvD"}
@@ -0,0 +1,78 @@
1
+ import { BaseCommand } from '../../kernel/base-command.js';
2
+ import { CommandCategory } from '../../kernel/types.js';
3
+ import { ErrorUtils } from '../../infrastructure/errors/error.utils.js';
4
+ import { printJsonPayload } from '../../commands/context/context-command.utils.js';
5
+ import { ApplicationConnectionRequestRefusedError, openApplicationConnectionSession, resolveApplicationApiTarget, } from '../../services/registry/application-provider-connection.service.js';
6
+ import { assertLocalGrantTransferTarget, describeGrantTransferOwner, grantTransferRefusalHint, parseGrantTransferOwner, readGrantTransferDocument, } from '../../services/registry/provider-grant-transfer.service.js';
7
+ const FLAG_CONNECTION = 'connection';
8
+ const FLAG_OWNER = 'owner';
9
+ const FLAG_FROM = 'from';
10
+ const FLAG_REPLACE = 'replace';
11
+ const FLAG_JSON = 'json';
12
+ const FLAGS = {
13
+ [FLAG_CONNECTION]: { type: 'string', description: 'The connection the document must be for (`asana`): a document for another one is refused.', required: true },
14
+ [FLAG_OWNER]: { type: 'string', description: 'Whose account to store it for here: `user:<email>`, `organization:<id or slug>` or `application`. Same scope as the export.', required: true },
15
+ [FLAG_FROM]: { type: 'string', description: 'The document `wildo providers grant export` wrote; `-` reads stdin.', required: true },
16
+ [FLAG_REPLACE]: { type: 'boolean', description: 'Replace a grant the owner already holds for the connection (default: refuse).', default: false },
17
+ [FLAG_JSON]: { type: 'boolean', description: 'Print the answer as JSON (never a token).', default: false },
18
+ };
19
+ /**
20
+ * Import a grant another development or test stack exported (grant seeding) into the LOCAL running application, for an
21
+ * owner named here.
22
+ *
23
+ * The application renews the grant at the vendor for its own client before storing it (a revoked or aged-out refresh
24
+ * token is refused here, by name), stores it through the door a completed connect writes into, and records the ordinary
25
+ * GRANTED event marked `grantImport`. A disconnect afterwards revokes it like any connected account.
26
+ */
27
+ export default class ProvidersGrantImportCommand extends BaseCommand {
28
+ meta = {
29
+ name: 'providers grant import',
30
+ description: 'Development and test only: store a grant `wildo providers grant export` wrote, in the local running application, for the owner you name '
31
+ + '(same scope as the export). The application renews it at the vendor first, stores it as a connect would, and records it as imported.',
32
+ category: CommandCategory.Core,
33
+ flags: FLAGS,
34
+ };
35
+ async run(ctx) {
36
+ let session;
37
+ try {
38
+ const owner = parseGrantTransferOwner(String(ctx.flags[FLAG_OWNER] ?? ''));
39
+ const connectionRef = String(ctx.flags[FLAG_CONNECTION] ?? '').trim();
40
+ const from = String(ctx.flags[FLAG_FROM] ?? '').trim();
41
+ if (connectionRef.length === 0 || from.length === 0)
42
+ throw new Error('Name the connection and the document: --connection <ref> --from <file|->.');
43
+ const document = readGrantTransferDocument(from);
44
+ if (document.connectionRef !== connectionRef) {
45
+ throw new Error(`The document is for connection '${document.connectionRef}', not '${connectionRef}'.`);
46
+ }
47
+ // Only the LOCAL stack of an application root: there is no --api-url here, by design.
48
+ if (!ctx.cliContext.resolvedHomes.app.declarationRoot)
49
+ throw new Error('Run it from the application root of a local stack (where wildo.saas.config.ts is): a grant moves only between local development stacks.');
50
+ // The fence BEFORE signing in: the local administrator's password goes nowhere but this machine.
51
+ assertLocalGrantTransferTarget((await resolveApplicationApiTarget(ctx.cliContext.resolvedHomes.app.declarationRoot)).apiBaseUrl);
52
+ session = await openApplicationConnectionSession({
53
+ appRoot: ctx.cliContext.resolvedHomes.app.declarationRoot ?? null,
54
+ frameworkRoot: ctx.cliContext.resolvedHomes.framework.repositoryRoot ?? null,
55
+ });
56
+ const answer = await session.importGrant({ owner, document, replaceExisting: ctx.flags[FLAG_REPLACE] === true });
57
+ if (ctx.flags[FLAG_JSON] === true) {
58
+ printJsonPayload(ctx, answer);
59
+ return { success: true };
60
+ }
61
+ ctx.log.success(`Imported the '${answer.connectionRef}' grant for ${describeGrantTransferOwner(owner)} (credential ${answer.credentialId}, slot ${answer.secretSlug})`
62
+ + `${answer.replacedExistingConnection ? ', replacing the one it held' : ''}.`);
63
+ ctx.log.info(answer.renewedAtImport
64
+ ? 'The vendor renewed it for this application before it was stored.'
65
+ : 'It was stored as exported (no refresh token, or no refresher in this application): it works until its access token expires.');
66
+ return { success: true };
67
+ }
68
+ catch (error) {
69
+ const hint = error instanceof ApplicationConnectionRequestRefusedError ? grantTransferRefusalHint(error.code) : undefined;
70
+ ctx.log.error(`${ErrorUtils.extractErrorMessage(error)}${hint === undefined ? '' : ` ${hint}`}`);
71
+ return { success: false };
72
+ }
73
+ finally {
74
+ await session?.signOut();
75
+ }
76
+ }
77
+ }
78
+ //# sourceMappingURL=grant-import.command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grant-import.command.js","sourceRoot":"","sources":["../../../../src/commands/providers/grant-import.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,EAA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YACjG,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC5B,CAAC;gBAAS,CAAC;YACT,MAAM,OAAO,EAAE,OAAO,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { BaseCommand } from '~wildo-cli/kernel/base-command';\nimport { CommandCategory } from '~wildo-cli/kernel/types';\nimport { ErrorUtils } from '~wildo-cli/infrastructure/errors/error.utils';\nimport { printJsonPayload } from '~wildo-cli/commands/context/context-command.utils';\nimport type { CommandMeta, CommandContext, CommandResult, FlagDefinition } from '~wildo-cli/kernel/types';\nimport {\n ApplicationConnectionRequestRefusedError,\n openApplicationConnectionSession,\n resolveApplicationApiTarget,\n type ApplicationProviderConnectionClient,\n} from '~wildo-cli/services/registry/application-provider-connection.service';\nimport {\n assertLocalGrantTransferTarget,\n describeGrantTransferOwner,\n grantTransferRefusalHint,\n parseGrantTransferOwner,\n readGrantTransferDocument,\n} from '~wildo-cli/services/registry/provider-grant-transfer.service';\n\nconst FLAG_CONNECTION = 'connection';\nconst FLAG_OWNER = 'owner';\nconst FLAG_FROM = 'from';\nconst FLAG_REPLACE = 'replace';\nconst FLAG_JSON = 'json';\n\nconst FLAGS: Record<string, FlagDefinition> = {\n [FLAG_CONNECTION]: { type: 'string', description: 'The connection the document must be for (`asana`): a document for another one is refused.', required: true },\n [FLAG_OWNER]: { type: 'string', description: 'Whose account to store it for here: `user:<email>`, `organization:<id or slug>` or `application`. Same scope as the export.', required: true },\n [FLAG_FROM]: { type: 'string', description: 'The document `wildo providers grant export` wrote; `-` reads stdin.', required: true },\n [FLAG_REPLACE]: { type: 'boolean', description: 'Replace a grant the owner already holds for the connection (default: refuse).', default: false },\n [FLAG_JSON]: { type: 'boolean', description: 'Print the answer as JSON (never a token).', default: false },\n};\n\n/**\n * Import a grant another development or test stack exported (grant seeding) into the LOCAL running application, for an\n * owner named here.\n *\n * The application renews the grant at the vendor for its own client before storing it (a revoked or aged-out refresh\n * token is refused here, by name), stores it through the door a completed connect writes into, and records the ordinary\n * GRANTED event marked `grantImport`. A disconnect afterwards revokes it like any connected account.\n */\nexport default class ProvidersGrantImportCommand extends BaseCommand {\n readonly meta: CommandMeta = {\n name: 'providers grant import',\n description:\n 'Development and test only: store a grant `wildo providers grant export` wrote, in the local running application, for the owner you name '\n + '(same scope as the export). The application renews it at the vendor first, stores it as a connect would, and records it as imported.',\n category: CommandCategory.Core,\n flags: FLAGS,\n };\n\n async run(ctx: CommandContext): Promise<CommandResult> {\n let session: ApplicationProviderConnectionClient | undefined;\n try {\n const owner = parseGrantTransferOwner(String(ctx.flags[FLAG_OWNER] ?? ''));\n const connectionRef = String(ctx.flags[FLAG_CONNECTION] ?? '').trim();\n const from = String(ctx.flags[FLAG_FROM] ?? '').trim();\n if (connectionRef.length === 0 || from.length === 0) throw new Error('Name the connection and the document: --connection <ref> --from <file|->.');\n const document = readGrantTransferDocument(from);\n if (document.connectionRef !== connectionRef) {\n throw new Error(`The document is for connection '${document.connectionRef}', not '${connectionRef}'.`);\n }\n\n // Only the LOCAL stack of an application root: there is no --api-url here, by design.\n if (!ctx.cliContext.resolvedHomes.app.declarationRoot) throw new Error('Run it from the application root of a local stack (where wildo.saas.config.ts is): a grant moves only between local development stacks.');\n // The fence BEFORE signing in: the local administrator's password goes nowhere but this machine.\n assertLocalGrantTransferTarget((await resolveApplicationApiTarget(ctx.cliContext.resolvedHomes.app.declarationRoot)).apiBaseUrl);\n session = await openApplicationConnectionSession({\n appRoot: ctx.cliContext.resolvedHomes.app.declarationRoot ?? null,\n frameworkRoot: ctx.cliContext.resolvedHomes.framework.repositoryRoot ?? null,\n });\n const answer = await session.importGrant({ owner, document, replaceExisting: ctx.flags[FLAG_REPLACE] === true });\n if (ctx.flags[FLAG_JSON] === true) {\n printJsonPayload(ctx, answer);\n return { success: true };\n }\n ctx.log.success(\n `Imported the '${answer.connectionRef}' grant for ${describeGrantTransferOwner(owner)} (credential ${answer.credentialId}, slot ${answer.secretSlug})`\n + `${answer.replacedExistingConnection ? ', replacing the one it held' : ''}.`,\n );\n ctx.log.info(answer.renewedAtImport\n ? 'The vendor renewed it for this application before it was stored.'\n : 'It was stored as exported (no refresh token, or no refresher in this application): it works until its access token expires.');\n return { success: true };\n } catch (error) {\n const hint = error instanceof ApplicationConnectionRequestRefusedError ? grantTransferRefusalHint(error.code) : undefined;\n ctx.log.error(`${ErrorUtils.extractErrorMessage(error)}${hint === undefined ? '' : ` ${hint}`}`);\n return { success: false };\n } finally {\n await session?.signOut();\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"command-runner.d.ts","sourceRoot":"","sources":["../../../src/kernel/command-runner.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EACV,WAAW,EAEX,aAAa,EACb,MAAM,EACN,UAAU,EACV,gCAAgC,EAChC,gBAAgB,EAChB,WAAW,EACZ,MAAM,SAAS,CAAC;AAgBjB;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,EAAE,CAOjE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG;IAAE,WAAW,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,CAAA;CAAE,CAgCzG;AAMD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,EAAE,GAChB;IAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,CA2DvG;AAmBD,MA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AAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,CA2DvG;AAmBD,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,YAAY,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,gCAAgC,GAAG,IAAI,CAAC;IACnD,WAAW,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B;AAsCD,wBAAsB,UAAU,CAC9B,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,MAAM,EAAE,EACjB,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,aAAa,CAAC,CAiCxB"}
@@ -5,6 +5,7 @@ import { Command as CommanderCommand, CommanderError } from 'commander';
5
5
  import { BaseCommand } from './base-command.js';
6
6
  import { DEFAULT_GLOBAL_FLAGS } from './types.js';
7
7
  import { createLogger, LoggerHumanLineSink } from './logger.js';
8
+ import { commandEmitsDocument } from './json-document-output.js';
8
9
  import { ErrorUtils } from '../infrastructure/errors/error.utils.js';
9
10
  // ---------------------------------------------------------------------------
10
11
  // Global flag extraction — strips global flags before command-specific parsing
@@ -138,10 +139,7 @@ function mapPositionalArgs(values, defs) {
138
139
  * probe`, `market generate`, `workbench status`, `frontend look`). Decided HERE, once, rather than at
139
140
  * each verb's branch, because the fifteen verbs that each decided it for themselves all decided it wrong.
140
141
  */
141
- function commandEmitsJsonDocument(parsedFlags) {
142
- return parsedFlags.json === true;
143
- }
144
- function buildCommandContext(parsedArgs, parsedFlags, rawArgs, globalFlags, answers, services) {
142
+ function buildCommandContext(meta, parsedArgs, parsedFlags, rawArgs, globalFlags, answers, services) {
145
143
  return {
146
144
  args: parsedArgs,
147
145
  flags: parsedFlags,
@@ -151,7 +149,7 @@ function buildCommandContext(parsedArgs, parsedFlags, rawArgs, globalFlags, answ
151
149
  activeEnv: services.activeEnv,
152
150
  preferences: services.preferences,
153
151
  cliContext: services.cliContext,
154
- log: commandEmitsJsonDocument(parsedFlags)
152
+ log: commandEmitsDocument(meta, parsedFlags)
155
153
  ? (services.documentModeLog ?? createLogger(LoggerHumanLineSink.STDERR))
156
154
  : services.log,
157
155
  registry: services.registry,
@@ -171,7 +169,7 @@ export async function runCommand(command, rawArgs, globalFlags, services) {
171
169
  if (globalFlags.answersFile) {
172
170
  answers = BaseCommand.loadAnswersFile(globalFlags.answersFile);
173
171
  }
174
- ctx = buildCommandContext(args, flags, rawArgs, globalFlags, answers, services);
172
+ ctx = buildCommandContext(command.meta, args, flags, rawArgs, globalFlags, answers, services);
175
173
  }
176
174
  catch (error) {
177
175
  const message = ErrorUtils.extractErrorMessage(error);
@@ -1 +1 @@
1
- {"version":3,"file":"command-runner.js","sourceRoot":"","sources":["../../../src/kernel/command-runner.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAa7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAE1E,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAE9E,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,IAAI,EAAE,mBAAmB;IACzB,WAAW;IACX,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,SAAS;CAChB,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAkB;IACrD,OAAO;QACL,GAAG,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WAAW,CAAC,CAAC;QACjE,CAAC;QAED,GAAG,GAAG,mBAAmB,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAClF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,UAAU,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QACtD,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC5B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACrC,CAAC;IAED,IAAI,CAAC;QACH,MAAM,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAClD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC3D,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1D,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,UAAU,CAAC,mBAAmB,CAAC,KAAK,CAAC;SAC/C,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["/**\n * CommandRunner — parse args, extract global flags, run lifecycle hooks, execute command.\n */\n\nimport { Command as CommanderCommand, CommanderError } from 'commander';\nimport { BaseCommand } from './base-command';\nimport type { CommandRegistry } from './command-registry';\nimport type { HookRegistry } from './hooks';\nimport type {\n CommandMeta,\n CommandContext,\n CommandResult,\n Logger,\n CliContext,\n PlatformEnvironmentConfiguration,\n WildoPreferences,\n GlobalFlags,\n} from './types';\nimport { DEFAULT_GLOBAL_FLAGS } from './types';\nimport { createLogger, LoggerHumanLineSink } from './logger';\nimport { ErrorUtils } from '~wildo-cli/infrastructure/errors/error.utils';\n\n// ---------------------------------------------------------------------------\n// Global flag extraction — strips global flags before command-specific parsing\n// ---------------------------------------------------------------------------\n\nconst GLOBAL_FLAG_NAMES = new Set([\n '-y', '--non-interactive',\n '--answers',\n '-v', '--verbose',\n '-q', '--quiet',\n]);\n\n/**\n * The inverse of {@link extractGlobalFlags}: the arguments a re-invoked `wildo` must receive to behave\n * like this one. Global flags are parsed from any position, so they may precede the command. Used by\n * every command that runs another `wildo` as a child (`update` re-executing the new CLI, `fwk publish\n * all` running each publish step).\n */\nexport function forwardedGlobalFlags(flags: GlobalFlags): string[] {\n return [\n ...(flags.nonInteractive ? ['-y'] : []),\n ...(flags.verbose ? ['--verbose'] : []),\n ...(flags.quiet ? ['--quiet'] : []),\n ...(flags.answersFile ? ['--answers', flags.answersFile] : []),\n ];\n}\n\nexport function extractGlobalFlags(rawArgs: string[]): { globalFlags: GlobalFlags; commandArgs: string[] } {\n const globalFlags: GlobalFlags = { ...DEFAULT_GLOBAL_FLAGS };\n const commandArgs: string[] = [];\n\n for (let i = 0; i < rawArgs.length; i++) {\n const arg = rawArgs[i];\n\n if (arg === '-y' || arg === '--non-interactive') {\n globalFlags.nonInteractive = true;\n } else if (arg === '--answers' || arg.startsWith('--answers=')) {\n if (arg.startsWith('--answers=')) {\n globalFlags.answersFile = arg.slice('--answers='.length);\n } else {\n const next = rawArgs[i + 1];\n if (!next || next.startsWith('-')) {\n console.error('--answers requires a file path argument.');\n process.exitCode = 1;\n return { globalFlags, commandArgs: [] };\n }\n globalFlags.answersFile = next;\n i++;\n }\n } else if (arg === '-v' || arg === '--verbose') {\n globalFlags.verbose = true;\n } else if (arg === '-q' || arg === '--quiet') {\n globalFlags.quiet = true;\n } else {\n commandArgs.push(arg);\n }\n }\n\n return { globalFlags, commandArgs };\n}\n\n// ---------------------------------------------------------------------------\n// Arg/flag parsing via Commander.js (instantiated per command, not global)\n// ---------------------------------------------------------------------------\n\nexport function parseCommandArgs(\n meta: CommandMeta,\n rawArgs: string[],\n): { flags: Record<string, unknown>; args: Record<string, string | undefined>; helpDisplayed?: boolean } {\n const program = new CommanderCommand();\n program.exitOverride();\n\n for (const [name, def] of Object.entries(meta.flags ?? {})) {\n const flag =\n def.type === 'boolean'\n ? `--${name}`\n : def.type === 'string[]'\n ? `--${name} <value...>`\n : `--${name} <value>`;\n\n if (def.type === 'number') {\n program.option(flag, def.description, (v: string) => Number(v), def.default);\n } else {\n // `string[]` uses Commander's variadic `<value...>` arity: every following\n // space-separated token is collected into an array, so `--units a b c` is\n // not silently truncated to its first token (the rest are no longer\n // swallowed as stray positionals).\n program.option(flag, def.description, def.default as string | boolean | string[] | undefined);\n }\n }\n\n for (const arg of meta.args ?? []) {\n const token = arg.required ? `<${arg.name}>` : `[${arg.name}]`;\n program.argument(token, arg.description);\n }\n\n try {\n program.parse(rawArgs, { from: 'user' });\n } catch (err) {\n if (err instanceof CommanderError) {\n if (err.code === 'commander.helpDisplayed') {\n return { flags: {}, args: {}, helpDisplayed: true };\n }\n throw new Error(`Invalid arguments for '${meta.name}': ${err.message}`);\n }\n throw err;\n }\n\n const flags = program.opts();\n // Commander CAMELIZES multi-word option names in `opts()` (`--register-only` →\n // `registerOnly`), while command code historically reads `ctx.flags['register-only']`.\n // Mirror every declared kebab name onto its camelized value so BOTH spellings are always\n // present — the kebab-only read silently shipped `--register-only` (the #50 guard bypass),\n // `db resolve --rolled-back`, `db generate --accept-planner-contract`,\n // `db diff --update-lockfile` and `registry ping --companion-port` as dead flags. Fixing it\n // HERE is the unbypassable form; per-command dual reads remain harmless.\n for (const name of Object.keys(meta.flags ?? {})) {\n if (!name.includes('-')) continue;\n const camelized = name.replace(/-([a-z0-9])/g, (_, character: string) => character.toUpperCase());\n if (!(name in flags) && camelized in flags) {\n flags[name] = flags[camelized];\n }\n }\n const positionals = program.processedArgs as unknown[];\n const args = mapPositionalArgs(positionals, meta.args);\n\n return { flags, args };\n}\n\nfunction mapPositionalArgs(\n values: unknown[],\n defs?: CommandMeta['args'],\n): Record<string, string | undefined> {\n const result: Record<string, string | undefined> = {};\n if (!defs) return result;\n\n for (let i = 0; i < defs.length; i++) {\n result[defs[i].name] = values[i] != null ? String(values[i]) : undefined;\n }\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Context builder\n// ---------------------------------------------------------------------------\n\nexport interface CommandRunnerServices {\n hooks: HookRegistry;\n log: Logger;\n /**\n * The logger a `--json` run gets: its human lines go to stderr, so stdout carries the command's\n * document alone (#2068). Defaults to the real one; a test injects its own.\n */\n documentModeLog?: Logger;\n cliContext: CliContext;\n activeEnv: PlatformEnvironmentConfiguration | null;\n preferences: WildoPreferences | null;\n registry?: CommandRegistry;\n}\n\n/**\n * A command's own `--json` means \"stdout is one machine document\" — every command that declares the flag\n * uses it that way (the creation and build console verbs, `context`, `secrets`, `local doctor`, `acp\n * probe`, `market generate`, `workbench status`, `frontend look`). Decided HERE, once, rather than at\n * each verb's branch, because the fifteen verbs that each decided it for themselves all decided it wrong.\n */\nfunction commandEmitsJsonDocument(parsedFlags: Record<string, unknown>): boolean {\n return parsedFlags.json === true;\n}\n\nfunction buildCommandContext(\n parsedArgs: Record<string, string | undefined>,\n parsedFlags: Record<string, unknown>,\n rawArgs: string[],\n globalFlags: GlobalFlags,\n answers: Record<string, unknown>,\n services: CommandRunnerServices,\n): CommandContext {\n return {\n args: parsedArgs,\n flags: parsedFlags,\n rawArgs,\n globalFlags,\n answers,\n activeEnv: services.activeEnv,\n preferences: services.preferences,\n cliContext: services.cliContext,\n log: commandEmitsJsonDocument(parsedFlags)\n ? (services.documentModeLog ?? createLogger(LoggerHumanLineSink.STDERR))\n : services.log,\n registry: services.registry,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Command runner — lifecycle orchestration\n// ---------------------------------------------------------------------------\n\nexport async function runCommand(\n command: BaseCommand,\n rawArgs: string[],\n globalFlags: GlobalFlags,\n services: CommandRunnerServices,\n): Promise<CommandResult> {\n let ctx: CommandContext;\n\n try {\n const { flags, args, helpDisplayed } = parseCommandArgs(command.meta, rawArgs);\n if (helpDisplayed) {\n return { success: true };\n }\n\n let answers: Record<string, unknown> = {};\n if (globalFlags.answersFile) {\n answers = BaseCommand.loadAnswersFile(globalFlags.answersFile);\n }\n\n ctx = buildCommandContext(args, flags, rawArgs, globalFlags, answers, services);\n } catch (error) {\n const message = ErrorUtils.extractErrorMessage(error);\n services.log.error(message);\n return { success: false, message };\n }\n\n try {\n await services.hooks.runPreRun(ctx, command.meta);\n const result = await command.run(ctx);\n await services.hooks.runPostRun(ctx, command.meta, result);\n return result;\n } catch (error) {\n await services.hooks.runOnError(ctx, command.meta, error);\n return {\n success: false,\n message: ErrorUtils.extractErrorMessage(error),\n };\n }\n}\n"]}
1
+ {"version":3,"file":"command-runner.js","sourceRoot":"","sources":["../../../src/kernel/command-runner.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAa7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAE1E,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAE9E,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,IAAI,EAAE,mBAAmB;IACzB,WAAW;IACX,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,SAAS;CAChB,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAkB;IAC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G,mBAAmB,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAChG,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,UAAU,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QACtD,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC5B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACrC,CAAC;IAED,IAAI,CAAC;QACH,MAAM,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAClD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC3D,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1D,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,UAAU,CAAC,mBAAmB,CAAC,KAAK,CAAC;SAC/C,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["/**\n * CommandRunner — parse args, extract global flags, run lifecycle hooks, execute command.\n */\n\nimport { Command as CommanderCommand, CommanderError } from 'commander';\nimport { BaseCommand } from './base-command';\nimport type { CommandRegistry } from './command-registry';\nimport type { HookRegistry } from './hooks';\nimport type {\n CommandMeta,\n CommandContext,\n CommandResult,\n Logger,\n CliContext,\n PlatformEnvironmentConfiguration,\n WildoPreferences,\n GlobalFlags,\n} from './types';\nimport { DEFAULT_GLOBAL_FLAGS } from './types';\nimport { createLogger, LoggerHumanLineSink } from './logger';\nimport { commandEmitsDocument } from './json-document-output';\nimport { ErrorUtils } from '~wildo-cli/infrastructure/errors/error.utils';\n\n// ---------------------------------------------------------------------------\n// Global flag extraction — strips global flags before command-specific parsing\n// ---------------------------------------------------------------------------\n\nconst GLOBAL_FLAG_NAMES = new Set([\n '-y', '--non-interactive',\n '--answers',\n '-v', '--verbose',\n '-q', '--quiet',\n]);\n\n/**\n * The inverse of {@link extractGlobalFlags}: the arguments a re-invoked `wildo` must receive to behave\n * like this one. Global flags are parsed from any position, so they may precede the command. Used by\n * every command that runs another `wildo` as a child (`update` re-executing the new CLI, `fwk publish\n * all` running each publish step).\n */\nexport function forwardedGlobalFlags(flags: GlobalFlags): string[] {\n return [\n ...(flags.nonInteractive ? ['-y'] : []),\n ...(flags.verbose ? ['--verbose'] : []),\n ...(flags.quiet ? ['--quiet'] : []),\n ...(flags.answersFile ? ['--answers', flags.answersFile] : []),\n ];\n}\n\nexport function extractGlobalFlags(rawArgs: string[]): { globalFlags: GlobalFlags; commandArgs: string[] } {\n const globalFlags: GlobalFlags = { ...DEFAULT_GLOBAL_FLAGS };\n const commandArgs: string[] = [];\n\n for (let i = 0; i < rawArgs.length; i++) {\n const arg = rawArgs[i];\n\n if (arg === '-y' || arg === '--non-interactive') {\n globalFlags.nonInteractive = true;\n } else if (arg === '--answers' || arg.startsWith('--answers=')) {\n if (arg.startsWith('--answers=')) {\n globalFlags.answersFile = arg.slice('--answers='.length);\n } else {\n const next = rawArgs[i + 1];\n if (!next || next.startsWith('-')) {\n console.error('--answers requires a file path argument.');\n process.exitCode = 1;\n return { globalFlags, commandArgs: [] };\n }\n globalFlags.answersFile = next;\n i++;\n }\n } else if (arg === '-v' || arg === '--verbose') {\n globalFlags.verbose = true;\n } else if (arg === '-q' || arg === '--quiet') {\n globalFlags.quiet = true;\n } else {\n commandArgs.push(arg);\n }\n }\n\n return { globalFlags, commandArgs };\n}\n\n// ---------------------------------------------------------------------------\n// Arg/flag parsing via Commander.js (instantiated per command, not global)\n// ---------------------------------------------------------------------------\n\nexport function parseCommandArgs(\n meta: CommandMeta,\n rawArgs: string[],\n): { flags: Record<string, unknown>; args: Record<string, string | undefined>; helpDisplayed?: boolean } {\n const program = new CommanderCommand();\n program.exitOverride();\n\n for (const [name, def] of Object.entries(meta.flags ?? {})) {\n const flag =\n def.type === 'boolean'\n ? `--${name}`\n : def.type === 'string[]'\n ? `--${name} <value...>`\n : `--${name} <value>`;\n\n if (def.type === 'number') {\n program.option(flag, def.description, (v: string) => Number(v), def.default);\n } else {\n // `string[]` uses Commander's variadic `<value...>` arity: every following\n // space-separated token is collected into an array, so `--units a b c` is\n // not silently truncated to its first token (the rest are no longer\n // swallowed as stray positionals).\n program.option(flag, def.description, def.default as string | boolean | string[] | undefined);\n }\n }\n\n for (const arg of meta.args ?? []) {\n const token = arg.required ? `<${arg.name}>` : `[${arg.name}]`;\n program.argument(token, arg.description);\n }\n\n try {\n program.parse(rawArgs, { from: 'user' });\n } catch (err) {\n if (err instanceof CommanderError) {\n if (err.code === 'commander.helpDisplayed') {\n return { flags: {}, args: {}, helpDisplayed: true };\n }\n throw new Error(`Invalid arguments for '${meta.name}': ${err.message}`);\n }\n throw err;\n }\n\n const flags = program.opts();\n // Commander CAMELIZES multi-word option names in `opts()` (`--register-only` →\n // `registerOnly`), while command code historically reads `ctx.flags['register-only']`.\n // Mirror every declared kebab name onto its camelized value so BOTH spellings are always\n // present — the kebab-only read silently shipped `--register-only` (the #50 guard bypass),\n // `db resolve --rolled-back`, `db generate --accept-planner-contract`,\n // `db diff --update-lockfile` and `registry ping --companion-port` as dead flags. Fixing it\n // HERE is the unbypassable form; per-command dual reads remain harmless.\n for (const name of Object.keys(meta.flags ?? {})) {\n if (!name.includes('-')) continue;\n const camelized = name.replace(/-([a-z0-9])/g, (_, character: string) => character.toUpperCase());\n if (!(name in flags) && camelized in flags) {\n flags[name] = flags[camelized];\n }\n }\n const positionals = program.processedArgs as unknown[];\n const args = mapPositionalArgs(positionals, meta.args);\n\n return { flags, args };\n}\n\nfunction mapPositionalArgs(\n values: unknown[],\n defs?: CommandMeta['args'],\n): Record<string, string | undefined> {\n const result: Record<string, string | undefined> = {};\n if (!defs) return result;\n\n for (let i = 0; i < defs.length; i++) {\n result[defs[i].name] = values[i] != null ? String(values[i]) : undefined;\n }\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Context builder\n// ---------------------------------------------------------------------------\n\nexport interface CommandRunnerServices {\n hooks: HookRegistry;\n log: Logger;\n /**\n * The logger a `--json` run gets: its human lines go to stderr, so stdout carries the command's\n * document alone (#2068). Defaults to the real one; a test injects its own.\n */\n documentModeLog?: Logger;\n cliContext: CliContext;\n activeEnv: PlatformEnvironmentConfiguration | null;\n preferences: WildoPreferences | null;\n registry?: CommandRegistry;\n}\n\n/**\n * A command's own `--json` means \"stdout is one machine document\" — every command that declares the flag\n * uses it that way (the creation and build console verbs, `context`, `secrets`, `local doctor`, `acp\n * probe`, `market generate`, `workbench status`, `frontend look`). Decided HERE, once, rather than at\n * each verb's branch, because the fifteen verbs that each decided it for themselves all decided it wrong.\n */\n\nfunction buildCommandContext(\n meta: Pick<CommandMeta, 'emitsDocumentOnStdout'>,\n parsedArgs: Record<string, string | undefined>,\n parsedFlags: Record<string, unknown>,\n rawArgs: string[],\n globalFlags: GlobalFlags,\n answers: Record<string, unknown>,\n services: CommandRunnerServices,\n): CommandContext {\n return {\n args: parsedArgs,\n flags: parsedFlags,\n rawArgs,\n globalFlags,\n answers,\n activeEnv: services.activeEnv,\n preferences: services.preferences,\n cliContext: services.cliContext,\n log: commandEmitsDocument(meta, parsedFlags)\n ? (services.documentModeLog ?? createLogger(LoggerHumanLineSink.STDERR))\n : services.log,\n registry: services.registry,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Command runner — lifecycle orchestration\n// ---------------------------------------------------------------------------\n\nexport async function runCommand(\n command: BaseCommand,\n rawArgs: string[],\n globalFlags: GlobalFlags,\n services: CommandRunnerServices,\n): Promise<CommandResult> {\n let ctx: CommandContext;\n\n try {\n const { flags, args, helpDisplayed } = parseCommandArgs(command.meta, rawArgs);\n if (helpDisplayed) {\n return { success: true };\n }\n\n let answers: Record<string, unknown> = {};\n if (globalFlags.answersFile) {\n answers = BaseCommand.loadAnswersFile(globalFlags.answersFile);\n }\n\n ctx = buildCommandContext(command.meta, args, flags, rawArgs, globalFlags, answers, services);\n } catch (error) {\n const message = ErrorUtils.extractErrorMessage(error);\n services.log.error(message);\n return { success: false, message };\n }\n\n try {\n await services.hooks.runPreRun(ctx, command.meta);\n const result = await command.run(ctx);\n await services.hooks.runPostRun(ctx, command.meta, result);\n return result;\n } catch (error) {\n await services.hooks.runOnError(ctx, command.meta, error);\n return {\n success: false,\n message: ErrorUtils.extractErrorMessage(error),\n };\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/kernel/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG1E,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AACnF,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAC3G,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAElG,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,UAAU,CAAmB;IAErC,cAAc,CAAC,IAAI,EAAE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AAW,GAAG,IAAI;IAIxC,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAIhC,SAAS,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAMhE,UAAU,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxF,UAAU,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAKxF;AAED,wBAAgB,kBAAkB,IAAI,YAAY,CA6BjD"}
@@ -1,3 +1,4 @@
1
+ import { commandEmitsDocument } from './json-document-output.js';
1
2
  import { ErrorUtils } from '../infrastructure/errors/error.utils.js';
2
3
  export class HookRegistry {
3
4
  preRunHooks = [];
@@ -43,7 +44,7 @@ export function createBuiltInHooks() {
43
44
  * "✔ … completed" made it invalid (measured 2026-10-01, `wildo frontend look --json`). A failure
44
45
  * still says so, below, on stderr.
45
46
  */
46
- if (!ctx.globalFlags?.quiet && ctx.flags?.json !== true)
47
+ if (!ctx.globalFlags?.quiet && !commandEmitsDocument(meta, ctx.flags ?? {}))
47
48
  ctx.log.success(`${meta.name} completed`);
48
49
  }
49
50
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/kernel/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAM1E,MAAM,OAAO,YAAY;IACf,WAAW,GAAiB,EAAE,CAAC;IAC/B,YAAY,GAAkB,EAAE,CAAC;IACjC,UAAU,GAAgB,EAAE,CAAC;IAErC,cAAc,CAAC,IAAgB;QAC7B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,eAAe,CAAC,IAAiB;QAC/B,IAAI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G,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC;QACrG,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,UAAU,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACrF,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAClD,MAAM,OAAO,GAAG,UAAU,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QACtD,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import type { CommandContext, CommandMeta, CommandResult } from './types';\nimport { ErrorUtils } from '~wildo-cli/infrastructure/errors/error.utils';\n\nexport type PreRunHook = (ctx: CommandContext, meta: CommandMeta) => Promise<void>;\nexport type PostRunHook = (ctx: CommandContext, meta: CommandMeta, result: CommandResult) => Promise<void>;\nexport type ErrorHook = (ctx: CommandContext, meta: CommandMeta, error: unknown) => Promise<void>;\n\nexport class HookRegistry {\n private preRunHooks: PreRunHook[] = [];\n private postRunHooks: PostRunHook[] = [];\n private errorHooks: ErrorHook[] = [];\n\n registerPreRun(hook: PreRunHook): void {\n this.preRunHooks.push(hook);\n }\n\n registerPostRun(hook: PostRunHook): void {\n this.postRunHooks.push(hook);\n }\n\n registerOnError(hook: ErrorHook): void {\n this.errorHooks.push(hook);\n }\n\n async runPreRun(ctx: CommandContext, meta: CommandMeta): Promise<void> {\n for (const hook of this.preRunHooks) {\n await hook(ctx, meta);\n }\n }\n\n async runPostRun(ctx: CommandContext, meta: CommandMeta, result: CommandResult): Promise<void> {\n for (const hook of this.postRunHooks) {\n await hook(ctx, meta, result);\n }\n }\n\n async runOnError(ctx: CommandContext, meta: CommandMeta, error: unknown): Promise<void> {\n for (const hook of this.errorHooks) {\n await hook(ctx, meta, error);\n }\n }\n}\n\nexport function createBuiltInHooks(): HookRegistry {\n const registry = new HookRegistry();\n\n // Env resolution is handled by bootstrap (ContextManager.detect + EnvironmentUtils.getCurrent).\n // This preRun hook is a placeholder for future per-command context enrichment.\n registry.registerPreRun(async (_ctx, _meta) => {\n });\n\n registry.registerPostRun(async (ctx, meta, result) => {\n if (result.success) {\n /*\n * Not under --quiet: a command whose stdout is CONSUMED — a Claude Code hook's, whose every line\n * becomes session context (#1657) — must not carry a completion line nobody asked for. Nor under a\n * command's own --json: its stdout is one JSON document for a parser, and a trailing\n * \"✔ … completed\" made it invalid (measured 2026-10-01, `wildo frontend look --json`). A failure\n * still says so, below, on stderr.\n */\n if (!ctx.globalFlags?.quiet && ctx.flags?.json !== true) ctx.log.success(`${meta.name} completed`);\n } else {\n ctx.log.error(`${meta.name} failed${result.message ? `: ${result.message}` : ''}`);\n }\n });\n\n registry.registerOnError(async (ctx, meta, error) => {\n const message = ErrorUtils.extractErrorMessage(error);\n ctx.log.error(`[${meta.name}] ${message}`);\n });\n\n return registry;\n}\n"]}
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/kernel/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAM1E,MAAM,OAAO,YAAY;IACf,WAAW,GAAiB,EAAE,CAAC;IAC/B,YAAY,GAAkB,EAAE,CAAC;IACjC,UAAU,GAAgB,EAAE,CAAC;IAErC,cAAc,CAAC,IAAgB;QAC7B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,e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AI,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;gBAAE,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC;QACzH,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,UAAU,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACrF,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAClD,MAAM,OAAO,GAAG,UAAU,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QACtD,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import type { CommandContext, CommandMeta, CommandResult } from './types';\nimport { commandEmitsDocument } from './json-document-output';\nimport { ErrorUtils } from '~wildo-cli/infrastructure/errors/error.utils';\n\nexport type PreRunHook = (ctx: CommandContext, meta: CommandMeta) => Promise<void>;\nexport type PostRunHook = (ctx: CommandContext, meta: CommandMeta, result: CommandResult) => Promise<void>;\nexport type ErrorHook = (ctx: CommandContext, meta: CommandMeta, error: unknown) => Promise<void>;\n\nexport class HookRegistry {\n private preRunHooks: PreRunHook[] = [];\n private postRunHooks: PostRunHook[] = [];\n private errorHooks: ErrorHook[] = [];\n\n registerPreRun(hook: PreRunHook): void {\n this.preRunHooks.push(hook);\n }\n\n registerPostRun(hook: PostRunHook): void {\n this.postRunHooks.push(hook);\n }\n\n registerOnError(hook: ErrorHook): void {\n this.errorHooks.push(hook);\n }\n\n async runPreRun(ctx: CommandContext, meta: CommandMeta): Promise<void> {\n for (const hook of this.preRunHooks) {\n await hook(ctx, meta);\n }\n }\n\n async runPostRun(ctx: CommandContext, meta: CommandMeta, result: CommandResult): Promise<void> {\n for (const hook of this.postRunHooks) {\n await hook(ctx, meta, result);\n }\n }\n\n async runOnError(ctx: CommandContext, meta: CommandMeta, error: unknown): Promise<void> {\n for (const hook of this.errorHooks) {\n await hook(ctx, meta, error);\n }\n }\n}\n\nexport function createBuiltInHooks(): HookRegistry {\n const registry = new HookRegistry();\n\n // Env resolution is handled by bootstrap (ContextManager.detect + EnvironmentUtils.getCurrent).\n // This preRun hook is a placeholder for future per-command context enrichment.\n registry.registerPreRun(async (_ctx, _meta) => {\n });\n\n registry.registerPostRun(async (ctx, meta, result) => {\n if (result.success) {\n /*\n * Not under --quiet: a command whose stdout is CONSUMED — a Claude Code hook's, whose every line\n * becomes session context (#1657) — must not carry a completion line nobody asked for. Nor under a\n * command's own --json: its stdout is one JSON document for a parser, and a trailing\n * \"✔ … completed\" made it invalid (measured 2026-10-01, `wildo frontend look --json`). A failure\n * still says so, below, on stderr.\n */\n if (!ctx.globalFlags?.quiet && !commandEmitsDocument(meta, ctx.flags ?? {})) ctx.log.success(`${meta.name} completed`);\n } else {\n ctx.log.error(`${meta.name} failed${result.message ? `: ${result.message}` : ''}`);\n }\n });\n\n registry.registerOnError(async (ctx, meta, error) => {\n const message = ErrorUtils.extractErrorMessage(error);\n ctx.log.error(`[${meta.name}] ${message}`);\n });\n\n return registry;\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import type { CommandMeta } from './types';
1
2
  /**
2
3
  * The one way a command prints a machine-readable document: written to stdout AS IS, never through
3
4
  * `ctx.log`. The logger prefixes every line with a glyph (`ℹ`, `✔`), so a document printed through it
@@ -21,5 +22,11 @@ export declare enum JsonDocumentLayout {
21
22
  COMPACT = "compact",
22
23
  INDENTED = "indented"
23
24
  }
25
+ /**
26
+ * Whether this run's stdout carries a machine document: a `--json` run, or one the command declares
27
+ * (`CommandMeta.emitsDocumentOnStdout`). The runner then gives the command a logger whose human lines go to stderr, and the
28
+ * completion hook prints no "✔ … completed".
29
+ */
30
+ export declare function commandEmitsDocument(meta: Pick<CommandMeta, 'emitsDocumentOnStdout'>, parsedFlags: Record<string, unknown>): boolean;
24
31
  export declare function writeJsonDocument(payload: unknown, layout?: JsonDocumentLayout): void;
25
32
  //# sourceMappingURL=json-document-output.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"json-document-output.d.ts","sourceRoot":"","sources":["../../../src/kernel/json-document-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;GAQG;AACH,oBAAY,kBAAkB;IAC5B,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAE,kBAA+C,GAAG,IAAI,CAGjH"}
1
+ {"version":3,"file":"json-document-output.d.ts","sourceRoot":"","sources":["../../../src/kernel/json-document-output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C;;;;;;;;;GASG;AAEH;;;;;;;;GAQG;AACH,oBAAY,kBAAkB;IAC5B,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,uBAAuB,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAEpI;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAE,kBAA+C,GAAG,IAAI,CAGjH"}
@@ -22,6 +22,14 @@ export var JsonDocumentLayout;
22
22
  JsonDocumentLayout["COMPACT"] = "compact";
23
23
  JsonDocumentLayout["INDENTED"] = "indented";
24
24
  })(JsonDocumentLayout || (JsonDocumentLayout = {}));
25
+ /**
26
+ * Whether this run's stdout carries a machine document: a `--json` run, or one the command declares
27
+ * (`CommandMeta.emitsDocumentOnStdout`). The runner then gives the command a logger whose human lines go to stderr, and the
28
+ * completion hook prints no "✔ … completed".
29
+ */
30
+ export function commandEmitsDocument(meta, parsedFlags) {
31
+ return parsedFlags.json === true || meta.emitsDocumentOnStdout?.(parsedFlags) === true;
32
+ }
25
33
  export function writeJsonDocument(payload, layout = JsonDocumentLayout.COMPACT) {
26
34
  const text = layout === JsonDocumentLayout.INDENTED ? JSON.stringify(payload, null, 2) : JSON.stringify(payload);
27
35
  process.stdout.write(`${text}\n`);
@@ -1 +1 @@
1
- {"version":3,"file":"json-document-output.js","sourceRoot":"","sources":["../../../src/kernel/json-document-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;GAQG;AACH,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,yCAAmB,CAAA;IACnB,2CAAqB,CAAA;AACvB,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAAE,SAA6B,kBAAkB,CAAC,OAAO;IACzG,MAAM,IAAI,GAAG,MAAM,KAAK,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACjH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;AACpC,CAAC","sourcesContent":["/**\n * The one way a command prints a machine-readable document: written to stdout AS IS, never through\n * `ctx.log`. The logger prefixes every line with a glyph (`ℹ`, `✔`), so a document printed through it\n * is not JSON. That shipped on fifteen `--json` verbs at once (#2068) — `wildo creation questions\n * --json` printed `ℹ {…}` and the plugin's `answer` / `status` skills read exactly that output.\n *\n * Pairs with the command runner: a run whose `--json` flag is set gets a logger whose human lines go to\n * stderr (`LoggerHumanLineSink.STDERR`), so a note a command logs beside its document cannot land in\n * the middle of it either.\n */\n\n/**\n * How the document is laid out on stdout.\n *\n * - `COMPACT` — one line. The form an agent reads into its context (the creation console verbs), and the\n * only form a stream of events can take: `wildo creation feed --json --follow` prints one document\n * per line.\n * - `INDENTED` — two-space indentation, for a document a person also scans (`wildo context …`,\n * `wildo local doctor --json`). Still exactly one JSON value.\n */\nexport enum JsonDocumentLayout {\n COMPACT = 'compact',\n INDENTED = 'indented',\n}\n\nexport function writeJsonDocument(payload: unknown, layout: JsonDocumentLayout = JsonDocumentLayout.COMPACT): void {\n const text = layout === JsonDocumentLayout.INDENTED ? JSON.stringify(payload, null, 2) : JSON.stringify(payload);\n process.stdout.write(`${text}\\n`);\n}\n"]}
1
+ {"version":3,"file":"json-document-output.js","sourceRoot":"","sources":["../../../src/kernel/json-document-output.ts"],"names":[],"mappings":"AACA;;;;;;;;;GASG;AAEH;;;;;;;;GAQG;AACH,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,yCAAmB,CAAA;IACnB,2CAAqB,CAAA;AACvB,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAgD,EAAE,WAAoC;IACzH,OAAO,WAAW,CAAC,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;AACzF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAAE,SAA6B,kBAAkB,CAAC,OAAO;IACzG,MAAM,IAAI,GAAG,MAAM,KAAK,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACjH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import type { CommandMeta } from './types';\n/**\n * The one way a command prints a machine-readable document: written to stdout AS IS, never through\n * `ctx.log`. The logger prefixes every line with a glyph (`ℹ`, `✔`), so a document printed through it\n * is not JSON. That shipped on fifteen `--json` verbs at once (#2068) — `wildo creation questions\n * --json` printed `ℹ {…}` and the plugin's `answer` / `status` skills read exactly that output.\n *\n * Pairs with the command runner: a run whose `--json` flag is set gets a logger whose human lines go to\n * stderr (`LoggerHumanLineSink.STDERR`), so a note a command logs beside its document cannot land in\n * the middle of it either.\n */\n\n/**\n * How the document is laid out on stdout.\n *\n * - `COMPACT` — one line. The form an agent reads into its context (the creation console verbs), and the\n * only form a stream of events can take: `wildo creation feed --json --follow` prints one document\n * per line.\n * - `INDENTED` — two-space indentation, for a document a person also scans (`wildo context …`,\n * `wildo local doctor --json`). Still exactly one JSON value.\n */\nexport enum JsonDocumentLayout {\n COMPACT = 'compact',\n INDENTED = 'indented',\n}\n\n/**\n * Whether this run's stdout carries a machine document: a `--json` run, or one the command declares\n * (`CommandMeta.emitsDocumentOnStdout`). The runner then gives the command a logger whose human lines go to stderr, and the\n * completion hook prints no \"✔ … completed\".\n */\nexport function commandEmitsDocument(meta: Pick<CommandMeta, 'emitsDocumentOnStdout'>, parsedFlags: Record<string, unknown>): boolean {\n return parsedFlags.json === true || meta.emitsDocumentOnStdout?.(parsedFlags) === true;\n}\n\nexport function writeJsonDocument(payload: unknown, layout: JsonDocumentLayout = JsonDocumentLayout.COMPACT): void {\n const text = layout === JsonDocumentLayout.INDENTED ? JSON.stringify(payload, null, 2) : JSON.stringify(payload);\n process.stdout.write(`${text}\\n`);\n}\n"]}
@@ -163,6 +163,14 @@ export interface CommandMeta {
163
163
  flags?: Record<string, FlagDefinition>;
164
164
  args?: ArgDefinition[];
165
165
  prompts?: PromptDefinition[];
166
+ /**
167
+ * True when this run's stdout carries a machine document other than a `--json` one (for example
168
+ * `providers grant export` writing its grant document to a pipe). The runner then sends the human lines to
169
+ * stderr and the completion hook prints no "✔ … completed", exactly as for `--json`, so stdout holds the
170
+ * document and nothing else. Without it the export's trailing completion line made the piped document
171
+ * unparseable (2026-11-18).
172
+ */
173
+ emitsDocumentOnStdout?: (flags: Record<string, unknown>) => boolean;
166
174
  }
167
175
  export interface Logger {
168
176
  info: (msg: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/kernel/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,IAAI,iCAAiC,EAAE,MAAM,qDAAqD,CAAC;AACjJ,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,IAAI,iBAAiB,EAAE,MAAM,6CAA6C,CAAC;AAC/H,OAAO,KAAK,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,KAAK,EAAE,eAAe,IAAI,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,MAAM,MAAM,gCAAgC,GAAG,iCAAiC,CAAC;AACjF,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AACjD,iGAAiG;AACjG,YAAY,EAAE,oBAAoB,EAAE,CAAC;AACrC,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC;AAMrC,oBAAY,eAAe;IACzB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB;;;;;;OAMG;IACH,MAAM,WAAW;IACjB;;;;;;;;;;;;;;;;;;OAkBG;IACH,QAAQ,aAAa;IACrB;;;;;;;OAOG;IACH,KAAK,UAAU;IACf;;;;OAIG;IACH,SAAS,cAAc;IACvB;;;;;;OAMG;IACH,OAAO,YAAY;IACnB,GAAG,QAAQ;IACX;;;;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 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/kernel/types.ts"],"names":[],"mappings":"AAYA,8EAA8E;AAC9E,2EAA2E;AAC3E,8EAA8E;AAE9E,MAAM,CAAN,IAAY,eAoFX;AApFD,WAAY,eAAe;IACzB,gCAAa,CAAA;IACb,kCAAe,CAAA;IACf,oCAAiB,CAAA;IACjB,8BAAW,CAAA;IACX,sCAAmB,CAAA;IACnB,oCAAiB,CAAA;IACjB,wCAAqB,CAAA;IACrB;;;;;;OAMG;IACH,oCAAiB,CAAA;IACjB;;;;;;;;;;;;;;;;;;OAkBG;IACH,wCAAqB,CAAA;IACrB;;;;;;;OAOG;IACH,kCAAe,CAAA;IACf;;;;OAIG;IACH,0CAAuB,CAAA;IACvB;;;;;;OAMG;IACH,sCAAmB,CAAA;IACnB,8BAAW,CAAA;IACX;;;;;;;;;;;;;;OAcG;IACH,gCAAa,CAAA;IACb;;;;;OAKG;IACH,0CAAuB,CAAA;AAEzB,CAAC,EApFW,eAAe,KAAf,eAAe,QAoF1B;AA4ED,MAAM,CAAC,MAAM,oBAAoB,GAAgB;IAC/C,cAAc,EAAE,KAAK;IACrB,WAAW,EAAE,IAAI;IACjB,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,KAAK;CACb,CAAC","sourcesContent":["import type { PlatformEnvironmentConfiguration as _PlatformEnvironmentConfiguration } from '~wildo-cli/services/environment/environment.schemas';\nimport type { WildoMachineDefaults, WildoPreferences as _WildoPreferences } from '~wildo-cli/services/context/context.schemas';\nimport type { CliContext as _CliContext } from '~wildo-cli/services/context/context.schemas';\nimport type { CommandRegistry as _CommandRegistry } from '~wildo-cli/kernel/command-registry';\nimport { WorkspaceScope } from '@wildo-ai/platform-config-lib';\n\nexport type PlatformEnvironmentConfiguration = _PlatformEnvironmentConfiguration;\nexport type WildoPreferences = _WildoPreferences;\n/** Re-exported beside {@link WildoPreferences}: `PromptDefinition.preference` is keyed on it. */\nexport type { WildoMachineDefaults };\nexport type CliContext = _CliContext;\n\n// ---------------------------------------------------------------------------\n// Command category — groups commands by domain and determines scope gating\n// ---------------------------------------------------------------------------\n\nexport enum CommandCategory {\n Core = 'core',\n Local = 'local',\n Remote = 'remote',\n Dev = 'dev',\n Website = 'website',\n Config = 'config',\n Generate = 'generate',\n /**\n * Market — drive the market-generation CLI surface against the application's\n * authored `MarketSnapshot` (Phase 4.2). Commands in this category POST to\n * the dev-companion's market routes and require `WorkspaceScope.SAAS_APP`\n * because they are inherently app-scoped (the snapshot lives in the\n * application's `specifications/` package).\n */\n Market = 'market',\n /**\n * Registry — module-registry workstream. The category covers CLI\n * surfaces that read/write `wildo.saas.config.ts > moduleRegistries`,\n * mutate `wildo-saas.lock.json > sections.modules`, add/update/remove\n * module source from the configured registry server, and publish\n * local modules.\n *\n * Scope split:\n * - SAAS-app verbs (category default `WorkspaceScope.SAAS_APP`):\n * `add`, `update`, `remove`, `publish`, `repair-lockfile`,\n * `lockfile-smoke`. They mutate the SaaS app source / lockfile\n * and require an app workspace.\n * - Workspace-independent verbs (declare\n * `minimumScope: WorkspaceScope.UNINITIALIZED` to override the\n * category default): `login`, `logout`, `whoami`, `info`,\n * `search`, `ping`. They operate against the registry server +\n * per-machine credential store and must run from a fresh install\n * where `~/.wildo/preferences.json` doesn't exist yet.\n */\n Registry = 'registry',\n /**\n * Brand — propagate the accepted brand-asset SSOT (the app's\n * `specifications/src/brand/resolved-assets.generated.ts`) to every frontend\n * destination (app / website / docs public dirs, head refs, config). Runs\n * independently of any generation step (a human may supply the logo), so it\n * requires `WorkspaceScope.SAAS_APP` — the SSOT lives in the application's\n * `specifications/` package.\n */\n Brand = 'brand',\n /**\n * Blueprint — define, pack and publish application blueprints (epic #2856): `wildo blueprint pack` / `status` /\n * `publish`, run in the application that DEFINES a blueprint (`blueprints/<name>/blueprint.definition.ts`). Applying\n * one is `wildo init --blueprint`, a Core command. Requires `WorkspaceScope.SAAS_APP`.\n */\n Blueprint = 'blueprint',\n /**\n * Context — the live-context door (issue #252): read-only queries against the\n * running dev companion's introspection behaviors and journey state, for\n * humans AND for tool-bearing coding/research agents working inside the\n * application. Never a mutation verb — anything that writes belongs in\n * another category by definition.\n */\n Context = 'context',\n Fwk = 'fwk',\n /**\n * Docs — publish and inspect the application's own CUSTOMER technical\n * documentation portal (`technical-doc/src/generated/consumer-documentation`\n * and the API reference beside it).\n *\n * The tree is generated, committed, and was reachable by exactly one door: a\n * hand-called `POST /api/companion/technical-doc/publish-managed`. Nothing in\n * `wildo local dev` published, no command existed, and no CI step ran — so\n * the committed tree went stale silently whenever the engine's content module\n * or the application's specifications changed, and the only way to notice was\n * to diff it (issue #275). This category is that missing door.\n *\n * Distinct from `Fwk`, which serves the FRAMEWORK developer's own knowledge\n * artifacts, and from `Website`, which is the marketing site.\n */\n Docs = 'docs',\n /**\n * Assurance — run the application's assurance cycle (collect, judge, findings, snapshot), print its schedule entry,\n * and read its coverage (#2302). The cycle runs from the framework checkout's `scripts/assurance/` for a dogfood\n * application and from the published `@wildo-ai/assurance-cycle` for every other one, so an application that owns\n * only its own repository can run it. Distinct from `Context`, which reads the dev companion: nothing here needs one.\n */\n Assurance = 'assurance',\n\n}\n\n// ---------------------------------------------------------------------------\n// Flag & Arg definitions — declarative metadata consumed by Commander.js\n// ---------------------------------------------------------------------------\n\nexport interface FlagDefinition {\n /**\n * Flag value kind. `'string[]'` is VARIADIC: Commander collects every\n * following space-separated token into an array (`--units a b c`), and a\n * comma-joined value still works too (`--units a,b,c`) — normalize with\n * `parseCsvFlag` from `~wildo-cli/kernel/flag-utils`. Use it for any flag\n * that legitimately takes multiple values, so extra tokens are captured\n * rather than silently dropped as stray args.\n */\n type: 'boolean' | 'string' | 'number' | 'string[]';\n description: string;\n default?: unknown;\n required?: boolean;\n}\n\nexport interface ArgDefinition {\n name: string;\n description: string;\n required?: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Prompt definitions — declarative prompts with automatic CLI flag mapping\n// ---------------------------------------------------------------------------\n\nexport interface PromptChoiceDefinition {\n value: string;\n label: string;\n}\n\nexport interface PromptDefinition {\n /** Unique id — used as key in answer files and as the CLI flag name. */\n id: string;\n type: 'input' | 'select' | 'confirm' | 'password';\n message: string;\n choices?: PromptChoiceDefinition[];\n default?: unknown;\n /**\n * The `~/.wildo/preferences.json` member that ANSWERS this prompt, when the machine states one.\n *\n * Resolution is `flag → answer file → preference → interactive prompt → declared default`, and the\n * position is the whole design. A preference sits BELOW a flag and an answer file, because both of\n * those are explicit inputs to THIS run and must be able to differ; it sits ABOVE the prompt,\n * because its entire purpose is that the question stops being asked. So it means \"stop asking me\",\n * never \"decide for me\" — one application can still differ without the file being edited.\n *\n * Declare it only where the answer is genuinely a property of the MACHINE rather than of the\n * application: the operator's own identity, a posture, a house default. A per-application decision\n * with real consequences (a port block, a name) does not belong here, because a stored answer\n * would silently apply it to an application whose author never considered it.\n */\n preference?: keyof WildoMachineDefaults;\n /**\n * Conditional — prompt is skipped when this returns false.\n * Receives the current CommandContext so decisions can depend on prior answers.\n */\n when?: (ctx: CommandContext) => boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Global flags — available on every command\n// ---------------------------------------------------------------------------\n\nexport interface GlobalFlags {\n nonInteractive: boolean;\n answersFile: string | null;\n verbose: boolean;\n quiet: boolean;\n}\n\nexport const DEFAULT_GLOBAL_FLAGS: GlobalFlags = {\n nonInteractive: false,\n answersFile: null,\n verbose: false,\n quiet: false,\n};\n\n// ---------------------------------------------------------------------------\n// CommandMeta — declarative command descriptor (static per command class)\n// ---------------------------------------------------------------------------\n\nexport interface CommandMeta {\n name: string;\n description: string;\n category: CommandCategory;\n /** Optional stricter scope than the category-wide default. */\n minimumScope?: WorkspaceScope;\n /** Optional command-specific unavailability copy. */\n unavailabilityMessage?: string;\n aliases?: string[];\n hidden?: boolean;\n flags?: Record<string, FlagDefinition>;\n args?: ArgDefinition[];\n prompts?: PromptDefinition[];\n}\n\n// ---------------------------------------------------------------------------\n// Logger — structured console output\n// ---------------------------------------------------------------------------\n\nexport interface Logger {\n info: (msg: string) => void;\n success: (msg: string) => void;\n warn: (msg: string) => void;\n error: (msg: string) => void;\n}\n\n// ---------------------------------------------------------------------------\n// CommandContext — enriched context injected into every command's run()\n// ---------------------------------------------------------------------------\n\nexport interface CommandContext {\n args: Record<string, string | undefined>;\n flags: Record<string, unknown>;\n rawArgs: string[];\n\n globalFlags: GlobalFlags;\n /** Parsed answers from --answers file. Keys = prompt ids. */\n answers: Record<string, unknown>;\n\n activeEnv: PlatformEnvironmentConfiguration | null;\n preferences: WildoPreferences | null;\n cliContext: CliContext;\n\n log: Logger;\n\n /** Available to kernel-level commands (e.g. help) for dynamic command listing. */\n registry?: _CommandRegistry;\n}\n\n// ---------------------------------------------------------------------------\n// CommandResult — returned by command's run()\n// ---------------------------------------------------------------------------\n\nexport interface CommandResult {\n success: boolean;\n message?: string;\n /**\n * The process exit code, when a failure has more than one meaning a caller must branch on — the\n * creation console's convention is 1 = refused or failed, 2 = the companion could not be reached\n * (#1652), so an agent tells \"your request was wrong\" from \"nothing is listening\" without parsing\n * prose. Omitted, a failure exits 1 and a success 0, as before.\n */\n exitCode?: number;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/kernel/types.ts"],"names":[],"mappings":"AAYA,8EAA8E;AAC9E,2EAA2E;AAC3E,8EAA8E;AAE9E,MAAM,CAAN,IAAY,eAoFX;AApFD,WAAY,eAAe;IACzB,gCAAa,CAAA;IACb,kCAAe,CAAA;IACf,oCAAiB,CAAA;IACjB,8BAAW,CAAA;IACX,sCAAmB,CAAA;IACnB,oCAAiB,CAAA;IACjB,wCAAqB,CAAA;IACrB;;;;;;OAMG;IACH,oCAAiB,CAAA;IACjB;;;;;;;;;;;;;;;;;;OAkBG;IACH,wCAAqB,CAAA;IACrB;;;;;;;OAOG;IACH,kCAAe,CAAA;IACf;;;;OAIG;IACH,0CAAuB,CAAA;IACvB;;;;;;OAMG;IACH,sCAAmB,CAAA;IACnB,8BAAW,CAAA;IACX;;;;;;;;;;;;;;OAcG;IACH,gCAAa,CAAA;IACb;;;;;OAKG;IACH,0CAAuB,CAAA;AAEzB,CAAC,EApFW,eAAe,KAAf,eAAe,QAoF1B;AA4ED,MAAM,CAAC,MAAM,oBAAoB,GAAgB;IAC/C,cAAc,EAAE,KAAK;IACrB,WAAW,EAAE,IAAI;IACjB,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,KAAK;CACb,CAAC","sourcesContent":["import type { PlatformEnvironmentConfiguration as _PlatformEnvironmentConfiguration } from '~wildo-cli/services/environment/environment.schemas';\nimport type { WildoMachineDefaults, WildoPreferences as _WildoPreferences } from '~wildo-cli/services/context/context.schemas';\nimport type { CliContext as _CliContext } from '~wildo-cli/services/context/context.schemas';\nimport type { CommandRegistry as _CommandRegistry } from '~wildo-cli/kernel/command-registry';\nimport { WorkspaceScope } from '@wildo-ai/platform-config-lib';\n\nexport type PlatformEnvironmentConfiguration = _PlatformEnvironmentConfiguration;\nexport type WildoPreferences = _WildoPreferences;\n/** Re-exported beside {@link WildoPreferences}: `PromptDefinition.preference` is keyed on it. */\nexport type { WildoMachineDefaults };\nexport type CliContext = _CliContext;\n\n// ---------------------------------------------------------------------------\n// Command category — groups commands by domain and determines scope gating\n// ---------------------------------------------------------------------------\n\nexport enum CommandCategory {\n Core = 'core',\n Local = 'local',\n Remote = 'remote',\n Dev = 'dev',\n Website = 'website',\n Config = 'config',\n Generate = 'generate',\n /**\n * Market — drive the market-generation CLI surface against the application's\n * authored `MarketSnapshot` (Phase 4.2). Commands in this category POST to\n * the dev-companion's market routes and require `WorkspaceScope.SAAS_APP`\n * because they are inherently app-scoped (the snapshot lives in the\n * application's `specifications/` package).\n */\n Market = 'market',\n /**\n * Registry — module-registry workstream. The category covers CLI\n * surfaces that read/write `wildo.saas.config.ts > moduleRegistries`,\n * mutate `wildo-saas.lock.json > sections.modules`, add/update/remove\n * module source from the configured registry server, and publish\n * local modules.\n *\n * Scope split:\n * - SAAS-app verbs (category default `WorkspaceScope.SAAS_APP`):\n * `add`, `update`, `remove`, `publish`, `repair-lockfile`,\n * `lockfile-smoke`. They mutate the SaaS app source / lockfile\n * and require an app workspace.\n * - Workspace-independent verbs (declare\n * `minimumScope: WorkspaceScope.UNINITIALIZED` to override the\n * category default): `login`, `logout`, `whoami`, `info`,\n * `search`, `ping`. They operate against the registry server +\n * per-machine credential store and must run from a fresh install\n * where `~/.wildo/preferences.json` doesn't exist yet.\n */\n Registry = 'registry',\n /**\n * Brand — propagate the accepted brand-asset SSOT (the app's\n * `specifications/src/brand/resolved-assets.generated.ts`) to every frontend\n * destination (app / website / docs public dirs, head refs, config). Runs\n * independently of any generation step (a human may supply the logo), so it\n * requires `WorkspaceScope.SAAS_APP` — the SSOT lives in the application's\n * `specifications/` package.\n */\n Brand = 'brand',\n /**\n * Blueprint — define, pack and publish application blueprints (epic #2856): `wildo blueprint pack` / `status` /\n * `publish`, run in the application that DEFINES a blueprint (`blueprints/<name>/blueprint.definition.ts`). Applying\n * one is `wildo init --blueprint`, a Core command. Requires `WorkspaceScope.SAAS_APP`.\n */\n Blueprint = 'blueprint',\n /**\n * Context — the live-context door (issue #252): read-only queries against the\n * running dev companion's introspection behaviors and journey state, for\n * humans AND for tool-bearing coding/research agents working inside the\n * application. Never a mutation verb — anything that writes belongs in\n * another category by definition.\n */\n Context = 'context',\n Fwk = 'fwk',\n /**\n * Docs — publish and inspect the application's own CUSTOMER technical\n * documentation portal (`technical-doc/src/generated/consumer-documentation`\n * and the API reference beside it).\n *\n * The tree is generated, committed, and was reachable by exactly one door: a\n * hand-called `POST /api/companion/technical-doc/publish-managed`. Nothing in\n * `wildo local dev` published, no command existed, and no CI step ran — so\n * the committed tree went stale silently whenever the engine's content module\n * or the application's specifications changed, and the only way to notice was\n * to diff it (issue #275). This category is that missing door.\n *\n * Distinct from `Fwk`, which serves the FRAMEWORK developer's own knowledge\n * artifacts, and from `Website`, which is the marketing site.\n */\n Docs = 'docs',\n /**\n * Assurance — run the application's assurance cycle (collect, judge, findings, snapshot), print its schedule entry,\n * and read its coverage (#2302). The cycle runs from the framework checkout's `scripts/assurance/` for a dogfood\n * application and from the published `@wildo-ai/assurance-cycle` for every other one, so an application that owns\n * only its own repository can run it. Distinct from `Context`, which reads the dev companion: nothing here needs one.\n */\n Assurance = 'assurance',\n\n}\n\n// ---------------------------------------------------------------------------\n// Flag & Arg definitions — declarative metadata consumed by Commander.js\n// ---------------------------------------------------------------------------\n\nexport interface FlagDefinition {\n /**\n * Flag value kind. `'string[]'` is VARIADIC: Commander collects every\n * following space-separated token into an array (`--units a b c`), and a\n * comma-joined value still works too (`--units a,b,c`) — normalize with\n * `parseCsvFlag` from `~wildo-cli/kernel/flag-utils`. Use it for any flag\n * that legitimately takes multiple values, so extra tokens are captured\n * rather than silently dropped as stray args.\n */\n type: 'boolean' | 'string' | 'number' | 'string[]';\n description: string;\n default?: unknown;\n required?: boolean;\n}\n\nexport interface ArgDefinition {\n name: string;\n description: string;\n required?: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Prompt definitions — declarative prompts with automatic CLI flag mapping\n// ---------------------------------------------------------------------------\n\nexport interface PromptChoiceDefinition {\n value: string;\n label: string;\n}\n\nexport interface PromptDefinition {\n /** Unique id — used as key in answer files and as the CLI flag name. */\n id: string;\n type: 'input' | 'select' | 'confirm' | 'password';\n message: string;\n choices?: PromptChoiceDefinition[];\n default?: unknown;\n /**\n * The `~/.wildo/preferences.json` member that ANSWERS this prompt, when the machine states one.\n *\n * Resolution is `flag → answer file → preference → interactive prompt → declared default`, and the\n * position is the whole design. A preference sits BELOW a flag and an answer file, because both of\n * those are explicit inputs to THIS run and must be able to differ; it sits ABOVE the prompt,\n * because its entire purpose is that the question stops being asked. So it means \"stop asking me\",\n * never \"decide for me\" — one application can still differ without the file being edited.\n *\n * Declare it only where the answer is genuinely a property of the MACHINE rather than of the\n * application: the operator's own identity, a posture, a house default. A per-application decision\n * with real consequences (a port block, a name) does not belong here, because a stored answer\n * would silently apply it to an application whose author never considered it.\n */\n preference?: keyof WildoMachineDefaults;\n /**\n * Conditional — prompt is skipped when this returns false.\n * Receives the current CommandContext so decisions can depend on prior answers.\n */\n when?: (ctx: CommandContext) => boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Global flags — available on every command\n// ---------------------------------------------------------------------------\n\nexport interface GlobalFlags {\n nonInteractive: boolean;\n answersFile: string | null;\n verbose: boolean;\n quiet: boolean;\n}\n\nexport const DEFAULT_GLOBAL_FLAGS: GlobalFlags = {\n nonInteractive: false,\n answersFile: null,\n verbose: false,\n quiet: false,\n};\n\n// ---------------------------------------------------------------------------\n// CommandMeta — declarative command descriptor (static per command class)\n// ---------------------------------------------------------------------------\n\nexport interface CommandMeta {\n name: string;\n description: string;\n category: CommandCategory;\n /** Optional stricter scope than the category-wide default. */\n minimumScope?: WorkspaceScope;\n /** Optional command-specific unavailability copy. */\n unavailabilityMessage?: string;\n aliases?: string[];\n hidden?: boolean;\n flags?: Record<string, FlagDefinition>;\n args?: ArgDefinition[];\n prompts?: PromptDefinition[];\n /**\n * True when this run's stdout carries a machine document other than a `--json` one (for example\n * `providers grant export` writing its grant document to a pipe). The runner then sends the human lines to\n * stderr and the completion hook prints no \"✔ … completed\", exactly as for `--json`, so stdout holds the\n * document and nothing else. Without it the export's trailing completion line made the piped document\n * unparseable (2026-11-18).\n */\n emitsDocumentOnStdout?: (flags: Record<string, unknown>) => boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Logger — structured console output\n// ---------------------------------------------------------------------------\n\nexport interface Logger {\n info: (msg: string) => void;\n success: (msg: string) => void;\n warn: (msg: string) => void;\n error: (msg: string) => void;\n}\n\n// ---------------------------------------------------------------------------\n// CommandContext — enriched context injected into every command's run()\n// ---------------------------------------------------------------------------\n\nexport interface CommandContext {\n args: Record<string, string | undefined>;\n flags: Record<string, unknown>;\n rawArgs: string[];\n\n globalFlags: GlobalFlags;\n /** Parsed answers from --answers file. Keys = prompt ids. */\n answers: Record<string, unknown>;\n\n activeEnv: PlatformEnvironmentConfiguration | null;\n preferences: WildoPreferences | null;\n cliContext: CliContext;\n\n log: Logger;\n\n /** Available to kernel-level commands (e.g. help) for dynamic command listing. */\n registry?: _CommandRegistry;\n}\n\n// ---------------------------------------------------------------------------\n// CommandResult — returned by command's run()\n// ---------------------------------------------------------------------------\n\nexport interface CommandResult {\n success: boolean;\n message?: string;\n /**\n * The process exit code, when a failure has more than one meaning a caller must branch on — the\n * creation console's convention is 1 = refused or failed, 2 = the companion could not be reached\n * (#1652), so an agent tells \"your request was wrong\" from \"nothing is listening\" without parsing\n * prose. Omitted, a failure exits 1 and a success 0, as before.\n */\n exitCode?: number;\n}\n"]}