gsd-pi 2.71.0-dev.e17e0ce → 2.72.0-dev.593fa74

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 (169) hide show
  1. package/README.md +34 -1
  2. package/dist/cli.js +17 -0
  3. package/dist/mcp-server.js +37 -14
  4. package/dist/resources/agents/debugger.md +58 -0
  5. package/dist/resources/agents/doc-writer.md +43 -0
  6. package/dist/resources/agents/git-ops.md +56 -0
  7. package/dist/resources/agents/javascript-pro.md +46 -271
  8. package/dist/resources/agents/planner.md +55 -0
  9. package/dist/resources/agents/refactorer.md +47 -0
  10. package/dist/resources/agents/reviewer.md +48 -0
  11. package/dist/resources/agents/security.md +59 -0
  12. package/dist/resources/agents/tester.md +50 -0
  13. package/dist/resources/agents/typescript-pro.md +41 -235
  14. package/dist/resources/extensions/claude-code-cli/partial-builder.js +40 -12
  15. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +103 -6
  16. package/dist/resources/extensions/gsd/auto/phases.js +4 -0
  17. package/dist/resources/extensions/gsd/auto-prompts.js +88 -33
  18. package/dist/resources/extensions/gsd/auto-start.js +24 -4
  19. package/dist/resources/extensions/gsd/auto.js +4 -0
  20. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +3 -3
  21. package/dist/resources/extensions/gsd/bootstrap/register-shortcuts.js +2 -5
  22. package/dist/resources/extensions/gsd/doctor-providers.js +23 -0
  23. package/dist/resources/extensions/gsd/error-classifier.js +4 -1
  24. package/dist/resources/extensions/gsd/gate-registry.js +208 -0
  25. package/dist/resources/extensions/gsd/gsd-db.js +41 -0
  26. package/dist/resources/extensions/gsd/milestone-validation-gates.js +11 -12
  27. package/dist/resources/extensions/gsd/notification-overlay.js +26 -12
  28. package/dist/resources/extensions/gsd/notification-store.js +5 -4
  29. package/dist/resources/extensions/gsd/prompt-validation.js +126 -0
  30. package/dist/resources/extensions/gsd/prompts/complete-slice.md +3 -1
  31. package/dist/resources/extensions/gsd/prompts/execute-task.md +2 -0
  32. package/dist/resources/extensions/gsd/prompts/validate-milestone.md +2 -0
  33. package/dist/resources/extensions/gsd/shortcut-defs.js +7 -1
  34. package/dist/resources/extensions/gsd/state.js +9 -2
  35. package/dist/resources/extensions/gsd/tools/complete-slice.js +52 -1
  36. package/dist/resources/extensions/gsd/tools/complete-task.js +51 -1
  37. package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +4 -1
  38. package/dist/resources/extensions/ollama/index.js +13 -5
  39. package/dist/resources/extensions/shared/gsd-phase-state.js +35 -0
  40. package/dist/resources/extensions/subagent/agents.js +8 -0
  41. package/dist/resources/extensions/subagent/index.js +17 -0
  42. package/dist/startup-model-validation.d.ts +0 -1
  43. package/dist/startup-model-validation.js +6 -2
  44. package/dist/web/standalone/.next/BUILD_ID +1 -1
  45. package/dist/web/standalone/.next/app-path-routes-manifest.json +13 -13
  46. package/dist/web/standalone/.next/build-manifest.json +2 -2
  47. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  48. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  49. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  50. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  51. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  52. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  53. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  54. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  55. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  56. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  57. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  58. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  59. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  60. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  61. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  62. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  63. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  64. package/dist/web/standalone/.next/server/app/index.html +1 -1
  65. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  66. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  67. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  68. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  69. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  70. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  71. package/dist/web/standalone/.next/server/app-paths-manifest.json +13 -13
  72. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  73. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  74. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  75. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  76. package/package.json +1 -1
  77. package/packages/mcp-server/dist/server.d.ts +12 -1
  78. package/packages/mcp-server/dist/server.d.ts.map +1 -1
  79. package/packages/mcp-server/dist/server.js +90 -42
  80. package/packages/mcp-server/dist/server.js.map +1 -1
  81. package/packages/mcp-server/dist/workflow-tools.js +1 -1
  82. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  83. package/packages/mcp-server/src/server.ts +110 -38
  84. package/packages/mcp-server/src/workflow-tools.ts +1 -1
  85. package/packages/pi-coding-agent/dist/core/model-resolver.test.d.ts +8 -0
  86. package/packages/pi-coding-agent/dist/core/model-resolver.test.d.ts.map +1 -0
  87. package/packages/pi-coding-agent/dist/core/model-resolver.test.js +75 -0
  88. package/packages/pi-coding-agent/dist/core/model-resolver.test.js.map +1 -0
  89. package/packages/pi-coding-agent/dist/core/retry-handler.d.ts +5 -0
  90. package/packages/pi-coding-agent/dist/core/retry-handler.d.ts.map +1 -1
  91. package/packages/pi-coding-agent/dist/core/retry-handler.js +55 -1
  92. package/packages/pi-coding-agent/dist/core/retry-handler.js.map +1 -1
  93. package/packages/pi-coding-agent/dist/core/retry-handler.test.js +57 -0
  94. package/packages/pi-coding-agent/dist/core/retry-handler.test.js.map +1 -1
  95. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-execution.test.js +36 -0
  96. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-execution.test.js.map +1 -1
  97. package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  98. package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.js +9 -2
  99. package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.js.map +1 -1
  100. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  101. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +87 -12
  102. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
  103. package/packages/pi-coding-agent/dist/modes/interactive/controllers/model-controller.d.ts.map +1 -1
  104. package/packages/pi-coding-agent/dist/modes/interactive/controllers/model-controller.js +6 -1
  105. package/packages/pi-coding-agent/dist/modes/interactive/controllers/model-controller.js.map +1 -1
  106. package/packages/pi-coding-agent/package.json +1 -1
  107. package/packages/pi-coding-agent/src/core/model-resolver.test.ts +85 -0
  108. package/packages/pi-coding-agent/src/core/retry-handler.test.ts +83 -0
  109. package/packages/pi-coding-agent/src/core/retry-handler.ts +60 -1
  110. package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/tool-execution.test.ts +72 -0
  111. package/packages/pi-coding-agent/src/modes/interactive/components/model-selector.ts +15 -6
  112. package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +84 -12
  113. package/packages/pi-coding-agent/src/modes/interactive/controllers/model-controller.ts +6 -1
  114. package/pkg/package.json +1 -1
  115. package/src/resources/agents/debugger.md +58 -0
  116. package/src/resources/agents/doc-writer.md +43 -0
  117. package/src/resources/agents/git-ops.md +56 -0
  118. package/src/resources/agents/javascript-pro.md +46 -271
  119. package/src/resources/agents/planner.md +55 -0
  120. package/src/resources/agents/refactorer.md +47 -0
  121. package/src/resources/agents/reviewer.md +48 -0
  122. package/src/resources/agents/security.md +59 -0
  123. package/src/resources/agents/tester.md +50 -0
  124. package/src/resources/agents/typescript-pro.md +41 -235
  125. package/src/resources/extensions/claude-code-cli/partial-builder.ts +45 -12
  126. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +109 -3
  127. package/src/resources/extensions/claude-code-cli/tests/partial-builder.test.ts +91 -2
  128. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +133 -2
  129. package/src/resources/extensions/gsd/auto/phases.ts +4 -0
  130. package/src/resources/extensions/gsd/auto-prompts.ts +111 -33
  131. package/src/resources/extensions/gsd/auto-start.ts +31 -4
  132. package/src/resources/extensions/gsd/auto.ts +4 -0
  133. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +3 -3
  134. package/src/resources/extensions/gsd/bootstrap/register-shortcuts.ts +2 -5
  135. package/src/resources/extensions/gsd/doctor-providers.ts +24 -0
  136. package/src/resources/extensions/gsd/error-classifier.ts +4 -1
  137. package/src/resources/extensions/gsd/gate-registry.ts +251 -0
  138. package/src/resources/extensions/gsd/gsd-db.ts +51 -0
  139. package/src/resources/extensions/gsd/milestone-validation-gates.ts +11 -13
  140. package/src/resources/extensions/gsd/notification-overlay.ts +27 -11
  141. package/src/resources/extensions/gsd/notification-store.ts +5 -4
  142. package/src/resources/extensions/gsd/prompt-validation.ts +157 -0
  143. package/src/resources/extensions/gsd/prompts/complete-slice.md +3 -1
  144. package/src/resources/extensions/gsd/prompts/execute-task.md +2 -0
  145. package/src/resources/extensions/gsd/prompts/validate-milestone.md +2 -0
  146. package/src/resources/extensions/gsd/shortcut-defs.ts +8 -1
  147. package/src/resources/extensions/gsd/state.ts +13 -2
  148. package/src/resources/extensions/gsd/tests/auto-start-model-capture.test.ts +14 -0
  149. package/src/resources/extensions/gsd/tests/complete-slice-gate-closure.test.ts +167 -0
  150. package/src/resources/extensions/gsd/tests/doctor-providers.test.ts +36 -0
  151. package/src/resources/extensions/gsd/tests/format-shortcut.test.ts +16 -0
  152. package/src/resources/extensions/gsd/tests/gate-dispatch.test.ts +27 -0
  153. package/src/resources/extensions/gsd/tests/gate-registry.test.ts +140 -0
  154. package/src/resources/extensions/gsd/tests/prompt-system-gate-coverage.test.ts +208 -0
  155. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +9 -0
  156. package/src/resources/extensions/gsd/tests/register-shortcuts.test.ts +3 -2
  157. package/src/resources/extensions/gsd/tools/complete-slice.ts +63 -0
  158. package/src/resources/extensions/gsd/tools/complete-task.ts +63 -0
  159. package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +4 -1
  160. package/src/resources/extensions/gsd/types.ts +26 -0
  161. package/src/resources/extensions/ollama/index.ts +13 -3
  162. package/src/resources/extensions/ollama/ollama-status-indicator.test.ts +28 -0
  163. package/src/resources/extensions/shared/gsd-phase-state.ts +42 -0
  164. package/src/resources/extensions/shared/tests/gsd-phase-state.test.ts +48 -0
  165. package/src/resources/extensions/subagent/agents.ts +10 -0
  166. package/src/resources/extensions/subagent/index.ts +18 -0
  167. package/src/resources/extensions/subagent/tests/agents-conflicts.test.ts +33 -0
  168. /package/dist/web/standalone/.next/static/{cYPZv_bAhZk2ms-Pz6vsY → h8B07q4xc-ujHRD7esO6O}/_buildManifest.js +0 -0
  169. /package/dist/web/standalone/.next/static/{cYPZv_bAhZk2ms-Pz6vsY → h8B07q4xc-ujHRD7esO6O}/_ssgManifest.js +0 -0
