gsd-pi 2.69.0 → 2.70.0

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 (87) hide show
  1. package/dist/resources/extensions/gsd/bootstrap/system-context.js +6 -2
  2. package/dist/resources/extensions/gsd/commands-cmux.js +30 -1
  3. package/dist/resources/extensions/gsd/workflow-mcp.js +53 -6
  4. package/dist/web/standalone/.next/BUILD_ID +1 -1
  5. package/dist/web/standalone/.next/app-path-routes-manifest.json +12 -12
  6. package/dist/web/standalone/.next/build-manifest.json +2 -2
  7. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  8. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  9. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  10. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  11. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  12. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  13. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  14. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  15. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  16. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  17. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  18. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  19. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  20. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  21. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  22. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  23. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  24. package/dist/web/standalone/.next/server/app/api/onboarding/route.js +1 -1
  25. package/dist/web/standalone/.next/server/app/index.html +1 -1
  26. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  27. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  28. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  29. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  30. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  31. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  32. package/dist/web/standalone/.next/server/app-paths-manifest.json +12 -12
  33. package/dist/web/standalone/.next/server/chunks/6897.js +3 -3
  34. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  35. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  36. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  37. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  38. package/package.json +1 -1
  39. package/packages/daemon/src/orchestrator.ts +9 -84
  40. package/packages/mcp-server/README.md +25 -3
  41. package/packages/mcp-server/dist/cli.d.ts +0 -1
  42. package/packages/mcp-server/dist/cli.d.ts.map +1 -1
  43. package/packages/mcp-server/dist/cli.js +4 -2
  44. package/packages/mcp-server/dist/cli.js.map +1 -1
  45. package/packages/mcp-server/dist/server.d.ts +32 -1
  46. package/packages/mcp-server/dist/server.d.ts.map +1 -1
  47. package/packages/mcp-server/dist/server.js +118 -1
  48. package/packages/mcp-server/dist/server.js.map +1 -1
  49. package/packages/mcp-server/dist/tool-credentials.d.ts +6 -0
  50. package/packages/mcp-server/dist/tool-credentials.d.ts.map +1 -0
  51. package/packages/mcp-server/dist/tool-credentials.js +90 -0
  52. package/packages/mcp-server/dist/tool-credentials.js.map +1 -0
  53. package/packages/mcp-server/dist/workflow-tools.d.ts +1 -0
  54. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  55. package/packages/mcp-server/dist/workflow-tools.js +274 -2
  56. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  57. package/packages/mcp-server/src/cli.ts +5 -3
  58. package/packages/mcp-server/src/mcp-server.test.ts +85 -1
  59. package/packages/mcp-server/src/server.ts +188 -1
  60. package/packages/mcp-server/src/tool-credentials.test.ts +95 -0
  61. package/packages/mcp-server/src/tool-credentials.ts +97 -0
  62. package/packages/mcp-server/src/workflow-tools.test.ts +32 -25
  63. package/packages/mcp-server/src/workflow-tools.ts +365 -2
  64. package/packages/pi-ai/dist/providers/anthropic.d.ts.map +1 -1
  65. package/packages/pi-ai/dist/providers/anthropic.js +1 -23
  66. package/packages/pi-ai/dist/providers/anthropic.js.map +1 -1
  67. package/packages/pi-ai/dist/utils/oauth/index.d.ts +3 -2
  68. package/packages/pi-ai/dist/utils/oauth/index.d.ts.map +1 -1
  69. package/packages/pi-ai/dist/utils/oauth/index.js +3 -5
  70. package/packages/pi-ai/dist/utils/oauth/index.js.map +1 -1
  71. package/packages/pi-ai/src/providers/anthropic.ts +1 -31
  72. package/packages/pi-ai/src/utils/oauth/index.ts +3 -5
  73. package/packages/pi-coding-agent/package.json +1 -1
  74. package/pkg/package.json +1 -1
  75. package/src/resources/extensions/gsd/bootstrap/system-context.ts +9 -5
  76. package/src/resources/extensions/gsd/commands-cmux.ts +32 -1
  77. package/src/resources/extensions/gsd/tests/cmux.test.ts +67 -1
  78. package/src/resources/extensions/gsd/tests/mcp-project-config.test.ts +6 -2
  79. package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +23 -7
  80. package/src/resources/extensions/gsd/workflow-mcp.ts +59 -5
  81. package/packages/pi-ai/dist/utils/oauth/anthropic.d.ts +0 -17
  82. package/packages/pi-ai/dist/utils/oauth/anthropic.d.ts.map +0 -1
  83. package/packages/pi-ai/dist/utils/oauth/anthropic.js +0 -106
  84. package/packages/pi-ai/dist/utils/oauth/anthropic.js.map +0 -1
  85. package/packages/pi-ai/src/utils/oauth/anthropic.ts +0 -140
  86. /package/dist/web/standalone/.next/static/{DrWdzskk28E5Qz-Wjw1mj → Nl6lg7zP5dNgNBV1107v1}/_buildManifest.js +0 -0
  87. /package/dist/web/standalone/.next/static/{DrWdzskk28E5Qz-Wjw1mj → Nl6lg7zP5dNgNBV1107v1}/_ssgManifest.js +0 -0
@@ -318,7 +318,7 @@ function getWriteGateModuleCandidates(): string[] {
318
318
  const candidates: string[] = [];
319
319
  const explicitModule = process.env.GSD_WORKFLOW_WRITE_GATE_MODULE?.trim();
320
320
  if (explicitModule) {
321
- if (/^[a-z]+:/i.test(explicitModule) && !explicitModule.startsWith("file:")) {
321
+ if (/^[a-z]{2,}:/i.test(explicitModule) && !explicitModule.startsWith("file:")) {
322
322
  throw new Error("GSD_WORKFLOW_WRITE_GATE_MODULE only supports file: URLs or filesystem paths.");
323
323
  }
324
324
  candidates.push(explicitModule.startsWith("file:") ? explicitModule : toFileUrl(explicitModule));
@@ -336,11 +336,15 @@ function toFileUrl(modulePath: string): string {
336
336
  return pathToFileURL(resolve(modulePath)).href;
337
337
  }
338
338
 
339
+ async function importLocalModule<T>(relativePath: string): Promise<T> {
340
+ return import(new URL(relativePath, import.meta.url).href) as Promise<T>;
341
+ }
342
+
339
343
  function getWorkflowExecutorModuleCandidates(env: NodeJS.ProcessEnv = process.env): string[] {
340
344
  const candidates: string[] = [];
341
345
  const explicitModule = env.GSD_WORKFLOW_EXECUTORS_MODULE?.trim();
342
346
  if (explicitModule) {
343
- if (/^[a-z]+:/i.test(explicitModule) && !explicitModule.startsWith("file:")) {
347
+ if (/^[a-z]{2,}:/i.test(explicitModule) && !explicitModule.startsWith("file:")) {
344
348
  throw new Error("GSD_WORKFLOW_EXECUTORS_MODULE only supports file: URLs or filesystem paths.");
345
349
  }
346
350
  candidates.push(explicitModule.startsWith("file:") ? explicitModule : toFileUrl(explicitModule));
@@ -420,6 +424,38 @@ interface McpToolServer {
420
424
  ): unknown;
421
425
  }
422
426
 
427
+ export const WORKFLOW_TOOL_NAMES = [
428
+ "gsd_decision_save",
429
+ "gsd_save_decision",
430
+ "gsd_requirement_update",
431
+ "gsd_update_requirement",
432
+ "gsd_requirement_save",
433
+ "gsd_save_requirement",
434
+ "gsd_milestone_generate_id",
435
+ "gsd_generate_milestone_id",
436
+ "gsd_plan_milestone",
437
+ "gsd_plan_slice",
438
+ "gsd_plan_task",
439
+ "gsd_task_plan",
440
+ "gsd_replan_slice",
441
+ "gsd_slice_replan",
442
+ "gsd_slice_complete",
443
+ "gsd_complete_slice",
444
+ "gsd_skip_slice",
445
+ "gsd_complete_milestone",
446
+ "gsd_milestone_complete",
447
+ "gsd_validate_milestone",
448
+ "gsd_milestone_validate",
449
+ "gsd_reassess_roadmap",
450
+ "gsd_roadmap_reassess",
451
+ "gsd_save_gate_result",
452
+ "gsd_summary_save",
453
+ "gsd_task_complete",
454
+ "gsd_complete_task",
455
+ "gsd_milestone_status",
456
+ "gsd_journal_query",
457
+ ] as const;
458
+
423
459
  async function runSerializedWorkflowOperation<T>(fn: () => Promise<T>): Promise<T> {
424
460
  // The shared DB adapter and workflow log base path are process-global, so
425
461
  // workflow MCP mutations must not overlap within a single server process.
@@ -566,6 +602,15 @@ async function handleSaveGateResult(
566
602
  return runSerializedWorkflowOperation(() => executeSaveGateResult(params, projectDir));
567
603
  }
568
604
 
605
+ async function ensureMilestoneDbRow(milestoneId: string): Promise<void> {
606
+ try {
607
+ const { insertMilestone } = await importLocalModule<any>("../../../src/resources/extensions/gsd/gsd-db.js");
608
+ insertMilestone({ id: milestoneId, status: "queued" });
609
+ } catch {
610
+ // Ignore pre-existing rows or transient DB availability issues.
611
+ }
612
+ }
613
+
569
614
  const projectDirParam = z.string().describe("Absolute path to the project directory within the configured workflow root");
570
615
 
571
616
  const planMilestoneParams = {
@@ -772,6 +817,73 @@ const summarySaveParams = {
772
817
  };
773
818
  const summarySaveSchema = z.object(summarySaveParams);
774
819
 
820
+ const decisionSaveParams = {
821
+ projectDir: projectDirParam,
822
+ scope: z.string().describe("Scope of the decision (e.g. architecture, library, observability)"),
823
+ decision: z.string().describe("What is being decided"),
824
+ choice: z.string().describe("The choice made"),
825
+ rationale: z.string().describe("Why this choice was made"),
826
+ revisable: z.string().optional().describe("Whether this can be revisited"),
827
+ when_context: z.string().optional().describe("When/context for the decision"),
828
+ made_by: z.enum(["human", "agent", "collaborative"]).optional().describe("Who made the decision"),
829
+ };
830
+ const decisionSaveSchema = z.object(decisionSaveParams);
831
+
832
+ const requirementUpdateParams = {
833
+ projectDir: projectDirParam,
834
+ id: z.string().describe("Requirement ID (e.g. R001)"),
835
+ status: z.string().optional().describe("New status"),
836
+ validation: z.string().optional().describe("Validation criteria or proof"),
837
+ notes: z.string().optional().describe("Additional notes"),
838
+ description: z.string().optional().describe("Updated description"),
839
+ primary_owner: z.string().optional().describe("Primary owning slice"),
840
+ supporting_slices: z.string().optional().describe("Supporting slices"),
841
+ };
842
+ const requirementUpdateSchema = z.object(requirementUpdateParams);
843
+
844
+ const requirementSaveParams = {
845
+ projectDir: projectDirParam,
846
+ class: z.string().describe("Requirement class"),
847
+ description: z.string().describe("Short description of the requirement"),
848
+ why: z.string().describe("Why this requirement matters"),
849
+ source: z.string().describe("Origin of the requirement"),
850
+ status: z.string().optional().describe("Requirement status"),
851
+ primary_owner: z.string().optional().describe("Primary owning slice"),
852
+ supporting_slices: z.string().optional().describe("Supporting slices"),
853
+ validation: z.string().optional().describe("Validation criteria"),
854
+ notes: z.string().optional().describe("Additional notes"),
855
+ };
856
+ const requirementSaveSchema = z.object(requirementSaveParams);
857
+
858
+ const milestoneGenerateIdParams = {
859
+ projectDir: projectDirParam,
860
+ };
861
+ const milestoneGenerateIdSchema = z.object(milestoneGenerateIdParams);
862
+
863
+ const planTaskParams = {
864
+ projectDir: projectDirParam,
865
+ milestoneId: z.string().describe("Milestone ID (e.g. M001)"),
866
+ sliceId: z.string().describe("Slice ID (e.g. S01)"),
867
+ taskId: z.string().describe("Task ID (e.g. T01)"),
868
+ title: z.string().describe("Task title"),
869
+ description: z.string().describe("Task description / steps block"),
870
+ estimate: z.string().describe("Task estimate"),
871
+ files: z.array(z.string()).describe("Files likely touched"),
872
+ verify: z.string().describe("Verification command or block"),
873
+ inputs: z.array(z.string()).describe("Input files or references"),
874
+ expectedOutput: z.array(z.string()).describe("Expected output files or artifacts"),
875
+ observabilityImpact: z.string().optional().describe("Task observability impact"),
876
+ };
877
+ const planTaskSchema = z.object(planTaskParams);
878
+
879
+ const skipSliceParams = {
880
+ projectDir: projectDirParam,
881
+ sliceId: z.string().describe("Slice ID (e.g. S02)"),
882
+ milestoneId: z.string().describe("Milestone ID (e.g. M003)"),
883
+ reason: z.string().optional().describe("Reason for skipping this slice"),
884
+ };
885
+ const skipSliceSchema = z.object(skipSliceParams);
886
+
775
887
  const taskCompleteParams = {
776
888
  projectDir: projectDirParam,
777
889
  taskId: z.string().describe("Task ID (e.g. T01)"),
@@ -803,7 +915,171 @@ const milestoneStatusParams = {
803
915
  };
804
916
  const milestoneStatusSchema = z.object(milestoneStatusParams);
805
917
 
918
+ const journalQueryParams = {
919
+ projectDir: projectDirParam,
920
+ flowId: z.string().optional().describe("Filter by flow ID"),
921
+ unitId: z.string().optional().describe("Filter by unit ID"),
922
+ rule: z.string().optional().describe("Filter by rule name"),
923
+ eventType: z.string().optional().describe("Filter by event type"),
924
+ after: z.string().optional().describe("ISO-8601 lower bound (inclusive)"),
925
+ before: z.string().optional().describe("ISO-8601 upper bound (inclusive)"),
926
+ limit: z.number().optional().describe("Maximum entries to return"),
927
+ };
928
+ const journalQuerySchema = z.object(journalQueryParams);
929
+
806
930
  export function registerWorkflowTools(server: McpToolServer): void {
931
+ server.tool(
932
+ "gsd_decision_save",
933
+ "Record a project decision to the GSD database and regenerate DECISIONS.md.",
934
+ decisionSaveParams,
935
+ async (args: Record<string, unknown>) => {
936
+ const parsed = parseWorkflowArgs(decisionSaveSchema, args);
937
+ const { projectDir, ...params } = parsed;
938
+ await enforceWorkflowWriteGate("gsd_decision_save", projectDir);
939
+ const result = await runSerializedWorkflowOperation(async () => {
940
+ const { saveDecisionToDb } = await importLocalModule<any>("../../../src/resources/extensions/gsd/db-writer.js");
941
+ return saveDecisionToDb(params, projectDir);
942
+ });
943
+ return { content: [{ type: "text" as const, text: `Saved decision ${result.id}` }] };
944
+ },
945
+ );
946
+
947
+ server.tool(
948
+ "gsd_save_decision",
949
+ "Alias for gsd_decision_save. Record a project decision to the GSD database and regenerate DECISIONS.md.",
950
+ decisionSaveParams,
951
+ async (args: Record<string, unknown>) => {
952
+ const parsed = parseWorkflowArgs(decisionSaveSchema, args);
953
+ const { projectDir, ...params } = parsed;
954
+ await enforceWorkflowWriteGate("gsd_decision_save", projectDir);
955
+ const result = await runSerializedWorkflowOperation(async () => {
956
+ const { saveDecisionToDb } = await importLocalModule<any>("../../../src/resources/extensions/gsd/db-writer.js");
957
+ return saveDecisionToDb(params, projectDir);
958
+ });
959
+ return { content: [{ type: "text" as const, text: `Saved decision ${result.id}` }] };
960
+ },
961
+ );
962
+
963
+ server.tool(
964
+ "gsd_requirement_update",
965
+ "Update an existing requirement in the GSD database and regenerate REQUIREMENTS.md.",
966
+ requirementUpdateParams,
967
+ async (args: Record<string, unknown>) => {
968
+ const parsed = parseWorkflowArgs(requirementUpdateSchema, args);
969
+ const { projectDir, id, ...updates } = parsed;
970
+ await enforceWorkflowWriteGate("gsd_requirement_update", projectDir);
971
+ await runSerializedWorkflowOperation(async () => {
972
+ const { updateRequirementInDb } = await importLocalModule<any>("../../../src/resources/extensions/gsd/db-writer.js");
973
+ return updateRequirementInDb(id, updates, projectDir);
974
+ });
975
+ return { content: [{ type: "text" as const, text: `Updated requirement ${id}` }] };
976
+ },
977
+ );
978
+
979
+ server.tool(
980
+ "gsd_update_requirement",
981
+ "Alias for gsd_requirement_update. Update an existing requirement in the GSD database and regenerate REQUIREMENTS.md.",
982
+ requirementUpdateParams,
983
+ async (args: Record<string, unknown>) => {
984
+ const parsed = parseWorkflowArgs(requirementUpdateSchema, args);
985
+ const { projectDir, id, ...updates } = parsed;
986
+ await enforceWorkflowWriteGate("gsd_requirement_update", projectDir);
987
+ await runSerializedWorkflowOperation(async () => {
988
+ const { updateRequirementInDb } = await importLocalModule<any>("../../../src/resources/extensions/gsd/db-writer.js");
989
+ return updateRequirementInDb(id, updates, projectDir);
990
+ });
991
+ return { content: [{ type: "text" as const, text: `Updated requirement ${id}` }] };
992
+ },
993
+ );
994
+
995
+ server.tool(
996
+ "gsd_requirement_save",
997
+ "Record a new requirement to the GSD database and regenerate REQUIREMENTS.md.",
998
+ requirementSaveParams,
999
+ async (args: Record<string, unknown>) => {
1000
+ const parsed = parseWorkflowArgs(requirementSaveSchema, args);
1001
+ const { projectDir, ...params } = parsed;
1002
+ await enforceWorkflowWriteGate("gsd_requirement_save", projectDir);
1003
+ const result = await runSerializedWorkflowOperation(async () => {
1004
+ const { saveRequirementToDb } = await importLocalModule<any>("../../../src/resources/extensions/gsd/db-writer.js");
1005
+ return saveRequirementToDb(params, projectDir);
1006
+ });
1007
+ return { content: [{ type: "text" as const, text: `Saved requirement ${result.id}` }] };
1008
+ },
1009
+ );
1010
+
1011
+ server.tool(
1012
+ "gsd_save_requirement",
1013
+ "Alias for gsd_requirement_save. Record a new requirement to the GSD database and regenerate REQUIREMENTS.md.",
1014
+ requirementSaveParams,
1015
+ async (args: Record<string, unknown>) => {
1016
+ const parsed = parseWorkflowArgs(requirementSaveSchema, args);
1017
+ const { projectDir, ...params } = parsed;
1018
+ await enforceWorkflowWriteGate("gsd_requirement_save", projectDir);
1019
+ const result = await runSerializedWorkflowOperation(async () => {
1020
+ const { saveRequirementToDb } = await importLocalModule<any>("../../../src/resources/extensions/gsd/db-writer.js");
1021
+ return saveRequirementToDb(params, projectDir);
1022
+ });
1023
+ return { content: [{ type: "text" as const, text: `Saved requirement ${result.id}` }] };
1024
+ },
1025
+ );
1026
+
1027
+ server.tool(
1028
+ "gsd_milestone_generate_id",
1029
+ "Generate the next milestone ID for a new GSD milestone.",
1030
+ milestoneGenerateIdParams,
1031
+ async (args: Record<string, unknown>) => {
1032
+ const { projectDir } = parseWorkflowArgs(milestoneGenerateIdSchema, args);
1033
+ await enforceWorkflowWriteGate("gsd_milestone_generate_id", projectDir);
1034
+ const id = await runSerializedWorkflowOperation(async () => {
1035
+ const {
1036
+ claimReservedId,
1037
+ findMilestoneIds,
1038
+ getReservedMilestoneIds,
1039
+ nextMilestoneId,
1040
+ } = await importLocalModule<any>("../../../src/resources/extensions/gsd/milestone-ids.js");
1041
+ const reserved = claimReservedId();
1042
+ if (reserved) {
1043
+ await ensureMilestoneDbRow(reserved);
1044
+ return reserved;
1045
+ }
1046
+ const allIds = [...new Set([...findMilestoneIds(projectDir), ...getReservedMilestoneIds()])];
1047
+ const nextId = nextMilestoneId(allIds);
1048
+ await ensureMilestoneDbRow(nextId);
1049
+ return nextId;
1050
+ });
1051
+ return { content: [{ type: "text" as const, text: id }] };
1052
+ },
1053
+ );
1054
+
1055
+ server.tool(
1056
+ "gsd_generate_milestone_id",
1057
+ "Alias for gsd_milestone_generate_id. Generate the next milestone ID for a new GSD milestone.",
1058
+ milestoneGenerateIdParams,
1059
+ async (args: Record<string, unknown>) => {
1060
+ const { projectDir } = parseWorkflowArgs(milestoneGenerateIdSchema, args);
1061
+ await enforceWorkflowWriteGate("gsd_milestone_generate_id", projectDir);
1062
+ const id = await runSerializedWorkflowOperation(async () => {
1063
+ const {
1064
+ claimReservedId,
1065
+ findMilestoneIds,
1066
+ getReservedMilestoneIds,
1067
+ nextMilestoneId,
1068
+ } = await importLocalModule<any>("../../../src/resources/extensions/gsd/milestone-ids.js");
1069
+ const reserved = claimReservedId();
1070
+ if (reserved) {
1071
+ await ensureMilestoneDbRow(reserved);
1072
+ return reserved;
1073
+ }
1074
+ const allIds = [...new Set([...findMilestoneIds(projectDir), ...getReservedMilestoneIds()])];
1075
+ const nextId = nextMilestoneId(allIds);
1076
+ await ensureMilestoneDbRow(nextId);
1077
+ return nextId;
1078
+ });
1079
+ return { content: [{ type: "text" as const, text: id }] };
1080
+ },
1081
+ );
1082
+
807
1083
  server.tool(
808
1084
  "gsd_plan_milestone",
809
1085
  "Write milestone planning state to the GSD database and render ROADMAP.md from DB.",
@@ -830,6 +1106,48 @@ export function registerWorkflowTools(server: McpToolServer): void {
830
1106
  },
831
1107
  );
832
1108
 
1109
+ server.tool(
1110
+ "gsd_plan_task",
1111
+ "Write task planning state to the GSD database and render tasks/T##-PLAN.md from DB.",
1112
+ planTaskParams,
1113
+ async (args: Record<string, unknown>) => {
1114
+ const parsed = parseWorkflowArgs(planTaskSchema, args);
1115
+ const { projectDir, ...params } = parsed;
1116
+ await enforceWorkflowWriteGate("gsd_plan_task", projectDir, params.milestoneId);
1117
+ const result = await runSerializedWorkflowOperation(async () => {
1118
+ const { handlePlanTask } = await importLocalModule<any>("../../../src/resources/extensions/gsd/tools/plan-task.js");
1119
+ return handlePlanTask(params, projectDir);
1120
+ });
1121
+ if ("error" in result) {
1122
+ throw new Error(result.error);
1123
+ }
1124
+ return {
1125
+ content: [{ type: "text" as const, text: `Planned task ${result.taskId} (${result.sliceId}/${result.milestoneId})` }],
1126
+ };
1127
+ },
1128
+ );
1129
+
1130
+ server.tool(
1131
+ "gsd_task_plan",
1132
+ "Alias for gsd_plan_task. Write task planning state to the GSD database and render tasks/T##-PLAN.md from DB.",
1133
+ planTaskParams,
1134
+ async (args: Record<string, unknown>) => {
1135
+ const parsed = parseWorkflowArgs(planTaskSchema, args);
1136
+ const { projectDir, ...params } = parsed;
1137
+ await enforceWorkflowWriteGate("gsd_plan_task", projectDir, params.milestoneId);
1138
+ const result = await runSerializedWorkflowOperation(async () => {
1139
+ const { handlePlanTask } = await importLocalModule<any>("../../../src/resources/extensions/gsd/tools/plan-task.js");
1140
+ return handlePlanTask(params, projectDir);
1141
+ });
1142
+ if ("error" in result) {
1143
+ throw new Error(result.error);
1144
+ }
1145
+ return {
1146
+ content: [{ type: "text" as const, text: `Planned task ${result.taskId} (${result.sliceId}/${result.milestoneId})` }],
1147
+ };
1148
+ },
1149
+ );
1150
+
833
1151
  server.tool(
834
1152
  "gsd_replan_slice",
835
1153
  "Replan a slice after a blocker is discovered, preserving completed tasks and re-rendering PLAN.md + REPLAN.md.",
@@ -870,6 +1188,36 @@ export function registerWorkflowTools(server: McpToolServer): void {
870
1188
  },
871
1189
  );
872
1190
 
1191
+ server.tool(
1192
+ "gsd_skip_slice",
1193
+ "Mark a slice as skipped so auto-mode advances past it without executing.",
1194
+ skipSliceParams,
1195
+ async (args: Record<string, unknown>) => {
1196
+ const { projectDir, milestoneId, sliceId, reason } = parseWorkflowArgs(skipSliceSchema, args);
1197
+ await enforceWorkflowWriteGate("gsd_skip_slice", projectDir, milestoneId);
1198
+ await runSerializedWorkflowOperation(async () => {
1199
+ const { getSlice, updateSliceStatus } = await importLocalModule<any>("../../../src/resources/extensions/gsd/gsd-db.js");
1200
+ const { invalidateStateCache } = await importLocalModule<any>("../../../src/resources/extensions/gsd/state.js");
1201
+ const { rebuildState } = await importLocalModule<any>("../../../src/resources/extensions/gsd/doctor.js");
1202
+ const slice = getSlice(milestoneId, sliceId);
1203
+ if (!slice) {
1204
+ throw new Error(`Slice ${sliceId} not found in milestone ${milestoneId}`);
1205
+ }
1206
+ if (slice.status === "complete" || slice.status === "done") {
1207
+ throw new Error(`Slice ${sliceId} is already complete and cannot be skipped`);
1208
+ }
1209
+ if (slice.status !== "skipped") {
1210
+ updateSliceStatus(milestoneId, sliceId, "skipped");
1211
+ invalidateStateCache();
1212
+ await rebuildState(projectDir);
1213
+ }
1214
+ });
1215
+ return {
1216
+ content: [{ type: "text" as const, text: `Skipped slice ${sliceId} (${milestoneId}). Reason: ${reason ?? "User-directed skip"}.` }],
1217
+ };
1218
+ },
1219
+ );
1220
+
873
1221
  server.tool(
874
1222
  "gsd_complete_milestone",
875
1223
  "Record a completed milestone to the GSD database and render its SUMMARY.md.",
@@ -994,4 +1342,19 @@ export function registerWorkflowTools(server: McpToolServer): void {
994
1342
  return runSerializedWorkflowOperation(() => executeMilestoneStatus({ milestoneId }, projectDir));
995
1343
  },
996
1344
  );
1345
+
1346
+ server.tool(
1347
+ "gsd_journal_query",
1348
+ "Query the structured event journal for auto-mode iterations.",
1349
+ journalQueryParams,
1350
+ async (args: Record<string, unknown>) => {
1351
+ const { projectDir, limit, ...filters } = parseWorkflowArgs(journalQuerySchema, args);
1352
+ const { queryJournal } = await importLocalModule<any>("../../../src/resources/extensions/gsd/journal.js");
1353
+ const entries = queryJournal(projectDir, filters).slice(0, limit ?? 100);
1354
+ if (entries.length === 0) {
1355
+ return { content: [{ type: "text" as const, text: "No matching journal entries found." }] };
1356
+ }
1357
+ return { content: [{ type: "text" as const, text: JSON.stringify(entries, null, 2) }] };
1358
+ },
1359
+ );
997
1360
  }
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAGX,mBAAmB,EACnB,cAAc,EACd,MAAM,aAAa,CAAC;AAKrB,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,mBAAmB,EAInB,MAAM,uBAAuB,CAAC;AAG/B,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAuH/B,eAAO,MAAM,eAAe,EAAE,cAAc,CAAC,oBAAoB,EAAE,gBAAgB,CAsClF,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,cAAc,CAAC,oBAAoB,EAAE,mBAAmB,CAuC3F,CAAC"}
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAGX,mBAAmB,EACnB,cAAc,EACd,MAAM,aAAa,CAAC;AAKrB,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,mBAAmB,EAInB,MAAM,uBAAuB,CAAC;AAG/B,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAyF/B,eAAO,MAAM,eAAe,EAAE,cAAc,CAAC,oBAAoB,EAAE,gBAAgB,CAsClF,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,cAAc,CAAC,oBAAoB,EAAE,mBAAmB,CAuC3F,CAAC"}
@@ -12,8 +12,6 @@ async function getAnthropicClass() {
12
12
  }
13
13
  return _AnthropicClass;
14
14
  }
15
- // Stealth mode: Mimic Claude Code's tool naming exactly
16
- const claudeCodeVersion = "2.1.62";
17
15
  function mergeHeaders(...headerSources) {
18
16
  const merged = {};
19
17
  for (const headers of headerSources) {
@@ -23,9 +21,6 @@ function mergeHeaders(...headerSources) {
23
21
  }
24
22
  return merged;
25
23
  }
26
- function isOAuthToken(apiKey) {
27
- return apiKey.includes("sk-ant-oat");
28
- }
29
24
  async function createClient(model, apiKey, interleavedThinking, optionsHeaders, dynamicHeaders) {
30
25
  const AnthropicClass = await getAnthropicClass();
31
26
  // Adaptive thinking models (Opus 4.6, Sonnet 4.6) have interleaved thinking built-in.
@@ -56,24 +51,7 @@ async function createClient(model, apiKey, interleavedThinking, optionsHeaders,
56
51
  if (needsInterleavedBeta && !skipBetaHeaders) {
57
52
  betaFeatures.push("interleaved-thinking-2025-05-14");
58
53
  }
59
- // OAuth: Bearer auth, Claude Code identity headers
60
- if (isOAuthToken(apiKey)) {
61
- const client = new AnthropicClass({
62
- apiKey: null,
63
- authToken: apiKey,
64
- baseURL: model.baseUrl,
65
- dangerouslyAllowBrowser: true,
66
- defaultHeaders: mergeHeaders({
67
- accept: "application/json",
68
- "anthropic-dangerous-direct-browser-access": "true",
69
- ...(betaFeatures.length > 0 ? { "anthropic-beta": `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}` } : {}),
70
- "user-agent": `claude-cli/${claudeCodeVersion}`,
71
- "x-app": "cli",
72
- }, model.headers, optionsHeaders),
73
- });
74
- return { client, isOAuthToken: true };
75
- }
76
- // API key auth
54
+ // API key auth (Anthropic OAuth removed per TOS compliance — use API keys or Claude CLI)
77
55
  // Alibaba Coding Plan uses Bearer token auth instead of x-api-key
78
56
  const isAlibabaProvider = model.provider === "alibaba-coding-plan";
79
57
  const client = new AnthropicClass({
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAOlD,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAGN,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAI/B,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAE/B,IAAI,eAA6C,CAAC;AAClD,KAAK,UAAU,iBAAiB;IAC/B,IAAI,CAAC,eAAe,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;QAC9C,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC;IAC/B,CAAC;IACD,OAAO,eAAe,CAAC;AACxB,CAAC;AAED,wDAAwD;AACxD,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAEnC,SAAS,YAAY,CAAC,GAAG,aAAqD;IAC7E,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;QACrC,IAAI,OAAO,EAAE,CAAC;YACb,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,CAAC;IACF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,YAAY,CAAC,MAAc;I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,CAAC,CAAC","sourcesContent":["// Lazy-loaded: Anthropic SDK (~500ms) is imported on first use, not at startup.\n// This avoids penalizing users who don't use Anthropic models.\nimport type Anthropic from \"@anthropic-ai/sdk\";\nimport { getEnvApiKey } from \"../env-api-keys.js\";\nimport type {\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamFunction,\n} from \"../types.js\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.js\";\n\nimport { buildCopilotDynamicHeaders, hasCopilotVisionInput } from \"./github-copilot-headers.js\";\nimport { adjustMaxTokensForThinking, buildBaseOptions } from \"./simple-options.js\";\nimport {\n\ttype AnthropicEffort,\n\ttype AnthropicOptions,\n\textractRetryAfterMs,\n\tmapThinkingLevelToEffort,\n\tprocessAnthropicStream,\n\tsupportsAdaptiveThinking,\n} from \"./anthropic-shared.js\";\n\n// Re-export types used by other modules\nexport type { AnthropicEffort, AnthropicOptions };\nexport { extractRetryAfterMs };\n\nlet _AnthropicClass: typeof Anthropic | undefined;\nasync function getAnthropicClass(): Promise<typeof Anthropic> {\n\tif (!_AnthropicClass) {\n\t\tconst mod = await import(\"@anthropic-ai/sdk\");\n\t\t_AnthropicClass = mod.default;\n\t}\n\treturn _AnthropicClass;\n}\n\n// Stealth mode: Mimic Claude Code's tool naming exactly\nconst claudeCodeVersion = \"2.1.62\";\n\nfunction mergeHeaders(...headerSources: (Record<string, string> | undefined)[]): Record<string, string> {\n\tconst merged: Record<string, string> = {};\n\tfor (const headers of headerSources) {\n\t\tif (headers) {\n\t\t\tObject.assign(merged, headers);\n\t\t}\n\t}\n\treturn merged;\n}\n\nfunction isOAuthToken(apiKey: string): boolean {\n\treturn apiKey.includes(\"sk-ant-oat\");\n}\n\nasync function createClient(\n\tmodel: Model<\"anthropic-messages\">,\n\tapiKey: string,\n\tinterleavedThinking: boolean,\n\toptionsHeaders?: Record<string, string>,\n\tdynamicHeaders?: Record<string, string>,\n): Promise<{ client: Anthropic; isOAuthToken: boolean }> {\n\tconst AnthropicClass = await getAnthropicClass();\n\t// Adaptive thinking models (Opus 4.6, Sonnet 4.6) have interleaved thinking built-in.\n\t// The beta header is deprecated on Opus 4.6 and redundant on Sonnet 4.6, so skip it.\n\tconst needsInterleavedBeta = interleavedThinking && !supportsAdaptiveThinking(model.id);\n\n\t// Copilot: Bearer auth, selective betas (no fine-grained-tool-streaming)\n\tif (model.provider === \"github-copilot\") {\n\t\tconst betaFeatures: string[] = [];\n\t\tif (needsInterleavedBeta) {\n\t\t\tbetaFeatures.push(\"interleaved-thinking-2025-05-14\");\n\t\t}\n\n\t\tconst client = new AnthropicClass({\n\t\t\tapiKey: null,\n\t\t\tauthToken: apiKey,\n\t\t\tbaseURL: model.baseUrl,\n\t\t\tdangerouslyAllowBrowser: true,\n\t\t\tdefaultHeaders: mergeHeaders(\n\t\t\t\t{\n\t\t\t\t\taccept: \"application/json\",\n\t\t\t\t\t\"anthropic-dangerous-direct-browser-access\": \"true\",\n\t\t\t\t\t...(betaFeatures.length > 0 ? { \"anthropic-beta\": betaFeatures.join(\",\") } : {}),\n\t\t\t\t},\n\t\t\t\tmodel.headers,\n\t\t\t\tdynamicHeaders,\n\t\t\t\toptionsHeaders,\n\t\t\t),\n\t\t});\n\n\t\treturn { client, isOAuthToken: false };\n\t}\n\n\t// Skip beta headers for providers that don't support them (e.g., Alibaba Coding Plan)\n\tconst skipBetaHeaders = model.provider === \"alibaba-coding-plan\";\n\tconst betaFeatures = skipBetaHeaders ? [] : [\"fine-grained-tool-streaming-2025-05-14\"];\n\tif (needsInterleavedBeta && !skipBetaHeaders) {\n\t\tbetaFeatures.push(\"interleaved-thinking-2025-05-14\");\n\t}\n\n\t// OAuth: Bearer auth, Claude Code identity headers\n\tif (isOAuthToken(apiKey)) {\n\t\tconst client = new AnthropicClass({\n\t\t\tapiKey: null,\n\t\t\tauthToken: apiKey,\n\t\t\tbaseURL: model.baseUrl,\n\t\t\tdangerouslyAllowBrowser: true,\n\t\t\tdefaultHeaders: mergeHeaders(\n\t\t\t\t{\n\t\t\t\t\taccept: \"application/json\",\n\t\t\t\t\t\"anthropic-dangerous-direct-browser-access\": \"true\",\n\t\t\t\t\t...(betaFeatures.length > 0 ? { \"anthropic-beta\": `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(\",\")}` } : {}),\n\t\t\t\t\t\"user-agent\": `claude-cli/${claudeCodeVersion}`,\n\t\t\t\t\t\"x-app\": \"cli\",\n\t\t\t\t},\n\t\t\t\tmodel.headers,\n\t\t\t\toptionsHeaders,\n\t\t\t),\n\t\t});\n\n\t\treturn { client, isOAuthToken: true };\n\t}\n\n\t// API key auth\n\t// Alibaba Coding Plan uses Bearer token auth instead of x-api-key\n\tconst isAlibabaProvider = model.provider === \"alibaba-coding-plan\";\n\tconst client = new AnthropicClass({\n\t\tapiKey: isAlibabaProvider ? null : apiKey,\n\t\tauthToken: isAlibabaProvider ? apiKey : undefined,\n\t\tbaseURL: model.baseUrl,\n\t\tdangerouslyAllowBrowser: true,\n\t\tdefaultHeaders: mergeHeaders(\n\t\t\t{\n\t\t\t\taccept: \"application/json\",\n\t\t\t\t\"anthropic-dangerous-direct-browser-access\": \"true\",\n\t\t\t\t...(betaFeatures.length > 0 ? { \"anthropic-beta\": betaFeatures.join(\",\") } : {}),\n\t\t\t},\n\t\t\tmodel.headers,\n\t\t\toptionsHeaders,\n\t\t),\n\t});\n\n\treturn { client, isOAuthToken: false };\n}\n\nexport const streamAnthropic: StreamFunction<\"anthropic-messages\", AnthropicOptions> = (\n\tmodel: Model<\"anthropic-messages\">,\n\tcontext: Context,\n\toptions?: AnthropicOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t(async () => {\n\t\tconst apiKey = options?.apiKey ?? getEnvApiKey(model.provider) ?? \"\";\n\n\t\tlet copilotDynamicHeaders: Record<string, string> | undefined;\n\t\tif (model.provider === \"github-copilot\") {\n\t\t\tconst hasImages = hasCopilotVisionInput(context.messages);\n\t\t\tcopilotDynamicHeaders = buildCopilotDynamicHeaders({\n\t\t\t\tmessages: context.messages,\n\t\t\t\thasImages,\n\t\t\t});\n\t\t}\n\n\t\tconst { client, isOAuthToken: isOAuth } = await createClient(\n\t\t\tmodel,\n\t\t\tapiKey,\n\t\t\toptions?.interleavedThinking ?? true,\n\t\t\toptions?.headers,\n\t\t\tcopilotDynamicHeaders,\n\t\t);\n\n\t\tprocessAnthropicStream(stream, {\n\t\t\tclient,\n\t\t\tmodel,\n\t\t\tcontext,\n\t\t\tisOAuthToken: isOAuth,\n\t\t\toptions,\n\t\t\tAnthropicSdkClass: _AnthropicClass,\n\t\t});\n\t})();\n\n\treturn stream;\n};\n\nexport const streamSimpleAnthropic: StreamFunction<\"anthropic-messages\", SimpleStreamOptions> = (\n\tmodel: Model<\"anthropic-messages\">,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst apiKey = options?.apiKey || getEnvApiKey(model.provider);\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\n\tconst base = buildBaseOptions(model, options, apiKey);\n\tif (!options?.reasoning) {\n\t\treturn streamAnthropic(model, context, { ...base, thinkingEnabled: false } satisfies AnthropicOptions);\n\t}\n\n\t// For Opus 4.6 and Sonnet 4.6: use adaptive thinking with effort level\n\t// For older models: use budget-based thinking\n\tif (supportsAdaptiveThinking(model.id)) {\n\t\tconst effort = mapThinkingLevelToEffort(options.reasoning, model.id);\n\t\treturn streamAnthropic(model, context, {\n\t\t\t...base,\n\t\t\tthinkingEnabled: true,\n\t\t\teffort,\n\t\t} satisfies AnthropicOptions);\n\t}\n\n\tconst adjusted = adjustMaxTokensForThinking(\n\t\tbase.maxTokens || 0,\n\t\tmodel.maxTokens,\n\t\toptions.reasoning,\n\t\toptions.thinkingBudgets,\n\t);\n\n\treturn streamAnthropic(model, context, {\n\t\t...base,\n\t\tmaxTokens: adjusted.maxTokens,\n\t\tthinkingEnabled: true,\n\t\tthinkingBudgetTokens: adjusted.thinkingBudget,\n\t} satisfies AnthropicOptions);\n};\n"]}
1
+ {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAOlD,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAGN,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAI/B,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAE/B,IAAI,eAA6C,CAAC;AAClD,KAAK,UAAU,iBAAiB;IAC/B,IAAI,CAAC,eAAe,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;QAC9C,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC;IAC/B,CAAC;IACD,OAAO,eAAe,CAAC;AACxB,CAAC;AAED,SAAS,YAAY,CAAC,GAAG,aAAqD;IAC7E,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;QACrC,IAAI,OAAO,EAAE,CAAC;YACb,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,CAAC;IACF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAED,KAAK,UAAU,YAAY,CAC1B,KAAkC,EAClC,MAAc,EACd,mBAA4B,EAC5B,cAAuC,EACvC,cAAuC;IAEvC,MAAM,cAAc,GAAG,MAAM,iBAAiB,EAAE,CAAC;IACjD,sFAAsF;IACtF,qFAAqF;IACrF,MAAM,oBAAoB,GAAG,mBAAmB,IAAI,CAAC,wBAAwB,C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K,CAAC,SAAS,EACf,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,eAAe,CACvB,CAAC;IAEF,OAAO,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE;QACtC,GAAG,IAAI;QACP,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,eAAe,EAAE,IAAI;QACrB,oBAAoB,EAAE,QAAQ,CAAC,cAAc;KAClB,CAAC,CAAC;AAC/B,CAAC,CAAC","sourcesContent":["// Lazy-loaded: Anthropic SDK (~500ms) is imported on first use, not at startup.\n// This avoids penalizing users who don't use Anthropic models.\nimport type Anthropic from \"@anthropic-ai/sdk\";\nimport { getEnvApiKey } from \"../env-api-keys.js\";\nimport type {\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamFunction,\n} from \"../types.js\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.js\";\n\nimport { buildCopilotDynamicHeaders, hasCopilotVisionInput } from \"./github-copilot-headers.js\";\nimport { adjustMaxTokensForThinking, buildBaseOptions } from \"./simple-options.js\";\nimport {\n\ttype AnthropicEffort,\n\ttype AnthropicOptions,\n\textractRetryAfterMs,\n\tmapThinkingLevelToEffort,\n\tprocessAnthropicStream,\n\tsupportsAdaptiveThinking,\n} from \"./anthropic-shared.js\";\n\n// Re-export types used by other modules\nexport type { AnthropicEffort, AnthropicOptions };\nexport { extractRetryAfterMs };\n\nlet _AnthropicClass: typeof Anthropic | undefined;\nasync function getAnthropicClass(): Promise<typeof Anthropic> {\n\tif (!_AnthropicClass) {\n\t\tconst mod = await import(\"@anthropic-ai/sdk\");\n\t\t_AnthropicClass = mod.default;\n\t}\n\treturn _AnthropicClass;\n}\n\nfunction mergeHeaders(...headerSources: (Record<string, string> | undefined)[]): Record<string, string> {\n\tconst merged: Record<string, string> = {};\n\tfor (const headers of headerSources) {\n\t\tif (headers) {\n\t\t\tObject.assign(merged, headers);\n\t\t}\n\t}\n\treturn merged;\n}\n\nasync function createClient(\n\tmodel: Model<\"anthropic-messages\">,\n\tapiKey: string,\n\tinterleavedThinking: boolean,\n\toptionsHeaders?: Record<string, string>,\n\tdynamicHeaders?: Record<string, string>,\n): Promise<{ client: Anthropic; isOAuthToken: boolean }> {\n\tconst AnthropicClass = await getAnthropicClass();\n\t// Adaptive thinking models (Opus 4.6, Sonnet 4.6) have interleaved thinking built-in.\n\t// The beta header is deprecated on Opus 4.6 and redundant on Sonnet 4.6, so skip it.\n\tconst needsInterleavedBeta = interleavedThinking && !supportsAdaptiveThinking(model.id);\n\n\t// Copilot: Bearer auth, selective betas (no fine-grained-tool-streaming)\n\tif (model.provider === \"github-copilot\") {\n\t\tconst betaFeatures: string[] = [];\n\t\tif (needsInterleavedBeta) {\n\t\t\tbetaFeatures.push(\"interleaved-thinking-2025-05-14\");\n\t\t}\n\n\t\tconst client = new AnthropicClass({\n\t\t\tapiKey: null,\n\t\t\tauthToken: apiKey,\n\t\t\tbaseURL: model.baseUrl,\n\t\t\tdangerouslyAllowBrowser: true,\n\t\t\tdefaultHeaders: mergeHeaders(\n\t\t\t\t{\n\t\t\t\t\taccept: \"application/json\",\n\t\t\t\t\t\"anthropic-dangerous-direct-browser-access\": \"true\",\n\t\t\t\t\t...(betaFeatures.length > 0 ? { \"anthropic-beta\": betaFeatures.join(\",\") } : {}),\n\t\t\t\t},\n\t\t\t\tmodel.headers,\n\t\t\t\tdynamicHeaders,\n\t\t\t\toptionsHeaders,\n\t\t\t),\n\t\t});\n\n\t\treturn { client, isOAuthToken: false };\n\t}\n\n\t// Skip beta headers for providers that don't support them (e.g., Alibaba Coding Plan)\n\tconst skipBetaHeaders = model.provider === \"alibaba-coding-plan\";\n\tconst betaFeatures = skipBetaHeaders ? [] : [\"fine-grained-tool-streaming-2025-05-14\"];\n\tif (needsInterleavedBeta && !skipBetaHeaders) {\n\t\tbetaFeatures.push(\"interleaved-thinking-2025-05-14\");\n\t}\n\n\t// API key auth (Anthropic OAuth removed per TOS compliance — use API keys or Claude CLI)\n\t// Alibaba Coding Plan uses Bearer token auth instead of x-api-key\n\tconst isAlibabaProvider = model.provider === \"alibaba-coding-plan\";\n\tconst client = new AnthropicClass({\n\t\tapiKey: isAlibabaProvider ? null : apiKey,\n\t\tauthToken: isAlibabaProvider ? apiKey : undefined,\n\t\tbaseURL: model.baseUrl,\n\t\tdangerouslyAllowBrowser: true,\n\t\tdefaultHeaders: mergeHeaders(\n\t\t\t{\n\t\t\t\taccept: \"application/json\",\n\t\t\t\t\"anthropic-dangerous-direct-browser-access\": \"true\",\n\t\t\t\t...(betaFeatures.length > 0 ? { \"anthropic-beta\": betaFeatures.join(\",\") } : {}),\n\t\t\t},\n\t\t\tmodel.headers,\n\t\t\toptionsHeaders,\n\t\t),\n\t});\n\n\treturn { client, isOAuthToken: false };\n}\n\nexport const streamAnthropic: StreamFunction<\"anthropic-messages\", AnthropicOptions> = (\n\tmodel: Model<\"anthropic-messages\">,\n\tcontext: Context,\n\toptions?: AnthropicOptions,\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t(async () => {\n\t\tconst apiKey = options?.apiKey ?? getEnvApiKey(model.provider) ?? \"\";\n\n\t\tlet copilotDynamicHeaders: Record<string, string> | undefined;\n\t\tif (model.provider === \"github-copilot\") {\n\t\t\tconst hasImages = hasCopilotVisionInput(context.messages);\n\t\t\tcopilotDynamicHeaders = buildCopilotDynamicHeaders({\n\t\t\t\tmessages: context.messages,\n\t\t\t\thasImages,\n\t\t\t});\n\t\t}\n\n\t\tconst { client, isOAuthToken: isOAuth } = await createClient(\n\t\t\tmodel,\n\t\t\tapiKey,\n\t\t\toptions?.interleavedThinking ?? true,\n\t\t\toptions?.headers,\n\t\t\tcopilotDynamicHeaders,\n\t\t);\n\n\t\tprocessAnthropicStream(stream, {\n\t\t\tclient,\n\t\t\tmodel,\n\t\t\tcontext,\n\t\t\tisOAuthToken: isOAuth,\n\t\t\toptions,\n\t\t\tAnthropicSdkClass: _AnthropicClass,\n\t\t});\n\t})();\n\n\treturn stream;\n};\n\nexport const streamSimpleAnthropic: StreamFunction<\"anthropic-messages\", SimpleStreamOptions> = (\n\tmodel: Model<\"anthropic-messages\">,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst apiKey = options?.apiKey || getEnvApiKey(model.provider);\n\tif (!apiKey) {\n\t\tthrow new Error(`No API key for provider: ${model.provider}`);\n\t}\n\n\tconst base = buildBaseOptions(model, options, apiKey);\n\tif (!options?.reasoning) {\n\t\treturn streamAnthropic(model, context, { ...base, thinkingEnabled: false } satisfies AnthropicOptions);\n\t}\n\n\t// For Opus 4.6 and Sonnet 4.6: use adaptive thinking with effort level\n\t// For older models: use budget-based thinking\n\tif (supportsAdaptiveThinking(model.id)) {\n\t\tconst effort = mapThinkingLevelToEffort(options.reasoning, model.id);\n\t\treturn streamAnthropic(model, context, {\n\t\t\t...base,\n\t\t\tthinkingEnabled: true,\n\t\t\teffort,\n\t\t} satisfies AnthropicOptions);\n\t}\n\n\tconst adjusted = adjustMaxTokensForThinking(\n\t\tbase.maxTokens || 0,\n\t\tmodel.maxTokens,\n\t\toptions.reasoning,\n\t\toptions.thinkingBudgets,\n\t);\n\n\treturn streamAnthropic(model, context, {\n\t\t...base,\n\t\tmaxTokens: adjusted.maxTokens,\n\t\tthinkingEnabled: true,\n\t\tthinkingBudgetTokens: adjusted.thinkingBudget,\n\t} satisfies AnthropicOptions);\n};\n"]}
@@ -3,12 +3,13 @@
3
3
  *
4
4
  * This module handles login, token refresh, and credential storage
5
5
  * for OAuth-based providers:
6
- * - Anthropic (Claude Pro/Max)
7
6
  * - GitHub Copilot
8
7
  * - Google Cloud Code Assist (Gemini CLI)
9
8
  * - Antigravity (Gemini 3, Claude, GPT-OSS via Google Cloud)
9
+ *
10
+ * Note: Anthropic OAuth was removed per TOS compliance (see docs/user-docs/claude-code-auth-compliance.md).
11
+ * Use API keys or the local Claude Code CLI for Anthropic access.
10
12
  */
11
- export { anthropicOAuthProvider, loginAnthropic, refreshAnthropicToken } from "./anthropic.js";
12
13
  export { getGitHubCopilotBaseUrl, githubCopilotOAuthProvider, loginGitHubCopilot, normalizeDomain, refreshGitHubCopilotToken, } from "./github-copilot.js";
13
14
  export { antigravityOAuthProvider, loginAntigravity, refreshAntigravityToken } from "./google-antigravity.js";
14
15
  export { geminiCliOAuthProvider, loginGeminiCli, refreshGoogleCloudToken } from "./google-gemini-cli.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/oauth/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAE/F,OAAO,EACN,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,eAAe,EACf,yBAAyB,GACzB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAE9G,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEzG,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAExG,cAAc,YAAY,CAAC;AAW3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAc5F;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,eAAe,GAAG,sBAAsB,GAAG,SAAS,CAExF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,sBAAsB,GAAG,IAAI,CAE5E;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAOxD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAK1C;AAED;;GAEG;AACH,wBAAgB,iBAAi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,CACnC,UAAU,EAAE,eAAe,EAC3B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAC3C,OAAO,CAAC;IAAE,cAAc,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAsBtE"}
@@ -3,13 +3,13 @@
3
3
  *
4
4
  * This module handles login, token refresh, and credential storage
5
5
  * for OAuth-based providers:
6
- * - Anthropic (Claude Pro/Max)
7
6
  * - GitHub Copilot
8
7
  * - Google Cloud Code Assist (Gemini CLI)
9
8
  * - Antigravity (Gemini 3, Claude, GPT-OSS via Google Cloud)
9
+ *
10
+ * Note: Anthropic OAuth was removed per TOS compliance (see docs/user-docs/claude-code-auth-compliance.md).
11
+ * Use API keys or the local Claude Code CLI for Anthropic access.
10
12
  */
11
- // Anthropic
12
- export { anthropicOAuthProvider, loginAnthropic, refreshAnthropicToken } from "./anthropic.js";
13
13
  // GitHub Copilot
14
14
  export { getGitHubCopilotBaseUrl, githubCopilotOAuthProvider, loginGitHubCopilot, normalizeDomain, refreshGitHubCopilotToken, } from "./github-copilot.js";
15
15
  // Google Antigravity
@@ -22,13 +22,11 @@ export * from "./types.js";
22
22
  // ============================================================================
23
23
  // Provider Registry
24
24
  // ============================================================================
25
- import { anthropicOAuthProvider } from "./anthropic.js";
26
25
  import { githubCopilotOAuthProvider } from "./github-copilot.js";
27
26
  import { antigravityOAuthProvider } from "./google-antigravity.js";
28
27
  import { geminiCliOAuthProvider } from "./google-gemini-cli.js";
29
28
  import { openaiCodexOAuthProvider } from "./openai-codex.js";
30
29
  const BUILT_IN_OAUTH_PROVIDERS = [
31
- anthropicOAuthProvider,
32
30
  githubCopilotOAuthProvider,
33
31
  geminiCliOAuthProvider,
34
32
  antigravityOAuthProvider,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/oauth/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,YAA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C;QACZ,OAAO,IAAI,CAAC;IACb,CAAC;IAED,qBAAqB;IACrB,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC;YACJ,KAAK,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC5C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,qCAAqC,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QACtF,CAAC;IACF,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["/**\n * OAuth credential management for AI providers.\n *\n * This module handles login, token refresh, and credential storage\n * for OAuth-based providers:\n * - Anthropic (Claude Pro/Max)\n * - GitHub Copilot\n * - Google Cloud Code Assist (Gemini CLI)\n * - Antigravity (Gemini 3, Claude, GPT-OSS via Google Cloud)\n */\n\n// Anthropic\nexport { anthropicOAuthProvider, loginAnthropic, refreshAnthropicToken } from \"./anthropic.js\";\n// GitHub Copilot\nexport {\n\tgetGitHubCopilotBaseUrl,\n\tgithubCopilotOAuthProvider,\n\tloginGitHubCopilot,\n\tnormalizeDomain,\n\trefreshGitHubCopilotToken,\n} from \"./github-copilot.js\";\n// Google Antigravity\nexport { antigravityOAuthProvider, loginAntigravity, refreshAntigravityToken } from \"./google-antigravity.js\";\n// Google Gemini CLI\nexport { geminiCliOAuthProvider, loginGeminiCli, refreshGoogleCloudToken } from \"./google-gemini-cli.js\";\n// OpenAI Codex (ChatGPT OAuth)\nexport { loginOpenAICodex, openaiCodexOAuthProvider, refreshOpenAICodexToken } from \"./openai-codex.js\";\n\nexport * from \"./types.js\";\n\n// ============================================================================\n// Provider Registry\n// ============================================================================\n\nimport { anthropicOAuthProvider } from \"./anthropic.js\";\nimport { githubCopilotOAuthProvider } from \"./github-copilot.js\";\nimport { antigravityOAuthProvider } from \"./google-antigravity.js\";\nimport { geminiCliOAuthProvider } from \"./google-gemini-cli.js\";\nimport { openaiCodexOAuthProvider } from \"./openai-codex.js\";\nimport type { OAuthCredentials, OAuthProviderId, OAuthProviderInterface } from \"./types.js\";\n\nconst BUILT_IN_OAUTH_PROVIDERS: OAuthProviderInterface[] = [\n\tanthropicOAuthProvider,\n\tgithubCopilotOAuthProvider,\n\tgeminiCliOAuthProvider,\n\tantigravityOAuthProvider,\n\topenaiCodexOAuthProvider,\n];\n\nconst oauthProviderRegistry = new Map<string, OAuthProviderInterface>(\n\tBUILT_IN_OAUTH_PROVIDERS.map((provider) => [provider.id, provider]),\n);\n\n/**\n * Get an OAuth provider by ID\n */\nexport function getOAuthProvider(id: OAuthProviderId): OAuthProviderInterface | undefined {\n\treturn oauthProviderRegistry.get(id);\n}\n\n/**\n * Register a custom OAuth provider\n */\nexport function registerOAuthProvider(provider: OAuthProviderInterface): void {\n\toauthProviderRegistry.set(provider.id, provider);\n}\n\n/**\n * Unregister an OAuth provider.\n *\n * If the provider is built-in, restores the built-in implementation.\n * Custom providers are removed completely.\n */\nexport function unregisterOAuthProvider(id: string): void {\n\tconst builtInProvider = BUILT_IN_OAUTH_PROVIDERS.find((provider) => provider.id === id);\n\tif (builtInProvider) {\n\t\toauthProviderRegistry.set(id, builtInProvider);\n\t\treturn;\n\t}\n\toauthProviderRegistry.delete(id);\n}\n\n/**\n * Reset OAuth providers to built-ins.\n */\nexport function resetOAuthProviders(): void {\n\toauthProviderRegistry.clear();\n\tfor (const provider of BUILT_IN_OAUTH_PROVIDERS) {\n\t\toauthProviderRegistry.set(provider.id, provider);\n\t}\n}\n\n/**\n * Get all registered OAuth providers\n */\nexport function getOAuthProviders(): OAuthProviderInterface[] {\n\treturn Array.from(oauthProviderRegistry.values());\n}\n\n// ============================================================================\n// High-level API (uses provider registry)\n// ============================================================================\n\n/**\n * Get API key for a provider from OAuth credentials.\n * Automatically refreshes expired tokens.\n *\n * @returns API key string and updated credentials, or null if no credentials\n * @throws Error if refresh fails\n */\nexport async function getOAuthApiKey(\n\tproviderId: OAuthProviderId,\n\tcredentials: Record<string, OAuthCredentials>,\n): Promise<{ newCredentials: OAuthCredentials; apiKey: string } | null> {\n\tconst provider = getOAuthProvider(providerId);\n\tif (!provider) {\n\t\tthrow new Error(`Unknown OAuth provider: ${providerId}`);\n\t}\n\n\tlet creds = credentials[providerId];\n\tif (!creds) {\n\t\treturn null;\n\t}\n\n\t// Refresh if expired\n\tif (Date.now() >= creds.expires) {\n\t\ttry {\n\t\t\tcreds = await provider.refreshToken(creds);\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to refresh OAuth token for ${providerId}`, { cause: error });\n\t\t}\n\t}\n\n\tconst apiKey = provider.getApiKey(creds);\n\treturn { newCredentials: creds, apiKey };\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/oauth/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,iBAAiB;AACjB,OAAO,EACN,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,eAAe,EACf,yBAAyB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,qBAAqB;AACrB,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAC9G,oBAAoB;AACpB,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACzG,+BAA+B;AAC/B,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAExG,cAAc,YAAY,CAAC;AAE3B,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAA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AClD,CAAC;AACF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAChC,OAAO,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAC;AACnD,CAAC;AAED,+EAA+E;AAC/E,0CAA0C;AAC1C,+EAA+E;AAE/E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,UAA2B,EAC3B,WAA6C;IAE7C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,2BAA2B,UAAU,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,KAAK,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACb,CAAC;IAED,qBAAqB;IACrB,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC;YACJ,KAAK,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC5C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,qCAAqC,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QACtF,CAAC;IACF,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["/**\n * OAuth credential management for AI providers.\n *\n * This module handles login, token refresh, and credential storage\n * for OAuth-based providers:\n * - GitHub Copilot\n * - Google Cloud Code Assist (Gemini CLI)\n * - Antigravity (Gemini 3, Claude, GPT-OSS via Google Cloud)\n *\n * Note: Anthropic OAuth was removed per TOS compliance (see docs/user-docs/claude-code-auth-compliance.md).\n * Use API keys or the local Claude Code CLI for Anthropic access.\n */\n\n// GitHub Copilot\nexport {\n\tgetGitHubCopilotBaseUrl,\n\tgithubCopilotOAuthProvider,\n\tloginGitHubCopilot,\n\tnormalizeDomain,\n\trefreshGitHubCopilotToken,\n} from \"./github-copilot.js\";\n// Google Antigravity\nexport { antigravityOAuthProvider, loginAntigravity, refreshAntigravityToken } from \"./google-antigravity.js\";\n// Google Gemini CLI\nexport { geminiCliOAuthProvider, loginGeminiCli, refreshGoogleCloudToken } from \"./google-gemini-cli.js\";\n// OpenAI Codex (ChatGPT OAuth)\nexport { loginOpenAICodex, openaiCodexOAuthProvider, refreshOpenAICodexToken } from \"./openai-codex.js\";\n\nexport * from \"./types.js\";\n\n// ============================================================================\n// Provider Registry\n// ============================================================================\n\nimport { githubCopilotOAuthProvider } from \"./github-copilot.js\";\nimport { antigravityOAuthProvider } from \"./google-antigravity.js\";\nimport { geminiCliOAuthProvider } from \"./google-gemini-cli.js\";\nimport { openaiCodexOAuthProvider } from \"./openai-codex.js\";\nimport type { OAuthCredentials, OAuthProviderId, OAuthProviderInterface } from \"./types.js\";\n\nconst BUILT_IN_OAUTH_PROVIDERS: OAuthProviderInterface[] = [\n\tgithubCopilotOAuthProvider,\n\tgeminiCliOAuthProvider,\n\tantigravityOAuthProvider,\n\topenaiCodexOAuthProvider,\n];\n\nconst oauthProviderRegistry = new Map<string, OAuthProviderInterface>(\n\tBUILT_IN_OAUTH_PROVIDERS.map((provider) => [provider.id, provider]),\n);\n\n/**\n * Get an OAuth provider by ID\n */\nexport function getOAuthProvider(id: OAuthProviderId): OAuthProviderInterface | undefined {\n\treturn oauthProviderRegistry.get(id);\n}\n\n/**\n * Register a custom OAuth provider\n */\nexport function registerOAuthProvider(provider: OAuthProviderInterface): void {\n\toauthProviderRegistry.set(provider.id, provider);\n}\n\n/**\n * Unregister an OAuth provider.\n *\n * If the provider is built-in, restores the built-in implementation.\n * Custom providers are removed completely.\n */\nexport function unregisterOAuthProvider(id: string): void {\n\tconst builtInProvider = BUILT_IN_OAUTH_PROVIDERS.find((provider) => provider.id === id);\n\tif (builtInProvider) {\n\t\toauthProviderRegistry.set(id, builtInProvider);\n\t\treturn;\n\t}\n\toauthProviderRegistry.delete(id);\n}\n\n/**\n * Reset OAuth providers to built-ins.\n */\nexport function resetOAuthProviders(): void {\n\toauthProviderRegistry.clear();\n\tfor (const provider of BUILT_IN_OAUTH_PROVIDERS) {\n\t\toauthProviderRegistry.set(provider.id, provider);\n\t}\n}\n\n/**\n * Get all registered OAuth providers\n */\nexport function getOAuthProviders(): OAuthProviderInterface[] {\n\treturn Array.from(oauthProviderRegistry.values());\n}\n\n// ============================================================================\n// High-level API (uses provider registry)\n// ============================================================================\n\n/**\n * Get API key for a provider from OAuth credentials.\n * Automatically refreshes expired tokens.\n *\n * @returns API key string and updated credentials, or null if no credentials\n * @throws Error if refresh fails\n */\nexport async function getOAuthApiKey(\n\tproviderId: OAuthProviderId,\n\tcredentials: Record<string, OAuthCredentials>,\n): Promise<{ newCredentials: OAuthCredentials; apiKey: string } | null> {\n\tconst provider = getOAuthProvider(providerId);\n\tif (!provider) {\n\t\tthrow new Error(`Unknown OAuth provider: ${providerId}`);\n\t}\n\n\tlet creds = credentials[providerId];\n\tif (!creds) {\n\t\treturn null;\n\t}\n\n\t// Refresh if expired\n\tif (Date.now() >= creds.expires) {\n\t\ttry {\n\t\t\tcreds = await provider.refreshToken(creds);\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to refresh OAuth token for ${providerId}`, { cause: error });\n\t\t}\n\t}\n\n\tconst apiKey = provider.getApiKey(creds);\n\treturn { newCredentials: creds, apiKey };\n}\n"]}