-
Notifications
You must be signed in to change notification settings - Fork 3
Devin/1778098342 phase 0 hygiene #44
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
9060b2f
Phase 1: add concrete types in src/types/
SPerekrestova 15268c9
Phase 1: add zod runtime schemas for LeetCode API responses
SPerekrestova 899ee5d
Phase 1: tighten LeetcodeServiceInterface and propagate concrete types
SPerekrestova 5e41b70
Phase 1: restore saved credentials at startup; push validated creds i…
SPerekrestova 2f12e5f
Phase 1: tests for auth restore + new types
SPerekrestova a345a83
chore: prettier sweep on scripts/sync-version.cjs
SPerekrestova a62a2e5
Phase 1 review: align signatures, tighten contracts on returns
SPerekrestova 5191a31
Phase 1 review: forward cause through ES2022 Error.cause
SPerekrestova 6f3d1b3
Phase 1 review: extract applyValidatedCredentials helper; drop dead t…
SPerekrestova a7b80ea
Merge pull request #36 from SPerekrestova/devin/1778111135-phase-1-types
SPerekrestova 56a4d4f
Phase 2: e2e harness — spawn build/index.js with nock-preloaded child
SPerekrestova e6c2b54
Phase 2: e2e — server lifecycle (handshake, tools, prompts, resources)
SPerekrestova 7388516
Phase 2: e2e — silent-logout-on-restart regression
SPerekrestova f8e2e12
Phase 2: e2e — problem-flow happy path + README; drop placeholder spec
SPerekrestova c4f29b7
Phase 2 review: walk all of src/ to detect stale build/index.js
SPerekrestova 1f5eafd
Phase 2 review: pathToFileURL for preload + isolate fixture from call…
SPerekrestova f66913d
Merge pull request #37 from SPerekrestova/devin/1778177573-phase-2-e2…
SPerekrestova 7c763d7
Phase 3: pedagogy domain (state machine, session store, hint generator)
SPerekrestova c8f9078
Phase 3: SessionService — application-layer wrapper around store + st…
SPerekrestova 8dc4aff
Phase 3: server-instructions — replace prompt-based pedagogy reminder…
SPerekrestova daa6dc4
Phase 3: session-tools — start_problem / request_hint / get_session_s…
SPerekrestova 99102ff
Phase 3: gate list_problem_solutions / get_problem_solution behind hi…
SPerekrestova 5e6965a
Phase 3: wire SessionService + instructions field through server boot…
SPerekrestova a77f7aa
Phase 3: integration + e2e regression for the pedagogy gate
SPerekrestova 6b5f02b
Merge pull request #38 from SPerekrestova/devin/1778178452-phase-3-pe…
SPerekrestova 4a125de
Phase 4a: Python local runner — run_local_tests + runner_doctor + str…
devin-ai-integration[bot] 6dfaeae
Address Phase 4a review feedback
devin-ai-integration[bot] 3761f7b
Merge remote-tracking branch 'origin/main' into devin/1778098342-phas…
devin-ai-integration[bot] 086ccb8
Address additional PR review findings
SPerekrestova 16c0a2c
Fix strict local-pass snapshot gating
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /** | ||
| * Authentication helpers that bridge the on-disk credentials store and the | ||
| * in-memory `LeetcodeServiceInterface`. | ||
| * | ||
| * Closes the silent-logout-on-restart gap where saved credentials existed in | ||
| * `~/.leetcode-mcp/credentials.json` but the running server never re-hydrated | ||
| * them, so every authenticated tool failed with "Authentication required" until | ||
| * the user pasted their cookies again. | ||
| */ | ||
| import { LeetcodeServiceInterface } from "../leetcode/leetcode-service-interface.js"; | ||
| import { CredentialsStorage } from "../types/credentials.js"; | ||
| import { credentialsStorage as defaultStorage } from "../utils/credentials.js"; | ||
| import logger from "../utils/logger.js"; | ||
|
|
||
| /** Outcome of an `restoreCredentials` call — useful in tests and logs. */ | ||
| export type RestoreOutcome = | ||
| | { status: "no_credentials" } | ||
| | { status: "invalid"; reason: "load_failed" | "expired" } | ||
| | { status: "restored"; username: string }; | ||
|
|
||
| /** | ||
| * Loads saved credentials from disk, validates them against LeetCode, and | ||
| * pushes them into the running service if they're still good. | ||
| * | ||
| * Safe to call at server startup; never throws — failures are logged and the | ||
| * outcome is returned for callers that want to react. | ||
| */ | ||
| export async function restoreCredentials( | ||
| service: LeetcodeServiceInterface, | ||
| storage: CredentialsStorage = defaultStorage | ||
| ): Promise<RestoreOutcome> { | ||
| let credentials: Awaited<ReturnType<CredentialsStorage["load"]>>; | ||
| try { | ||
| if (!(await storage.exists())) { | ||
| return { status: "no_credentials" }; | ||
| } | ||
| credentials = await storage.load(); | ||
| } catch (error) { | ||
| logger.warn( | ||
| "Saved credentials could not be loaded; ignoring: %s", | ||
| error instanceof Error ? error.message : String(error) | ||
| ); | ||
| return { status: "invalid", reason: "load_failed" }; | ||
| } | ||
|
|
||
| if (!credentials) { | ||
| logger.warn( | ||
| "Saved credentials file exists but could not be parsed; ignoring." | ||
| ); | ||
| return { status: "invalid", reason: "load_failed" }; | ||
| } | ||
|
|
||
| let username: string | null; | ||
| try { | ||
| username = await applyValidatedCredentials( | ||
| service, | ||
| credentials.csrftoken, | ||
| credentials.LEETCODE_SESSION | ||
| ); | ||
| } catch (error) { | ||
| logger.warn( | ||
| "Saved credentials validation failed; user will need to re-authenticate: %s", | ||
| error instanceof Error ? error.message : String(error) | ||
| ); | ||
| return { status: "invalid", reason: "expired" }; | ||
| } | ||
|
|
||
| if (!username) { | ||
| logger.info( | ||
| "Saved credentials are no longer valid; user will need to re-authenticate." | ||
| ); | ||
| return { status: "invalid", reason: "expired" }; | ||
| } | ||
|
|
||
| logger.info( | ||
| "Restored LeetCode session for %s from saved credentials.", | ||
| username | ||
| ); | ||
| return { status: "restored", username }; | ||
| } | ||
|
|
||
| /** | ||
| * Validates `csrf` / `session` against LeetCode and, on success, pushes them | ||
| * into the running service so the very next authenticated tool call works | ||
| * without forcing a server restart. | ||
| * | ||
| * Returns the validated username, or `null` if LeetCode rejected the cookies. | ||
| * Trusts the `validateCredentials` interface contract (`Promise<string | null>`) | ||
| * and does not catch — any exception thrown by the service propagates. | ||
| */ | ||
| export async function applyValidatedCredentials( | ||
| service: LeetcodeServiceInterface, | ||
| csrf: string, | ||
| session: string | ||
| ): Promise<string | null> { | ||
| const username = await service.validateCredentials(csrf, session); | ||
| if (!username) { | ||
| return null; | ||
| } | ||
| service.updateCredentials(csrf, session); | ||
| return username; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /** | ||
| * Pure-logic hint state machine. | ||
| * | ||
| * The "tutor, not solution oracle" contract is enforced **here** — not in | ||
| * prompts, not in tool descriptions, not in the agent's instruction-following. | ||
| * Every transition that affects hint progression flows through these | ||
| * functions, and gated tools call {@link assertSolutionUnlocked} before | ||
| * returning content. If a code path bypasses this module it is a bug. | ||
| * | ||
| * Intentionally has no IO: takes a {@link SessionState}, returns a new one | ||
| * (or throws). The session store handles persistence. | ||
| */ | ||
| import { | ||
| ErrorCode, | ||
| LeetCodeError, | ||
| MAX_HINT_LEVEL, | ||
| type HintLevel, | ||
| type SessionState | ||
| } from "../types/index.js"; | ||
|
|
||
| /** Hint level at which the canonical solution becomes callable. */ | ||
| export const SOLUTION_HINT_LEVEL: HintLevel = MAX_HINT_LEVEL; | ||
|
|
||
| /** | ||
| * Bumps `session.hintLevel` by one (clamped at {@link MAX_HINT_LEVEL}) and | ||
| * stamps `updatedAt`. Returns a new object — the input is not mutated. | ||
| * | ||
| * Bumping at the maximum level is a no-op rather than an error: callers | ||
| * that want a different behaviour should check `session.hintLevel` before | ||
| * calling. | ||
| */ | ||
| export function advanceHint(session: SessionState): SessionState { | ||
| const next: HintLevel = | ||
| session.hintLevel >= MAX_HINT_LEVEL | ||
| ? MAX_HINT_LEVEL | ||
| : ((session.hintLevel + 1) as HintLevel); | ||
| return { | ||
| ...session, | ||
| hintLevel: next, | ||
| updatedAt: new Date().toISOString() | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Resets the session back to its level-0 initial state, preserving the | ||
| * slug / language / workspace so the user can re-attempt from scratch. | ||
| * | ||
| * `attempts` and `lastLocalRunPassed` are zeroed too, because resetting | ||
| * the hint level without resetting effort would mislead future hint | ||
| * generation about how much the user has already tried. | ||
| */ | ||
| export function resetSession(session: SessionState): SessionState { | ||
| return { | ||
| ...session, | ||
| hintLevel: 0, | ||
| attempts: 0, | ||
| lastLocalRunPassed: null, | ||
| lastLocalRunSnapshot: null, | ||
| status: "started", | ||
| updatedAt: new Date().toISOString() | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Throws `LeetCodeError(HINT_LEVEL_TOO_LOW)` unless the session has | ||
| * reached the level required to unlock the canonical solution. | ||
| * | ||
| * `list_problem_solutions` and `get_problem_solution` MUST call this | ||
| * before returning content. If the session doesn't exist (the user | ||
| * never called `start_problem`) callers should throw | ||
| * `SESSION_NOT_FOUND` themselves — that's a different failure mode and | ||
| * the agent should react differently to it. | ||
| */ | ||
| export function assertSolutionUnlocked(session: SessionState): void { | ||
| if (session.hintLevel < SOLUTION_HINT_LEVEL) { | ||
| throw new LeetCodeError( | ||
| ErrorCode.HINT_LEVEL_TOO_LOW, | ||
| `Solution is gated behind hint level ${SOLUTION_HINT_LEVEL}; ` + | ||
| `session for "${session.slug}" is at level ${session.hintLevel}. ` + | ||
| `Drive the user through \`request_hint\` until they have engaged with each level.` | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { createHash } from "node:crypto"; | ||
|
|
||
| export interface LocalRunSnapshotInput { | ||
| code: string; | ||
| language: string; | ||
| } | ||
|
|
||
| export function createLocalRunSnapshot(input: LocalRunSnapshotInput): string { | ||
| return createHash("sha256") | ||
| .update(JSON.stringify([input.language, input.code])) | ||
| .digest("hex"); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.