@@ -2,254 +2,60 @@
2
2
  name: typescript-pro
3
3
  description: "TypeScript specialist for advanced type system patterns, complex generics, type-level programming, and end-to-end type safety across full-stack applications. Use when designing type-first APIs, creating branded types for domain modeling, building generic utilities, implementing discriminated unions for state machines, configuring tsconfig and build tooling, authoring type-safe libraries, setting up monorepo project references, migrating JavaScript to TypeScript, or optimizing TypeScript compilation and bundle performance."
4
4
  model: sonnet
5
- memory: project
6
5
  ---
7
6
 
8
- You are a senior TypeScript developer with mastery of TypeScript 5.0+ and its ecosystem, specializing in advanced type system features, full-stack type safety, and modern build tooling. Your expertise spans frontend frameworks, Node.js backends, and cross-platform development with focus on type safety and developer productivity.
7
+ You are a senior TypeScript developer with mastery of TypeScript 5.0+ and its ecosystem. You specialize in advanced type system features, full-stack type safety, and modern build tooling. Types are the specification start there.
9
8
 
10
- ## Core Operating Principles
9
+ ## Initialization
11
10
 
12
- - **Type-first development**: Always start with type definitions before implementation. Types are the specification.
13
- - **Strict mode always**: Assume `strict: true` and all strict compiler flags unless the project explicitly opts out. Never introduce `any` without documented justification.
14
- - **Verify before stating**: Read actual project configuration (tsconfig.json, package.json, build configs) before making assumptions about the project setup.
15
- - **Observable facts over assumptions**: If you need to know the TypeScript version, compiler options, or existing patterns — read the files. Do not guess.
11
+ 1. Read `tsconfig.json`, `package.json`, and build tool configs
12
+ 2. Assess existing type patterns generics, utility types, declaration files
13
+ 3. Identify framework and runtime (React, Vue, Node.js, Deno)
14
+ 4. Check lint/format config to align with project conventions
16
15
 
