Repository navigation
[pull] main from Tencent:main - #83
Merged
Merged
Conversation
Pi becomes the sixth agent `teamai models switch` can point at a team gateway. TeamAI writes one provider into `~/.pi/agent/models.json`, holding every catalog model; a member's other providers in that file are never touched. - **Key is the profile ref** (`team:<id>` / `local:<id>`), not the bare `id` — an `id` is unique only within one catalog file, so a root and a namespace profile may both be `tokenhub`, and a bare id would make the second switch silently overwrite the first gateway. Pi shows the profile's `name`. - **One provider covers all three protocols.** Pi resolves the api and URL per model: the first in Chat Completions, Responses, Anthropic order becomes the provider's own, and a model reached through another carries `api` and `baseUrl` itself. A model served both ways is registered once, preferring an OpenAI one; an `anthropic`-only group pins a Claude model to Anthropic Messages. - **An environment key is written as `$VAR`**, and `settings.json` is left alone, so the default model stays the member's choice. `PI_CODING_AGENT_DIR` is honored the way `CODEX_HOME` is. - **Restore** removes the key the last switch created, even after the catalog re-points the profile at a different ref. Restoring without `--agent` now covers Pi too. Rebased onto current `origin/main` (3a9a24a). The only conflict was the `./profile.js` import in `src/models/switch.ts`, where this change adds `ModelProtocol` and #894 adds `LocalConfig` / `sameTeamIdentity`; resolved as the union of both, and `git range-diff` confirms that line is the sole difference from the original commit. Verification on the rebased tree: `tsc --noEmit` and `lint` clean. Unit suite 5501 passed (the same three `push-env` cases fail on clean `origin/main`, verified in a separate worktree). Pi e2e suite 4 passed. Real built CLI against a scratch `HOME`: `models add` -> `models switch --agent pi` writes one provider keyed `local:tokenhub` with `settings.json` untouched; `models list` reports Pi active; `models restore --agent pi` returns the file to `{}`; a pre-existing user provider under the same ref is refused with `pi already has a user-owned provider named local:tokenhub` and left byte for byte intact; `PI_CODING_AGENT_DIR` redirects the write to a custom directory.
…odule (#847) * fix(code-knowledge): resolve Swift symbols across files in the same module Swift declarations are module-scoped, but the AST track resolved calls and conformances with a file-scoped model: declared in this file, or reachable through a resolved import. That model is correct for TS/Go/Python, where a cross-file symbol has to be imported. Swift needs no import inside a module, so a conformance or a call to a symbol in a sibling file emitted nothing. Add a third, Swift-only level of lookup after the existing two: a declaration elsewhere in the same module, with the module boundary read from the layout SwiftPM mandates (Sources/<Target>/, Tests/<Target>/). Outside that layout no scope is claimed, and a name declared more than once in the module emits nothing rather than picking one arbitrarily. Fixes #843 * fix(code-knowledge): index only module-visible Swift declarations Addresses the three P1 findings the automated review raised on the first revision of #847. All three were real. The fallback widened the candidate set without narrowing eligibility. The candidate set is "every declaration in the module"; what a bare name can actually reach is strictly smaller, and that has to be decided where the declaration and its modifiers are still in hand. - module-scope.ts: the module key now keeps the package root, so Packages/A/Sources/App and Packages/B/Sources/App stay two modules instead of merging into Sources/App. - walk.ts: a declaration enters the module index only when it is top-level and not private/fileprivate. Neither fact survives into AstSymbol, so it is computed in the walker and surfaced as FileWalkResult.swiftModuleSymbols. - index.ts: feeds that subset to the module index. queries.ts and the shared AstSymbol type are untouched, and the tie rule agreed in #843 is unchanged: only module-visible declarations can tie. Verification on the merge result (main a8ab8e0 + this change): - real-CLI e2e, 15/15 assertions, three new negative probes each in a file that declares nothing else; both cross-package directions stay clean while each package resolves to its own Proto.swift - four mutations, each removing one guard, each caught by exactly the matching test and nothing else - ast-swift-module-scope.test.ts 15 cases; related suite 68 -> 83 passed - oxlint --deny-warnings and tsc --noEmit: rc=0 on this change and rc=0 on unmodified main, same binary and flags, so the comparison is real * fix(code-knowledge): take the innermost SwiftPM marker as the module boundary Addresses the P1 the automated review raised on the previous head. Keeping the package root only fixes packages that sit side by side. A package vendored under the outer package's own Tests/ has two markers on its path, and the scan took the first: Tests/Fixtures/A/Sources/App and Tests/Fixtures/B/Sources/App were both scoped to Tests/Fixtures, which is the same merge as the earlier package-root finding, reached one level out. The scan now runs from the end, so the innermost marker wins. The direction also decides how a layout this function misreads can fail: an inner marker can only yield a scope nested inside the true module, which loses a resolution, while an outer one can span two real modules and fabricate an edge. The layer already prefers a missing edge to a wrong one, so the bias is deliberate and is stated in the docstring and in the tests. Verification on the merge result (main a8ab8e0 + this change): - real-CLI e2e, 20/20 assertions; both vendored fixture packages now resolve to their own Proto.swift while neither cross-package direction produces an edge - five mutations, each removing one guard, each caught by exactly the matching tests and nothing else - ast-swift-module-scope.test.ts 18 cases; related suite 68 -> 86 passed - oxlint --deny-warnings and tsc --noEmit: rc=0 here and rc=0 on unmodified main, same binary and flags * fix(code-knowledge): a name an enclosing scope binds is not a module reference Addresses the P1 the automated review raised on the previous head. The fallback answered "which module does this bare call belong to" without first asking whether the call is a module-level reference at all. With A.swift declaring func work() and B.swift declaring func run(work: () -> Void) { work() }, Swift calls the parameter, and the lookup resolved it to A.swift and emitted a fabricated cross-file REFERENCES edge. The receiver fallback had the same hole for a local value shadowing a type name. The walker now records, per call site, the names an enclosing scope binds: function and closure parameters, local let/var, and what a for / if let / guard let / catch let / case let introduces. Both module-wide lookups decline when the callee or receiver is one of those names. The walk stops at the call own ancestors, so a binding in an unrelated function of the same file shadows nothing; it over-collects only within the scopes it does visit, which costs a resolution rather than inventing an edge. This is the same mistake as the earlier four findings on a different axis: eligibility was narrowed at one end of the edge (can a sibling reach this declaration) and not at the other (can this call reach anything module-level). Verification on the merge result (main a8ab8e0 + this change): - real-CLI e2e, 24/24 assertions; ShadowParam.swift (its only call bound by its own parameter) ends with 0 outgoing edges, ShadowMixed.swift (one bound call, one unbound) with exactly 1, and the heuristic track is byte-identical - seven mutations, each removing one guard, each caught by exactly the matching tests and nothing else; originals restored byte for byte - ast-swift-module-scope.test.ts 24 cases; affected set derived from the changed modules: 93/106 passed on unmodified main and 93/106 here - Node 24.14.0, the runtime the matrix gained while this sat in review, on the merge result (main 5fb316c, which carries #861): the two Swift AST test files pass, 2/2. On this branch tree alone Node 24 aborts during the first Swift parse (Fatal process out of memory: Zone) and a command-line --wasm-tier-up-filter does not help, which is why #861 has to set the flag inside the worker. - oxlint --deny-warnings and tsc --noEmit: rc=0 here and rc=0 on unmodified main, same binary and flags * fix(code-knowledge): keep a call's own name from counting as a shadow Two follow-ups from review. The closed rule collected every identifier in the enclosing scopes, and that included the callee of a sibling call: in `func run() { work(); work() }` each call read the other's `work` as evidence, so both cross-file resolutions were suppressed. The name a call goes through is a use, not a binding. Arguments are still walked, so a closure that does bind a name keeps counting. `SWIFT_IDENTIFIER` also admitted ASCII only, so a parameter named `π` was dropped from the set and a sibling `func π()` won the fallback. Swift identifiers are not ASCII. Both shapes now have cases; all four mutations the rule has to survive are killed by the suite. * fix(code-knowledge): collect Swift shadowing once per declaration, for any identifier Two follow-ups from review, both in the same set of names. The character class guarding `addSwiftName` admitted Unicode letters after the previous pass but still rejected escaped identifiers such as `repeat` -- which Swift requires when a name collides with a keyword -- and symbol or emoji names. A parameter with such a name never reached `localBindings`, so a sibling `func` of the same name won the fallback and a fabricated cross-file edge was emitted. Every caller passes the text of a `simple_identifier` or a `type_identifier`, which is the grammar's own verdict that the token is a name, so the class was the whole defect and nothing else is tested there now. The set was also rebuilt for every call by re-walking that call's ancestors. The union over those ancestors is exactly the top-level declaration that holds the call -- every ancestor sits inside it, and the declaration is one of them -- so the declaration is now read once per file and each call site looks its answer up. Same names, minus the quadratic term: a function holding N calls went from roughly N^2 AST visits to a single traversal per declaration. Reading the declaration whole is a shade coarser than the per-call walk: a name occurring only inside the call now counts as well. That costs nothing where the field is consumed, because the resolver asks about the callee and the receiver, and both are callee positions, skipped below as uses. A name can only enter the set through a position that is not the very call it would resolve. Verification against the pushed head 891da08, same fixtures, same runtime: - 16-shape before/after matrix (5 shadowed shapes, 2 of the dropped identifiers, 2 scope cases, 7 controls). The only rows that move are the two identifier shapes, each 1 fabricated edge -> 0. Every other row is identical, including the controls for those two shapes, which still resolve. - The two new identifier cases fail on the unmodified head (2 failed | 31 passed of 33) and pass here (33/33), so they pin the defect rather than the change. - Five mutations, each removing one guard: reinstating the ASCII shape test, keeping the callee as evidence, scoping to the nearest function instead of the declaration, looking the declaration up by endIndex, collecting type positions. All five are killed; walk.ts restored byte for byte afterwards. - ast-swift-module-scope.test.ts 29 -> 33 cases. The four AST suites: 65 passed. - The quadratic term, measured on one function holding the same call N times: 200 -> 800 calls is 477 ms -> 8428 ms on the head (x17.7, and it overruns the 15 s test timeout) against 12.6 ms -> 29.5 ms here. - oxlint --deny-warnings --report-unused-disable-directives and tsc --noEmit: rc=0. No reference to the two helpers removed here is left in src/. * fix(code-knowledge): treat an argument as a use, not a binding, in Swift shadowing Two follow-ups from review, both about positions that mention a name without binding it. The review bot reported that `consume(work)` before a bare `work()` suppresses the call: the argument's mention of `work` entered the shadowing set, the resolver saw its callee there and dropped the edge. The bot labels it P2; it is also older than this branch. The per-call walk it replaced had the same hole -- it excluded the call's own subtree, but a mention in a *sibling* call was still counted, and `consume(work)` is a sibling of `work()`. Rebuilding the set from the whole declaration lost that exclusion entirely, and that loss was a real regression the bot did not report: `work(work)` counts its own argument as evidence and stops resolving through its callee. The previous commit message claimed reading the declaration whole "costs nothing where the field is consumed, because ... callee positions are skipped". That is wrong. Skipping the callee position says nothing about a mention of the same name reaching the set from anywhere else in the declaration -- its own argument list included. Both are the same defect in one direction: an argument is an expression position, so it can mention a name but never bind one. A marker now follows the walk into `value_arguments` and is cleared on the way into a `lambda_literal`, since a closure handed over as an argument still opens its own scope and its parameters and captures do bind. Nothing enumerates binding constructs, so the rule stays closed. Verification spans three states of walk.ts, same fixtures, same runtime: 891da08 (the branch's starting point, before the previous pass), da6f894 (the pushed head, after it) and this commit. - 18-shape matrix, covering every shape the review rounds produced: four shadowed shapes (parameter, stored property, generic parameter, closure capture list), three identifier shapes (Unicode, escaped, symbol), two repeated-call shapes (two calls, twelve calls), the inherited-member shape, the bot's two argument shapes, `work(work)`, a closure passed to itself, a bare mention beside a call, and three controls. Against the pushed head no row is worse and three rows move up, all of them positions this commit is about: bot shape, argument mention after the call no edge -> 1 edge bot shape, argument mention before the call no edge -> 1 edge work(work) no edge -> 1 edge The third is the regression above: it resolves on 891da08, does not resolve on the pushed head, and resolves again here. Against 891da08 no row is worse either; the escaped and symbol shapes go from 2 edges to 1, because before the previous pass a name written with backticks or as a symbol was dropped from the set, so the call inside the shadowing declaration resolved along with the one that should. - Every shadowed shape -- parameter, stored property, generic parameter, closure capture list, Unicode parameter, inherited member -- still resolves to no edge, and the three controls still resolve. - ast-swift-module-scope.test.ts 29 -> 33 -> 36 cases. The four AST suites: 68 passed. With the test file at 36 cases and walk.ts at 891da08 the suite is 3 failed | 33 passed -- escaped, symbol and the argument mention, which is what pinning those defects looks like. With walk.ts at the pushed head it is 2 failed | 34 passed, the argument mention and `work(work)`: the two shapes this commit repairs. The closure-parameter case passes against both, so it guards a rule rather than recording new behaviour. - Four mutations, each removing one guard: ignoring the argument marker, not clearing it inside a closure, never marking arguments, and no longer skipping callee identifiers. All four are killed; walk.ts restored byte for byte afterwards (sha256 62332202bcc5c72a53417bd0fc9be8d0b88f674237a606104d20a5f7816c2673). - oxlint --deny-warnings --report-unused-disable-directives and tsc --noEmit: rc=0. The repo's lint script also adds --type-aware; that half is exercised by CI. Still open, unchanged and out of scope here: inherited and cross-file extension members, tracked in #909. It needs a member table the AST index does not build today, so no amount of argument-position handling reaches it.
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )