@elysiumoss/grepo 0.2.0 → 0.4.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.
- package/README.md +79 -40
- package/lib/cli.js +30 -2
- package/lib/cli.js.map +1 -1
- package/lib/commands/analyze.js +1 -1
- package/lib/commands/analyze.js.map +1 -1
- package/lib/commands/describe.js +2 -2
- package/lib/commands/describe.js.map +1 -1
- package/lib/commands/readme.js +3 -3
- package/lib/commands/readme.js.map +1 -1
- package/lib/commands/topics.js +2 -2
- package/lib/commands/topics.js.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +7 -5
- package/lib/config.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/mermaid.d.ts.map +1 -1
- package/lib/mermaid.js +38 -6
- package/lib/mermaid.js.map +1 -1
- package/lib/prompts/readme.d.ts.map +1 -1
- package/lib/prompts/readme.js +5 -1
- package/lib/prompts/readme.js.map +1 -1
- package/lib/services.d.ts +2 -1
- package/lib/services.d.ts.map +1 -1
- package/lib/services.js +9 -2
- package/lib/services.js.map +1 -1
- package/lib/utils/config-file.d.ts +16 -0
- package/lib/utils/config-file.d.ts.map +1 -0
- package/lib/utils/config-file.js +80 -0
- package/lib/utils/config-file.js.map +1 -0
- package/lib/utils/gemini.d.ts.map +1 -1
- package/lib/utils/gemini.js +7 -3
- package/lib/utils/gemini.js.map +1 -1
- package/lib/utils/github.d.ts +1 -0
- package/lib/utils/github.d.ts.map +1 -1
- package/lib/utils/github.js +7 -0
- package/lib/utils/github.js.map +1 -1
- package/lib/utils/gitingest.d.ts +1 -1
- package/lib/utils/gitingest.d.ts.map +1 -1
- package/lib/utils/gitingest.js +2 -2
- package/lib/utils/gitingest.js.map +1 -1
- package/package.json +1 -1
package/lib/mermaid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mermaid.js","names":["Logger"],"sources":["../src/mermaid.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport { execFile } from \"node:child_process\";\nimport { mkdtemp, rm, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { Effect, Schema } from \"effect\";\n\nimport type { GeminiServiceApi } from \"./services.js\";\nimport { Logger } from \"./utils/logger.js\";\n\nconst execFileAsync = promisify(execFile);\nconst logger = new Logger(\"GREPO:MERMAID\");\n\nexport const MermaidBlock = Schema.Struct({\n\tcode: Schema.String,\n\tend: Schema.Number,\n\tindex: Schema.Number,\n\tstart: Schema.Number,\n});\nexport type MermaidBlock = Schema.Schema.Type<typeof MermaidBlock>;\n\nexport function extractMermaidBlocks(markdown: string): MermaidBlock[] {\n\tconst blocks: MermaidBlock[] = [];\n\tconst regex = /```mermaid\\n([\\s\\S]*?)```/g;\n\tlet index = 0;\n\n\tfor (\n\t\tlet match = regex.exec(markdown);\n\t\tmatch !== null;\n\t\tmatch = regex.exec(markdown)\n\t) {\n\t\tblocks.push({\n\t\t\tcode: match[1].trim(),\n\t\t\tend: match.index + match[0].length,\n\t\t\tindex: index++,\n\t\t\tstart: match.index,\n\t\t});\n\t}\n\n\treturn blocks;\n}\n\nasync function validateBlock(\n\tblock: MermaidBlock,\n): Promise<{ error?: string; valid: boolean }> {\n\
|
|
1
|
+
{"version":3,"file":"mermaid.js","names":["Logger"],"sources":["../src/mermaid.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport { execFile } from \"node:child_process\";\nimport { mkdtemp, rm, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { Effect, Schema } from \"effect\";\n\nimport type { GeminiServiceApi } from \"./services.js\";\nimport { Logger } from \"./utils/logger.js\";\n\nconst execFileAsync = promisify(execFile);\nconst logger = new Logger(\"GREPO:MERMAID\");\n\nexport const MermaidBlock = Schema.Struct({\n\tcode: Schema.String,\n\tend: Schema.Number,\n\tindex: Schema.Number,\n\tstart: Schema.Number,\n});\nexport type MermaidBlock = Schema.Schema.Type<typeof MermaidBlock>;\n\nexport function extractMermaidBlocks(markdown: string): MermaidBlock[] {\n\tconst blocks: MermaidBlock[] = [];\n\tconst regex = /```mermaid\\n([\\s\\S]*?)```/g;\n\tlet index = 0;\n\n\tfor (\n\t\tlet match = regex.exec(markdown);\n\t\tmatch !== null;\n\t\tmatch = regex.exec(markdown)\n\t) {\n\t\tblocks.push({\n\t\t\tcode: match[1].trim(),\n\t\t\tend: match.index + match[0].length,\n\t\t\tindex: index++,\n\t\t\tstart: match.index,\n\t\t});\n\t}\n\n\treturn blocks;\n}\n\nasync function validateBlock(\n\tblock: MermaidBlock,\n): Promise<{ error?: string; valid: boolean }> {\n\tlet dir: string;\n\ttry {\n\t\tdir = await mkdtemp(join(tmpdir(), \"mermaid-\"));\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tlogger.warn(`Failed to create temp directory: ${message}`);\n\t\treturn {\n\t\t\terror: `Temp directory creation failed: ${message}`,\n\t\t\tvalid: false,\n\t\t};\n\t}\n\n\tconst inputFile = join(dir, \"input.mmd\");\n\tconst outputFile = join(dir, \"output.svg\");\n\n\ttry {\n\t\tawait writeFile(inputFile, block.code);\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tlogger.warn(`Failed to write mermaid input file: ${message}`);\n\t\tawait rm(dir, { force: true, recursive: true }).catch(() => {});\n\t\treturn { error: `File write failed: ${message}`, valid: false };\n\t}\n\n\ttry {\n\t\tawait execFileAsync(\n\t\t\t\"npx\",\n\t\t\t[\"mmdc\", \"-i\", inputFile, \"-o\", outputFile, \"-e\", \"svg\"],\n\t\t\t{ timeout: 15_000 },\n\t\t);\n\n\t\treturn { valid: true };\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tconst stderr =\n\t\t\terr &&\n\t\t\ttypeof err === \"object\" &&\n\t\t\t\"stderr\" in err &&\n\t\t\ttypeof err.stderr === \"string\"\n\t\t\t\t? err.stderr\n\t\t\t\t: \"\";\n\t\treturn { error: stderr.trim() || message, valid: false };\n\t} finally {\n\t\tawait rm(dir, { force: true, recursive: true }).catch(() => {});\n\t}\n}\n\nfunction buildFixPrompt(code: string, error: string): string {\n\treturn `The following Mermaid diagram has a syntax error. Fix it and return ONLY the corrected Mermaid code — no fences, no explanation.\n\n<broken_diagram>\n${code}\n</broken_diagram>\n\n<error>\n${error}\n</error>\n\nCommon fixes:\n- Wrap labels with special chars in quotes: A[\"Label (info)\"]\n- Use --> not -> in flowcharts\n- Use ->> not --> in sequence diagrams\n- Use \"flowchart\" not \"graph\"\n- Subgraph IDs cannot have spaces\n- No semicolons at end of lines\n\nReturn ONLY the fixed Mermaid code.`;\n}\n\nexport const validateAndFixMermaid = (\n\tcontent: string,\n\tgemini: GeminiServiceApi,\n\tmaxRetries = 2,\n): Effect.Effect<string, never> =>\n\tEffect.gen(function* () {\n\t\tconst blocks = extractMermaidBlocks(content);\n\t\tif (blocks.length === 0) {\n\t\t\treturn content;\n\t\t}\n\n\t\tlogger.info(`Validating ${blocks.length} Mermaid diagram(s)...`);\n\t\tlet result = content;\n\t\tlet offset = 0;\n\n\t\tfor (const block of blocks) {\n\t\t\tlet currentCode = block.code;\n\t\t\tlet attempt = 0;\n\t\t\tlet validation = yield* Effect.promise(() =>\n\t\t\t\tvalidateBlock({ ...block, code: currentCode }),\n\t\t\t);\n\n\t\t\twhile (!validation.valid && attempt < maxRetries) {\n\t\t\t\tattempt++;\n\t\t\t\tlogger.warn(\n\t\t\t\t\t`Diagram ${block.index + 1} invalid (attempt ${attempt}/${maxRetries}): ${validation.error}`,\n\t\t\t\t);\n\n\t\t\t\tconst fixPrompt = buildFixPrompt(\n\t\t\t\t\tcurrentCode,\n\t\t\t\t\tvalidation.error ?? \"Unknown error\",\n\t\t\t\t);\n\t\t\t\tconst fixed: string = yield* Effect.catchAll(\n\t\t\t\t\tgemini.generateContent(fixPrompt),\n\t\t\t\t\t(err) => {\n\t\t\t\t\t\tlogger.warn(\n\t\t\t\t\t\t\t`Diagram ${block.index + 1}: Gemini fix failed (${err.message}), keeping current code`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn Effect.succeed(currentCode);\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tcurrentCode = fixed\n\t\t\t\t\t.replace(/^```(?:mermaid)?\\s*/i, \"\")\n\t\t\t\t\t.replace(/\\s*```\\s*$/, \"\")\n\t\t\t\t\t.trim();\n\n\t\t\t\tvalidation = yield* Effect.promise(() =>\n\t\t\t\t\tvalidateBlock({ ...block, code: currentCode }),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst start = block.start + offset;\n\t\t\tconst end = block.end + offset;\n\n\t\t\tif (validation.valid && currentCode !== block.code) {\n\t\t\t\tlogger.success(\n\t\t\t\t\t`Diagram ${block.index + 1} fixed after ${attempt} attempt(s)`,\n\t\t\t\t);\n\t\t\t\tconst replacement = `\\`\\`\\`mermaid\\n${currentCode}\\n\\`\\`\\``;\n\t\t\t\tresult = result.slice(0, start) + replacement + result.slice(end);\n\t\t\t\toffset += replacement.length - (block.end - block.start);\n\t\t\t} else if (validation.valid) {\n\t\t\t\tlogger.success(`Diagram ${block.index + 1} valid`);\n\t\t\t} else {\n\t\t\t\tlogger.warn(\n\t\t\t\t\t`Diagram ${block.index + 1} could not be fixed after ${attempt} attempt(s), removing it: ${validation.error}`,\n\t\t\t\t);\n\t\t\t\tresult = result.slice(0, start) + result.slice(end);\n\t\t\t\toffset -= block.end - block.start;\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,gBAAgB,UAAU,SAAS;AACzC,MAAM,SAAS,IAAIA,SAAO,gBAAgB;AAE1C,MAAa,eAAe,OAAO,OAAO;CACzC,MAAM,OAAO;CACb,KAAK,OAAO;CACZ,OAAO,OAAO;CACd,OAAO,OAAO;CACd,CAAC;AAGF,SAAgB,qBAAqB,UAAkC;CACtE,MAAM,SAAyB,EAAE;CACjC,MAAM,QAAQ;CACd,IAAI,QAAQ;AAEZ,MACC,IAAI,QAAQ,MAAM,KAAK,SAAS,EAChC,UAAU,MACV,QAAQ,MAAM,KAAK,SAAS,CAE5B,QAAO,KAAK;EACX,MAAM,MAAM,GAAG,MAAM;EACrB,KAAK,MAAM,QAAQ,MAAM,GAAG;EAC5B,OAAO;EACP,OAAO,MAAM;EACb,CAAC;AAGH,QAAO;;AAGR,eAAe,cACd,OAC8C;CAC9C,IAAI;AACJ,KAAI;AACH,QAAM,MAAM,QAAQ,KAAK,QAAQ,EAAE,WAAW,CAAC;UACvC,KAAK;EACb,MAAM,UAAU,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;AAChE,SAAO,KAAK,oCAAoC,UAAU;AAC1D,SAAO;GACN,OAAO,mCAAmC;GAC1C,OAAO;GACP;;CAGF,MAAM,YAAY,KAAK,KAAK,YAAY;CACxC,MAAM,aAAa,KAAK,KAAK,aAAa;AAE1C,KAAI;AACH,QA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,cAMC,QANgB,EAMR,MAAA,CAAA,MANqC,CAAA;EAM7C,OAAA,EAAA,oBAKX;;;;;AALmB,KAMT,QAAA,GAAW,MAAA,CAAO,MAAA,CAAO,IANhB,CAAA,OAM4B,QAN5B,CAAA;AAAA,cAYR,gBAZQ,EAYU,cAZV;AAMT,iBA0CI,qBAAA,CA1Cc,OAAO,EAAA,MAAI,CAAA,EAAA,MAAA,GAAA,IAAA;AAM5B,iBA+CG,aAAA,CA/Ce,GAAA,EAAA,MAAA,CA8B9B,EAiB2C,cAjB3C;AAMe,iBA4CA,mBAAA,CA5CqB,QAAA,EA6C1B,QA7C0B,EAAA,cAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA;AAWrB,cA+HH,cA/H+B,EA+Hf,MA/He,CA+HR,kBA/HsB,EAAA,MAAA,CAAA;AAiC1C,iBAuGA,+BAAA,CAtGG,QAAA,EAuGR,cAvGQ,CAAA,EAAA,MAAA;AA6FN,iBA6CG,qBAAA,CA7CoB,QAAP,EA8ClB,cA9CwB,EAAA,QAAA,EA+CxB,QA/CwB,EAAA,OAAA,EAgDzB,iBAhDyB,CAAA,EAAA,MAAA"}
|
package/lib/prompts/readme.js
CHANGED
|
@@ -110,7 +110,11 @@ function parseAnalysis(raw) {
|
|
|
110
110
|
if (!result.sections.recommended.length) throw new Error("sections.recommended must not be empty");
|
|
111
111
|
return result;
|
|
112
112
|
} catch (err) {
|
|
113
|
-
new Logger$1("GREPO:README-PROMPT").warn(`Failed to parse analysis JSON, falling back to DEFAULT_ANALYSIS
|
|
113
|
+
new Logger$1("GREPO:README-PROMPT").warn(`Failed to parse analysis JSON, falling back to DEFAULT_ANALYSIS`, {
|
|
114
|
+
error: err instanceof Error ? err.message : String(err),
|
|
115
|
+
rawLength: raw.length,
|
|
116
|
+
rawPreview: raw.slice(0, 200)
|
|
117
|
+
});
|
|
114
118
|
return DEFAULT_ANALYSIS;
|
|
115
119
|
}
|
|
116
120
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readme.js","names":["Logger"],"sources":["../../src/prompts/readme.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport { Schema } from \"effect\";\n\nimport type { DocumentationStyle } from \"../config.js\";\nimport { Logger } from \"../utils/logger.js\";\n\n// ============================================================================\n// Types & Schemas\n// ============================================================================\n\nexport const DiagramSchema = Schema.Struct({\n\tkeyNodes: Schema.Array(Schema.String),\n\tpurpose: Schema.String,\n\tscope: Schema.String,\n\ttype: Schema.Literal(\"c4-context\", \"er\", \"flowchart\", \"sequence\", \"state\"),\n});\n\nexport const ExistingReadmeSchema = Schema.Struct({\n\timprove: Schema.Array(Schema.String),\n\tmissing: Schema.Array(Schema.String),\n\tpreserve: Schema.Array(Schema.String),\n\tquality: Schema.Literal(\"decent\", \"good\", \"none\", \"poor\"),\n});\n\nexport const IdentitySchema = Schema.Struct({\n\tdifferentiators: Schema.Array(Schema.String),\n\tname: Schema.String,\n\toneLiner: Schema.String,\n});\n\nexport const SectionsSchema = Schema.Struct({\n\trecommended: Schema.Array(Schema.String),\n\tskip: Schema.Array(\n\t\tSchema.Struct({\n\t\t\treason: Schema.String,\n\t\t\tsection: Schema.String,\n\t\t}),\n\t),\n});\n\nexport const ToneSchema = Schema.Literal(\n\t\"casual\",\n\t\"minimal\",\n\t\"professional\",\n\t\"technical\",\n);\nexport type Tone = Schema.Schema.Type<typeof ToneSchema>;\n\nexport const ToneDetectionSchema = Schema.Struct({\n\tdetected: ToneSchema,\n\tevidence: Schema.String,\n});\n\nexport const AnalysisResult = Schema.Struct({\n\tdiagrams: Schema.Array(DiagramSchema),\n\texistingReadme: ExistingReadmeSchema,\n\tidentity: IdentitySchema,\n\trepoType: Schema.String,\n\tsections: SectionsSchema,\n\ttone: ToneDetectionSchema,\n});\nexport type AnalysisResult = Schema.Schema.Type<typeof AnalysisResult>;\n\nexport const GenerationOptions = Schema.Struct({\n\tformat: Schema.Literal(\"md\", \"mdx\"),\n\tstyle: Schema.Literal(\"minimal\", \"standard\", \"comprehensive\"),\n\ttone: Schema.optional(ToneSchema),\n});\nexport type GenerationOptions = Schema.Schema.Type<typeof GenerationOptions>;\n\n// ============================================================================\n// Repo Data Schema\n// ============================================================================\n\nexport const RepoData = Schema.Struct({\n\tcontent: Schema.String,\n\trepo_url: Schema.String,\n\tsummary: Schema.String,\n\ttree: Schema.String,\n});\nexport type RepoData = Schema.Schema.Type<typeof RepoData>;\n\n// ============================================================================\n// Default Fallback\n// ============================================================================\n\nexport const DEFAULT_ANALYSIS: AnalysisResult = {\n\tdiagrams: [],\n\texistingReadme: {\n\t\timprove: [],\n\t\tmissing: [],\n\t\tpreserve: [],\n\t\tquality: \"none\",\n\t},\n\tidentity: {\n\t\tdifferentiators: [],\n\t\tname: \"Unknown\",\n\t\toneLiner: \"\",\n\t},\n\trepoType: \"library\",\n\tsections: {\n\t\trecommended: [\n\t\t\t\"hero\",\n\t\t\t\"overview\",\n\t\t\t\"installation\",\n\t\t\t\"quick-start\",\n\t\t\t\"usage\",\n\t\t\t\"development\",\n\t\t\t\"license\",\n\t\t],\n\t\tskip: [],\n\t},\n\ttone: {\n\t\tdetected: \"professional\",\n\t\tevidence: \"fallback default\",\n\t},\n};\n\n// ============================================================================\n// Utilities\n// ============================================================================\n\nexport function extractExistingReadme(content: string): string | null {\n\tconst readmeMatch =\n\t\t/(?:^|\\n)(?:={3,}|─{3,})?\\s*README\\.md\\s*(?:={3,}|─{3,})?\\n([\\s\\S]*?)(?=\\n(?:={3,}|─{3,})\\s*\\S+\\.\\S+|$)/.exec(\n\t\t\tcontent,\n\t\t);\n\tif (readmeMatch?.[1] && readmeMatch[1].trim().length > 50) {\n\t\treturn readmeMatch[1].trim();\n\t}\n\treturn null;\n}\n\nexport function parseAnalysis(raw: string): AnalysisResult {\n\ttry {\n\t\tconst stripped = raw\n\t\t\t.replace(/^```(?:json)?\\s*/i, \"\")\n\t\t\t.replace(/\\s*```\\s*$/, \"\")\n\t\t\t.trim();\n\n\t\tconst json = JSON.parse(stripped) as unknown;\n\t\tconst result = Schema.decodeUnknownSync(AnalysisResult)(json);\n\n\t\tif (!result.sections.recommended.length) {\n\t\t\tthrow new Error(\"sections.recommended must not be empty\");\n\t\t}\n\n\t\treturn result;\n\t} catch (err) {\n\t\tconst logger = new Logger(\"GREPO:README-PROMPT\");\n\t\tlogger.warn(\n\t\t\t`Failed to parse analysis JSON, falling back to DEFAULT_ANALYSIS. Error: ${\n\t\t\t\terr instanceof Error ? err.message : String(err)\n\t\t\t}`,\n\t\t);\n\t\treturn DEFAULT_ANALYSIS;\n\t}\n}\n\n// ============================================================================\n// Phase 1: Analysis Prompt\n// ============================================================================\n\nexport function buildAnalysisPrompt(\n\trepoData: RepoData,\n\texistingReadme?: string,\n): string {\n\tconst existingReadmeBlock = existingReadme\n\t\t? `\n<existing_readme>\n${existingReadme.slice(0, 4000)}\n</existing_readme>`\n\t\t: \"\";\n\n\treturn `You are an expert technical analyst. Analyze the repository below and return ONLY valid JSON — no markdown fences, no commentary, no extra text.\n\n<output_schema>\n{\n \"repoType\": \"string — e.g. cli-tool, library, web-app, api, monorepo, config, data-pipeline, etc.\",\n \"identity\": {\n \"name\": \"string — canonical project name\",\n \"oneLiner\": \"string — one sentence describing what it does\",\n \"differentiators\": [\"string — unique selling points\"]\n },\n \"tone\": {\n \"detected\": \"casual | professional | minimal | technical\",\n \"evidence\": \"string — quote or observation that led to this conclusion\"\n },\n \"sections\": {\n \"recommended\": [\"string — section keys from the catalog below, in logical order\"],\n \"skip\": [{ \"section\": \"string\", \"reason\": \"string\" }]\n },\n \"diagrams\": [\n {\n \"type\": \"flowchart | sequence | c4-context | er | state\",\n \"purpose\": \"string — what this diagram explains\",\n \"scope\": \"string — what subsystem or flow it covers\",\n \"keyNodes\": [\"string — important nodes or actors\"]\n }\n ],\n \"existingReadme\": {\n \"quality\": \"good | decent | poor | none\",\n \"preserve\": [\"string — sections or content worth keeping verbatim\"],\n \"improve\": [\"string — sections that exist but need rework\"],\n \"missing\": [\"string — important topics not covered\"]\n }\n}\n</output_schema>\n\n<section_catalog>\nhero — project name, tagline, badges\noverview — what it does and why it exists\nfeatures — bullet list of capabilities\narchitecture — system design, component overview\ninstallation — how to install/setup\nquick-start — minimal working example\nusage — detailed usage instructions\ncli-reference — CLI flags and subcommands\napi-reference — public API docs\nconfiguration — env vars, config files\ndevelopment — local dev setup, contributing workflow\ndeployment — how to deploy/release\ncontributing — contribution guidelines\nlicense — license info\n</section_catalog>\n\n<rules>\n- Only recommend sections that have real supporting content in the repository.\n- Recommend at most 2 diagrams. Choose diagram types based on:\n - c4-context: multi-service architectures with external dependencies\n - sequence: request/response workflows or multi-actor interactions\n - flowchart: data pipelines, build processes, or decision trees\n - state: object lifecycle or state machine logic\n - er: data models with relationships\n- Detect tone from existing docs, comments, and README style (if present).\n- Be conservative: fewer well-chosen sections beat a bloated list.\n</rules>\n\n<repository_context>\nurl: ${repoData.repo_url}\nsummary: ${repoData.summary}\n\n<tree>\n${repoData.tree}\n</tree>\n\n<content>\n${repoData.content.slice(0, 8000)}\n</content>\n</repository_context>\n${existingReadmeBlock}`;\n}\n\n// ============================================================================\n// Phase 2: Generation Helpers\n// ============================================================================\n\nexport const STYLE_GUIDANCE: Record<DocumentationStyle, string> = {\n\tcomprehensive:\n\t\t\"Be thorough. Multiple examples, edge cases, full API surface. Expand every recommended section fully.\",\n\tminimal:\n\t\t\"Keep it concise. Favor short sentences and small sections. Omit exhaustive examples. Badge count ≤ 3.\",\n\tstandard:\n\t\t\"Balance depth and brevity. One code example per major section. Moderate badge set. Include a quick-start.\",\n};\n\nexport function buildExistingReadmeInstructions(\n\tanalysis: AnalysisResult,\n): string {\n\tif (analysis.existingReadme.quality === \"none\") {\n\t\treturn \"No existing README was found. Generate the document from scratch.\";\n\t}\n\n\tconst lines: string[] = [\n\t\t`Existing README quality: ${analysis.existingReadme.quality}.`,\n\t];\n\n\tif (analysis.existingReadme.preserve.length > 0) {\n\t\tlines.push(\n\t\t\t`Preserve the following content verbatim where possible:\\n${analysis.existingReadme.preserve.map((s) => ` - ${s}`).join(\"\\n\")}`,\n\t\t);\n\t}\n\n\tif (analysis.existingReadme.improve.length > 0) {\n\t\tlines.push(\n\t\t\t`Improve (rewrite/expand) these sections:\\n${analysis.existingReadme.improve.map((s) => ` - ${s}`).join(\"\\n\")}`,\n\t\t);\n\t}\n\n\tif (analysis.existingReadme.missing.length > 0) {\n\t\tlines.push(\n\t\t\t`Add these missing topics:\\n${analysis.existingReadme.missing.map((s) => ` - ${s}`).join(\"\\n\")}`,\n\t\t);\n\t}\n\n\treturn lines.join(\"\\n\");\n}\n\n// ============================================================================\n// Phase 2: Generation Prompt\n// ============================================================================\n\nexport function buildGenerationPrompt(\n\tanalysis: AnalysisResult,\n\trepoData: RepoData,\n\toptions: GenerationOptions,\n): string {\n\tconst effectiveTone: Tone = options.tone ?? analysis.tone.detected;\n\n\tconst toneDescriptions: Record<Tone, string> = {\n\t\tcasual:\n\t\t\t\"Friendly, approachable, first-person plural ('we'). Use contractions. Short paragraphs. Light humor is fine.\",\n\t\tminimal:\n\t\t\t\"Extremely terse. Bullet points over prose. No introductory fluff. Every word must earn its place.\",\n\t\tprofessional:\n\t\t\t\"Clear, precise, authoritative. Third-person or imperative. No jargon without definition. Avoid filler words.\",\n\t\ttechnical:\n\t\t\t\"Assume a developer audience. Use correct terminology. Include type signatures, flags, and internals where relevant.\",\n\t};\n\n\treturn `You are a senior technical writer generating a README for a software project.\n\n<output_rules>\n- Output ONLY the raw ${options.format.toUpperCase()} content. No preamble, no explanation, no markdown fences wrapping the whole document.\n- Only generate the sections listed in recommended_sections below. Do not add extras.\n- No generic filler phrases like \"In this section we will…\" or \"This project is a…\".\n- Mermaid diagrams must follow diagram_rules exactly.\n</output_rules>\n\n<analysis>\n${JSON.stringify(analysis, null, 2)}\n</analysis>\n\n<recommended_sections>\n${analysis.sections.recommended.join(\", \")}\n</recommended_sections>\n\n<tone>\nStyle: ${effectiveTone}\nDescription: ${toneDescriptions[effectiveTone]}\n</tone>\n\n<diagram_rules>\nCRITICAL SYNTAX RULES (violations cause render errors):\n- Wrap ALL node labels in quotes if they contain spaces, special chars, or parentheses: A[\"My Label\"]\n- NEVER use bare parentheses in labels — use quotes: A[\"Deploy (prod)\"] NOT A[Deploy (prod)]\n- NEVER use colons in labels without quotes: A[\"Step: Init\"] NOT A[Step: Init]\n- Arrow syntax: use --> for solid, -.-> for dotted. NEVER use -> alone in flowcharts.\n- Subgraph IDs must not contain spaces: subgraph auth_flow[\"Auth Flow\"]\n- Semicolons are NOT terminators — do not end lines with ;\n- Each node definition must be on its own line.\n\nSTYLE RULES:\n- Use descriptive labels on all nodes — never single letters like A, B, C.\n- Add meaningful labels on edges to describe data flow or actions.\n- Use subgraphs to group related nodes into logical clusters.\n- Limit diagrams to 15 nodes maximum.\n\nTYPE-SPECIFIC TEMPLATES (follow these exactly):\n\nflowchart (always TD):\n\\`\\`\\`mermaid\nflowchart TD\n A[\"User Request\"] --> B{\"Auth Valid?\"}\n B -->|Yes| C[\"Process Request\"]\n B -->|No| D[\"Return 401\"]\n C --> E[\"Send Response\"]\n\\`\\`\\`\n\nsequence:\n\\`\\`\\`mermaid\nsequenceDiagram\n actor User\n participant API\n participant DB\n User->>API: POST /login\n activate API\n API->>DB: Query user\n DB-->>API: User record\n API-->>User: JWT token\n deactivate API\n\\`\\`\\`\n\nc4-context (use C4Context):\n\\`\\`\\`mermaid\nC4Context\n Person(user, \"Developer\", \"Uses the CLI tool\")\n System(cli, \"CLI\", \"Command-line interface\")\n System_Ext(api, \"GitHub API\", \"Repository management\")\n Rel(user, cli, \"Runs commands\")\n Rel(cli, api, \"REST calls\")\n\\`\\`\\`\n\ner:\n\\`\\`\\`mermaid\nerDiagram\n USER ||--o{ ORDER : places\n ORDER ||--|{ LINE_ITEM : contains\n PRODUCT ||--o{ LINE_ITEM : \"ordered in\"\n\\`\\`\\`\n\nstate:\n\\`\\`\\`mermaid\nstateDiagram-v2\n [*] --> Idle\n Idle --> Processing : start\n Processing --> Done : complete\n Processing --> Failed : error\n Failed --> Idle : retry\n Done --> [*]\n\\`\\`\\`\n\nCOMMON MISTAKES TO AVOID:\n- Using \"graph\" instead of \"flowchart\"\n- Missing quotes around labels with special characters\n- Using C4_Context instead of C4Context\n- Forgetting \"activate/deactivate\" in sequence diagrams\n- Using --> in sequence diagrams (use ->> or -->> instead)\n</diagram_rules>\n\n<existing_readme_handling>\n${buildExistingReadmeInstructions(analysis)}\n</existing_readme_handling>\n\n<style_profile>\nDocumentation style: ${options.style}\n${STYLE_GUIDANCE[options.style]}\n</style_profile>\n\n<repository_context>\nurl: ${repoData.repo_url}\nsummary: ${repoData.summary}\n\n<tree>\n${repoData.tree}\n</tree>\n\n<content>\n${repoData.content}\n</content>\n</repository_context>`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,gBAAgB,OAAO,OAAO;CAC1C,UAAU,OAAO,MAAM,OAAO,OAAO;CACrC,SAAS,OAAO;CAChB,OAAO,OAAO;CACd,MAAM,OAAO,QAAQ,cAAc,MAAM,aAAa,YAAY,QAAQ;CAC1E,CAAC;AAEF,MAAa,uBAAuB,OAAO,OAAO;CACjD,SAAS,OAAO,MAAM,OAAO,OAAO;CACpC,SAAS,OAAO,MAAM,OAAO,OAAO;CACpC,UAAU,OAAO,MAAM,OAAO,OAAO;CACrC,SAAS,OAAO,QAAQ,UAAU,QAAQ,QAAQ,OAAO;CACzD,CAAC;AAEF,MAAa,iBAAiB,OAAO,OAAO;CAC3C,iBAAiB,OAAO,MAAM,OAAO,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AQ,KAAK,MAAM,OAAO,IAAI,CAAC,KAAK,KAAK,GAC/F;AAGF,QAAO,MAAM,KAAK,KAAK;;AAOxB,SAAgB,sBACf,UACA,UACA,SACS;CACT,MAAM,gBAAsB,QAAQ,QAAQ,SAAS,KAAK;AAa1D,QAAO;;;wBAGgB,QAAQ,OAAO,aAAa,CAAC;;;;;;;EAOnD,KAAK,UAAU,UAAU,MAAM,EAAE,CAAC;;;;EAIlC,SAAS,SAAS,YAAY,KAAK,KAAK,CAAC;;;;SAIlC,cAAc;eA7ByB;EAC9C,QACC;EACD,SACC;EACD,cACC;EACD,WACC;EACD,CAqB8B,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkF7C,gCAAgC,SAAS,CAAC;;;;uBAIrB,QAAQ,MAAM;EACnC,eAAe,QAAQ,OAAO;;;;OAIzB,SAAS,SAAS;WACd,SAAS,QAAQ;;;EAG1B,SAAS,KAAK;;;;EAId,SAAS,QAAQ"}
|
|
1
|
+
{"version":3,"file":"readme.js","names":["Logger"],"sources":["../../src/prompts/readme.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport { Schema } from \"effect\";\n\nimport type { DocumentationStyle } from \"../config.js\";\nimport { Logger } from \"../utils/logger.js\";\n\n// ============================================================================\n// Types & Schemas\n// ============================================================================\n\nexport const DiagramSchema = Schema.Struct({\n\tkeyNodes: Schema.Array(Schema.String),\n\tpurpose: Schema.String,\n\tscope: Schema.String,\n\ttype: Schema.Literal(\"c4-context\", \"er\", \"flowchart\", \"sequence\", \"state\"),\n});\n\nexport const ExistingReadmeSchema = Schema.Struct({\n\timprove: Schema.Array(Schema.String),\n\tmissing: Schema.Array(Schema.String),\n\tpreserve: Schema.Array(Schema.String),\n\tquality: Schema.Literal(\"decent\", \"good\", \"none\", \"poor\"),\n});\n\nexport const IdentitySchema = Schema.Struct({\n\tdifferentiators: Schema.Array(Schema.String),\n\tname: Schema.String,\n\toneLiner: Schema.String,\n});\n\nexport const SectionsSchema = Schema.Struct({\n\trecommended: Schema.Array(Schema.String),\n\tskip: Schema.Array(\n\t\tSchema.Struct({\n\t\t\treason: Schema.String,\n\t\t\tsection: Schema.String,\n\t\t}),\n\t),\n});\n\nexport const ToneSchema = Schema.Literal(\n\t\"casual\",\n\t\"minimal\",\n\t\"professional\",\n\t\"technical\",\n);\nexport type Tone = Schema.Schema.Type<typeof ToneSchema>;\n\nexport const ToneDetectionSchema = Schema.Struct({\n\tdetected: ToneSchema,\n\tevidence: Schema.String,\n});\n\nexport const AnalysisResult = Schema.Struct({\n\tdiagrams: Schema.Array(DiagramSchema),\n\texistingReadme: ExistingReadmeSchema,\n\tidentity: IdentitySchema,\n\trepoType: Schema.String,\n\tsections: SectionsSchema,\n\ttone: ToneDetectionSchema,\n});\nexport type AnalysisResult = Schema.Schema.Type<typeof AnalysisResult>;\n\nexport const GenerationOptions = Schema.Struct({\n\tformat: Schema.Literal(\"md\", \"mdx\"),\n\tstyle: Schema.Literal(\"minimal\", \"standard\", \"comprehensive\"),\n\ttone: Schema.optional(ToneSchema),\n});\nexport type GenerationOptions = Schema.Schema.Type<typeof GenerationOptions>;\n\n// ============================================================================\n// Repo Data Schema\n// ============================================================================\n\nexport const RepoData = Schema.Struct({\n\tcontent: Schema.String,\n\trepo_url: Schema.String,\n\tsummary: Schema.String,\n\ttree: Schema.String,\n});\nexport type RepoData = Schema.Schema.Type<typeof RepoData>;\n\n// ============================================================================\n// Default Fallback\n// ============================================================================\n\nexport const DEFAULT_ANALYSIS: AnalysisResult = {\n\tdiagrams: [],\n\texistingReadme: {\n\t\timprove: [],\n\t\tmissing: [],\n\t\tpreserve: [],\n\t\tquality: \"none\",\n\t},\n\tidentity: {\n\t\tdifferentiators: [],\n\t\tname: \"Unknown\",\n\t\toneLiner: \"\",\n\t},\n\trepoType: \"library\",\n\tsections: {\n\t\trecommended: [\n\t\t\t\"hero\",\n\t\t\t\"overview\",\n\t\t\t\"installation\",\n\t\t\t\"quick-start\",\n\t\t\t\"usage\",\n\t\t\t\"development\",\n\t\t\t\"license\",\n\t\t],\n\t\tskip: [],\n\t},\n\ttone: {\n\t\tdetected: \"professional\",\n\t\tevidence: \"fallback default\",\n\t},\n};\n\n// ============================================================================\n// Utilities\n// ============================================================================\n\nexport function extractExistingReadme(content: string): string | null {\n\tconst readmeMatch =\n\t\t/(?:^|\\n)(?:={3,}|─{3,})?\\s*README\\.md\\s*(?:={3,}|─{3,})?\\n([\\s\\S]*?)(?=\\n(?:={3,}|─{3,})\\s*\\S+\\.\\S+|$)/.exec(\n\t\t\tcontent,\n\t\t);\n\tif (readmeMatch?.[1] && readmeMatch[1].trim().length > 50) {\n\t\treturn readmeMatch[1].trim();\n\t}\n\treturn null;\n}\n\nexport function parseAnalysis(raw: string): AnalysisResult {\n\ttry {\n\t\tconst stripped = raw\n\t\t\t.replace(/^```(?:json)?\\s*/i, \"\")\n\t\t\t.replace(/\\s*```\\s*$/, \"\")\n\t\t\t.trim();\n\n\t\tconst json = JSON.parse(stripped) as unknown;\n\t\tconst result = Schema.decodeUnknownSync(AnalysisResult)(json);\n\n\t\tif (!result.sections.recommended.length) {\n\t\t\tthrow new Error(\"sections.recommended must not be empty\");\n\t\t}\n\n\t\treturn result;\n\t} catch (err) {\n\t\tconst logger = new Logger(\"GREPO:README-PROMPT\");\n\t\tlogger.warn(\n\t\t\t`Failed to parse analysis JSON, falling back to DEFAULT_ANALYSIS`,\n\t\t\t{\n\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t\trawLength: raw.length,\n\t\t\t\trawPreview: raw.slice(0, 200),\n\t\t\t},\n\t\t);\n\t\treturn DEFAULT_ANALYSIS;\n\t}\n}\n\n// ============================================================================\n// Phase 1: Analysis Prompt\n// ============================================================================\n\nexport function buildAnalysisPrompt(\n\trepoData: RepoData,\n\texistingReadme?: string,\n): string {\n\tconst existingReadmeBlock = existingReadme\n\t\t? `\n<existing_readme>\n${existingReadme.slice(0, 4000)}\n</existing_readme>`\n\t\t: \"\";\n\n\treturn `You are an expert technical analyst. Analyze the repository below and return ONLY valid JSON — no markdown fences, no commentary, no extra text.\n\n<output_schema>\n{\n \"repoType\": \"string — e.g. cli-tool, library, web-app, api, monorepo, config, data-pipeline, etc.\",\n \"identity\": {\n \"name\": \"string — canonical project name\",\n \"oneLiner\": \"string — one sentence describing what it does\",\n \"differentiators\": [\"string — unique selling points\"]\n },\n \"tone\": {\n \"detected\": \"casual | professional | minimal | technical\",\n \"evidence\": \"string — quote or observation that led to this conclusion\"\n },\n \"sections\": {\n \"recommended\": [\"string — section keys from the catalog below, in logical order\"],\n \"skip\": [{ \"section\": \"string\", \"reason\": \"string\" }]\n },\n \"diagrams\": [\n {\n \"type\": \"flowchart | sequence | c4-context | er | state\",\n \"purpose\": \"string — what this diagram explains\",\n \"scope\": \"string — what subsystem or flow it covers\",\n \"keyNodes\": [\"string — important nodes or actors\"]\n }\n ],\n \"existingReadme\": {\n \"quality\": \"good | decent | poor | none\",\n \"preserve\": [\"string — sections or content worth keeping verbatim\"],\n \"improve\": [\"string — sections that exist but need rework\"],\n \"missing\": [\"string — important topics not covered\"]\n }\n}\n</output_schema>\n\n<section_catalog>\nhero — project name, tagline, badges\noverview — what it does and why it exists\nfeatures — bullet list of capabilities\narchitecture — system design, component overview\ninstallation — how to install/setup\nquick-start — minimal working example\nusage — detailed usage instructions\ncli-reference — CLI flags and subcommands\napi-reference — public API docs\nconfiguration — env vars, config files\ndevelopment — local dev setup, contributing workflow\ndeployment — how to deploy/release\ncontributing — contribution guidelines\nlicense — license info\n</section_catalog>\n\n<rules>\n- Only recommend sections that have real supporting content in the repository.\n- Recommend at most 2 diagrams. Choose diagram types based on:\n - c4-context: multi-service architectures with external dependencies\n - sequence: request/response workflows or multi-actor interactions\n - flowchart: data pipelines, build processes, or decision trees\n - state: object lifecycle or state machine logic\n - er: data models with relationships\n- Detect tone from existing docs, comments, and README style (if present).\n- Be conservative: fewer well-chosen sections beat a bloated list.\n</rules>\n\n<repository_context>\nurl: ${repoData.repo_url}\nsummary: ${repoData.summary}\n\n<tree>\n${repoData.tree}\n</tree>\n\n<content>\n${repoData.content.slice(0, 8000)}\n</content>\n</repository_context>\n${existingReadmeBlock}`;\n}\n\n// ============================================================================\n// Phase 2: Generation Helpers\n// ============================================================================\n\nexport const STYLE_GUIDANCE: Record<DocumentationStyle, string> = {\n\tcomprehensive:\n\t\t\"Be thorough. Multiple examples, edge cases, full API surface. Expand every recommended section fully.\",\n\tminimal:\n\t\t\"Keep it concise. Favor short sentences and small sections. Omit exhaustive examples. Badge count ≤ 3.\",\n\tstandard:\n\t\t\"Balance depth and brevity. One code example per major section. Moderate badge set. Include a quick-start.\",\n};\n\nexport function buildExistingReadmeInstructions(\n\tanalysis: AnalysisResult,\n): string {\n\tif (analysis.existingReadme.quality === \"none\") {\n\t\treturn \"No existing README was found. Generate the document from scratch.\";\n\t}\n\n\tconst lines: string[] = [\n\t\t`Existing README quality: ${analysis.existingReadme.quality}.`,\n\t];\n\n\tif (analysis.existingReadme.preserve.length > 0) {\n\t\tlines.push(\n\t\t\t`Preserve the following content verbatim where possible:\\n${analysis.existingReadme.preserve.map((s) => ` - ${s}`).join(\"\\n\")}`,\n\t\t);\n\t}\n\n\tif (analysis.existingReadme.improve.length > 0) {\n\t\tlines.push(\n\t\t\t`Improve (rewrite/expand) these sections:\\n${analysis.existingReadme.improve.map((s) => ` - ${s}`).join(\"\\n\")}`,\n\t\t);\n\t}\n\n\tif (analysis.existingReadme.missing.length > 0) {\n\t\tlines.push(\n\t\t\t`Add these missing topics:\\n${analysis.existingReadme.missing.map((s) => ` - ${s}`).join(\"\\n\")}`,\n\t\t);\n\t}\n\n\treturn lines.join(\"\\n\");\n}\n\n// ============================================================================\n// Phase 2: Generation Prompt\n// ============================================================================\n\nexport function buildGenerationPrompt(\n\tanalysis: AnalysisResult,\n\trepoData: RepoData,\n\toptions: GenerationOptions,\n): string {\n\tconst effectiveTone: Tone = options.tone ?? analysis.tone.detected;\n\n\tconst toneDescriptions: Record<Tone, string> = {\n\t\tcasual:\n\t\t\t\"Friendly, approachable, first-person plural ('we'). Use contractions. Short paragraphs. Light humor is fine.\",\n\t\tminimal:\n\t\t\t\"Extremely terse. Bullet points over prose. No introductory fluff. Every word must earn its place.\",\n\t\tprofessional:\n\t\t\t\"Clear, precise, authoritative. Third-person or imperative. No jargon without definition. Avoid filler words.\",\n\t\ttechnical:\n\t\t\t\"Assume a developer audience. Use correct terminology. Include type signatures, flags, and internals where relevant.\",\n\t};\n\n\treturn `You are a senior technical writer generating a README for a software project.\n\n<output_rules>\n- Output ONLY the raw ${options.format.toUpperCase()} content. No preamble, no explanation, no markdown fences wrapping the whole document.\n- Only generate the sections listed in recommended_sections below. Do not add extras.\n- No generic filler phrases like \"In this section we will…\" or \"This project is a…\".\n- Mermaid diagrams must follow diagram_rules exactly.\n</output_rules>\n\n<analysis>\n${JSON.stringify(analysis, null, 2)}\n</analysis>\n\n<recommended_sections>\n${analysis.sections.recommended.join(\", \")}\n</recommended_sections>\n\n<tone>\nStyle: ${effectiveTone}\nDescription: ${toneDescriptions[effectiveTone]}\n</tone>\n\n<diagram_rules>\nCRITICAL SYNTAX RULES (violations cause render errors):\n- Wrap ALL node labels in quotes if they contain spaces, special chars, or parentheses: A[\"My Label\"]\n- NEVER use bare parentheses in labels — use quotes: A[\"Deploy (prod)\"] NOT A[Deploy (prod)]\n- NEVER use colons in labels without quotes: A[\"Step: Init\"] NOT A[Step: Init]\n- Arrow syntax: use --> for solid, -.-> for dotted. NEVER use -> alone in flowcharts.\n- Subgraph IDs must not contain spaces: subgraph auth_flow[\"Auth Flow\"]\n- Semicolons are NOT terminators — do not end lines with ;\n- Each node definition must be on its own line.\n\nSTYLE RULES:\n- Use descriptive labels on all nodes — never single letters like A, B, C.\n- Add meaningful labels on edges to describe data flow or actions.\n- Use subgraphs to group related nodes into logical clusters.\n- Limit diagrams to 15 nodes maximum.\n\nTYPE-SPECIFIC TEMPLATES (follow these exactly):\n\nflowchart (always TD):\n\\`\\`\\`mermaid\nflowchart TD\n A[\"User Request\"] --> B{\"Auth Valid?\"}\n B -->|Yes| C[\"Process Request\"]\n B -->|No| D[\"Return 401\"]\n C --> E[\"Send Response\"]\n\\`\\`\\`\n\nsequence:\n\\`\\`\\`mermaid\nsequenceDiagram\n actor User\n participant API\n participant DB\n User->>API: POST /login\n activate API\n API->>DB: Query user\n DB-->>API: User record\n API-->>User: JWT token\n deactivate API\n\\`\\`\\`\n\nc4-context (use C4Context):\n\\`\\`\\`mermaid\nC4Context\n Person(user, \"Developer\", \"Uses the CLI tool\")\n System(cli, \"CLI\", \"Command-line interface\")\n System_Ext(api, \"GitHub API\", \"Repository management\")\n Rel(user, cli, \"Runs commands\")\n Rel(cli, api, \"REST calls\")\n\\`\\`\\`\n\ner:\n\\`\\`\\`mermaid\nerDiagram\n USER ||--o{ ORDER : places\n ORDER ||--|{ LINE_ITEM : contains\n PRODUCT ||--o{ LINE_ITEM : \"ordered in\"\n\\`\\`\\`\n\nstate:\n\\`\\`\\`mermaid\nstateDiagram-v2\n [*] --> Idle\n Idle --> Processing : start\n Processing --> Done : complete\n Processing --> Failed : error\n Failed --> Idle : retry\n Done --> [*]\n\\`\\`\\`\n\nCOMMON MISTAKES TO AVOID:\n- Using \"graph\" instead of \"flowchart\"\n- Missing quotes around labels with special characters\n- Using C4_Context instead of C4Context\n- Forgetting \"activate/deactivate\" in sequence diagrams\n- Using --> in sequence diagrams (use ->> or -->> instead)\n</diagram_rules>\n\n<existing_readme_handling>\n${buildExistingReadmeInstructions(analysis)}\n</existing_readme_handling>\n\n<style_profile>\nDocumentation style: ${options.style}\n${STYLE_GUIDANCE[options.style]}\n</style_profile>\n\n<repository_context>\nurl: ${repoData.repo_url}\nsummary: ${repoData.summary}\n\n<tree>\n${repoData.tree}\n</tree>\n\n<content>\n${repoData.content}\n</content>\n</repository_context>`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,gBAAgB,OAAO,OAAO;CAC1C,UAAU,OAAO,MAAM,OAAO,OAAO;CACrC,SAAS,OAAO;CAChB,OAAO,OAAO;CACd,MAAM,OAAO,QAAQ,cAAc,MAAM,aAAa,YAAY,QAAQ;CAC1E,CAAC;AAEF,MAAa,uBAAuB,OAAO,OAAO;CACjD,SAAS,OAAO,MAAM,OAAO,OAAO;CACpC,SAAS,OAAO,MAAM,OAAO,OAAO;CACpC,UAAU,OAAO,MAAM,OAAO,OAAO;CACrC,SAAS,OAAO,QAAQ,UAAU,QAAQ,QAAQ,OAAO;CACzD,CAAC;AAEF,MAAa,iBAAiB,OAAO,OAAO;CAC3C,iBAAiB,OAAO,MAAM,OAAO,OAAO;CAC5C,MAAM,OAAO;CACb,UAAU,OAAO;CACjB,CAAC;AAEF,MAAa,iBAAiB,OAAO,OAAO;CAC3C,aAAa,OAAO,MAAM,OAAO,OAAO;CACxC,MAAM,OAAO,MACZ,OAAO,OAAO;EACb,QAAQ,OAAO;EACf,SAAS,OAAO;EAChB,CAAC,CACF;CACD,CAAC;AAEF,MAAa,aAAa,OAAO,QAChC,UACA,WACA,gBACA,YACA;AAGD,MAAa,sBAAsB,OAAO,OAAO;CAChD,UAAU;CACV,UAAU,OAAO;CACjB,CAAC;AAEF,MAAa,iBAAiB,OAAO,OAAO;CAC3C,UAAU,OAAO,MAAM,cAAc;CACrC,gBAAgB;CAChB,UAAU;CACV,UAAU,OAAO;CACjB,UAAU;CACV,MAAM;CACN,CAAC;AAGF,MAAa,oBAAoB,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkF7C,gCAAgC,SAAS,CAAC;;;;uBAIrB,QAAQ,MAAM;EACnC,eAAe,QAAQ,OAAO;;;;OAIzB,SAAS,SAAS;WACd,SAAS,QAAQ;;;EAG1B,SAAS,KAAK;;;;EAId,SAAS,QAAQ"}
|
package/lib/services.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ declare const Gemini_base: Context.TagClass<Gemini, "Gemini", GeminiServiceApi>;
|
|
|
11
11
|
declare class Gemini extends Gemini_base {}
|
|
12
12
|
declare const GeminiLive: (apiKey: string) => Layer.Layer<Gemini, never, never>;
|
|
13
13
|
interface GitHubServiceApi {
|
|
14
|
+
readonly getDefaultBranch: (owner: string, repo: string) => Effect.Effect<string, GitHubError>;
|
|
14
15
|
readonly getTopics: (owner: string, repo: string) => Effect.Effect<readonly string[], GitHubError>;
|
|
15
16
|
readonly pushFile: (owner: string, repo: string, path: string, content: string, message: string, branch: string) => Effect.Effect<void, GitHubError>;
|
|
16
17
|
readonly setTopics: (owner: string, repo: string, topics: string[]) => Effect.Effect<void, GitHubError>;
|
|
@@ -23,7 +24,7 @@ declare const GitHub_base: Context.TagClass<GitHub, "GitHub", GitHubServiceApi>;
|
|
|
23
24
|
declare class GitHub extends GitHub_base {}
|
|
24
25
|
declare const GitHubLive: (token?: string) => Layer.Layer<GitHub, never, never>;
|
|
25
26
|
type RepoData = Schema.Schema.Type<typeof GitIngestResponse>;
|
|
26
|
-
declare const fetchRepo: (repoUrl: string) => Effect.Effect<RepoData, GitIngestError>;
|
|
27
|
+
declare const fetchRepo: (repoUrl: string, token?: string) => Effect.Effect<RepoData, GitIngestError>;
|
|
27
28
|
//#endregion
|
|
28
29
|
export { Gemini, GeminiLive, GeminiServiceApi, GitHub, GitHubLive, GitHubServiceApi, RepoData, fetchRepo };
|
|
29
30
|
//# sourceMappingURL=services.d.ts.map
|
package/lib/services.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.d.ts","names":[],"sources":["../src/services.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"services.d.ts","names":[],"sources":["../src/services.ts"],"sourcesContent":[],"mappings":";;;;;;AA+EM,UA9CW,gBAAA,CA8CJ;EAKa,SAAA,eAAA,EAAA,CAAA,MAAA,EAAA,MAAA,EAAA,GAhDpB,MAAA,CAAO,MAgDa,CAAA,MAAA,EAhDE,WAgDF,CAAA;;cA/CzB,WA+CkB,kBAAA,OAAA,EAAA,QAAA,kBAAA,CAAA;AAClB,cA9CY,MAAA,SAAe,WAAA,CA8C3B;cA5CY,gCAA4B,KAAA,CAAA,MAAA;UAiBxB,gBAAA;8DAIX,MAAA,CAAO,eAAe;EAyBf,SAAO,SAAA,EAAA,CAAQ,KAAA,EAAA,MAAiD,EAAA,IAAA,EAAA,MAAA,EAAA,GArBvE,MAAA,CAAO,MAqBgE,CAAA,SAAA,MAAA,EAAA,EArBtC,WAqBsC,CAAA;EAEhE,SAAA,QAiDZ,EAAA,CAAA,KAjDwC,EAAA,MAAA,EAAA,IAAA,EAAA,MAAA,EAAA,IAAA,EAAA,MAAA,EAAA,OAAA,EAAA,MAAA,EAAA,OAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,EAAA,GAfnC,MAAA,CAAO,MAe4B,CAAA,IAAA,EAff,WAee,CAAA;EAuD7B,SAAA,SAAQ,EAAA,CAAA,KAA6B,EAAA,MAAA,EAAA,IAAA,EAA1B,MAAA,EAAO,MAAO,EAAA,MAAI,EAAA,EAAA,GAjEnC,MAAA,CAAO,MAiE4B,CAAA,IAAA,EAjEf,WAiEe,CAAA;EAE5B,SAAA,UAWV,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,IAAA,EAAA,MAAA,EAAA,IAAA,EAAA;IARc,WAAA,CAAA,EAAA,MAAA;IAAU,QAAA,CAAA,EAAA,MAAA;EAAxB,CAAA,EAAA,GAjEG,MAAA,CAAO,MAiEH,CAAA,IAAA,EAjEgB,WAiEhB,CAAA;;cAhET;cAEY,MAAA,SAAe,WAAA;cAEf,gCAA4B,KAAA,CAAA,MAAA;KAuD7B,QAAA,GAAW,MAAA,CAAO,MAAA,CAAO,YAAY;cAEpC,gDAGV,MAAA,CAAO,OAAO,UAAU"}
|
package/lib/services.js
CHANGED
|
@@ -16,6 +16,13 @@ var GitHub = class extends Context.Tag("GitHub")() {};
|
|
|
16
16
|
const GitHubLive = (token) => {
|
|
17
17
|
const client = new GitHubClient(token);
|
|
18
18
|
return Layer.succeed(GitHub, {
|
|
19
|
+
getDefaultBranch: (owner, repo) => Effect.tryPromise({
|
|
20
|
+
catch: (error) => new GitHubError({
|
|
21
|
+
endpoint: `repos/${owner}/${repo}`,
|
|
22
|
+
message: error instanceof Error ? error.message : String(error)
|
|
23
|
+
}),
|
|
24
|
+
try: () => client.getDefaultBranch(owner, repo)
|
|
25
|
+
}),
|
|
19
26
|
getTopics: (owner, repo) => Effect.tryPromise({
|
|
20
27
|
catch: (error) => new GitHubError({
|
|
21
28
|
endpoint: `repos/${owner}/${repo}/topics`,
|
|
@@ -46,12 +53,12 @@ const GitHubLive = (token) => {
|
|
|
46
53
|
})
|
|
47
54
|
});
|
|
48
55
|
};
|
|
49
|
-
const fetchRepo = (repoUrl) => Effect.tryPromise({
|
|
56
|
+
const fetchRepo = (repoUrl, token) => Effect.tryPromise({
|
|
50
57
|
catch: (error) => new GitIngestError({
|
|
51
58
|
cause: error,
|
|
52
59
|
message: error instanceof Error ? error.message : String(error)
|
|
53
60
|
}),
|
|
54
|
-
try: () => fetchRepositoryContent(repoUrl)
|
|
61
|
+
try: () => fetchRepositoryContent(repoUrl, token)
|
|
55
62
|
});
|
|
56
63
|
//#endregion
|
|
57
64
|
export { Gemini, GeminiLive, GitHub, GitHubLive, fetchRepo };
|
package/lib/services.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.js","names":["GeminiClient"],"sources":["../src/services.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport type { Schema } from \"effect\";\nimport { Context, Effect, Layer } from \"effect\";\n\nimport { GeminiError, GitHubError, GitIngestError } from \"./errors.js\";\nimport { GeminiService as GeminiClient } from \"./utils/gemini.js\";\nimport { GitHubClient } from \"./utils/github.js\";\nimport {\n\tfetchRepositoryContent,\n\ttype GitIngestResponse,\n} from \"./utils/gitingest.js\";\n\n// ============================================================================\n// Gemini Service\n// ============================================================================\n\nexport interface GeminiServiceApi {\n\treadonly generateContent: (\n\t\tprompt: string,\n\t) => Effect.Effect<string, GeminiError>;\n}\n\nexport class Gemini extends Context.Tag(\"Gemini\")<Gemini, GeminiServiceApi>() {}\n\nexport const GeminiLive = (apiKey: string) =>\n\tLayer.succeed(Gemini, {\n\t\tgenerateContent: (prompt: string) =>\n\t\t\tEffect.tryPromise({\n\t\t\t\tcatch: (error) =>\n\t\t\t\t\tnew GeminiError({\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t}),\n\t\t\t\ttry: () => new GeminiClient(apiKey).generateContent(prompt),\n\t\t\t}),\n\t});\n\n// ============================================================================\n// GitHub Service\n// ============================================================================\n\nexport interface GitHubServiceApi {\n\treadonly getTopics: (\n\t\towner: string,\n\t\trepo: string,\n\t) => Effect.Effect<readonly string[], GitHubError>;\n\treadonly pushFile: (\n\t\towner: string,\n\t\trepo: string,\n\t\tpath: string,\n\t\tcontent: string,\n\t\tmessage: string,\n\t\tbranch: string,\n\t) => Effect.Effect<void, GitHubError>;\n\treadonly setTopics: (\n\t\towner: string,\n\t\trepo: string,\n\t\ttopics: string[],\n\t) => Effect.Effect<void, GitHubError>;\n\treadonly updateRepo: (\n\t\towner: string,\n\t\trepo: string,\n\t\tdata: { description?: string; homepage?: string },\n\t) => Effect.Effect<void, GitHubError>;\n}\n\nexport class GitHub extends Context.Tag(\"GitHub\")<GitHub, GitHubServiceApi>() {}\n\nexport const GitHubLive = (token?: string) => {\n\tconst client = new GitHubClient(token);\n\treturn Layer.succeed(GitHub, {\n\t\tgetTopics: (owner, repo) =>\n\t\t\tEffect.tryPromise({\n\t\t\t\tcatch: (error) =>\n\t\t\t\t\tnew GitHubError({\n\t\t\t\t\t\tendpoint: `repos/${owner}/${repo}/topics`,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t}),\n\t\t\t\ttry: () => client.getTopics(owner, repo),\n\t\t\t}),\n\t\tpushFile: (owner, repo, path, content, message, branch) =>\n\t\t\tEffect.tryPromise({\n\t\t\t\tcatch: (error) =>\n\t\t\t\t\tnew GitHubError({\n\t\t\t\t\t\tendpoint: `repos/${owner}/${repo}/contents/${path}`,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t}),\n\t\t\t\ttry: () => client.pushFile(owner, repo, path, content, message, branch),\n\t\t\t}),\n\t\tsetTopics: (owner, repo, topics) =>\n\t\t\tEffect.tryPromise({\n\t\t\t\tcatch: (error) =>\n\t\t\t\t\tnew GitHubError({\n\t\t\t\t\t\tendpoint: `repos/${owner}/${repo}/topics`,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t}),\n\t\t\t\ttry: () => client.setTopics(owner, repo, topics),\n\t\t\t}),\n\t\tupdateRepo: (owner, repo, data) =>\n\t\t\tEffect.tryPromise({\n\t\t\t\tcatch: (error) =>\n\t\t\t\t\tnew GitHubError({\n\t\t\t\t\t\tendpoint: `repos/${owner}/${repo}`,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t}),\n\t\t\t\ttry: () => client.updateRepo(owner, repo, data),\n\t\t\t}),\n\t});\n};\n\n// ============================================================================\n// GitIngest Service\n// ============================================================================\n\nexport type RepoData = Schema.Schema.Type<typeof GitIngestResponse>;\n\nexport const fetchRepo = (\n\trepoUrl: string,\n): Effect.Effect<RepoData, GitIngestError> =>\n\tEffect.tryPromise({\n\t\tcatch: (error) =>\n\t\t\tnew GitIngestError({\n\t\t\t\tcause: error,\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t}),\n\t\ttry: () => fetchRepositoryContent(repoUrl),\n\t});\n"],"mappings":";;;;;;AAuCA,IAAa,SAAb,cAA4B,QAAQ,IAAI,SAAS,EAA4B,CAAC;AAE9E,MAAa,cAAc,WAC1B,MAAM,QAAQ,QAAQ,EACrB,kBAAkB,WACjB,OAAO,WAAW;CACjB,QAAQ,UACP,IAAI,YAAY;EACf,OAAO;EACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;EAC/D,CAAC;CACH,WAAW,IAAIA,cAAa,OAAO,CAAC,gBAAgB,OAAO;CAC3D,CAAC,EACH,CAAC;
|
|
1
|
+
{"version":3,"file":"services.js","names":["GeminiClient"],"sources":["../src/services.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport type { Schema } from \"effect\";\nimport { Context, Effect, Layer } from \"effect\";\n\nimport { GeminiError, GitHubError, GitIngestError } from \"./errors.js\";\nimport { GeminiService as GeminiClient } from \"./utils/gemini.js\";\nimport { GitHubClient } from \"./utils/github.js\";\nimport {\n\tfetchRepositoryContent,\n\ttype GitIngestResponse,\n} from \"./utils/gitingest.js\";\n\n// ============================================================================\n// Gemini Service\n// ============================================================================\n\nexport interface GeminiServiceApi {\n\treadonly generateContent: (\n\t\tprompt: string,\n\t) => Effect.Effect<string, GeminiError>;\n}\n\nexport class Gemini extends Context.Tag(\"Gemini\")<Gemini, GeminiServiceApi>() {}\n\nexport const GeminiLive = (apiKey: string) =>\n\tLayer.succeed(Gemini, {\n\t\tgenerateContent: (prompt: string) =>\n\t\t\tEffect.tryPromise({\n\t\t\t\tcatch: (error) =>\n\t\t\t\t\tnew GeminiError({\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t}),\n\t\t\t\ttry: () => new GeminiClient(apiKey).generateContent(prompt),\n\t\t\t}),\n\t});\n\n// ============================================================================\n// GitHub Service\n// ============================================================================\n\nexport interface GitHubServiceApi {\n\treadonly getDefaultBranch: (\n\t\towner: string,\n\t\trepo: string,\n\t) => Effect.Effect<string, GitHubError>;\n\treadonly getTopics: (\n\t\towner: string,\n\t\trepo: string,\n\t) => Effect.Effect<readonly string[], GitHubError>;\n\treadonly pushFile: (\n\t\towner: string,\n\t\trepo: string,\n\t\tpath: string,\n\t\tcontent: string,\n\t\tmessage: string,\n\t\tbranch: string,\n\t) => Effect.Effect<void, GitHubError>;\n\treadonly setTopics: (\n\t\towner: string,\n\t\trepo: string,\n\t\ttopics: string[],\n\t) => Effect.Effect<void, GitHubError>;\n\treadonly updateRepo: (\n\t\towner: string,\n\t\trepo: string,\n\t\tdata: { description?: string; homepage?: string },\n\t) => Effect.Effect<void, GitHubError>;\n}\n\nexport class GitHub extends Context.Tag(\"GitHub\")<GitHub, GitHubServiceApi>() {}\n\nexport const GitHubLive = (token?: string) => {\n\tconst client = new GitHubClient(token);\n\treturn Layer.succeed(GitHub, {\n\t\tgetDefaultBranch: (owner, repo) =>\n\t\t\tEffect.tryPromise({\n\t\t\t\tcatch: (error) =>\n\t\t\t\t\tnew GitHubError({\n\t\t\t\t\t\tendpoint: `repos/${owner}/${repo}`,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t}),\n\t\t\t\ttry: () => client.getDefaultBranch(owner, repo),\n\t\t\t}),\n\t\tgetTopics: (owner, repo) =>\n\t\t\tEffect.tryPromise({\n\t\t\t\tcatch: (error) =>\n\t\t\t\t\tnew GitHubError({\n\t\t\t\t\t\tendpoint: `repos/${owner}/${repo}/topics`,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t}),\n\t\t\t\ttry: () => client.getTopics(owner, repo),\n\t\t\t}),\n\t\tpushFile: (owner, repo, path, content, message, branch) =>\n\t\t\tEffect.tryPromise({\n\t\t\t\tcatch: (error) =>\n\t\t\t\t\tnew GitHubError({\n\t\t\t\t\t\tendpoint: `repos/${owner}/${repo}/contents/${path}`,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t}),\n\t\t\t\ttry: () => client.pushFile(owner, repo, path, content, message, branch),\n\t\t\t}),\n\t\tsetTopics: (owner, repo, topics) =>\n\t\t\tEffect.tryPromise({\n\t\t\t\tcatch: (error) =>\n\t\t\t\t\tnew GitHubError({\n\t\t\t\t\t\tendpoint: `repos/${owner}/${repo}/topics`,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t}),\n\t\t\t\ttry: () => client.setTopics(owner, repo, topics),\n\t\t\t}),\n\t\tupdateRepo: (owner, repo, data) =>\n\t\t\tEffect.tryPromise({\n\t\t\t\tcatch: (error) =>\n\t\t\t\t\tnew GitHubError({\n\t\t\t\t\t\tendpoint: `repos/${owner}/${repo}`,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t}),\n\t\t\t\ttry: () => client.updateRepo(owner, repo, data),\n\t\t\t}),\n\t});\n};\n\n// ============================================================================\n// GitIngest Service\n// ============================================================================\n\nexport type RepoData = Schema.Schema.Type<typeof GitIngestResponse>;\n\nexport const fetchRepo = (\n\trepoUrl: string,\n\ttoken?: string,\n): Effect.Effect<RepoData, GitIngestError> =>\n\tEffect.tryPromise({\n\t\tcatch: (error) =>\n\t\t\tnew GitIngestError({\n\t\t\t\tcause: error,\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t}),\n\t\ttry: () => fetchRepositoryContent(repoUrl, token),\n\t});\n"],"mappings":";;;;;;AAuCA,IAAa,SAAb,cAA4B,QAAQ,IAAI,SAAS,EAA4B,CAAC;AAE9E,MAAa,cAAc,WAC1B,MAAM,QAAQ,QAAQ,EACrB,kBAAkB,WACjB,OAAO,WAAW;CACjB,QAAQ,UACP,IAAI,YAAY;EACf,OAAO;EACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;EAC/D,CAAC;CACH,WAAW,IAAIA,cAAa,OAAO,CAAC,gBAAgB,OAAO;CAC3D,CAAC,EACH,CAAC;AAmCH,IAAa,SAAb,cAA4B,QAAQ,IAAI,SAAS,EAA4B,CAAC;AAE9E,MAAa,cAAc,UAAmB;CAC7C,MAAM,SAAS,IAAI,aAAa,MAAM;AACtC,QAAO,MAAM,QAAQ,QAAQ;EAC5B,mBAAmB,OAAO,SACzB,OAAO,WAAW;GACjB,QAAQ,UACP,IAAI,YAAY;IACf,UAAU,SAAS,MAAM,GAAG;IAC5B,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;IAC/D,CAAC;GACH,WAAW,OAAO,iBAAiB,OAAO,KAAK;GAC/C,CAAC;EACH,YAAY,OAAO,SAClB,OAAO,WAAW;GACjB,QAAQ,UACP,IAAI,YAAY;IACf,UAAU,SAAS,MAAM,GAAG,KAAK;IACjC,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;IAC/D,CAAC;GACH,WAAW,OAAO,UAAU,OAAO,KAAK;GACxC,CAAC;EACH,WAAW,OAAO,MAAM,MAAM,SAAS,SAAS,WAC/C,OAAO,WAAW;GACjB,QAAQ,UACP,IAAI,YAAY;IACf,UAAU,SAAS,MAAM,GAAG,KAAK,YAAY;IAC7C,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;IAC/D,CAAC;GACH,WAAW,OAAO,SAAS,OAAO,MAAM,MAAM,SAAS,SAAS,OAAO;GACvE,CAAC;EACH,YAAY,OAAO,MAAM,WACxB,OAAO,WAAW;GACjB,QAAQ,UACP,IAAI,YAAY;IACf,UAAU,SAAS,MAAM,GAAG,KAAK;IACjC,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;IAC/D,CAAC;GACH,WAAW,OAAO,UAAU,OAAO,MAAM,OAAO;GAChD,CAAC;EACH,aAAa,OAAO,MAAM,SACzB,OAAO,WAAW;GACjB,QAAQ,UACP,IAAI,YAAY;IACf,UAAU,SAAS,MAAM,GAAG;IAC5B,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;IAC/D,CAAC;GACH,WAAW,OAAO,WAAW,OAAO,MAAM,KAAK;GAC/C,CAAC;EACH,CAAC;;AASH,MAAa,aACZ,SACA,UAEA,OAAO,WAAW;CACjB,QAAQ,UACP,IAAI,eAAe;EAClB,OAAO;EACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;EAC/D,CAAC;CACH,WAAW,uBAAuB,SAAS,MAAM;CACjD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/config-file.d.ts
|
|
4
|
+
|
|
5
|
+
declare const CONFIG_PATH: string;
|
|
6
|
+
declare const ConfigFileSchema: Schema.Struct<{
|
|
7
|
+
geminiApiKey: Schema.optional<typeof Schema.String>;
|
|
8
|
+
githubToken: Schema.optional<typeof Schema.String>;
|
|
9
|
+
}>;
|
|
10
|
+
type ConfigFile = Schema.Schema.Type<typeof ConfigFileSchema>;
|
|
11
|
+
declare function writeConfigFile(config: ConfigFile): void;
|
|
12
|
+
declare function promptConfigSetup(): Promise<ConfigFile>;
|
|
13
|
+
declare function loadConfigFile(): ConfigFile;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { CONFIG_PATH, ConfigFile, ConfigFileSchema, loadConfigFile, promptConfigSetup, writeConfigFile };
|
|
16
|
+
//# sourceMappingURL=config-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-file.d.ts","names":[],"sources":["../../src/utils/config-file.ts"],"sourcesContent":[],"mappings":";;;;cAkCa;cAEA,kBAAgB,MAAA,CAAA;;;;KAKjB,UAAA,GAAa,MAAA,CAAO,MAAA,CAAO,YAAY;iBAEnC,eAAA,SAAwB;iBAiBlB,iBAAA,CAAA,GAAqB,QAAQ;iBA4BnC,cAAA,CAAA,GAAkB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Logger as Logger$1 } from "./logger.js";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { createInterface } from "node:readline";
|
|
7
|
+
//#region src/utils/config-file.ts
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* Copyright 2026 Mike Odnis
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
const logger = Logger$1.getLogger("GREPO:CONFIG");
|
|
26
|
+
const CONFIG_PATH = join(homedir(), ".config", "grepo", "config.json");
|
|
27
|
+
const ConfigFileSchema = Schema.Struct({
|
|
28
|
+
geminiApiKey: Schema.optional(Schema.String),
|
|
29
|
+
githubToken: Schema.optional(Schema.String)
|
|
30
|
+
});
|
|
31
|
+
function writeConfigFile(config) {
|
|
32
|
+
mkdirSync(CONFIG_PATH.replace(/\/[^/]+$/, ""), { recursive: true });
|
|
33
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
|
34
|
+
chmodSync(CONFIG_PATH, 384);
|
|
35
|
+
logger.info("Config file written", { path: CONFIG_PATH });
|
|
36
|
+
}
|
|
37
|
+
function ask(rl, question) {
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
rl.question(question, (answer) => {
|
|
40
|
+
resolve(answer);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async function promptConfigSetup() {
|
|
45
|
+
const rl = createInterface({
|
|
46
|
+
input: process.stdin,
|
|
47
|
+
output: process.stderr
|
|
48
|
+
});
|
|
49
|
+
try {
|
|
50
|
+
logger.info("No API keys found. Let's set up your config.");
|
|
51
|
+
const geminiApiKey = await ask(rl, " Gemini API key: ");
|
|
52
|
+
const githubToken = await ask(rl, " GitHub token (optional, press Enter to skip): ");
|
|
53
|
+
const config = {
|
|
54
|
+
geminiApiKey: geminiApiKey || void 0,
|
|
55
|
+
githubToken: githubToken || void 0
|
|
56
|
+
};
|
|
57
|
+
writeConfigFile(config);
|
|
58
|
+
return config;
|
|
59
|
+
} finally {
|
|
60
|
+
rl.close();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function loadConfigFile() {
|
|
64
|
+
if (!existsSync(CONFIG_PATH)) return {};
|
|
65
|
+
try {
|
|
66
|
+
const raw = readFileSync(CONFIG_PATH, "utf-8");
|
|
67
|
+
const parsed = JSON.parse(raw);
|
|
68
|
+
return Schema.decodeUnknownSync(ConfigFileSchema)(parsed);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
logger.warn("Failed to read config file", {
|
|
71
|
+
path: CONFIG_PATH,
|
|
72
|
+
error: error instanceof Error ? error.message : String(error)
|
|
73
|
+
});
|
|
74
|
+
return {};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { CONFIG_PATH, ConfigFileSchema, loadConfigFile, promptConfigSetup, writeConfigFile };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=config-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-file.js","names":["Logger"],"sources":["../../src/utils/config-file.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport {\n\tchmodSync,\n\texistsSync,\n\tmkdirSync,\n\treadFileSync,\n\twriteFileSync,\n} from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { createInterface, type Interface } from \"node:readline\";\nimport { Schema } from \"effect\";\n\nimport { Logger } from \"./logger.js\";\n\nconst logger = Logger.getLogger(\"GREPO:CONFIG\");\n\nexport const CONFIG_PATH = join(homedir(), \".config\", \"grepo\", \"config.json\");\n\nexport const ConfigFileSchema = Schema.Struct({\n\tgeminiApiKey: Schema.optional(Schema.String),\n\tgithubToken: Schema.optional(Schema.String),\n});\n\nexport type ConfigFile = Schema.Schema.Type<typeof ConfigFileSchema>;\n\nexport function writeConfigFile(config: ConfigFile): void {\n\tconst dir = CONFIG_PATH.replace(/\\/[^/]+$/, \"\");\n\tmkdirSync(dir, { recursive: true });\n\tconst content = JSON.stringify(config, null, 2);\n\twriteFileSync(CONFIG_PATH, content, \"utf-8\");\n\tchmodSync(CONFIG_PATH, 0o600);\n\tlogger.info(\"Config file written\", { path: CONFIG_PATH });\n}\n\nfunction ask(rl: Interface, question: string): Promise<string> {\n\treturn new Promise((resolve) => {\n\t\trl.question(question, (answer: string) => {\n\t\t\tresolve(answer);\n\t\t});\n\t});\n}\n\nexport async function promptConfigSetup(): Promise<ConfigFile> {\n\tconst rl = createInterface({\n\t\tinput: process.stdin,\n\t\toutput: process.stderr,\n\t});\n\n\ttry {\n\t\tlogger.info(\"No API keys found. Let's set up your config.\");\n\n\t\tconst geminiApiKey = await ask(rl, \" Gemini API key: \");\n\t\tconst githubToken = await ask(\n\t\t\trl,\n\t\t\t\" GitHub token (optional, press Enter to skip): \",\n\t\t);\n\n\t\tconst config: ConfigFile = {\n\t\t\tgeminiApiKey: geminiApiKey || undefined,\n\t\t\tgithubToken: githubToken || undefined,\n\t\t};\n\n\t\twriteConfigFile(config);\n\n\t\treturn config;\n\t} finally {\n\t\trl.close();\n\t}\n}\n\nexport function loadConfigFile(): ConfigFile {\n\tif (!existsSync(CONFIG_PATH)) {\n\t\treturn {};\n\t}\n\n\ttry {\n\t\tconst raw = readFileSync(CONFIG_PATH, \"utf-8\");\n\t\tconst parsed: unknown = JSON.parse(raw);\n\t\treturn Schema.decodeUnknownSync(ConfigFileSchema)(parsed);\n\t} catch (error) {\n\t\tlogger.warn(\"Failed to read config file\", {\n\t\t\tpath: CONFIG_PATH,\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t});\n\t\treturn {};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAM,SAASA,SAAO,UAAU,eAAe;A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E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.d.ts","names":[],"sources":["../../src/utils/gemini.ts"],"sourcesContent":[],"mappings":";;;;cAwBa,mBAAiB,MAAA,CAAA;;;;;;KAMlB,iBAAA,GAAoB,MAAA,CAAO,MAAA,CAAO,YAAY;cAE7C,aAAA;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","names":[],"sources":["../../src/utils/gemini.ts"],"sourcesContent":[],"mappings":";;;;cAwBa,mBAAiB,MAAA,CAAA;;;;;;KAMlB,iBAAA,GAAoB,MAAA,CAAO,MAAA,CAAO,YAAY;cAE7C,aAAA;;;;;;;;;4CA0GF,oBACP"}
|
package/lib/utils/gemini.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ApiError } from "./validation.js";
|
|
2
1
|
import { Logger as Logger$1 } from "./logger.js";
|
|
2
|
+
import { ApiError } from "./validation.js";
|
|
3
3
|
import { Schema } from "effect";
|
|
4
4
|
import { GoogleGenAI } from "@google/genai";
|
|
5
5
|
//#region src/utils/gemini.ts
|
|
@@ -45,7 +45,7 @@ var GeminiService = class {
|
|
|
45
45
|
return names;
|
|
46
46
|
} catch (error) {
|
|
47
47
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
48
|
-
this.logger.warn(`Failed to fetch models list`, { error: errorMsg });
|
|
48
|
+
this.logger.warn(`Failed to fetch models list, falling back to hardcoded defaults`, { error: errorMsg });
|
|
49
49
|
return [];
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -93,12 +93,16 @@ var GeminiService = class {
|
|
|
93
93
|
} catch (error) {
|
|
94
94
|
const nextModel = models[i + 1];
|
|
95
95
|
if (this.isRateLimitError(error) && nextModel) {
|
|
96
|
-
this.logger.warn(`Rate limited on ${modelName}, falling back to ${nextModel}
|
|
96
|
+
this.logger.warn(`Rate limited on ${modelName}, falling back to ${nextModel}`, {
|
|
97
|
+
model: modelName,
|
|
98
|
+
fallback: nextModel
|
|
99
|
+
});
|
|
97
100
|
continue;
|
|
98
101
|
}
|
|
99
102
|
throw new ApiError(`Gemini generation failed (${modelName}): ${error instanceof Error ? error.message : "Unknown error"}`, void 0, "Gemini API");
|
|
100
103
|
}
|
|
101
104
|
}
|
|
105
|
+
this.logger.warn("All Gemini models exhausted", { modelsAttempted: models.join(", ") });
|
|
102
106
|
throw new ApiError("All Gemini models exhausted", void 0, "Gemini API");
|
|
103
107
|
}
|
|
104
108
|
};
|
package/lib/utils/gemini.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.js","names":["Logger"],"sources":["../../src/utils/gemini.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport { GoogleGenAI, type Model } from \"@google/genai\";\nimport { Schema } from \"effect\";\n\nimport { Logger } from \"./logger.js\";\nimport { ApiError } from \"./validation.js\";\n\nexport const GenerationOptions = Schema.Struct({\n\tmodel: Schema.optional(Schema.String),\n\ttemperature: Schema.optional(Schema.Number),\n\ttopK: Schema.optional(Schema.Number),\n\ttopP: Schema.optional(Schema.Number),\n});\nexport type GenerationOptions = Schema.Schema.Type<typeof GenerationOptions>;\n\nexport class GeminiService {\n\tprivate readonly genAI: GoogleGenAI;\n\tprivate readonly logger: Logger;\n\n\tconstructor(apiKey: string) {\n\t\tthis.genAI = new GoogleGenAI({ apiKey });\n\t\tthis.logger = new Logger(\"GeminiService\");\n\t}\n\n\tprivate cachedModels: string[] | null = null;\n\n\tprivate async fetchAvailableModels(): Promise<string[]> {\n\t\tif (this.cachedModels) {\n\t\t\treturn this.cachedModels;\n\t\t}\n\n\t\ttry {\n\t\t\tconst modelsPager = await this.genAI.models.list();\n\t\t\tconst allModels: Model[] = [];\n\t\t\tfor await (const model of modelsPager) {\n\t\t\t\tallModels.push(model);\n\t\t\t}\n\n\t\t\tconst names = allModels\n\t\t\t\t.filter(\n\t\t\t\t\t(m) => m.name && m.supportedActions?.includes(\"generateContent\"),\n\t\t\t\t)\n\t\t\t\t.map((m) => (m.name ?? \"\").replace(\"models/\", \"\"));\n\n\t\t\tthis.cachedModels = names;\n\t\t\treturn names;\n\t\t} catch (error) {\n\t\t\tconst errorMsg = error instanceof Error ? error.message : String(error);\n\t\t\tthis.logger.warn(`Failed to fetch models list
|
|
1
|
+
{"version":3,"file":"gemini.js","names":["Logger"],"sources":["../../src/utils/gemini.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport { GoogleGenAI, type Model } from \"@google/genai\";\nimport { Schema } from \"effect\";\n\nimport { Logger } from \"./logger.js\";\nimport { ApiError } from \"./validation.js\";\n\nexport const GenerationOptions = Schema.Struct({\n\tmodel: Schema.optional(Schema.String),\n\ttemperature: Schema.optional(Schema.Number),\n\ttopK: Schema.optional(Schema.Number),\n\ttopP: Schema.optional(Schema.Number),\n});\nexport type GenerationOptions = Schema.Schema.Type<typeof GenerationOptions>;\n\nexport class GeminiService {\n\tprivate readonly genAI: GoogleGenAI;\n\tprivate readonly logger: Logger;\n\n\tconstructor(apiKey: string) {\n\t\tthis.genAI = new GoogleGenAI({ apiKey });\n\t\tthis.logger = new Logger(\"GeminiService\");\n\t}\n\n\tprivate cachedModels: string[] | null = null;\n\n\tprivate async fetchAvailableModels(): Promise<string[]> {\n\t\tif (this.cachedModels) {\n\t\t\treturn this.cachedModels;\n\t\t}\n\n\t\ttry {\n\t\t\tconst modelsPager = await this.genAI.models.list();\n\t\t\tconst allModels: Model[] = [];\n\t\t\tfor await (const model of modelsPager) {\n\t\t\t\tallModels.push(model);\n\t\t\t}\n\n\t\t\tconst names = allModels\n\t\t\t\t.filter(\n\t\t\t\t\t(m) => m.name && m.supportedActions?.includes(\"generateContent\"),\n\t\t\t\t)\n\t\t\t\t.map((m) => (m.name ?? \"\").replace(\"models/\", \"\"));\n\n\t\t\tthis.cachedModels = names;\n\t\t\treturn names;\n\t\t} catch (error) {\n\t\t\tconst errorMsg = error instanceof Error ? error.message : String(error);\n\t\t\tthis.logger.warn(\n\t\t\t\t`Failed to fetch models list, falling back to hardcoded defaults`,\n\t\t\t\t{ error: errorMsg },\n\t\t\t);\n\t\t\treturn [];\n\t\t}\n\t}\n\n\tprivate parseModelVersion(name: string): number {\n\t\tconst match = /(\\d+)\\.(\\d+)/.exec(name);\n\t\tif (!match) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn Number(match[1]) * 1000 + Number(match[2]);\n\t}\n\n\tprivate async getModelFallbackChain(preferred?: string): Promise<string[]> {\n\t\tconst available = await this.fetchAvailableModels();\n\n\t\tconst tierOf = (name: string) => {\n\t\t\tif (name.includes(\"flash-lite\")) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tif (name.includes(\"flash\")) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif (name.includes(\"pro\")) {\n\t\t\t\treturn 2;\n\t\t\t}\n\t\t\treturn 3;\n\t\t};\n\n\t\tconst ranked = available\n\t\t\t.filter(\n\t\t\t\t(m) =>\n\t\t\t\t\t!m.includes(\"embedding\") &&\n\t\t\t\t\t!m.includes(\"aqa\") &&\n\t\t\t\t\t!m.includes(\"imagen\") &&\n\t\t\t\t\t!m.includes(\"veo\") &&\n\t\t\t\t\t!m.includes(\"tts\"),\n\t\t\t)\n\t\t\t.sort((a, b) => {\n\t\t\t\tconst tierDiff = tierOf(a) - tierOf(b);\n\t\t\t\tif (tierDiff !== 0) {\n\t\t\t\t\treturn tierDiff;\n\t\t\t\t}\n\t\t\t\treturn this.parseModelVersion(b) - this.parseModelVersion(a);\n\t\t\t});\n\n\t\tif (preferred) {\n\t\t\treturn [preferred, ...ranked.filter((m) => m !== preferred)];\n\t\t}\n\n\t\treturn ranked.length > 0\n\t\t\t? ranked\n\t\t\t: [\"gemini-2.0-flash\", \"gemini-1.5-flash\"];\n\t}\n\n\tprivate isRateLimitError(error: unknown): boolean {\n\t\tif (!(error instanceof Error)) {\n\t\t\treturn false;\n\t\t}\n\t\tconst msg = error.message.toLowerCase();\n\t\treturn (\n\t\t\tmsg.includes(\"429\") ||\n\t\t\tmsg.includes(\"rate limit\") ||\n\t\t\tmsg.includes(\"resource exhausted\") ||\n\t\t\tmsg.includes(\"quota\")\n\t\t);\n\t}\n\n\tasync generateContent(\n\t\tprompt: string,\n\t\toptions: GenerationOptions = {},\n\t): Promise<string> {\n\t\tconst models = await this.getModelFallbackChain(options.model);\n\n\t\tfor (let i = 0; i < models.length; i++) {\n\t\t\tconst modelName = models[i];\n\t\t\tif (!modelName) continue;\n\t\t\ttry {\n\t\t\t\tconst result = await this.genAI.models.generateContent({\n\t\t\t\t\tcontents: [{ parts: [{ text: prompt }], role: \"user\" }],\n\t\t\t\t\tmodel: modelName,\n\t\t\t\t});\n\n\t\t\t\tconst text = result.text;\n\n\t\t\t\tif (!text) {\n\t\t\t\t\tthrow new ApiError(\n\t\t\t\t\t\t\"Gemini returned empty content\",\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\"Gemini API\",\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn text;\n\t\t\t} catch (error) {\n\t\t\t\tconst nextModel = models[i + 1];\n\t\t\t\tif (this.isRateLimitError(error) && nextModel) {\n\t\t\t\t\tthis.logger.warn(\n\t\t\t\t\t\t`Rate limited on ${modelName}, falling back to ${nextModel}`,\n\t\t\t\t\t\t{ model: modelName, fallback: nextModel },\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst message =\n\t\t\t\t\terror instanceof Error ? error.message : \"Unknown error\";\n\t\t\t\tthrow new ApiError(\n\t\t\t\t\t`Gemini generation failed (${modelName}): ${message}`,\n\t\t\t\t\tundefined,\n\t\t\t\t\t\"Gemini API\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tthis.logger.warn(\"All Gemini models exhausted\", {\n\t\t\tmodelsAttempted: models.join(\", \"),\n\t\t});\n\t\tthrow new ApiError(\"All Gemini models exhausted\", undefined, \"Gemini API\");\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,oBAAoB,OAAO,OAAO;CAC9C,OAAO,OAAO,SAAS,OAAO,OAAO;CACrC,aAAa,OAAO,SAAS,OAAO,OAAO;CAC3C,MAAM,OAAO,SAAS,OAAO,OAAO;CACpC,MAAM,OAAO,SAAS,OAAO,OAAO;CACpC,CAAC;AAGF,IAAa,gBAAb,MAA2B;CAC1B;CACA;CAEA,YAAY,QAAgB;AAC3B,OAAK,QAAQ,IAAI,YAAY,EAAE,QAAQ,CAAC;AACxC,OAAK,SAAS,IAAIA,SAAO,gBAAgB;;CAG1C,eAAwC;CAExC,MAAc,uBAA0C;AACvD,MAAI,KAAK,aACR,QAAO,KAAK;AAGb,MAAI;GACH,MAAM,cAAc,MAAM,KAAK,MAAM,OAAO,MAAM;GAClD,MAAM,YAAqB,EAAE;AAC7B,cAAW,MAAM,SAAS,YACzB,WAAU,KAAK,MAAM;GAGtB,MAAM,QAAQ,UACZ,QACC,MAAM,EAAE,QAAQ,EAAE,kBAAkB,SAAS,kBAAkB,CAChE,CACA,KAAK,OAAO,EAAE,QAAQ,IAAI,QAAQ,WAAW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IAClC,IAAI,SAAS,QAAQ;;CAIvB,MAAM,gBACL,QACA,UAA6B,EAAE,EACb;EAClB,MAAM,SAAS,MAAM,KAAK,sBAAsB,QAAQ,MAAM;AAE9D,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;GACvC,MAAM,YAAY,OAAO;AACzB,OAAI,CAAC,UAAW;AAChB,OAAI;IAMH,MAAM,QALS,MAAM,KAAK,MAAM,OAAO,gBAAgB;KACtD,UAAU,CAAC;MAAE,OAAO,CAAC,EAAE,MAAM,QAAQ,CAAC;MAAE,MAAM;MAAQ,CAAC;KACvD,OAAO;KACP,CAAC,EAEkB;AAEpB,QAAI,CAAC,KACJ,OAAM,IAAI,SACT,iCACA,KAAA,GACA,aACA;AAGF,WAAO;YACC,OAAO;IACf,MAAM,YAAY,OAAO,IAAI;AAC7B,QAAI,KAAK,iBAAiB,MAAM,IAAI,WAAW;AAC9C,UAAK,OAAO,KACX,mBAAmB,UAAU,oBAAoB,aACjD;MAAE,OAAO;MAAW,UAAU;MAAW,CACzC;AACD;;AAID,UAAM,IAAI,SACT,6BAA6B,UAAU,KAFvC,iBAAiB,QAAQ,MAAM,UAAU,mBAGzC,KAAA,GACA,aACA;;;AAIH,OAAK,OAAO,KAAK,+BAA+B,EAC/C,iBAAiB,OAAO,KAAK,KAAK,EAClC,CAAC;AACF,QAAM,IAAI,SAAS,+BAA+B,KAAA,GAAW,aAAa"}
|
package/lib/utils/github.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ declare class GitHubClient {
|
|
|
18
18
|
pushFile(owner: string, repo: string, path: string, content: string, message: string, branch: string): Promise<void>;
|
|
19
19
|
getTopics(owner: string, repo: string): Promise<readonly string[]>;
|
|
20
20
|
setTopics(owner: string, repo: string, topics: string[]): Promise<void>;
|
|
21
|
+
getDefaultBranch(owner: string, repo: string): Promise<string>;
|
|
21
22
|
updateRepo(owner: string, repo: string, data: {
|
|
22
23
|
description?: string;
|
|
23
24
|
homepage?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github.d.ts","names":[],"sources":["../../src/utils/github.ts"],"sourcesContent":[],"mappings":";;;;AA0II,cA/GS,iBA+GT,EA/G0B,MAAA,CAAA,MA+G1B,CAAA;
|
|
1
|
+
{"version":3,"file":"github.d.ts","names":[],"sources":["../../src/utils/github.ts"],"sourcesContent":[],"mappings":";;;;AA0II,cA/GS,iBA+GT,EA/G0B,MAAA,CAAA,MA+G1B,CAAA;EAsBkD,OAAA,EAAA,oBAAA;EAoBlD,QAAA,EAAA,oBAAA;EAAO,IAAA,EAAA,oBAAA;;;;;cAhJE,YAAA;;;;sDAkBT,QAAQ,MAAA,CAAO,MAAA,CAAO,YAAY;yGAmClC;0CA6B2C;4DAoB3C;iDAsBkD;;;;MAoBlD"}
|
package/lib/utils/github.js
CHANGED
|
@@ -80,6 +80,13 @@ var GitHubClient = class {
|
|
|
80
80
|
"Content-Type": "application/json"
|
|
81
81
|
} }), FetchHttpClient.layer));
|
|
82
82
|
}
|
|
83
|
+
async getDefaultBranch(owner, repo) {
|
|
84
|
+
const RepoResponse = Schema.Struct({ default_branch: Schema.String });
|
|
85
|
+
return (await Effect.runPromise(Effect.provide(get(`${GITHUB_API}/repos/${owner}/${repo}`, {
|
|
86
|
+
headers: this.headers,
|
|
87
|
+
schema: RepoResponse
|
|
88
|
+
}), FetchHttpClient.layer))).default_branch;
|
|
89
|
+
}
|
|
83
90
|
async updateRepo(owner, repo, data) {
|
|
84
91
|
if (!this.token) throw new Error("GitHub token is required for updating repository");
|
|
85
92
|
await Effect.runPromise(Effect.provide(patch(`${GITHUB_API}/repos/${owner}/${repo}`, data, { headers: {
|
package/lib/utils/github.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github.js","names":[],"sources":["../../src/utils/github.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport * as FetchHttpClient from \"@effect/platform/FetchHttpClient\";\nimport { Effect, Schema } from \"effect\";\n\nimport { get, patch, put } from \"./fetcher.js\";\nimport { ApiError } from \"./validation.js\";\n\nconst GITHUB_API = \"https://api.github.com\" as const;\nconst GITHUB_API_VERSION = \"2022-11-28\" as const;\n\nexport const GitHubFileContent = Schema.Struct({\n\tcontent: Schema.String,\n\tencoding: Schema.String,\n\tname: Schema.String,\n\tpath: Schema.String,\n\tsha: Schema.String,\n\tsize: Schema.Number,\n});\n\nexport class GitHubClient {\n\tconstructor(private readonly token?: string) {}\n\n\tprivate get headers(): Record<string, string> {\n\t\tconst headers: Record<string, string> = {\n\t\t\tAccept: \"application/vnd.github+json\",\n\t\t\t\"X-GitHub-Api-Version\": GITHUB_API_VERSION,\n\t\t};\n\t\tif (this.token) {\n\t\t\theaders.Authorization = `Bearer ${this.token}`;\n\t\t}\n\t\treturn headers;\n\t}\n\n\tasync getFile(\n\t\towner: string,\n\t\trepo: string,\n\t\tpath: string,\n\t): Promise<Schema.Schema.Type<typeof GitHubFileContent> | null> {\n\t\ttry {\n\t\t\treturn Effect.runPromise(\n\t\t\t\tEffect.provide(\n\t\t\t\t\tget(`${GITHUB_API}/repos/${owner}/${repo}/contents/${path}`, {\n\t\t\t\t\t\theaders: this.headers,\n\t\t\t\t\t\tschema: GitHubFileContent,\n\t\t\t\t\t}),\n\t\t\t\t\tFetchHttpClient.layer,\n\t\t\t\t),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror &&\n\t\t\t\ttypeof error === \"object\" &&\n\t\t\t\t\"status\" in error &&\n\t\t\t\terror.status === 404\n\t\t\t) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tthrow new ApiError(\n\t\t\t\t`GitHub API error: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\tundefined,\n\t\t\t\t\"GitHub API\",\n\t\t\t);\n\t\t}\n\t}\n\n\tasync pushFile(\n\t\towner: string,\n\t\trepo: string,\n\t\tpath: string,\n\t\tcontent: string,\n\t\tmessage: string,\n\t\tbranch: string,\n\t): Promise<void> {\n\t\tif (!this.token) {\n\t\t\tthrow new Error(\"GitHub token is required for push operations\");\n\t\t}\n\n\t\tconst existingFile = await this.getFile(owner, repo, path);\n\n\t\tawait Effect.runPromise(\n\t\t\tEffect.provide(\n\t\t\t\tput(\n\t\t\t\t\t`${GITHUB_API}/repos/${owner}/${repo}/contents/${path}`,\n\t\t\t\t\t{\n\t\t\t\t\t\tbranch,\n\t\t\t\t\t\tcontent: Buffer.from(content).toString(\"base64\"),\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\t...(existingFile && { sha: existingFile.sha }),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t...this.headers,\n\t\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t\tFetchHttpClient.layer,\n\t\t\t),\n\t\t);\n\t}\n\n\tasync getTopics(owner: string, repo: string): Promise<readonly string[]> {\n\t\tconst TopicsResponse = Schema.Struct({\n\t\t\tnames: Schema.Array(Schema.String),\n\t\t});\n\t\tconst result = await Effect.runPromise(\n\t\t\tEffect.provide(\n\t\t\t\tget(`${GITHUB_API}/repos/${owner}/${repo}/topics`, {\n\t\t\t\t\theaders: this.headers,\n\t\t\t\t\tschema: TopicsResponse,\n\t\t\t\t}),\n\t\t\t\tFetchHttpClient.layer,\n\t\t\t),\n\t\t);\n\t\treturn result.names;\n\t}\n\n\tasync setTopics(\n\t\towner: string,\n\t\trepo: string,\n\t\ttopics: string[],\n\t): Promise<void> {\n\t\tif (!this.token) {\n\t\t\tthrow new Error(\"GitHub token is required for setting topics\");\n\t\t}\n\n\t\tawait Effect.runPromise(\n\t\t\tEffect.provide(\n\t\t\t\tput(\n\t\t\t\t\t`${GITHUB_API}/repos/${owner}/${repo}/topics`,\n\t\t\t\t\t{ names: topics },\n\t\t\t\t\t{\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t...this.headers,\n\t\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t\tFetchHttpClient.layer,\n\t\t\t),\n\t\t);\n\t}\n\n\tasync updateRepo(\n\t\towner: string,\n\t\trepo: string,\n\t\tdata: { description?: string; homepage?: string },\n\t): Promise<void> {\n\t\tif (!this.token) {\n\t\t\tthrow new Error(\"GitHub token is required for updating repository\");\n\t\t}\n\n\t\tawait Effect.runPromise(\n\t\t\tEffect.provide(\n\t\t\t\tpatch(`${GITHUB_API}/repos/${owner}/${repo}`, data, {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t...this.headers,\n\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\tFetchHttpClient.layer,\n\t\t\t),\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,aAAa;AACnB,MAAM,qBAAqB;AAE3B,MAAa,oBAAoB,OAAO,OAAO;CAC9C,SAAS,OAAO;CAChB,UAAU,OAAO;CACjB,MAAM,OAAO;CACb,MAAM,OAAO;CACb,KAAK,OAAO;CACZ,MAAM,OAAO;CACb,CAAC;AAEF,IAAa,eAAb,MAA0B;CACzB,YAAY,OAAiC;AAAhB,OAAA,QAAA;;CAE7B,IAAY,UAAkC;EAC7C,MAAM,UAAkC;GACvC,QAAQ;GACR,wBAAwB;GACxB;AACD,MAAI,KAAK,MACR,SAAQ,gBAAgB,UAAU,KAAK;AAExC,SAAO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AW,SAAS,MAAM,GAAG,KAAK,UACrC,EAAE,OAAO,QAAQ,EACjB,EACC,SAAS;GACR,GAAG,KAAK;GACR,gBAAgB;GAChB,EACD,CACD,EACD,gBAAgB,MAChB,CACD;;CAGF,MAAM,WACL,OACA,MACA,MACgB;AAChB,MAAI,CAAC,KAAK,MACT,OAAM,IAAI,MAAM,mDAAmD;AAGpE,QAAM,OAAO,WACZ,OAAO,QACN,MAAM,GAAG,WAAW,SAAS,MAAM,GAAG,QAAQ,MAAM,EACnD,SAAS;GACR,GAAG,KAAK;GACR,gBAAgB;GAChB,EACD,CAAC,EACF,gBAAgB,MAChB,CACD"}
|
|
1
|
+
{"version":3,"file":"github.js","names":[],"sources":["../../src/utils/github.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport * as FetchHttpClient from \"@effect/platform/FetchHttpClient\";\nimport { Effect, Schema } from \"effect\";\n\nimport { get, patch, put } from \"./fetcher.js\";\nimport { ApiError } from \"./validation.js\";\n\nconst GITHUB_API = \"https://api.github.com\" as const;\nconst GITHUB_API_VERSION = \"2022-11-28\" as const;\n\nexport const GitHubFileContent = Schema.Struct({\n\tcontent: Schema.String,\n\tencoding: Schema.String,\n\tname: Schema.String,\n\tpath: Schema.String,\n\tsha: Schema.String,\n\tsize: Schema.Number,\n});\n\nexport class GitHubClient {\n\tconstructor(private readonly token?: string) {}\n\n\tprivate get headers(): Record<string, string> {\n\t\tconst headers: Record<string, string> = {\n\t\t\tAccept: \"application/vnd.github+json\",\n\t\t\t\"X-GitHub-Api-Version\": GITHUB_API_VERSION,\n\t\t};\n\t\tif (this.token) {\n\t\t\theaders.Authorization = `Bearer ${this.token}`;\n\t\t}\n\t\treturn headers;\n\t}\n\n\tasync getFile(\n\t\towner: string,\n\t\trepo: string,\n\t\tpath: string,\n\t): Promise<Schema.Schema.Type<typeof GitHubFileContent> | null> {\n\t\ttry {\n\t\t\treturn Effect.runPromise(\n\t\t\t\tEffect.provide(\n\t\t\t\t\tget(`${GITHUB_API}/repos/${owner}/${repo}/contents/${path}`, {\n\t\t\t\t\t\theaders: this.headers,\n\t\t\t\t\t\tschema: GitHubFileContent,\n\t\t\t\t\t}),\n\t\t\t\t\tFetchHttpClient.layer,\n\t\t\t\t),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror &&\n\t\t\t\ttypeof error === \"object\" &&\n\t\t\t\t\"status\" in error &&\n\t\t\t\terror.status === 404\n\t\t\t) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tthrow new ApiError(\n\t\t\t\t`GitHub API error: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\tundefined,\n\t\t\t\t\"GitHub API\",\n\t\t\t);\n\t\t}\n\t}\n\n\tasync pushFile(\n\t\towner: string,\n\t\trepo: string,\n\t\tpath: string,\n\t\tcontent: string,\n\t\tmessage: string,\n\t\tbranch: string,\n\t): Promise<void> {\n\t\tif (!this.token) {\n\t\t\tthrow new Error(\"GitHub token is required for push operations\");\n\t\t}\n\n\t\tconst existingFile = await this.getFile(owner, repo, path);\n\n\t\tawait Effect.runPromise(\n\t\t\tEffect.provide(\n\t\t\t\tput(\n\t\t\t\t\t`${GITHUB_API}/repos/${owner}/${repo}/contents/${path}`,\n\t\t\t\t\t{\n\t\t\t\t\t\tbranch,\n\t\t\t\t\t\tcontent: Buffer.from(content).toString(\"base64\"),\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\t...(existingFile && { sha: existingFile.sha }),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t...this.headers,\n\t\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t\tFetchHttpClient.layer,\n\t\t\t),\n\t\t);\n\t}\n\n\tasync getTopics(owner: string, repo: string): Promise<readonly string[]> {\n\t\tconst TopicsResponse = Schema.Struct({\n\t\t\tnames: Schema.Array(Schema.String),\n\t\t});\n\t\tconst result = await Effect.runPromise(\n\t\t\tEffect.provide(\n\t\t\t\tget(`${GITHUB_API}/repos/${owner}/${repo}/topics`, {\n\t\t\t\t\theaders: this.headers,\n\t\t\t\t\tschema: TopicsResponse,\n\t\t\t\t}),\n\t\t\t\tFetchHttpClient.layer,\n\t\t\t),\n\t\t);\n\t\treturn result.names;\n\t}\n\n\tasync setTopics(\n\t\towner: string,\n\t\trepo: string,\n\t\ttopics: string[],\n\t): Promise<void> {\n\t\tif (!this.token) {\n\t\t\tthrow new Error(\"GitHub token is required for setting topics\");\n\t\t}\n\n\t\tawait Effect.runPromise(\n\t\t\tEffect.provide(\n\t\t\t\tput(\n\t\t\t\t\t`${GITHUB_API}/repos/${owner}/${repo}/topics`,\n\t\t\t\t\t{ names: topics },\n\t\t\t\t\t{\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t...this.headers,\n\t\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t\tFetchHttpClient.layer,\n\t\t\t),\n\t\t);\n\t}\n\n\tasync getDefaultBranch(owner: string, repo: string): Promise<string> {\n\t\tconst RepoResponse = Schema.Struct({\n\t\t\tdefault_branch: Schema.String,\n\t\t});\n\t\tconst result = await Effect.runPromise(\n\t\t\tEffect.provide(\n\t\t\t\tget(`${GITHUB_API}/repos/${owner}/${repo}`, {\n\t\t\t\t\theaders: this.headers,\n\t\t\t\t\tschema: RepoResponse,\n\t\t\t\t}),\n\t\t\t\tFetchHttpClient.layer,\n\t\t\t),\n\t\t);\n\t\treturn result.default_branch;\n\t}\n\n\tasync updateRepo(\n\t\towner: string,\n\t\trepo: string,\n\t\tdata: { description?: string; homepage?: string },\n\t): Promise<void> {\n\t\tif (!this.token) {\n\t\t\tthrow new Error(\"GitHub token is required for updating repository\");\n\t\t}\n\n\t\tawait Effect.runPromise(\n\t\t\tEffect.provide(\n\t\t\t\tpatch(`${GITHUB_API}/repos/${owner}/${repo}`, data, {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t...this.headers,\n\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\tFetchHttpClient.layer,\n\t\t\t),\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,aAAa;AACnB,MAAM,qBAAqB;AAE3B,MAAa,oBAAoB,OAAO,OAAO;CAC9C,SAAS,OAAO;CAChB,UAAU,OAAO;CACjB,MAAM,OAAO;CACb,MAAM,OAAO;CACb,KAAK,OAAO;CACZ,MAAM,OAAO;CACb,CAAC;AAEF,IAAa,eAAb,MAA0B;CACzB,YAAY,OAAiC;AAAhB,OAAA,QAAA;;CAE7B,IAAY,UAAkC;EAC7C,MAAM,UAAkC;GACvC,QAAQ;GACR,wBAAwB;GACxB;AACD,MAAI,KAAK,MACR,SAAQ,gBAAgB,UAAU,KAAK;AAExC,SAAO;;CAGR,MAAM,QACL,OACA,MACA,MAC+D;AAC/D,MAAI;AACH,UAAO,OAAO,WACb,OAAO,QACN,IAAI,GAAG,WAAW,SAAS,MAAM,GAAG,KAAK,YAAY,QAAQ;IAC5D,SAAS,KAAK;IACd,QAAQ;IACR,CAAC,EACF,gBAAgB,MAChB,CACD;WACO,OAAO;AACf,OACC,SACA,OAAO,UAAU,YACjB,YAAY,SACZ,MAAM,WAAW,IAEjB,QAAO;AAER,SAAM,IAAI,SACT,qBAAqB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM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GACR,CAAC,EACF,gBAAgB,MAChB,CACD,EACa;;CAGf,MAAM,WACL,OACA,MACA,MACgB;AAChB,MAAI,CAAC,KAAK,MACT,OAAM,IAAI,MAAM,mDAAmD;AAGpE,QAAM,OAAO,WACZ,OAAO,QACN,MAAM,GAAG,WAAW,SAAS,MAAM,GAAG,QAAQ,MAAM,EACnD,SAAS;GACR,GAAG,KAAK;GACR,gBAAgB;GAChB,EACD,CAAC,EACF,gBAAgB,MAChB,CACD"}
|
package/lib/utils/gitingest.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare const GitIngestResponse: Schema.Struct<{
|
|
|
13
13
|
summary: typeof Schema.String;
|
|
14
14
|
tree: typeof Schema.String;
|
|
15
15
|
}>;
|
|
16
|
-
declare function fetchRepositoryContent(repoUrl: string, maxFileSize?: string): Promise<Schema.Schema.Type<typeof GitIngestResponse>>;
|
|
16
|
+
declare function fetchRepositoryContent(repoUrl: string, token?: string, maxFileSize?: string): Promise<Schema.Schema.Type<typeof GitIngestResponse>>;
|
|
17
17
|
//#endregion
|
|
18
18
|
export { GitIngestResponse, fetchRepositoryContent };
|
|
19
19
|
//# sourceMappingURL=gitingest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitingest.d.ts","names":[],"sources":["../../src/utils/gitingest.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"gitingest.d.ts","names":[],"sources":["../../src/utils/gitingest.ts"],"sourcesContent":[],"mappings":";;;;AAyCG,cAhBU,iBAgBV,EAhB2B,MAAA,CAAA,MAgB3B,CAAA;EAAO,OAAA,EAAA,oBAAA;;;;;;;;;;iBAJY,sBAAA,yDAInB,QAAQ,MAAA,CAAO,MAAA,CAAO,YAAY"}
|
package/lib/utils/gitingest.js
CHANGED
|
@@ -31,13 +31,13 @@ const GitIngestResponse = Schema.Struct({
|
|
|
31
31
|
summary: Schema.String,
|
|
32
32
|
tree: Schema.String
|
|
33
33
|
});
|
|
34
|
-
async function fetchRepositoryContent(repoUrl, maxFileSize = "1118") {
|
|
34
|
+
async function fetchRepositoryContent(repoUrl, token, maxFileSize = "1118") {
|
|
35
35
|
return Effect.runPromise(Effect.provide(post(GITINGEST_API, {
|
|
36
36
|
input_text: repoUrl,
|
|
37
37
|
max_file_size: maxFileSize,
|
|
38
38
|
pattern: "",
|
|
39
39
|
pattern_type: "exclude",
|
|
40
|
-
token: ""
|
|
40
|
+
token: token ?? ""
|
|
41
41
|
}, { schema: GitIngestResponse }), FetchHttpClient.layer));
|
|
42
42
|
}
|
|
43
43
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitingest.js","names":[],"sources":["../../src/utils/gitingest.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport * as FetchHttpClient from \"@effect/platform/FetchHttpClient\";\nimport { Effect, Schema } from \"effect\";\n\nimport { post } from \"./fetcher.js\";\n\nconst GITINGEST_API = \"https://gitingest.com/api/ingest\" as const;\n\nexport const GitIngestResponse = Schema.Struct({\n\tcontent: Schema.String,\n\tdefault_max_file_size: Schema.Number,\n\tdigest_url: Schema.String,\n\tpattern: Schema.String,\n\tpattern_type: Schema.String,\n\trepo_url: Schema.String,\n\tshort_repo_url: Schema.String,\n\tsummary: Schema.String,\n\ttree: Schema.String,\n});\n\nexport async function fetchRepositoryContent(\n\trepoUrl: string,\n\tmaxFileSize: string = \"1118\",\n): Promise<Schema.Schema.Type<typeof GitIngestResponse>> {\n\treturn Effect.runPromise(\n\t\tEffect.provide(\n\t\t\tpost(\n\t\t\t\tGITINGEST_API,\n\t\t\t\t{\n\t\t\t\t\tinput_text: repoUrl,\n\t\t\t\t\tmax_file_size: maxFileSize,\n\t\t\t\t\tpattern: \"\",\n\t\t\t\t\tpattern_type: \"exclude\",\n\t\t\t\t\ttoken: \"\",\n\t\t\t\t},\n\t\t\t\t{ schema: GitIngestResponse },\n\t\t\t),\n\t\t\tFetchHttpClient.layer,\n\t\t),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,gBAAgB;AAEtB,MAAa,oBAAoB,OAAO,OAAO;CAC9C,SAAS,OAAO;CAChB,uBAAuB,OAAO;CAC9B,YAAY,OAAO;CACnB,SAAS,OAAO;CAChB,cAAc,OAAO;CACrB,UAAU,OAAO;CACjB,gBAAgB,OAAO;CACvB,SAAS,OAAO;CAChB,MAAM,OAAO;CACb,CAAC;AAEF,eAAsB,uBACrB,SACA,cAAsB,QACkC;AACxD,QAAO,OAAO,WACb,OAAO,QACN,KACC,eACA;EACC,YAAY;EACZ,eAAe;EACf,SAAS;EACT,cAAc;EACd,OAAO;
|
|
1
|
+
{"version":3,"file":"gitingest.js","names":[],"sources":["../../src/utils/gitingest.ts"],"sourcesContent":["/**\n *\n * Copyright 2026 Mike Odnis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport * as FetchHttpClient from \"@effect/platform/FetchHttpClient\";\nimport { Effect, Schema } from \"effect\";\n\nimport { post } from \"./fetcher.js\";\n\nconst GITINGEST_API = \"https://gitingest.com/api/ingest\" as const;\n\nexport const GitIngestResponse = Schema.Struct({\n\tcontent: Schema.String,\n\tdefault_max_file_size: Schema.Number,\n\tdigest_url: Schema.String,\n\tpattern: Schema.String,\n\tpattern_type: Schema.String,\n\trepo_url: Schema.String,\n\tshort_repo_url: Schema.String,\n\tsummary: Schema.String,\n\ttree: Schema.String,\n});\n\nexport async function fetchRepositoryContent(\n\trepoUrl: string,\n\ttoken?: string,\n\tmaxFileSize: string = \"1118\",\n): Promise<Schema.Schema.Type<typeof GitIngestResponse>> {\n\treturn Effect.runPromise(\n\t\tEffect.provide(\n\t\t\tpost(\n\t\t\t\tGITINGEST_API,\n\t\t\t\t{\n\t\t\t\t\tinput_text: repoUrl,\n\t\t\t\t\tmax_file_size: maxFileSize,\n\t\t\t\t\tpattern: \"\",\n\t\t\t\t\tpattern_type: \"exclude\",\n\t\t\t\t\ttoken: token ?? \"\",\n\t\t\t\t},\n\t\t\t\t{ schema: GitIngestResponse },\n\t\t\t),\n\t\t\tFetchHttpClient.layer,\n\t\t),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,gBAAgB;AAEtB,MAAa,oBAAoB,OAAO,OAAO;CAC9C,SAAS,OAAO;CAChB,uBAAuB,OAAO;CAC9B,YAAY,OAAO;CACnB,SAAS,OAAO;CAChB,cAAc,OAAO;CACrB,UAAU,OAAO;CACjB,gBAAgB,OAAO;CACvB,SAAS,OAAO;CAChB,MAAM,OAAO;CACb,CAAC;AAEF,eAAsB,uBACrB,SACA,OACA,cAAsB,QACkC;AACxD,QAAO,OAAO,WACb,OAAO,QACN,KACC,eACA;EACC,YAAY;EACZ,eAAe;EACf,SAAS;EACT,cAAc;EACd,OAAO,SAAS;EAChB,EACD,EAAE,QAAQ,mBAAmB,CAC7B,EACD,gBAAgB,MAChB,CACD"}
|