17
- ## Initialization Protocol
16
+ ## Core Principles
18
17
 
19
- When invoked for any task:
18
+ - **Strict mode always**: `strict: true`, no `any` without documented justification
19
+ - **Type-first**: Define data shapes and API contracts before writing logic
20
+ - **Inference over annotation**: Let TypeScript infer where it produces correct, readable types
21
+ - **`satisfies` over type annotation**: Preserves literal types while validating
22
+ - **`as const`** for literal preservation in arrays and objects
23
+ - **`import type`** for type-only imports — reduces emit, improves tree shaking
24
+ - **Exhaustive checks** with `never` in switch/if-else — catch unhandled cases at compile time
20
25
 
21
- 1. **Read project configuration**: Check for `tsconfig.json`, `package.json`, and build tool configs (vite.config.ts, next.config.js, webpack.config.ts, etc.)
22
- 2. **Assess existing type patterns**: Grep for type imports, generic usage, utility types, and declaration files to understand the project's type maturity
23
- 3. **Identify framework and runtime**: Determine if this is React, Vue, Angular, Node.js, Deno, or another target — this affects type patterns and available APIs
24
- 4. **Check existing lint/format config**: Look for .eslintrc, prettier config, biome config to align with project conventions
26
+ ## Key Patterns
25
27
 
26
- ## TypeScript Development Checklist
28
+ - Conditional types for flexible APIs: `T extends Array<infer U> ? { data: U[] } : { data: T }`
29
+ - Mapped types for transformations: `{ readonly [K in keyof T]: T[K] }`
30
+ - Template literal types for string manipulation: `` `on${Capitalize<T>}` ``
31
+ - Discriminated unions for state machines — each variant has a literal tag
32
+ - Branded types for domain modeling: `T & { readonly __brand: B }`
33
+ - Result types for error handling: `{ ok: true; value: T } | { ok: false; error: E }`
34
+ - Type guards at runtime boundaries — validate all external data (APIs, user input, files)
27
35
 
28
- Apply to every implementation:
36
+ ## Build & Tooling
29
37
 
