toolcraft 0.0.1

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 (135) hide show
  1. package/README.md +91 -0
  2. package/dist/cli.compile-check.d.ts +1 -0
  3. package/dist/cli.compile-check.js +26 -0
  4. package/dist/cli.d.ts +12 -0
  5. package/dist/cli.js +1312 -0
  6. package/dist/index.compile-check.d.ts +1 -0
  7. package/dist/index.compile-check.js +50 -0
  8. package/dist/index.d.ts +164 -0
  9. package/dist/index.js +366 -0
  10. package/dist/mcp.compile-check.d.ts +1 -0
  11. package/dist/mcp.compile-check.js +26 -0
  12. package/dist/mcp.d.ts +31 -0
  13. package/dist/mcp.js +354 -0
  14. package/dist/number-schema.d.ts +3 -0
  15. package/dist/number-schema.js +8 -0
  16. package/dist/renderer.d.ts +5 -0
  17. package/dist/renderer.js +148 -0
  18. package/dist/schema-scope.d.ts +4 -0
  19. package/dist/schema-scope.js +34 -0
  20. package/dist/sdk.compile-check.d.ts +1 -0
  21. package/dist/sdk.compile-check.js +79 -0
  22. package/dist/sdk.d.ts +63 -0
  23. package/dist/sdk.js +218 -0
  24. package/node_modules/@poe-code/design-system/dist/acp/components.d.ts +11 -0
  25. package/node_modules/@poe-code/design-system/dist/acp/components.js +121 -0
  26. package/node_modules/@poe-code/design-system/dist/acp/index.d.ts +3 -0
  27. package/node_modules/@poe-code/design-system/dist/acp/index.js +2 -0
  28. package/node_modules/@poe-code/design-system/dist/acp/writer.d.ts +13 -0
  29. package/node_modules/@poe-code/design-system/dist/acp/writer.js +21 -0
  30. package/node_modules/@poe-code/design-system/dist/components/command-errors.d.ts +16 -0
  31. package/node_modules/@poe-code/design-system/dist/components/command-errors.js +22 -0
  32. package/node_modules/@poe-code/design-system/dist/components/help-formatter.d.ts +20 -0
  33. package/node_modules/@poe-code/design-system/dist/components/help-formatter.js +27 -0
  34. package/node_modules/@poe-code/design-system/dist/components/index.d.ts +10 -0
  35. package/node_modules/@poe-code/design-system/dist/components/index.js +7 -0
  36. package/node_modules/@poe-code/design-system/dist/components/logger.d.ts +11 -0
  37. package/node_modules/@poe-code/design-system/dist/components/logger.js +60 -0
  38. package/node_modules/@poe-code/design-system/dist/components/symbols.d.ts +12 -0
  39. package/node_modules/@poe-code/design-system/dist/components/symbols.js +71 -0
  40. package/node_modules/@poe-code/design-system/dist/components/table.d.ts +13 -0
  41. package/node_modules/@poe-code/design-system/dist/components/table.js +74 -0
  42. package/node_modules/@poe-code/design-system/dist/components/text.d.ts +14 -0
  43. package/node_modules/@poe-code/design-system/dist/components/text.js +104 -0
  44. package/node_modules/@poe-code/design-system/dist/dashboard/ansi.d.ts +18 -0
  45. package/node_modules/@poe-code/design-system/dist/dashboard/ansi.js +298 -0
  46. package/node_modules/@poe-code/design-system/dist/dashboard/buffer.d.ts +25 -0
  47. package/node_modules/@poe-code/design-system/dist/dashboard/buffer.js +189 -0
  48. package/node_modules/@poe-code/design-system/dist/dashboard/components/border.d.ts +9 -0
  49. package/node_modules/@poe-code/design-system/dist/dashboard/components/border.js +123 -0
  50. package/node_modules/@poe-code/design-system/dist/dashboard/components/footer.d.ts +8 -0
  51. package/node_modules/@poe-code/design-system/dist/dashboard/components/footer.js +57 -0
  52. package/node_modules/@poe-code/design-system/dist/dashboard/components/output-pane.d.ts +12 -0
  53. package/node_modules/@poe-code/design-system/dist/dashboard/components/output-pane.js +254 -0
  54. package/node_modules/@poe-code/design-system/dist/dashboard/components/stats-pane.d.ts +7 -0
  55. package/node_modules/@poe-code/design-system/dist/dashboard/components/stats-pane.js +121 -0
  56. package/node_modules/@poe-code/design-system/dist/dashboard/dashboard.d.ts +20 -0
  57. package/node_modules/@poe-code/design-system/dist/dashboard/dashboard.js +167 -0
  58. package/node_modules/@poe-code/design-system/dist/dashboard/demo.d.ts +13 -0
  59. package/node_modules/@poe-code/design-system/dist/dashboard/demo.js +145 -0
  60. package/node_modules/@poe-code/design-system/dist/dashboard/index.d.ts +8 -0
  61. package/node_modules/@poe-code/design-system/dist/dashboard/index.js +4 -0
  62. package/node_modules/@poe-code/design-system/dist/dashboard/keymap.d.ts +3 -0
  63. package/node_modules/@poe-code/design-system/dist/dashboard/keymap.js +99 -0
  64. package/node_modules/@poe-code/design-system/dist/dashboard/layout.d.ts +25 -0
  65. package/node_modules/@poe-code/design-system/dist/dashboard/layout.js +79 -0
  66. package/node_modules/@poe-code/design-system/dist/dashboard/should-use-dashboard.d.ts +10 -0
  67. package/node_modules/@poe-code/design-system/dist/dashboard/should-use-dashboard.js +7 -0
  68. package/node_modules/@poe-code/design-system/dist/dashboard/snapshot.d.ts +10 -0
  69. package/node_modules/@poe-code/design-system/dist/dashboard/snapshot.js +68 -0
  70. package/node_modules/@poe-code/design-system/dist/dashboard/store.d.ts +8 -0
  71. package/node_modules/@poe-code/design-system/dist/dashboard/store.js +51 -0
  72. package/node_modules/@poe-code/design-system/dist/dashboard/terminal.d.ts +37 -0
  73. package/node_modules/@poe-code/design-system/dist/dashboard/terminal.js +233 -0
  74. package/node_modules/@poe-code/design-system/dist/dashboard/types.d.ts +36 -0
  75. package/node_modules/@poe-code/design-system/dist/dashboard/types.js +1 -0
  76. package/node_modules/@poe-code/design-system/dist/index.d.ts +33 -0
  77. package/node_modules/@poe-code/design-system/dist/index.js +31 -0
  78. package/node_modules/@poe-code/design-system/dist/internal/output-format.d.ts +6 -0
  79. package/node_modules/@poe-code/design-system/dist/internal/output-format.js +22 -0
  80. package/node_modules/@poe-code/design-system/dist/internal/strip-ansi.d.ts +1 -0
  81. package/node_modules/@poe-code/design-system/dist/internal/strip-ansi.js +3 -0
  82. package/node_modules/@poe-code/design-system/dist/internal/theme-detect.d.ts +11 -0
  83. package/node_modules/@poe-code/design-system/dist/internal/theme-detect.js +49 -0
  84. package/node_modules/@poe-code/design-system/dist/prompts/index.d.ts +66 -0
  85. package/node_modules/@poe-code/design-system/dist/prompts/index.js +132 -0
  86. package/node_modules/@poe-code/design-system/dist/prompts/primitives/cancel.d.ts +2 -0
  87. package/node_modules/@poe-code/design-system/dist/prompts/primitives/cancel.js +9 -0
  88. package/node_modules/@poe-code/design-system/dist/prompts/primitives/intro.d.ts +1 -0
  89. package/node_modules/@poe-code/design-system/dist/prompts/primitives/intro.js +15 -0
  90. package/node_modules/@poe-code/design-system/dist/prompts/primitives/log.d.ts +18 -0
  91. package/node_modules/@poe-code/design-system/dist/prompts/primitives/log.js +101 -0
  92. package/node_modules/@poe-code/design-system/dist/prompts/primitives/note.d.ts +1 -0
  93. package/node_modules/@poe-code/design-system/dist/prompts/primitives/note.js +39 -0
  94. package/node_modules/@poe-code/design-system/dist/prompts/primitives/outro.d.ts +1 -0
  95. package/node_modules/@poe-code/design-system/dist/prompts/primitives/outro.js +16 -0
  96. package/node_modules/@poe-code/design-system/dist/prompts/primitives/spinner.d.ts +6 -0
  97. package/node_modules/@poe-code/design-system/dist/prompts/primitives/spinner.js +74 -0
  98. package/node_modules/@poe-code/design-system/dist/prompts/theme.d.ts +11 -0
  99. package/node_modules/@poe-code/design-system/dist/prompts/theme.js +12 -0
  100. package/node_modules/@poe-code/design-system/dist/static/index.d.ts +4 -0
  101. package/node_modules/@poe-code/design-system/dist/static/index.js +2 -0
  102. package/node_modules/@poe-code/design-system/dist/static/menu.d.ts +11 -0
  103. package/node_modules/@poe-code/design-system/dist/static/menu.js +36 -0
  104. package/node_modules/@poe-code/design-system/dist/static/spinner.d.ts +14 -0
  105. package/node_modules/@poe-code/design-system/dist/static/spinner.js +46 -0
  106. package/node_modules/@poe-code/design-system/dist/terminal-markdown/ast.d.ts +92 -0
  107. package/node_modules/@poe-code/design-system/dist/terminal-markdown/ast.js +1 -0
  108. package/node_modules/@poe-code/design-system/dist/terminal-markdown/demo-content.d.ts +2 -0
  109. package/node_modules/@poe-code/design-system/dist/terminal-markdown/demo-content.js +139 -0
  110. package/node_modules/@poe-code/design-system/dist/terminal-markdown/index.d.ts +6 -0
  111. package/node_modules/@poe-code/design-system/dist/terminal-markdown/index.js +8 -0
  112. package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/block.d.ts +7 -0
  113. package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/block.js +1495 -0
  114. package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/frontmatter.d.ts +8 -0
  115. package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/frontmatter.js +412 -0
  116. package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/inline.d.ts +10 -0
  117. package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser/inline.js +1166 -0
  118. package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser.d.ts +5 -0
  119. package/node_modules/@poe-code/design-system/dist/terminal-markdown/parser.js +42 -0
  120. package/node_modules/@poe-code/design-system/dist/terminal-markdown/renderer.d.ts +6 -0
  121. package/node_modules/@poe-code/design-system/dist/terminal-markdown/renderer.js +572 -0
  122. package/node_modules/@poe-code/design-system/dist/terminal-markdown/testing/theme-render-fixture.d.ts +1 -0
  123. package/node_modules/@poe-code/design-system/dist/terminal-markdown/testing/theme-render-fixture.js +27 -0
  124. package/node_modules/@poe-code/design-system/dist/tokens/colors.d.ts +35 -0
  125. package/node_modules/@poe-code/design-system/dist/tokens/colors.js +34 -0
  126. package/node_modules/@poe-code/design-system/dist/tokens/index.d.ts +4 -0
  127. package/node_modules/@poe-code/design-system/dist/tokens/index.js +4 -0
  128. package/node_modules/@poe-code/design-system/dist/tokens/spacing.d.ts +6 -0
  129. package/node_modules/@poe-code/design-system/dist/tokens/spacing.js +6 -0
  130. package/node_modules/@poe-code/design-system/dist/tokens/typography.d.ts +7 -0
  131. package/node_modules/@poe-code/design-system/dist/tokens/typography.js +8 -0
  132. package/node_modules/@poe-code/design-system/dist/tokens/widths.d.ts +5 -0
  133. package/node_modules/@poe-code/design-system/dist/tokens/widths.js +5 -0
  134. package/node_modules/@poe-code/design-system/package.json +25 -0
  135. package/package.json +57 -0
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ import type { ObjectSchema, Static } from "agent-kit-schema";
2
+ import type { Group, Scope } from "./index.js";
3
+ type ScopeInput = readonly Scope[] | undefined;
4
+ type Primitive = string | number | boolean | bigint | symbol | null | undefined;
5
+ type EmptyRecord = Record<never, never>;
6
+ type EffectiveCommandScope<TOwnScope extends ScopeInput, TInheritedScope extends ScopeInput> = TOwnScope extends readonly Scope[] ? TOwnScope : TInheritedScope extends readonly Scope[] ? TInheritedScope : readonly ["cli", "sdk"];
7
+ type EffectiveGroupScope<TOwnScope extends ScopeInput, TInheritedScope extends ScopeInput> = TOwnScope extends readonly Scope[] ? TOwnScope : TInheritedScope extends readonly Scope[] ? TInheritedScope : undefined;
8
+ type IncludesSDK<TScope> = TScope extends readonly Scope[] ? "sdk" extends TScope[number] ? true : false : false;
9
+ type Separator = "-" | "_" | " " | ".";
10
+ type IsUppercase<TValue extends string> = TValue extends Uppercase<TValue> ? TValue extends Lowercase<TValue> ? false : true : false;
11
+ type IsLowercase<TValue extends string> = TValue extends Lowercase<TValue> ? TValue extends Uppercase<TValue> ? false : true : false;
12
+ type LastCharacter<TValue extends string> = TValue extends `${infer THead}${infer TTail}` ? TTail extends "" ? THead : LastCharacter<TTail> : never;
13
+ type PushCurrentWord<TCurrent extends string, TWords extends readonly string[]> = TCurrent extends "" ? TWords : [...TWords, Lowercase<TCurrent>];
14
+ type SplitCamelWords<TValue extends string, TCurrent extends string = "", TWords extends readonly string[] = []> = TValue extends `${infer TChar}${infer TRest}` ? TChar extends Separator ? SplitCamelWords<TRest, "", PushCurrentWord<TCurrent, TWords>> : IsUppercase<TChar> extends true ? TCurrent extends "" ? SplitCamelWords<TRest, TChar, TWords> : TRest extends `${infer TNext}${string}` ? IsLowercase<LastCharacter<TCurrent>> extends true ? SplitCamelWords<TRest, TChar, PushCurrentWord<TCurrent, TWords>> : IsLowercase<TNext> extends true ? SplitCamelWords<TRest, TChar, PushCurrentWord<TCurrent, TWords>> : SplitCamelWords<TRest, `${TCurrent}${TChar}`, TWords> : SplitCamelWords<TRest, `${TCurrent}${TChar}`, TWords> : SplitCamelWords<TRest, `${TCurrent}${TChar}`, TWords> : PushCurrentWord<TCurrent, TWords>;
15
+ type JoinCamelWords<TWords extends readonly string[]> = TWords extends readonly [
16
+ infer THead extends string,
17
+ ...infer TTail extends readonly string[]
18
+ ] ? `${THead}${CapitalizeJoinCamelWords<TTail>}` : "";
19
+ type CapitalizeJoinCamelWords<TWords extends readonly string[]> = TWords extends readonly [
20
+ infer THead extends string,
21
+ ...infer TTail extends readonly string[]
22
+ ] ? `${Capitalize<THead>}${CapitalizeJoinCamelWords<TTail>}` : "";
23
+ type CamelCase<TValue extends string> = JoinCamelWords<SplitCamelWords<TValue>>;
24
+ type Camelize<TValue> = TValue extends Primitive ? TValue : TValue extends readonly (infer TItem)[] ? Array<Camelize<TItem>> : TValue extends object ? {
25
+ [TKey in keyof TValue as TKey extends string ? CamelCase<TKey> : TKey]: Camelize<TValue[TKey]>;
26
+ } : TValue;
27
+ type SDKMethod<TParamsSchema extends ObjectSchema<any>, TResult> = (params: Camelize<Static<TParamsSchema>>) => Promise<TResult>;
28
+ type UnionToIntersection<TValue> = (TValue extends unknown ? (value: TValue) => void : never) extends (value: infer TResult) => void ? TResult : never;
29
+ type Simplify<TValue> = {
30
+ [TKey in keyof TValue]: TValue[TKey];
31
+ };
32
+ type RawChildrenValue<TChildren> = TChildren extends readonly unknown[] ? TChildren[number] : never;
33
+ type SDKNodeShape<TNode, TInheritedScope extends ScopeInput> = TNode extends {
34
+ kind: "command";
35
+ readonly __agentKitCommandTypeInfo: {
36
+ name: infer TName extends string;
37
+ params: infer TParamsSchema extends ObjectSchema<any>;
38
+ result: infer TResult;
39
+ ownScope: infer TOwnScope extends ScopeInput;
40
+ };
41
+ } ? IncludesSDK<EffectiveCommandScope<TOwnScope, TInheritedScope>> extends true ? {
42
+ [TKey in CamelCase<TName>]: SDKMethod<TParamsSchema, TResult>;
43
+ } : EmptyRecord : TNode extends {
44
+ kind: "group";
45
+ readonly __agentKitGroupTypeInfo: {
46
+ name: infer TName extends string;
47
+ children: infer TChildren extends readonly unknown[];
48
+ ownScope: infer TOwnScope extends ScopeInput;
49
+ };
50
+ } ? SDKChildrenShape<TChildren, EffectiveGroupScope<TOwnScope, TInheritedScope>> extends infer TChildShape extends object ? keyof TChildShape extends never ? EmptyRecord : {
51
+ [TKey in CamelCase<TName>]: TChildShape;
52
+ } : never : EmptyRecord;
53
+ type SDKChildrenShape<TChildren, TInheritedScope extends ScopeInput> = Simplify<UnionToIntersection<SDKNodeShape<RawChildrenValue<TChildren>, TInheritedScope>>>;
54
+ export interface CreateSDKOptions<TServices extends object = Record<string, unknown>> {
55
+ services?: TServices;
56
+ casing?: "camel";
57
+ }
58
+ export declare function createSDK<TRootInfo, TServices extends object = Record<string, unknown>>(root: Group<any> & {
59
+ readonly __agentKitGroupTypeInfo: TRootInfo;
60
+ }, options?: CreateSDKOptions<TServices>): TRootInfo extends {
61
+ children: infer TChildren extends readonly unknown[];
62
+ } ? SDKChildrenShape<TChildren, undefined> : EmptyRecord;
63
+ export {};
package/dist/sdk.js ADDED
@@ -0,0 +1,218 @@
1
+ import { access, readFile, writeFile } from "node:fs/promises";
2
+ import { UserError, assertCommandRequirements, resolveCommandSecrets } from "./index.js";
3
+ import { getExpectedNumberDescription, isValidNumberSchemaValue } from "./number-schema.js";
4
+ import { filterSchemaForScope } from "./schema-scope.js";
5
+ const RESERVED_SERVICE_NAMES = new Set(["params", "secrets", "fetch", "fs", "env", "progress"]);
6
+ function splitWords(value) {
7
+ const words = [];
8
+ let current = "";
9
+ for (let index = 0; index < value.length; index += 1) {
10
+ const char = value[index] ?? "";
11
+ const lower = char.toLowerCase();
12
+ const upper = char.toUpperCase();
13
+ const isSeparator = char === "-" || char === "_" || char === " " || char === ".";
14
+ if (isSeparator) {
15
+ if (current.length > 0) {
16
+ words.push(current.toLowerCase());
17
+ current = "";
18
+ }
19
+ continue;
20
+ }
21
+ const isUppercase = char !== lower && char === upper;
22
+ const previous = value[index - 1];
23
+ const next = value[index + 1];
24
+ const previousIsLowercase = previous !== undefined && previous === previous.toLowerCase() && previous !== previous.toUpperCase();
25
+ const nextIsLowercase = next !== undefined && next === next.toLowerCase() && next !== next.toUpperCase();
26
+ if (isUppercase && current.length > 0 && (previousIsLowercase || nextIsLowercase)) {
27
+ words.push(current.toLowerCase());
28
+ current = char;
29
+ continue;
30
+ }
31
+ current += char;
32
+ }
33
+ if (current.length > 0) {
34
+ words.push(current.toLowerCase());
35
+ }
36
+ return words;
37
+ }
38
+ function formatSegment(segment) {
39
+ return splitWords(segment)
40
+ .map((word, index) => (index === 0 ? word : `${word[0]?.toUpperCase() ?? ""}${word.slice(1)}`))
41
+ .join("");
42
+ }
43
+ function unwrapOptional(schema) {
44
+ if (schema.kind === "optional") {
45
+ return unwrapOptional(schema.inner);
46
+ }
47
+ return schema;
48
+ }
49
+ function isOptional(schema) {
50
+ return schema.kind === "optional";
51
+ }
52
+ function isPlainObject(value) {
53
+ return typeof value === "object" && value !== null && !Array.isArray(value);
54
+ }
55
+ function createFs() {
56
+ return {
57
+ readFile: async (path, encoding = "utf8") => readFile(path, { encoding }),
58
+ writeFile: async (path, contents) => {
59
+ await writeFile(path, contents);
60
+ },
61
+ exists: async (path) => {
62
+ try {
63
+ await access(path);
64
+ return true;
65
+ }
66
+ catch {
67
+ return false;
68
+ }
69
+ },
70
+ };
71
+ }
72
+ function createEnv(values = process.env) {
73
+ return {
74
+ get(key) {
75
+ return values[key];
76
+ },
77
+ };
78
+ }
79
+ function validateServices(services) {
80
+ for (const name of Object.keys(services)) {
81
+ if (RESERVED_SERVICE_NAMES.has(name)) {
82
+ throw new Error(`Service name "${name}" is reserved. Choose a different name.`);
83
+ }
84
+ }
85
+ }
86
+ function validateEnum(value, schema, label) {
87
+ if (!schema.values.includes(value)) {
88
+ throw new UserError(`Invalid value for "${label}". Expected one of: ${schema.values.map((candidate) => String(candidate)).join(", ")}.`);
89
+ }
90
+ return value;
91
+ }
92
+ function validateSchemaValue(schema, value, label) {
93
+ const unwrappedSchema = unwrapOptional(schema);
94
+ if (value === null && unwrappedSchema.nullable === true) {
95
+ return null;
96
+ }
97
+ switch (unwrappedSchema.kind) {
98
+ case "string":
99
+ if (typeof value !== "string") {
100
+ throw new UserError(`Invalid value for "${label}". Expected a string.`);
101
+ }
102
+ return value;
103
+ case "number":
104
+ if (!isValidNumberSchemaValue(value, unwrappedSchema)) {
105
+ throw new UserError(`Invalid value for "${label}". Expected ${getExpectedNumberDescription(unwrappedSchema)}.`);
106
+ }
107
+ return value;
108
+ case "boolean":
109
+ if (typeof value !== "boolean") {
110
+ throw new UserError(`Invalid value for "${label}". Expected a boolean.`);
111
+ }
112
+ return value;
113
+ case "enum":
114
+ return validateEnum(value, unwrappedSchema, label);
115
+ case "array":
116
+ if (!Array.isArray(value)) {
117
+ throw new UserError(`Invalid value for "${label}". Expected an array.`);
118
+ }
119
+ return value.map((item, index) => validateSchemaValue(unwrappedSchema.item, item, `${label}[${index}]`));
120
+ case "object":
121
+ return validateObjectSchema(unwrappedSchema, value, label);
122
+ }
123
+ }
124
+ function validateObjectSchema(schema, value, label) {
125
+ if (!isPlainObject(value)) {
126
+ throw new UserError(`Invalid value for "${label}". Expected an object.`);
127
+ }
128
+ const result = {};
129
+ const expectedKeys = new Map();
130
+ for (const [key, childSchema] of Object.entries(schema.shape)) {
131
+ expectedKeys.set(formatSegment(key), [key, childSchema]);
132
+ }
133
+ for (const key of Object.keys(value)) {
134
+ if (!expectedKeys.has(key)) {
135
+ const fieldLabel = label.length === 0 ? key : `${label}.${key}`;
136
+ throw new UserError(`Unexpected parameter "${fieldLabel}".`);
137
+ }
138
+ }
139
+ for (const [inputKey, [outputKey, rawChildSchema]] of expectedKeys.entries()) {
140
+ const childSchema = unwrapOptional(rawChildSchema);
141
+ const hasValue = Object.prototype.hasOwnProperty.call(value, inputKey);
142
+ const fieldLabel = label.length === 0 ? inputKey : `${label}.${inputKey}`;
143
+ if (!hasValue) {
144
+ if (childSchema.default !== undefined) {
145
+ result[outputKey] = childSchema.default;
146
+ continue;
147
+ }
148
+ if (isOptional(rawChildSchema)) {
149
+ continue;
150
+ }
151
+ throw new UserError(`Missing required parameter "${fieldLabel}".`);
152
+ }
153
+ result[outputKey] = validateSchemaValue(rawChildSchema, value[inputKey], fieldLabel);
154
+ }
155
+ return result;
156
+ }
157
+ function validateSDKArguments(schema, argumentsValue) {
158
+ return validateObjectSchema(schema, argumentsValue ?? {}, "");
159
+ }
160
+ function defineMember(target, key, value) {
161
+ if (Object.prototype.hasOwnProperty.call(target, key)) {
162
+ throw new Error(`Duplicate SDK member "${key}".`);
163
+ }
164
+ Object.defineProperty(target, key, {
165
+ value,
166
+ enumerable: true,
167
+ configurable: false,
168
+ writable: false,
169
+ });
170
+ }
171
+ export function createSDK(root, options = {}) {
172
+ const services = options.services ?? {};
173
+ void options.casing;
174
+ validateServices(services);
175
+ function build(node) {
176
+ if (node.kind === "command") {
177
+ return async (params) => {
178
+ const secrets = resolveCommandSecrets(node);
179
+ const baseContext = {
180
+ ...services,
181
+ secrets,
182
+ fetch: globalThis.fetch,
183
+ fs: createFs(),
184
+ env: createEnv(),
185
+ progress() {
186
+ return undefined;
187
+ },
188
+ };
189
+ await assertCommandRequirements(node, { ...baseContext, params: undefined });
190
+ const paramsSchema = filterSchemaForScope(node.params, "sdk");
191
+ if (paramsSchema === undefined || paramsSchema.kind !== "object") {
192
+ throw new Error(`Bug: command "${node.name}" must define an object params schema for SDK.`);
193
+ }
194
+ const validatedParams = validateSDKArguments(paramsSchema, params);
195
+ return node.handler({
196
+ ...baseContext,
197
+ params: validatedParams,
198
+ });
199
+ };
200
+ }
201
+ const output = {};
202
+ for (const child of node.children) {
203
+ if (child.kind === "command") {
204
+ if (!child.scope.includes("sdk")) {
205
+ continue;
206
+ }
207
+ defineMember(output, formatSegment(child.name), build(child));
208
+ continue;
209
+ }
210
+ const childValue = build(child);
211
+ if (isPlainObject(childValue) && Object.keys(childValue).length > 0) {
212
+ defineMember(output, formatSegment(child.name), childValue);
213
+ }
214
+ }
215
+ return output;
216
+ }
217
+ return build(root);
218
+ }
@@ -0,0 +1,11 @@
1
+ export declare function renderAgentMessage(text: string): void;
2
+ export declare function renderToolStart(kind: string, title: string): void;
3
+ export declare function renderToolComplete(kind: string): void;
4
+ export declare function renderReasoning(text: string): void;
5
+ export declare function renderUsage(tokens: {
6
+ input: number;
7
+ output: number;
8
+ cached?: number;
9
+ costUsd?: number;
10
+ }): void;
11
+ export declare function renderError(message: string): void;
@@ -0,0 +1,121 @@
1
+ import chalk from "chalk";
2
+ import { resolveOutputFormat } from "../internal/output-format.js";
3
+ import { renderMarkdown } from "../terminal-markdown/index.js";
4
+ import { getAcpWriter } from "./writer.js";
5
+ function truncate(text, maxLength) {
6
+ if (text.length <= maxLength)
7
+ return text;
8
+ if (maxLength <= 3)
9
+ return text.slice(0, maxLength);
10
+ return `${text.slice(0, maxLength - 3)}...`;
11
+ }
12
+ const KIND_COLORS = {
13
+ exec: (text) => chalk.yellow(text),
14
+ edit: (text) => chalk.magenta(text),
15
+ read: (text) => chalk.cyan(text),
16
+ search: (text) => chalk.blue(text),
17
+ think: (text) => chalk.dim(text),
18
+ other: (text) => chalk.dim(text)
19
+ };
20
+ function colorForKind(kind) {
21
+ return KIND_COLORS[kind] ?? ((text) => chalk.dim(text));
22
+ }
23
+ function writeLine(line) {
24
+ getAcpWriter()(line);
25
+ }
26
+ const AGENT_PREFIX = `${chalk.green.bold("✓")} agent: `;
27
+ function formatCost(costUsd) {
28
+ return new Intl.NumberFormat("en-US", {
29
+ style: "currency",
30
+ currency: "USD",
31
+ minimumFractionDigits: 2,
32
+ maximumFractionDigits: 6
33
+ }).format(costUsd);
34
+ }
35
+ export function renderAgentMessage(text) {
36
+ const format = resolveOutputFormat();
37
+ if (format === "markdown") {
38
+ writeLine(`- **agent:** ${text}`);
39
+ return;
40
+ }
41
+ if (format === "json") {
42
+ writeLine(JSON.stringify({ event: "agent_message", text }));
43
+ return;
44
+ }
45
+ const rendered = renderMarkdown(text).trimEnd();
46
+ writeLine(`${AGENT_PREFIX}${rendered}`);
47
+ }
48
+ export function renderToolStart(kind, title) {
49
+ const format = resolveOutputFormat();
50
+ if (format === "markdown") {
51
+ writeLine(`- *→ ${kind}: ${title}*`);
52
+ return;
53
+ }
54
+ if (format === "json") {
55
+ writeLine(JSON.stringify({ event: "tool_start", kind, title }));
56
+ return;
57
+ }
58
+ const color = colorForKind(kind);
59
+ writeLine(color(` → ${kind}: ${title}`));
60
+ }
61
+ export function renderToolComplete(kind) {
62
+ const format = resolveOutputFormat();
63
+ if (format === "markdown") {
64
+ writeLine(`- *✓ ${kind}*`);
65
+ return;
66
+ }
67
+ if (format === "json") {
68
+ writeLine(JSON.stringify({ event: "tool_complete", kind }));
69
+ return;
70
+ }
71
+ const color = colorForKind(kind);
72
+ writeLine(color(` ✓ ${kind}`));
73
+ }
74
+ export function renderReasoning(text) {
75
+ const format = resolveOutputFormat();
76
+ if (format === "markdown") {
77
+ writeLine(`- *thinking:* ${truncate(text, 80)}`);
78
+ return;
79
+ }
80
+ if (format === "json") {
81
+ writeLine(JSON.stringify({ event: "reasoning", text }));
82
+ return;
83
+ }
84
+ writeLine(chalk.dim(` ✓ ${truncate(text, 80)}`));
85
+ }
86
+ export function renderUsage(tokens) {
87
+ const format = resolveOutputFormat();
88
+ const cached = typeof tokens.cached === "number" && tokens.cached > 0 ? ` (${tokens.cached} cached)` : "";
89
+ let cost = "";
90
+ if (typeof tokens.costUsd === "number") {
91
+ cost = ` (${formatCost(tokens.costUsd)})`;
92
+ }
93
+ if (format === "markdown") {
94
+ writeLine(`- **tokens:** ${tokens.input} in → ${tokens.output} out${cost}`);
95
+ return;
96
+ }
97
+ if (format === "json") {
98
+ writeLine(JSON.stringify({
99
+ event: "usage",
100
+ inputTokens: tokens.input,
101
+ outputTokens: tokens.output,
102
+ cachedTokens: tokens.cached ?? 0,
103
+ costUsd: tokens.costUsd ?? 0
104
+ }));
105
+ return;
106
+ }
107
+ writeLine("");
108
+ writeLine(chalk.green(`✓ tokens: ${tokens.input} in${cached} → ${tokens.output} out${cost}`));
109
+ }
110
+ export function renderError(message) {
111
+ const format = resolveOutputFormat();
112
+ if (format === "markdown") {
113
+ writeLine(`- **error:** ${message}`);
114
+ return;
115
+ }
116
+ if (format === "json") {
117
+ writeLine(JSON.stringify({ event: "error", message }));
118
+ return;
119
+ }
120
+ writeLine(chalk.red(`✗ ${message}`));
121
+ }
@@ -0,0 +1,3 @@
1
+ export { renderAgentMessage, renderToolStart, renderToolComplete, renderReasoning, renderUsage, renderError } from "./components.js";
2
+ export { getAcpWriter, withAcpWriter } from "./writer.js";
3
+ export type { AcpLineWriter } from "./writer.js";
@@ -0,0 +1,2 @@
1
+ export { renderAgentMessage, renderToolStart, renderToolComplete, renderReasoning, renderUsage, renderError } from "./components.js";
2
+ export { getAcpWriter, withAcpWriter } from "./writer.js";
@@ -0,0 +1,13 @@
1
+ export type AcpLineWriter = (line: string) => void;
2
+ /**
3
+ * Return the writer active in the current async context, or the default
4
+ * stdout writer if none is bound.
5
+ */
6
+ export declare function getAcpWriter(): AcpLineWriter;
7
+ /**
8
+ * Run `fn` with `writer` bound as the active ACP line writer. All calls to
9
+ * `renderAgentMessage`, `renderToolStart`, `renderAcpEvent`, etc. made inside
10
+ * `fn` (or async work awaited from `fn`) will go through `writer` instead of
11
+ * writing to `process.stdout`.
12
+ */
13
+ export declare function withAcpWriter<T>(writer: AcpLineWriter, fn: () => Promise<T>): Promise<T>;
@@ -0,0 +1,21 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ const storage = new AsyncLocalStorage();
3
+ const defaultWriter = (line) => {
4
+ process.stdout.write(`${line}\n`);
5
+ };
6
+ /**
7
+ * Return the writer active in the current async context, or the default
8
+ * stdout writer if none is bound.
9
+ */
10
+ export function getAcpWriter() {
11
+ return storage.getStore() ?? defaultWriter;
12
+ }
13
+ /**
14
+ * Run `fn` with `writer` bound as the active ACP line writer. All calls to
15
+ * `renderAgentMessage`, `renderToolStart`, `renderAcpEvent`, etc. made inside
16
+ * `fn` (or async work awaited from `fn`) will go through `writer` instead of
17
+ * writing to `process.stdout`.
18
+ */
19
+ export function withAcpWriter(writer, fn) {
20
+ return storage.run(writer, fn);
21
+ }
@@ -0,0 +1,16 @@
1
+ export declare function formatCommandNotFound(input: {
2
+ unknownCommand: string;
3
+ helpCommand: string;
4
+ }): {
5
+ label: string;
6
+ hint: string;
7
+ };
8
+ export declare function formatCommandNotFoundPanel(input: {
9
+ unknownCommand: string;
10
+ helpCommand: string;
11
+ title?: string;
12
+ }): {
13
+ title: string;
14
+ label: string;
15
+ footer: string;
16
+ };
@@ -0,0 +1,22 @@
1
+ import { typography } from "../tokens/typography.js";
2
+ import { text } from "./text.js";
3
+ export function formatCommandNotFound(input) {
4
+ const unknown = input.unknownCommand.length > 0
5
+ ? input.unknownCommand
6
+ : "<command>";
7
+ return {
8
+ label: `${typography.bold("Unknown command:")} ${text.command(unknown)}`,
9
+ hint: `${text.muted("Run")} ${text.usageCommand(input.helpCommand)} ${text.muted("for available commands.")}`
10
+ };
11
+ }
12
+ export function formatCommandNotFoundPanel(input) {
13
+ const message = formatCommandNotFound({
14
+ unknownCommand: input.unknownCommand,
15
+ helpCommand: input.helpCommand
16
+ });
17
+ return {
18
+ title: input.title ?? "command not found",
19
+ label: message.label,
20
+ footer: message.hint
21
+ };
22
+ }
@@ -0,0 +1,20 @@
1
+ export interface CommandInfo {
2
+ name: string;
3
+ description: string;
4
+ }
5
+ export interface OptionInfo {
6
+ flags: string;
7
+ description: string;
8
+ }
9
+ export declare function formatCommand(name: string, description: string): string;
10
+ export declare function formatUsage(command: string, args?: string): string;
11
+ export declare function formatOption(flags: string, description: string): string;
12
+ export declare function formatCommandList(commands: CommandInfo[]): string;
13
+ export declare function formatOptionList(options: OptionInfo[]): string;
14
+ export declare const helpFormatter: {
15
+ readonly formatCommand: typeof formatCommand;
16
+ readonly formatUsage: typeof formatUsage;
17
+ readonly formatOption: typeof formatOption;
18
+ readonly formatCommandList: typeof formatCommandList;
19
+ readonly formatOptionList: typeof formatOptionList;
20
+ };
@@ -0,0 +1,27 @@
1
+ import { text } from "./text.js";
2
+ import { widths } from "../tokens/widths.js";
3
+ export function formatCommand(name, description) {
4
+ const paddedName = name.padEnd(widths.helpColumn);
5
+ return ` ${text.command(paddedName)} ${description}`;
6
+ }
7
+ export function formatUsage(command, args) {
8
+ const argsStr = args ? ` ${text.argument(args)}` : "";
9
+ return `${text.usageCommand(command)}${argsStr}`;
10
+ }
11
+ export function formatOption(flags, description) {
12
+ const paddedFlags = flags.padEnd(widths.helpColumn);
13
+ return ` ${text.option(paddedFlags)} ${description}`;
14
+ }
15
+ export function formatCommandList(commands) {
16
+ return commands.map((cmd) => formatCommand(cmd.name, cmd.description)).join("\n");
17
+ }
18
+ export function formatOptionList(options) {
19
+ return options.map((opt) => formatOption(opt.flags, opt.description)).join("\n");
20
+ }
21
+ export const helpFormatter = {
22
+ formatCommand,
23
+ formatUsage,
24
+ formatOption,
25
+ formatCommandList,
26
+ formatOptionList
27
+ };
@@ -0,0 +1,10 @@
1
+ export { text } from "./text.js";
2
+ export { symbols } from "./symbols.js";
3
+ export { createLogger, logger } from "./logger.js";
4
+ export type { LoggerOutput } from "./logger.js";
5
+ export { helpFormatter, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList } from "./help-formatter.js";
6
+ export type { CommandInfo, OptionInfo } from "./help-formatter.js";
7
+ export { formatCommandNotFound } from "./command-errors.js";
8
+ export { formatCommandNotFoundPanel } from "./command-errors.js";
9
+ export { renderTable } from "./table.js";
10
+ export type { TableColumn, RenderTableOptions } from "./table.js";
@@ -0,0 +1,7 @@
1
+ export { text } from "./text.js";
2
+ export { symbols } from "./symbols.js";
3
+ export { createLogger, logger } from "./logger.js";
4
+ export { helpFormatter, formatCommand, formatUsage, formatOption, formatCommandList, formatOptionList } from "./help-formatter.js";
5
+ export { formatCommandNotFound } from "./command-errors.js";
6
+ export { formatCommandNotFoundPanel } from "./command-errors.js";
7
+ export { renderTable } from "./table.js";
@@ -0,0 +1,11 @@
1
+ export interface LoggerOutput {
2
+ info(message: string): void;
3
+ success(message: string): void;
4
+ warn(message: string): void;
5
+ error(message: string): void;
6
+ resolved(label: string, value: string): void;
7
+ errorResolved(label: string, value: string): void;
8
+ message(message: string, symbol?: string): void;
9
+ }
10
+ export declare function createLogger(emitter?: (message: string) => void): LoggerOutput;
11
+ export declare const logger: LoggerOutput;
@@ -0,0 +1,60 @@
1
+ import chalk from "chalk";
2
+ import { log } from "../prompts/primitives/log.js";
3
+ import { symbols } from "./symbols.js";
4
+ export function createLogger(emitter) {
5
+ const emit = (level, message) => {
6
+ if (emitter) {
7
+ emitter(message);
8
+ return;
9
+ }
10
+ if (level === "success") {
11
+ log.success(message);
12
+ return;
13
+ }
14
+ if (level === "warn") {
15
+ log.warn(message);
16
+ return;
17
+ }
18
+ if (level === "error") {
19
+ log.error(message);
20
+ return;
21
+ }
22
+ log.info(message);
23
+ };
24
+ return {
25
+ info(message) {
26
+ emit("info", message);
27
+ },
28
+ success(message) {
29
+ emit("success", message);
30
+ },
31
+ warn(message) {
32
+ emit("warn", message);
33
+ },
34
+ error(message) {
35
+ emit("error", message);
36
+ },
37
+ resolved(label, value) {
38
+ if (emitter) {
39
+ emitter(`${label}: ${value}`);
40
+ return;
41
+ }
42
+ log.message(`${label}\n ${value}`, { symbol: symbols.resolved });
43
+ },
44
+ errorResolved(label, value) {
45
+ if (emitter) {
46
+ emitter(`${label}: ${value}`);
47
+ return;
48
+ }
49
+ log.message(`${label}\n ${value}`, { symbol: symbols.errorResolved });
50
+ },
51
+ message(message, symbol) {
52
+ if (emitter) {
53
+ emitter(message);
54
+ return;
55
+ }
56
+ log.message(message, { symbol: symbol ?? chalk.gray("│") });
57
+ }
58
+ };
59
+ }
60
+ export const logger = createLogger();
@@ -0,0 +1,12 @@
1
+ export declare const symbols: {
2
+ readonly info: string;
3
+ readonly success: string;
4
+ readonly resolved: string;
5
+ readonly errorResolved: string;
6
+ readonly bar: string;
7
+ readonly cornerTopRight: "╮";
8
+ readonly cornerBottomRight: "╯";
9
+ readonly warning: string;
10
+ readonly active: string;
11
+ readonly inactive: string;
12
+ };