-
Notifications
You must be signed in to change notification settings - Fork 4
docs: integrate npm package documentation #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| --- | ||
| title: Adapters | ||
| description: ILanguageAdapter — pluggable analysis, transforms, and verification. | ||
| --- | ||
|
|
||
| ## Interface | ||
|
|
||
| Language adapters implement `ILanguageAdapter` (`src/adapters/interface.ts`): | ||
|
|
||
| ```typescript | ||
| interface ILanguageAdapter { | ||
| readonly name: string; | ||
| readonly extensions: string[]; | ||
| readonly displayName: string; | ||
|
|
||
| detect(projectRoot: string): Promise<boolean>; | ||
|
|
||
| analyze(files: string[]): Promise<CodeIssue[]>; | ||
|
|
||
| transform(file: string, code: string, issue: CodeIssue): Promise<TransformResult>; | ||
|
|
||
| verifySyntax(path: string, code: string): Promise<CheckResult>; | ||
| verifyImports(path: string, code: string): Promise<CheckResult>; | ||
| verifyTests(path: string, code: string): Promise<CheckResult>; | ||
|
|
||
| generateDiff(original: string, transformed: string): string; | ||
|
|
||
| buildImportGraph(projectRoot: string): Promise<ImportGraph>; | ||
| buildCallGraph(files: string[]): Promise<CallGraph>; | ||
| } | ||
| ``` | ||
|
|
||
| **Contract:** `analyze` must return issues with **blast radius** populated for every item. | ||
|
|
||
| --- | ||
|
|
||
| ## Graphs | ||
|
|
||
| - **ImportGraph** — `dependentsOf`, `dependenciesOf`, `allFiles` for blast radius fan-in. | ||
| - **CallGraph** — `transitiveCallersOf`, `allPublicFunctionsIn` for function-level impact. | ||
|
|
||
| --- | ||
|
|
||
| ## Built-in adapters | ||
|
|
||
| | Adapter | Module | Notes | | ||
| |---------|--------|------| | ||
| | Python | `PythonAdapter` | Full analyzer suite | | ||
| | TypeScript | `TypeScriptAdapter` | Graphs + verification; static analysis coverage varies by version | | ||
|
|
||
| `AdapterRegistry` discovers adapters and scores them against the project. | ||
|
|
||
| --- | ||
|
|
||
| ## Transforms | ||
|
|
||
| `transform` returns `TransformResult` with `transformedCode`, human-readable `description`, and a coarse `riskLevel`. The **autofix engine** chooses fixers by issue; verification runs **after** transform. | ||
|
|
||
| --- | ||
|
|
||
| ## See also | ||
|
|
||
| - [Languages](/docs-npm/languages/python) | ||
| - [Orchestrator](/docs-npm/api/orchestrator) | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,110 @@ | ||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||
| title: Models | ||||||||||||||||||||||||||||||
| description: Core types for issues, blast radius, verification, and analysis results. | ||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## Severity and blast levels | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ```typescript | ||||||||||||||||||||||||||||||
| type Severity = 'critical' | 'high' | 'medium' | 'low'; | ||||||||||||||||||||||||||||||
| type BlastLevel = 'trivial' | 'low' | 'medium' | 'high' | 'critical'; | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## BlastRadius | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Every `CodeIssue` carries a non-optional `BlastRadius`: | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ```typescript | ||||||||||||||||||||||||||||||
| interface BlastRadius { | ||||||||||||||||||||||||||||||
| affectedFiles: string[]; | ||||||||||||||||||||||||||||||
| affectedFunctions: string[]; | ||||||||||||||||||||||||||||||
| affectedTestFiles: string[]; | ||||||||||||||||||||||||||||||
| score: number; // 0–100 | ||||||||||||||||||||||||||||||
| level: BlastLevel; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## TemporalProfile | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Optional enrichment when Git history is available: | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ```typescript | ||||||||||||||||||||||||||||||
| interface TemporalProfile { | ||||||||||||||||||||||||||||||
| lastModified: Date; | ||||||||||||||||||||||||||||||
| changeVelocity: number; | ||||||||||||||||||||||||||||||
| coChangePairs: string[]; | ||||||||||||||||||||||||||||||
| daysSinceLastTouch: number; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## CodeIssue | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ```typescript | ||||||||||||||||||||||||||||||
| interface CodeIssue { | ||||||||||||||||||||||||||||||
| id: string; | ||||||||||||||||||||||||||||||
| file: string; | ||||||||||||||||||||||||||||||
| line: number; | ||||||||||||||||||||||||||||||
| column?: number; | ||||||||||||||||||||||||||||||
| severity: Severity; | ||||||||||||||||||||||||||||||
| type: string; | ||||||||||||||||||||||||||||||
| message: string; | ||||||||||||||||||||||||||||||
| suggestion?: string; | ||||||||||||||||||||||||||||||
| fixable: boolean; | ||||||||||||||||||||||||||||||
| fixerName?: string; | ||||||||||||||||||||||||||||||
| blastRadius: BlastRadius; | ||||||||||||||||||||||||||||||
| temporal?: TemporalProfile; | ||||||||||||||||||||||||||||||
| ruleId: string; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## VerificationResult | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ```typescript | ||||||||||||||||||||||||||||||
| interface VerificationResult { | ||||||||||||||||||||||||||||||
| safeToApply: boolean; | ||||||||||||||||||||||||||||||
| passed: boolean; | ||||||||||||||||||||||||||||||
| checksRun: string[]; | ||||||||||||||||||||||||||||||
| checksPassed: string[]; | ||||||||||||||||||||||||||||||
| checksFailed: string[]; | ||||||||||||||||||||||||||||||
| blockingReason?: string; | ||||||||||||||||||||||||||||||
| confidenceScore: number; | ||||||||||||||||||||||||||||||
| verificationMs: number; | ||||||||||||||||||||||||||||||
| skippedChecks: string[]; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## AnalysisResult | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ```typescript | ||||||||||||||||||||||||||||||
| interface AnalysisResult { | ||||||||||||||||||||||||||||||
| target: string; | ||||||||||||||||||||||||||||||
| filesAnalyzed: number; | ||||||||||||||||||||||||||||||
| filesSkipped: number; | ||||||||||||||||||||||||||||||
| issues: CodeIssue[]; | ||||||||||||||||||||||||||||||
| languageBreakdown: Record<string, number>; | ||||||||||||||||||||||||||||||
| durationMs: number; | ||||||||||||||||||||||||||||||
| timestamp: Date; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## Pipeline / fix queue | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| The orchestrator uses `PipelineSession`, `FixQueueItem`, `FixStatus`, and related types for fix application and blocking. See `src/core/models.ts` for full definitions. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## Source | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Definitions live in `src/core/models.ts` in the repository. | ||||||||||||||||||||||||||||||
|
Comment on lines
+104
to
+110
|
||||||||||||||||||||||||||||||
| The orchestrator uses `PipelineSession`, `FixQueueItem`, `FixStatus`, and related types for fix application and blocking. See `src/core/models.ts` for full definitions. | |
| --- | |
| ## Source | |
| Definitions live in `src/core/models.ts` in the repository. | |
| The orchestrator uses `PipelineSession`, `FixQueueItem`, `FixStatus`, and related types for fix application and blocking. These additional types are part of the TypeScript/npm implementation, but the `src/core/models.ts` path referenced previously is not present in this repository. | |
| --- | |
| ## Source | |
| This page documents the public model shapes shown above. The previously referenced `src/core/models.ts` path is not present in this repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Checking for referenced TypeScript models path..."
fd -a "models.ts" || true
rg -n "src/core/models.ts|refactron/core/models.py" docs/docs-npm/api/models.mdx refactron/core/models.py || true
echo
echo "If src/core/models.ts is absent and refactron/core/models.py exists, docs path is incorrect for this repository."Repository: Refactron-ai/Refactron_lib
Length of output: 528
🏁 Script executed:
# Check repository root structure
git ls-files | head -30
# Look for src/ directory
fd -type d "src" --max-depth 2
# Check for any TypeScript files in the repo
fd -type f "\.ts$" | head -20
# Verify Python structure
fd -type d "refactron" --max-depth 1Repository: Refactron-ai/Refactron_lib
Length of output: 1351
🏁 Script executed:
# Check the actual models.py file to understand the structure
cat -n refactron/core/models.py | head -50Repository: Refactron-ai/Refactron_lib
Length of output: 1646
Documentation path references non-existent TypeScript file.
Lines 104 and 110 direct readers to src/core/models.ts, but this repository contains Python source code with model definitions in refactron/core/models.py. The src/ directory does not exist. Either update the reference to point to refactron/core/models.py or clarify if this documentation targets a separate JavaScript/TypeScript package.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/docs-npm/api/models.mdx` around lines 104 - 110, The docs reference the
non-existent TypeScript file src/core/models.ts; update the link and text to
point to the actual Python source refactron/core/models.py (or explicitly state
this doc targets a separate JS/TS package if that was intended) and ensure the
types mentioned (PipelineSession, FixQueueItem, FixStatus) are referenced to
their Python definitions or a note is added clarifying language mismatch.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,64 @@ | ||||||
| --- | ||||||
| title: Orchestrator | ||||||
| description: High-level analyze and autofix pipeline. | ||||||
| --- | ||||||
|
|
||||||
| ## Class | ||||||
|
|
||||||
| ```typescript | ||||||
| class Orchestrator { | ||||||
| constructor( | ||||||
| adapter: ILanguageAdapter, | ||||||
| config: RefactronConfig, | ||||||
| projectRoot: string, | ||||||
| ); | ||||||
|
|
||||||
| analyze(target: string): Promise<OrchestratorResult>; | ||||||
|
|
||||||
| autofix( | ||||||
| target: string, | ||||||
| options?: { dryRun?: boolean; verify?: boolean }, | ||||||
| ): Promise<{ session: PipelineSession; analysis: AnalysisResult }>; | ||||||
|
|
||||||
| autofixFromAnalysis( | ||||||
| analysis: AnalysisResult, | ||||||
| options?: { dryRun?: boolean; verify?: boolean }, | ||||||
| ): Promise<PipelineSession>; | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| `OrchestratorResult` bundles a `PipelineSession` with the `AnalysisResult` from **`analyze`**. | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| ## analyze | ||||||
|
|
||||||
| Runs the **AnalysisEngine** on the target path, records issue counts on an internal pipeline session, persists via **SessionStore**, and returns both session summary and full **AnalysisResult**. | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| ## autofix | ||||||
|
|
||||||
| 1. Calls **`analyze`** on the same target. | ||||||
| 2. Enqueues fixable issues, runs **AutoFixEngine** transforms. | ||||||
| 3. If verification is required (CLI flag or `config.autofix.require_verification`), runs **VerificationEngine** before each write. | ||||||
| 4. On success, **BackupManager** + **atomicWrite** persist changes. | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| ## autofixFromAnalysis | ||||||
|
|
||||||
| Skips a new scan — used by the REPL **`autofix`** command when reconstructing analysis from a **WorkSession** so fixes apply to the stored issue list without re-running analyzers. | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| ## Source | ||||||
|
|
||||||
| `src/core/orchestrator.ts` | ||||||
|
||||||
| `src/core/orchestrator.ts` | |
| This API is implemented in the project's TypeScript/npm source package. Refer to that package's repository for the current `Orchestrator` implementation. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||
| --- | ||||||
| title: API overview | ||||||
| description: Programmatic building blocks in the Refactron TypeScript codebase. | ||||||
| --- | ||||||
|
|
||||||
| ## Package layout | ||||||
|
|
||||||
| The published **npm** package is primarily the **`refactron`** CLI (`dist/cli/index.js`). The same build outputs library modules under `dist/` (for example `dist/core/models.js`, `dist/core/orchestrator.js`). | ||||||
|
|
||||||
| If you embed Refactron programmatically, import from the compiled paths your bundler resolves (check `package.json` **exports** for supported entry points in your version). | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| ## Core layers | ||||||
|
|
||||||
| | Layer | Role | | ||||||
| |-------|------| | ||||||
| | **Models** | `CodeIssue`, `BlastRadius`, `VerificationResult`, `AnalysisResult`, pipeline types — see [Models](/docs-npm/api/models) | | ||||||
| | **Orchestrator** | Wires analysis → autofix → verification → backup → atomic write — see [Orchestrator](/docs-npm/api/orchestrator) | | ||||||
| | **Adapters** | `ILanguageAdapter` for language-specific analyze/transform/verify — see [Adapters](/docs-npm/api/adapters) | | ||||||
| | **Session (CLI)** | `WorkSessionManager` persists REPL sessions under `.refactron/work-sessions/` | | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| ## Stability | ||||||
|
|
||||||
| Types under `src/core/models.ts` and `src/adapters/interface.ts` are marked **LOCKED** in-repo: treat them as semver-sensitive when depending on them from outside the project. | ||||||
|
||||||
| Types under `src/core/models.ts` and `src/adapters/interface.ts` are marked **LOCKED** in-repo: treat them as semver-sensitive when depending on them from outside the project. | |
| The Models and Adapters API surfaces documented here are treated as **LOCKED**: if you depend on them from outside the project, treat them as semver-sensitive. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --- | ||
| title: analyze | ||
| description: Scan a path, create a work session, and open the issue browser. | ||
| --- | ||
|
|
||
| ## Usage | ||
|
|
||
| At the REPL prompt: | ||
|
|
||
| ``` | ||
| analyze [target] | ||
| ``` | ||
|
|
||
| - **`target`** — Directory or path to scan. Defaults to `.` if omitted (parsed as the second token; see below). | ||
|
|
||
| Examples: | ||
|
|
||
| ``` | ||
| ❯ analyze . | ||
| ❯ analyze src/ | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Behavior | ||
|
|
||
| 1. Resolves `target` to an absolute path. | ||
| 2. Runs the analysis engine (analyzers, import/call graphs, blast radius, optional temporal data). | ||
| 3. Creates a new **work session** with a unique id and stores it under `.refactron/work-sessions/`. | ||
| 4. Sets this session as **active**. | ||
| 5. Prints a severity-grouped summary to the REPL. | ||
| 6. Opens the **interactive issue browser** automatically. | ||
|
|
||
| If you need the browser again later, run **`issues`** (requires an active session). | ||
|
|
||
| --- | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Authenticated session (unless your deployment waives auth). | ||
| - Supported language detected for the project. See [Languages](/docs-npm/languages/python). | ||
|
|
||
|
Comment on lines
+40
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Language prerequisite link is too narrow. The text says “supported language” but links only to Python. Consider linking to a neutral languages index or both Python and TypeScript pages to avoid misrouting Node users. 🤖 Prompt for AI Agents |
||
| --- | ||
|
|
||
| ## See also | ||
|
|
||
| - [Work sessions](/docs-npm/concepts/sessions) | ||
| - [Issue browser](/docs-npm/cli/issue-browser) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| --- | ||
| title: autofix | ||
| description: Apply fixes for all fixable issues in the active session. | ||
| --- | ||
|
|
||
| ## Usage | ||
|
|
||
| ``` | ||
| autofix [--dry-run] [--verify] | ||
| ``` | ||
|
|
||
| There is **no path argument** in the REPL: autofix always uses the **active** session’s stored issues (from the last `analyze`). | ||
|
|
||
| | Flag | Meaning | | ||
| |------|---------| | ||
| | `--dry-run` | Compute transforms and queue results **without** writing files | | ||
| | `--verify` | Run the verification engine before each write (in addition to config `autofix.require_verification`) | | ||
|
|
||
| --- | ||
|
|
||
| ## Behavior | ||
|
|
||
| 1. Loads fixable issues from the active session. | ||
| 2. Reconstructs the analysis result and runs the **orchestrator** autofix pipeline (fixers → verification gate → atomic writes → backups when not dry-run). | ||
| 3. Updates the session with applied vs blocked fixes and timestamps. | ||
|
|
||
| --- | ||
|
|
||
| ## Output | ||
|
|
||
| You will see counts for **Applied** and **Blocked**, plus any block reasons (for example verification failure). Session **phase** moves to `fixed` when updates succeed. | ||
|
|
||
| --- | ||
|
|
||
| ## Configuration | ||
|
|
||
| Global behavior is controlled in `refactron.yaml`: | ||
|
|
||
| - `autofix.dry_run` — Default dry-run for automation (REPL flag overrides per run when passed). | ||
| - `autofix.require_verification` — If true, fixes that fail verification are not written. | ||
|
|
||
| See [Configuration](/docs-npm/configuration). | ||
|
|
||
| --- | ||
|
|
||
| ## See also | ||
|
|
||
| - [Verification](/docs-npm/cli/verify) | ||
| - [Verification engine](/docs-npm/concepts/verification) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface reference
src/adapters/interface.tsdoes not exist in this repository. If these docs are meant to describe the npm/TypeScript codebase hosted elsewhere, link to that repo/path (or rephrase to avoid a broken “Source” reference for readers browsing this repo).