30
- - [ ] Strict mode enabled with all compiler flags
31
- - [ ] No explicit `any` usage without documented justification
32
- - [ ] 100% type coverage for public APIs
33
- - [ ] Type-only imports used where applicable (`import type { ... }`)
34
- - [ ] Source maps properly configured for debugging
35
- - [ ] Declaration files generated for library code
36
- - [ ] Generic constraints are as narrow as possible
37
- - [ ] Discriminated unions preferred over optional fields for variant types
38
+ - `moduleResolution: "bundler"` for modern bundler projects
39
+ - `isolatedModules: true` for esbuild/SWC compatibility
40
+ - `incremental: true` with `.tsbuildinfo` for faster rebuilds
41
+ - `composite: true` + `declarationMap: true` for monorepo project references
42
+ - Type-only imports to reduce emit and improve tree shaking
43
+ - Monitor type instantiation counts with `--generateTrace` for slow compiles
38
44
 
39
- ## Advanced Type Patterns
45
+ ## Testing
40
46
 
41
- Apply these patterns where they improve safety and developer experience:
42
-
43
- **Conditional types** for flexible APIs:
44
- ```typescript
45
- type ApiResponse<T> = T extends Array<infer U>
46
- ? { data: U[]; total: number }
47
- : { data: T };
48
- ```
49
-
50
- **Mapped types** for transformations:
51
- ```typescript
52
- type Readonly<T> = { readonly [K in keyof T]: T[K] };
53
- type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
54
- ```
55
-
56
- **Template literal types** for string manipulation:
57
- ```typescript
58
- type EventName<T extends string> = `on${Capitalize<T>}`;
59
- type RouteParam<T extends string> = T extends `${infer _}:${infer Param}/${infer Rest}`
60
- ? Param | RouteParam<Rest>
61
- : T extends `${infer _}:${infer Param}` ? Param : never;
62
- ```
63
-
64
- **Discriminated unions** for state machines:
65
- ```typescript
66
- type State =
67
- | { status: 'idle' }
68
- | { status: 'loading'; startedAt: number }
69
- | { status: 'success'; data: unknown; completedAt: number }
70
- | { status: 'error'; error: Error; failedAt: number };
71
- ```
72
-
73
- **Branded types** for domain modeling:
74
- ```typescript
75
- type Brand<T, B extends string> = T & { readonly __brand: B };
76
- type UserId = Brand<string, 'UserId'>;
77
- type OrderId = Brand<string, 'OrderId'>;
78
- ```
79
-
80
- **Result types** for error handling:
81
- ```typescript
82
- type Result<T, E = Error> =
83
- | { ok: true; value: T }
84
- | { ok: false; error: E };
85
- ```
86
-
87
- ## Implementation Strategy
88
-
89
- When implementing TypeScript code:
90
-
91
- 1. **Design types first**: Define the data shapes, API contracts, and state types before writing any logic
92
- 2. **Use the compiler as a correctness tool**: Structure types so invalid states are unrepresentable
93
- 3. **Leverage inference**: Don't over-annotate — let TypeScript infer where it produces correct and readable types
94
- 4. **Create type guards for runtime boundaries**: All external data (API responses, user input, file reads) must pass through type guards or validation
95
- 5. **Use `satisfies` for type validation without widening**: Prefer `const config = { ... } satisfies Config` over `const config: Config = { ... }` when you want to preserve literal types
96
- 6. **Use `as const` for literal types**: Apply const assertions to preserve literal types in arrays and objects
97
- 7. **Exhaustive checking**: Use `never` type in switch/if-else chains to ensure all cases are handled
98
-
99
- ```typescript
100
- function assertNever(x: never): never {
101
- throw new Error(`Unexpected value: ${x}`);
102
- }
103
-
104
- function handleState(state: State): string {
105
- switch (state.status) {
106
- case 'idle': return 'Waiting';
107
- case 'loading': return 'Loading...';
108
- case 'success': return 'Done';
109
- case 'error': return state.error.message;
110
- default: return assertNever(state);
111
- }
112
- }
113
- ```
114
-
115
- ## Build and Tooling Optimization
116
-
117
- **tsconfig.json best practices**:
118
- - Use `moduleResolution: "bundler"` for modern bundler-based projects
119
- - Use `module: "ESNext"` or `"NodeNext"` depending on target
120
- - Enable `isolatedModules: true` for compatibility with transpile-only tools (esbuild, SWC)
121
- - Set `skipLibCheck: true` only if third-party declarations cause issues — prefer fixing the root cause
122
- - Use `paths` mapping for clean imports, backed by bundler aliases
123
- - Configure `project references` for monorepos with `composite: true` and `declarationMap: true`
124
-
125
- **Incremental compilation**:
126
- - Enable `incremental: true` with a `.tsbuildinfo` output path
127
- - Use `--build` mode for project references
128
- - Configure `tsBuildInfoFile` to a persistent location in CI
129
-
130
- **Performance tuning**:
131
- - Use `type-only imports` to reduce emit and improve tree shaking
132
- - Prefer `const enum` only when bundle size savings justify the trade-off (they don't work with `isolatedModules`)
133
- - Avoid deeply recursive conditional types in hot paths — they slow the compiler
134
- - Monitor type instantiation counts with `--generateTrace`
135
-
136
- ## Testing With Types
137
-
138
- - Write type tests using `expectTypeOf` (from vitest) or `tsd` for declaration testing
139
- - Create type-safe test utilities and fixtures
140
- - Use generic factory functions for test data
141
- - Ensure mock types match the real implementations
47
+ - Type tests with `expectTypeOf` (vitest) or `tsd` for declaration testing
48
+ - Type-safe test utilities and generic factory functions for test data
142
49
  - Test type narrowing paths explicitly
50
+ - Ensure mock types match real implementations
143
51
 
144
- ```typescript
145
- import { expectTypeOf } from 'vitest';
146
-
147
- test('type narrowing works', () => {
148
- const result: Result<string> = { ok: true, value: 'hello' };
149
- if (result.ok) {
150
- expectTypeOf(result.value).toBeString();
151
- } else {
152
- expectTypeOf(result.error).toEqualTypeOf<Error>();
153
- }
154
- });
155
- ```
156
-
157
- ## Full-Stack Type Safety
158
-
159
- - **tRPC**: Use for end-to-end type safety between client and server without code generation
160
- - **GraphQL**: Use code generation (graphql-codegen) for type-safe queries and mutations
161
- - **OpenAPI**: Generate TypeScript clients from OpenAPI specs
162
- - **Shared packages**: Extract shared types into dedicated packages in monorepos
163
- - **Database types**: Use query builders (Prisma, Drizzle, Kysely) that generate types from schema
164
- - **Form validation**: Use Zod schemas that infer TypeScript types (`z.infer<typeof schema>`)
165
-
166
- ## Error Handling Patterns
167
-
168
- - Prefer `Result<T, E>` types over throwing exceptions for expected error cases
169
- - Use `never` return type for functions that always throw
170
- - Create typed error hierarchies with discriminated unions
171
- - Type-safe error boundaries in React with proper generic constraints
172
- - Validate all external data at boundaries using Zod or similar runtime validators
173
-
174
- ## Library Authoring
175
-
176
- When creating libraries or shared packages:
177
-
178
- - Generate `.d.ts` declaration files with `declaration: true`
179
- - Enable `declarationMap: true` for go-to-definition into source
180
- - Use `exports` field in package.json for proper dual CJS/ESM support
181
- - Design generic APIs with minimal constraints — widen later if needed
182
- - Document generic type parameters with JSDoc `@typeParam`
183
- - Test declarations with `tsd` or `@ts-expect-error` assertions
184
- - Version type changes according to semver (breaking type changes = major version)
185
-
186
- ## Code Generation
187
-
188
- - **OpenAPI → TypeScript**: Use `openapi-typescript` for type generation, `openapi-fetch` for type-safe clients
189
- - **GraphQL → TypeScript**: Use `@graphql-codegen/cli` with appropriate plugins
190
- - **Database → TypeScript**: Use Prisma's `prisma generate` or Drizzle's schema inference
191
- - **Route → TypeScript**: Leverage framework-specific type generation (Next.js, tRPC)
192
-
193
- ## Quality Verification
194
-
195
- Before declaring any TypeScript task complete:
196
-
197
- 1. **Compile check**: Run `npx tsc --noEmit` and resolve all errors
198
- 2. **Lint check**: Run the project's configured linter (ESLint, Biome) with zero warnings
199
- 3. **Type coverage**: Verify no untyped public APIs remain
200
- 4. **Test execution**: Run the test suite and verify passing
201
- 5. **Bundle analysis**: If applicable, verify bundle size impact
202
- 6. **Declaration quality**: If library code, verify generated `.d.ts` files are correct and complete
203
-
204
- ## Communication Standards
205
-
206
- - State what you observed in the codebase, not what you assume
207
- - When proposing type patterns, explain why they improve safety or DX over alternatives
208
- - If a type pattern is complex, include a usage example showing how it catches errors at compile time
209
- - Report type coverage metrics when completing type-heavy work
210
- - Flag any `any` types introduced with explicit justification
211
-
212
- **Update your agent memory** as you discover TypeScript configuration patterns, type conventions, framework-specific typing approaches, build tool configurations, and architectural decisions in the codebase. Write concise notes about what you found and where.
213
-
214
- Examples of what to record:
215
- - tsconfig.json settings and their rationale
216
- - Custom utility types defined in the project
217
- - Type generation pipelines and their configuration
218
- - Framework-specific typing patterns used
219
- - Build performance characteristics and optimization strategies
220
- - Common type errors encountered and their fixes
221
- - Module resolution quirks specific to the project
222
-
223
- # Persistent Agent Memory
224
-
225
- You have a persistent Persistent Agent Memory directory at `/home/ubuntulinuxqa2/repos/claude_skills/.claude/agent-memory/typescript-pro/`. Its contents persist across conversations.
226
-
227
- As you work, consult your memory files to build on previous experience. When you encounter a mistake that seems like it could be common, check your Persistent Agent Memory for relevant notes — and if nothing is written yet, record what you learned.
228
-
229
- Guidelines:
230
- - `MEMORY.md` is always loaded into your system prompt — lines after 200 will be truncated, so keep it concise
231
- - Create separate topic files (e.g., `debugging.md`, `patterns.md`) for detailed notes and link to them from MEMORY.md
232
- - Update or remove memories that turn out to be wrong or outdated
233
- - Organize memory semantically by topic, not chronologically
234
- - Use the Write and Edit tools to update your memory files
235
-
236
- What to save:
237
- - Stable patterns and conventions confirmed across multiple interactions
238
- - Key architectural decisions, important file paths, and project structure
239
- - User preferences for workflow, tools, and communication style
240
- - Solutions to recurring problems and debugging insights
241
-
242
- What NOT to save:
243
- - Session-specific context (current task details, in-progress work, temporary state)
244
- - Information that might be incomplete — verify against project docs before writing
245
- - Anything that duplicates or contradicts existing CLAUDE.md instructions
246
- - Speculative or unverified conclusions from reading a single file
247
-
248
- Explicit user requests:
249
- - When the user asks you to remember something across sessions (e.g., "always use bun", "never auto-commit"), save it — no need to wait for multiple interactions
250
- - When the user asks to forget or stop remembering something, find and remove the relevant entries from your memory files
251
- - Since this memory is project-scope and shared with your team via version control, tailor your memories to this project
52
+ ## Verification Checklist
252
53
 
253
- ## MEMORY.md
54
+ 1. `npx tsc --noEmit` — zero errors
55
+ 2. Linter passes with zero warnings
56
+ 3. No untyped public APIs remain
57
+ 4. Tests passing, coverage target met
58
+ 5. Declaration files correct for library code
59
+ 6. No `any` without justification comment
254
60
 
255
- Your MEMORY.md is currently empty. When you notice a pattern worth preserving across sessions, save it here. Anything in MEMORY.md will be included in your system prompt next time.
61
+ Report concrete outcomes files changed, type coverage, test results, trade-offs made.
@@ -6,6 +6,44 @@
6
6
  */
7
7
  import { hasXmlParameterTags, repairToolJson } from "@gsd/pi-ai";
8
8
  // ---------------------------------------------------------------------------
9
+ // MCP tool name parsing
10
+ // ---------------------------------------------------------------------------
11
+ /**
12
+ * Split a Claude Code MCP tool name (`mcp__<server>__<tool>`) into its parts.
13
+ * Returns null for non-prefixed names so callers can fall through unchanged.
14
+ *
15
+ * Server names may contain hyphens (`gsd-workflow`); the SDK uses the literal
16
+ * `__` delimiter between the server name and the tool name.
17
+ */
18
+ export function parseMcpToolName(name) {
19
+ if (!name.startsWith("mcp__"))
20
+ return null;
21
+ const rest = name.slice("mcp__".length);
22
+ const delim = rest.indexOf("__");
23
+ if (delim <= 0 || delim === rest.length - 2)
24
+ return null;
25
+ return { server: rest.slice(0, delim), tool: rest.slice(delim + 2) };
26
+ }
27
+ /**
28
+ * Build a GSD ToolCall block from a Claude Code SDK tool_use block, stripping
29
+ * the `mcp__<server>__` prefix from the name so registered extension renderers
30
+ * (which use the unprefixed canonical names) can match. The original server
31
+ * name is preserved on the block for diagnostics and rendering.
32
+ */
33
+ function toolCallFromBlock(id, rawName, input) {
34
+ const parsed = parseMcpToolName(rawName);
35
+ const toolCall = {
36
+ type: "toolCall",
37
+ id,
38
+ name: parsed ? parsed.tool : rawName,
39
+ arguments: input,
40
+ };
41
+ if (parsed) {
42
+ toolCall.mcpServer = parsed.server;
43
+ }
44
+ return toolCall;
45
+ }
46
+ // ---------------------------------------------------------------------------
9
47
  // Content-block mapping helpers
10
48
  // ---------------------------------------------------------------------------
11
49
  /**
@@ -22,12 +60,7 @@ export function mapContentBlock(block) {
22
60
  ...(block.signature ? { thinkingSignature: block.signature } : {}),
23
61
  };
24
62
  case "tool_use":
25
- return {
26
- type: "toolCall",
27
- id: block.id,
28
- name: block.name,
29
- arguments: block.input,
30
- };
63
+ return toolCallFromBlock(block.id, block.name, block.input);
31
64
  case "server_tool_use":
32
65
  return {
33
66
  type: "serverToolUse",
@@ -149,12 +182,7 @@ export class PartialMessageBuilder {
149
182
  }
150
183
  if (block.type === "tool_use") {
151
184
  this.toolJsonAccum.set(streamIndex, "");
152
- this.partial.content.push({
153
- type: "toolCall",
154
- id: block.id,
155
- name: block.name,
156
- arguments: {},
157
- });
185
+ this.partial.content.push(toolCallFromBlock(block.id, block.name, {}));
158
186
  return { type: "toolcall_start", contentIndex, partial: this.partial };
159
187
  }
160
188
  if (block.type === "server_tool_use") {
@@ -363,17 +363,73 @@ export function createClaudeCodeElicitationHandler(ui) {
363
363
  return { action: "decline" };
364
364
  };
365
365
  }
366
+ /**
367
+ * Aborted by the caller's AbortSignal — distinct from exhaustion. GSD's
368
+ * agent loop keys off `stopReason === "aborted"` to treat this as a clean
369
+ * user cancel instead of a retry-eligible provider failure.
370
+ */
371
+ export function makeAbortedMessage(model, lastTextContent) {
372
+ const message = {
373
+ role: "assistant",
374
+ content: lastTextContent
375
+ ? [{ type: "text", text: lastTextContent }]
376
+ : [{ type: "text", text: "Claude Code stream aborted by caller" }],
377
+ api: "anthropic-messages",
378
+ provider: "claude-code",
379
+ model,
380
+ usage: { ...ZERO_USAGE },
381
+ stopReason: "aborted",
382
+ timestamp: Date.now(),
383
+ };
384
+ return message;
385
+ }
366
386
  // ---------------------------------------------------------------------------
367
387
  // SDK options builder
368
388
  // ---------------------------------------------------------------------------
389
+ /**
390
+ * Resolve the Claude Code permission mode for the current run.
391
+ *
392
+ * - Auto-mode / headless runs bypass permissions so tool calls don't block
393
+ * on prompts the user isn't watching.
394
+ * - Interactive runs default to `acceptEdits` so file/bash writes still
395
+ * land quickly but the SDK retains a permission gate.
396
+ * - `GSD_CLAUDE_CODE_PERMISSION_MODE` forces a specific mode when set.
397
+ *
398
+ * Cross-extension coupling is kept minimal by dynamically importing
399
+ * `isAutoActive` and falling back to the bypass default if the import
400
+ * fails (e.g. in unit tests that load stream-adapter in isolation).
401
+ */
402
+ export async function resolveClaudePermissionMode(env = process.env) {
403
+ const override = env.GSD_CLAUDE_CODE_PERMISSION_MODE?.trim();
404
+ if (override === "bypassPermissions" || override === "acceptEdits" || override === "default" || override === "plan") {
405
+ return override;
406
+ }
407
+ try {
408
+ const autoMod = (await import("../gsd/auto.js"));
409
+ if (typeof autoMod.isAutoActive === "function" && autoMod.isAutoActive()) {
410
+ return "bypassPermissions";
411
+ }
412
+ return "acceptEdits";
413
+ }
414
+ catch {
415
+ // auto.ts unavailable (tests, non-GSD contexts) — stay permissive.
416
+ return "bypassPermissions";
417
+ }
418
+ }
369
419
  /**
370
420
  * Build the options object passed to the Claude Agent SDK's `query()` call.
371
421
  *
372
422
  * Extracted for testability — callers can verify session persistence,
373
423
  * beta flags, and other configuration without mocking the full SDK.
424
+ *
425
+ * `permissionMode` / `allowDangerouslySkipPermissions` are resolved through
426
+ * {@link resolveClaudePermissionMode} so interactive runs don't silently
427
+ * bypass the SDK's permission gate. Callers that want the old always-bypass
428
+ * behaviour pass `permissionMode: "bypassPermissions"` explicitly.
374
429
  */
375
- export function buildSdkOptions(modelId, prompt, extraOptions = {}) {
430
+ export function buildSdkOptions(modelId, prompt, overrides, extraOptions = {}) {
376
431
  const mcpServers = buildWorkflowMcpServers();
432
+ const permissionMode = overrides?.permissionMode ?? "bypassPermissions";
377
433
  const disallowedTools = ["AskUserQuestion"];
378
434
  return {
379
435
  pathToClaudeCodeExecutable: getClaudePath(),
@@ -381,8 +437,8 @@ export function buildSdkOptions(modelId, prompt, extraOptions = {}) {
381
437
  includePartialMessages: true,
382
438
  persistSession: true,
383
439
  cwd: process.cwd(),
384
- permissionMode: "bypassPermissions",
385
- allowDangerouslySkipPermissions: true,
440
+ permissionMode,
441
+ allowDangerouslySkipPermissions: permissionMode === "bypassPermissions",
386
442
  settingSources: ["project"],
387
443
  systemPrompt: { type: "preset", preset: "claude_code" },
388
444
  disallowedTools,
@@ -479,6 +535,28 @@ function attachExternalResultsToToolBlocks(toolBlocks, toolResultsById) {
479
535
  block.externalResult = externalResult;
480
536
  }
481
537
  }
538
+ /**
539
+ * Merge tool-call blocks from the active partial-message builder into the
540
+ * running list of intermediate tool calls, preserving order and de-duping
541
+ * by tool-call id. Exposed for testing the F3 fix (final-turn tool calls
542
+ * dropped when `result` arrives without a preceding synthetic `user`).
543
+ */
544
+ export function mergePendingToolCalls(intermediate, pending) {
545
+ const alreadyIncluded = new Set();
546
+ for (const block of intermediate) {
547
+ if (block.type === "toolCall")
548
+ alreadyIncluded.add(block.id);
549
+ }
550
+ for (const block of pending) {
551
+ if (block.type !== "toolCall")
552
+ continue;
553
+ if (alreadyIncluded.has(block.id))
554
+ continue;
555
+ alreadyIncluded.add(block.id);
556
+ intermediate.push(block);
557
+ }
558
+ return intermediate;
559
+ }
482
560
  // ---------------------------------------------------------------------------
483
561
  // streamSimple implementation
484
562
  // ---------------------------------------------------------------------------
@@ -514,7 +592,8 @@ async function pumpSdkMessages(model, context, options, stream) {
514
592
  options.signal.addEventListener("abort", () => controller.abort(), { once: true });
515
593
  }
516
594
  const prompt = buildPromptFromContext(context);
517
- const sdkOpts = buildSdkOptions(modelId, prompt, typeof options?.extensionUIContext === "object"
595
+ const permissionMode = await resolveClaudePermissionMode();
596
+ const sdkOpts = buildSdkOptions(modelId, prompt, { permissionMode }, typeof options?.extensionUIContext === "object"
518
597
  ? {
519
598
  onElicitation: createClaudeCodeElicitationHandler(options?.extensionUIContext),
520
599
  }
@@ -539,8 +618,17 @@ async function pumpSdkMessages(model, context, options, stream) {
539
618
  };
540
619
  stream.push({ type: "start", partial: initialPartial });
541
620
  for await (const msg of queryResult) {
542
- if (options?.signal?.aborted)
543
- break;
621
+ if (options?.signal?.aborted) {
622
+ // User-initiated cancel — emit an aborted error so the agent
623
+ // loop classifies this as a deliberate stop, not a transient
624
+ // provider failure that should be retried.
625
+ stream.push({
626
+ type: "error",
627
+ reason: "aborted",
628
+ error: makeAbortedMessage(modelId, lastTextContent),
629
+ });
630
+ return;
631
+ }
544
632
  switch (msg.type) {
545
633
  // -- Init --
546
634
  case "system": {
@@ -641,6 +729,15 @@ async function pumpSdkMessages(model, context, options, stream) {
641
729
  // agent loop's externalToolExecution path emits tool_execution
642
730
  // events for proper TUI rendering, followed by the text response.
643
731
  const finalContent = [];
732
+ // If the final turn ended without a synthetic user message
733
+ // (e.g. stop_reason: "tool_use" followed directly by result,
734
+ // or a turn with text but no tool execution), the `builder`
735
+ // still holds toolCall blocks that were never pushed into
736
+ // `intermediateToolBlocks`. Fold them in here so they aren't
737
+ // dropped from the final AssistantMessage.
738
+ if (builder) {
739
+ mergePendingToolCalls(intermediateToolBlocks, builder.message.content);
740
+ }
644
741
  // Add tool calls from intermediate turns first (renders above text)
645
742
  attachExternalResultsToToolBlocks(intermediateToolBlocks, toolResultsById);
646
743
  finalContent.push(...intermediateToolBlocks);
@@ -13,6 +13,7 @@ import { runUnit } from "./run-unit.js";
13
13
  import { debugLog } from "../debug-logger.js";
14
14
  import { PROJECT_FILES } from "../detection.js";
15
15
  import { MergeConflictError } from "../git-service.js";
16
+ import { setCurrentPhase, clearCurrentPhase } from "../../shared/gsd-phase-state.js";
16
17
  import { join, basename, dirname, parse as parsePath } from "node:path";
17
18
  import { existsSync, cpSync, readdirSync } from "node:fs";
18
19
  import { logWarning, logError } from "../workflow-logger.js";
@@ -770,6 +771,7 @@ export async function runUnitPhase(ic, iterData, loopState, sidecarItem) {
770
771
  s.currentUnit.id === unitId);
771
772
  const previousTier = s.currentUnitRouting?.tier;
772
773
  s.currentUnit = { type: unitType, id: unitId, startedAt: Date.now() };
774
+ setCurrentPhase(unitType);
773
775
  s.lastToolInvocationError = null; // #2883: clear stale error from previous unit
774
776
  const unitStartSeq = ic.nextSeq();
775
777
  deps.emitJournalEvent({ ts: new Date().toISOString(), flowId: ic.flowId, seq: unitStartSeq, eventType: "unit-start", data: { unitType, unitId } });
@@ -1115,6 +1117,7 @@ export async function runFinalize(ic, iterData, loopState, sidecarItem) {
1115
1117
  // Detach session from the timed-out unit so late async completions
1116
1118
  // cannot mutate state for the next unit (#3757).
1117
1119
  s.currentUnit = null;
1120
+ clearCurrentPhase();
1118
1121
  loopState.consecutiveFinalizeTimeouts++;
1119
1122
  debugLog("autoLoop", {
1120
1123
  phase: "pre-verification-timeout",
@@ -1189,6 +1192,7 @@ export async function runFinalize(ic, iterData, loopState, sidecarItem) {
1189
1192
  // Detach session from the timed-out unit so late async completions
1190
1193
  // cannot mutate state for the next unit (#3757).
1191
1194
  s.currentUnit = null;
1195
+ clearCurrentPhase();
1192
1196
  loopState.consecutiveFinalizeTimeouts++;
1193
1197
  debugLog("autoLoop", {
1194
1198
  phase: "post-verification-timeout",