EVEMISSTechnology

Repository 指南 · 架構 · v2

simonw / llm · 架構

這個 repository 是一個有 116 個被分析檔案的 Python 專案,分成 docs、llm 和 tests 三個目錄。有界靜態路徑從 llm/__main__.py 開始,到達 llm/cli.py:cli,再經由 llm/plugins.py 裡的 load_plugins 停在未解析的邊界。在 9,698 條靜態關係中,7,374 條是外部或未解析:這是一幅有界的靜態圖像,不是執行時的紀錄。

原始 repository
simonw/llm
授權
Apache-2.0 · 開源授權
分析的版本 · 最後驗證
1df47ddcac20d58726a993949da8ef84f4081085 ·

原始專案有更新,但本指南引用的程式碼沒有變動。預設分支已前進到 764dc386c58b,2026-10-03 檢查。版本差異比對了 32 個變動的檔案,本指南引用的程式碼區域都沒有變動。本頁描述的仍是版本 1df47ddcac20;整個 repository 的統計數字(檔案數、呼叫次數等)指的是那個版本。

本頁中文由負責的 AI 編輯依英文正式版本 v2 翻譯;程式碼名稱、路徑、行號與數字都經確定性檢查,與英文版一致。陳述與依據表保留英文原文,因為那是獨立驗證者核對過的紀錄。看英文原文

simonw/llm 架構:有界的靜態重建

本頁用語說明
Entrypoint record(進入點記錄)
分析器標記為「程式可能從這裡開始執行」的檔案。附有 __main__ guard 摘錄時,表示檔案裡有 if __name__ == "__main__": 區塊,摘錄顯示它呼叫了什麼;沒有摘錄時,只是依檔名判斷。
Bounded static execution path(有界靜態執行路徑)
不執行程式、直接從原始碼重建出的呼叫鏈,走到固定步數就停。它說明在紙面上能追到多遠,不代表實際執行時會發生什麼。
Unresolved boundary(未解析邊界)
靜態路徑停下的地方:下一個呼叫進入外部函式庫,或不執行就無法確定。這是本次分析的邊界,不是 repository 的缺陷。
Static relations(靜態關係)
在原始碼中找到的呼叫與 import。「external or unresolved」表示指向分析範圍以外。
Module role(模組角色)
分析器依呼叫進出次數推論的檔案標籤(例如 core、entry/orchestration、leaf)。它描述的是在呼叫圖中的位置,不是作者的設計意圖。
Test-like files(類測試檔案)
名稱或位置看起來像測試的檔案。本次分析只計數,不執行。
Observed · inferred · author-claimed · unresolved
每句話的依據:直接讀自分析的檔案;由分析器從檔案推論;repository 作者自述(metadata、README);或本次分析無法確定。
Verified(已驗證)
本頁有兩種用法。在分析器的記錄裡(「verified provenance」「verified entrypoint」),它表示這筆記錄是直接從分析的檔案讀到的,也就是本指南所說的 observed;以進入點來說,就是檔案裡確實有 __main__ guard 的文字。分析器在 2026-10-04 修正後,只有 cli.py、main.py 這類像進入點的檔名、沒有 guard 的檔案,會記為 inferred(推測);在那之前分析的指南仍把這類檔案標成 verified,它依然只是對檔案用途的推測。它不代表程式被執行或測試過。「最後驗證」是這份指南最後一次通過本實驗室檢查的日期,檢查對象是所標示版本的分析記錄,不是對 repository 本身的審查。

整體樣貌

分析器的摘要描述這是一個有 116 個被分析檔案的 Python 專案,圍繞三個目錄子系統組織:docs、llm 和 tests。檔案清單算到根目錄 11 個檔案、.github 6 個、docs 35 個、llm 20 個、tests 44 個,整體共記錄到 44 個類測試檔案。

llm 套件裡放著角色記錄點名為活躍程式碼的路徑:cli.py、plugins.py、models.py、logs.py、migrations.py、utils.py、parts.py 和 default_plugins/openai_models.py。在根目錄,README.md、pyproject.toml 和 LICENSE 被標為專案層級的重要檔案,llm/__main__.py 和 llm/cli.py 則被標為可能的進入點。唯一解析出的依賴記錄來自 docs/requirements.txt(sphinx 及相關工具),所以 docs 負責的是文件的建置。

進入點與控制流

偵測到兩個進入點:llm/__main__.py,它的 __main__ 守衛呼叫 cli();以及依檔名啟發式規則被標為可能可執行的 llm/cli.py。從 llm/__main__.py 出發的有界路徑,只以一步本地呼叫走到 llm/cli.py:cli,然後以葉節點結束,沒有循環也沒有截斷。

從 llm/cli.py 出發,有一條路徑馬上停在 warnings.simplefilter。另有八條路徑深入 llm/plugins.py [load_plugins],停在外部或未解析的目標:hasattr、pm.load_setuptools_entrypoints、LLM_LOAD_PLUGINS.split、name.strip、metadata.distribution、entry_point.load、pm.register 和 pm._plugin_distinfo.append。重建結果回報了 13 條有界執行路徑、2 個進入點和 2059 條已解析的呼叫關係;這份分析資料收錄了其中十條路徑。從靜態的角度讀,llm/cli.py 是第一個到達的模組,而從 llm/cli.py 追出的九條路徑中,有八條是在 load_plugins 離開已解析的呼叫圖;第九條停在 warnings.simplefilter,沒有經過 load_plugins。

核心模組與它們的角色

這些角色標籤是分析器依已解析的靜態呼叫次數和是否屬於進入點推論出來的;它們描述的是在呼叫圖中的位置,不是設計意圖。llm/__init__.py 是連結最多的模組(754 個呼入、48 個呼出),其次是 llm/parts.py(470 個呼入、22 個呼出);兩者都被標為 service/core 候選。llm/cli.py 帶有 entry/orchestration 標籤(105 入、245 出),和它的進入點身分一致。在函式庫模組中,llm/models.py(130 入/96 出)、llm/logs.py(123 入/64 出)、llm/utils.py(102 入/12 出)和 llm/default_plugins/openai_models.py(89 入/130 出)都被標為 service/core 候選。llm/plugins.py 位在邊緣(41 入、0 出,標為 leaf/data-boundary),附近還有 llm/migrations.py(38 入、1 出)。這些標籤反映的是呼叫量:tests/test_parts.py 因為有 422 個呼出而拿到 orchestration 標籤,tests/test_logs_store.py 則被標為 service/core。

靜態路徑停在哪裡

外掛載入是最主要的邊界:從 load_plugins 出發,追蹤到的路徑到達 pm.load_setuptools_entrypoints、entry_point.load、pm.register 和 metadata.distribution,全都是外部或未解析;分析器的邊界清單還點名了 importlib.import_module,不過沒有任何執行路徑停在那裡。一般程式碼的停止點也有:llm/cli.py 停在 warnings.simplefilter,load_plugins 則碰到 hasattr、LLM_LOAD_PLUGINS.split 和 name.strip;邊界清單另外點名了 sys.stderr.write,但沒有對應的執行記錄。規模很大:9,698 條關係中有 7,374 條是 external_or_unresolved,本地的只有 2,324 條,而分析器保留的是文字形式的目標,不會捏造本地目的地。實際上,外掛載入背後的一切(安裝好的 entry point、hook 的註冊)都在這次重建之外,因為進入 load_plugins 的八條追蹤路徑全都停在 unresolved_boundary;分析器也另外記錄了動態 import 沒有被解析。

各部分之間的依賴

依靜態呼叫次數,llm/__init__.py 是這個套件的匯集點(754 個呼入),llm/cli.py 則是依賴這個樞紐的大量使用者(105 入、245 出)。llm/parts.py 和 llm/models.py 承擔了其餘大部分的本地呼叫量,llm/plugins.py 則是葉節點(41 個呼入、0 個呼出)。解析出的七筆依賴記錄都標為 scope 'runtime',但來源是 docs/requirements.txt(sphinx 和文件工具),所以它們描述的是文件建置的工具鏈。因為 pyproject.toml 的依賴表沒有被解析,這次分析無法確定這個套件本身的執行期依賴。未解析的邊在圖中占多數:7,374 條 external_or_unresolved,對上 2,324 條本地,而且動態 import 明確沒有被解析。

靜態分析看不到的東西

這是一幅靜態的圖像:反射、執行期依賴注入、動態 import、monkey-patching、產生的程式碼、框架在執行期的接線和動態分派,分析器都沒有解析。外掛載入、模型解析和 logging 在執行時怎麼互動,這份分析資料無法確定。安裝/執行/建置的推論並不完整,安裝指令也沒有驗證,所以這裡沒有任何可以照做的步驟。測試以 44 個類測試檔案和呼叫圖節點的形式出現,但分析資料無法顯示它們是否通過,也無法顯示程式碼執行時的行為。在這條流程裡,來自 README 的陳述是逐行擷取的,可能抓到程式碼行,所以最多只能算作者的說法。

架構的閱讀順序

先讀 README.md 和 pyproject.toml 掌握整體框架,再順著執行走:llm/__main__.py、llm/cli.py:cli,然後是 llm/plugins.py [load_plugins]。分析器的教學記錄建議同樣的順序:先看清單檔和重要符號,再看有界路徑,然後是未解析的邊界。核心部分,先把 llm/__init__.py 當作樞紐來讀,再讀 llm/parts.py 和 llm/models.py。在改任何程式碼之前,最後看 tests/test_parts.py:它有 422 個呼出,因此被標為 orchestration 候選。

這次分析無法確定的事

這些是撰寫模型對分析記錄自己的說明。lim_3、exec_* 或 claim_… 這類識別碼指的是那次分析裡的記錄;陳述與依據表引用的也是同一批記錄。

  • 所有關於控制流的陳述描述的都是有界靜態路徑;執行期的接線、設定和動態 import 都無法確定(lim_1)。
  • 套件本身的執行期依賴不明:只解析了 docs/requirements.txt 的記錄,pyproject.toml 的依賴表被略過(lim_3)。
  • 角色標籤是從呼叫計數推出的,會把一些測試檔案標為 service/core 候選(role_30、role_35);它們不是關於設計的陳述。
  • 重建結果回報了 13 條有界執行路徑;這份分析資料收錄其中十條,所以有三條路徑沒有在這裡描述。
  • 安裝/執行/建置的行為只有部分推論,安裝指令也沒有驗證(lim_2)。
陳述與依據 — 35 條陳述,35 條經獨立驗證者確認(英文原文)

Every substantive statement above is a claim bound to grounding IDs of the analyzed revision. Global grounding IDs are namespaced by the analysis run.

Claim Epistemic status Verifier Grounding (global IDs)
c1 The analyzer's summary describes a Python project of 116 analyzed files organized around three top-level directory subsystems: docs, llm, and tests. inferred supported analysis_f20a9f60553ce57f:summary_repository, analysis_f20a9f60553ce57f:subsys_1, analysis_f20a9f60553ce57f:subsys_2, analysis_f20a9f60553ce57f:subsys_3
c2 The inventory counts 11 root files, 6 in .github, 35 in docs, 20 in llm, and 44 in tests, and the maturity signals note 44 test-like files. inferred supported analysis_f20a9f60553ce57f:summary_repository
c3 The llm package holds the modules the role records name: cli.py, plugins.py, models.py, logs.py, migrations.py, utils.py, parts.py, and default_plugins/openai_models.py. inferred supported analysis_f20a9f60553ce57f:role_2, analysis_f20a9f60553ce57f:role_4, analysis_f20a9f60553ce57f:role_5, analysis_f20a9f60553ce57f:role_9, analysis_f20a9f60553ce57f:role_10, analysis_f20a9f60553ce57f:role_11, analysis_f20a9f60553ce57f:role_12, analysis_f20a9f60553ce57f:role_13, analysis_f20a9f60553ce57f:role_15
c4 README.md, pyproject.toml, and LICENSE are flagged as project-level important files; llm/__main__.py and llm/cli.py are flagged as likely entrypoints. observed supported analysis_f20a9f60553ce57f:important_1, analysis_f20a9f60553ce57f:important_3, analysis_f20a9f60553ce57f:important_4, analysis_f20a9f60553ce57f:important_5, analysis_f20a9f60553ce57f:important_6
c5 The only parsed dependency records are seven docs/requirements.txt entries: sphinx, furo, sphinx-autobuild, sphinx-copybutton, sphinx-markdown-builder, myst-parser, and cogapp. observed supported analysis_f20a9f60553ce57f:dep_1, analysis_f20a9f60553ce57f:dep_2, analysis_f20a9f60553ce57f:dep_3, analysis_f20a9f60553ce57f:dep_4, analysis_f20a9f60553ce57f:dep_5, analysis_f20a9f60553ce57f:dep_6, analysis_f20a9f60553ce57f:dep_7
c6 Two entrypoints were detected: llm/__main__.py, whose __main__ guard calls cli(), and llm/cli.py, flagged as likely executable by filename heuristic. observed supported analysis_f20a9f60553ce57f:py_entry_8d052da6b4aa, analysis_f20a9f60553ce57f:entry_1, analysis_f20a9f60553ce57f:important_5, analysis_f20a9f60553ce57f:important_6
c7 The bounded path from llm/__main__.py has one local step, llm/__main__.py -> llm/cli.py:cli, and ends with terminal_reason 'leaf'; no cycle, not truncated. inferred supported analysis_f20a9f60553ce57f:exec_1883828468e7
c8 One bounded path from llm/cli.py ends immediately at warnings.simplefilter with terminal_reason 'unresolved_boundary'. inferred supported analysis_f20a9f60553ce57f:exec_837f2dee781c
c9 Eight bounded paths run llm/cli.py -> llm/plugins.py [load_plugins] and end at external or unresolved targets: hasattr, pm.load_setuptools_entrypoints, LLM_LOAD_PLUGINS.split, name.strip, metadata.distribution, entry_point.load, pm.register, and pm._plugin_distinfo.append. inferred supported analysis_f20a9f60553ce57f:exec_bbf7b5170507, analysis_f20a9f60553ce57f:exec_c714034a13f9, analysis_f20a9f60553ce57f:exec_cf7f251ec694, analysis_f20a9f60553ce57f:exec_25ee09cebebb, analysis_f20a9f60553ce57f:exec_a02b71c30924, analysis_f20a9f60553ce57f:exec_8eb173511297, analysis_f20a9f60553ce57f:exec_bfffaa01eacb, analysis_f20a9f60553ce57f:exec_6e97406cf140
c10 The reconstruction reports 2 entrypoints, 2059 resolved static call relations, and 13 bounded execution paths; this packet includes ten of those paths. inferred supported analysis_f20a9f60553ce57f:architecture_reconstruction, analysis_f20a9f60553ce57f:exec_1883828468e7
c11 Read statically, llm/cli.py is the first module reached from the package entrypoint, and load_plugins is where eight of the nine traced paths from llm/cli.py leave the resolved call graph; the ninth ends at warnings.simplefilter without passing load_plugins. inferred supported analysis_f20a9f60553ce57f:exec_1883828468e7, analysis_f20a9f60553ce57f:exec_c714034a13f9, analysis_f20a9f60553ce57f:exec_837f2dee781c
c12 Role labels are inferred by the analyzer from static resolved call degree and entrypoint membership; they describe call-graph position, not design intent. inferred supported analysis_f20a9f60553ce57f:role_2, analysis_f20a9f60553ce57f:role_4
c13 llm/__init__.py has the highest static call degree: 754 incoming and 48 outgoing calls, labeled service/core candidate. inferred supported analysis_f20a9f60553ce57f:role_2
c14 llm/parts.py follows: 470 incoming and 22 outgoing calls, labeled service/core candidate. inferred supported analysis_f20a9f60553ce57f:role_12
c15 llm/cli.py is labeled entry/orchestration candidate: 105 incoming and 245 outgoing calls. inferred supported analysis_f20a9f60553ce57f:role_4
c16 llm/models.py (130 in / 96 out), llm/logs.py (123 in / 64 out), llm/utils.py (102 in / 12 out), and llm/default_plugins/openai_models.py (89 in / 130 out) are labeled service/core candidates. inferred supported analysis_f20a9f60553ce57f:role_11, analysis_f20a9f60553ce57f:role_9, analysis_f20a9f60553ce57f:role_15, analysis_f20a9f60553ce57f:role_5
c17 llm/plugins.py is labeled leaf/data-boundary candidate with 41 incoming and 0 outgoing calls; llm/migrations.py shows 38 incoming and 1 outgoing. inferred supported analysis_f20a9f60553ce57f:role_13, analysis_f20a9f60553ce57f:role_10
c18 The labels track call volume: tests/test_parts.py draws the orchestration label with 422 outgoing calls, and tests/test_logs_store.py is labeled service/core candidate. inferred supported analysis_f20a9f60553ce57f:role_35, analysis_f20a9f60553ce57f:role_30
c19 Plugin loading is the dominant boundary: from load_plugins the traced paths reach pm.load_setuptools_entrypoints, entry_point.load, pm.register, and metadata.distribution, all external or unresolved; the analyzer's boundary list also names importlib.import_module, though no exec path terminates there. inferred supported analysis_f20a9f60553ce57f:exec_c714034a13f9, analysis_f20a9f60553ce57f:exec_8eb173511297, analysis_f20a9f60553ce57f:exec_bfffaa01eacb, analysis_f20a9f60553ce57f:exec_a02b71c30924
c20 Plain-code stops also appear: llm/cli.py ends at warnings.simplefilter, and load_plugins touches hasattr, LLM_LOAD_PLUGINS.split, and name.strip; the boundary list additionally names sys.stderr.write without an exec record. inferred supported analysis_f20a9f60553ce57f:exec_837f2dee781c, analysis_f20a9f60553ce57f:exec_bbf7b5170507, analysis_f20a9f60553ce57f:exec_cf7f251ec694, analysis_f20a9f60553ce57f:exec_25ee09cebebb
c21 Of 9,698 static relations, 7,374 are external_or_unresolved against 2,324 local; the analyzer preserves textual targets rather than fabricating local destinations. inferred supported analysis_f20a9f60553ce57f:relation_counts
c22 Anything reached through plugin loading — installed entry points, hook registration — lies outside the resolved graph, since all eight traced paths into load_plugins terminate at unresolved_boundary. inferred supported analysis_f20a9f60553ce57f:exec_8eb173511297, analysis_f20a9f60553ce57f:exec_c714034a13f9, analysis_f20a9f60553ce57f:exec_bbf7b5170507, analysis_f20a9f60553ce57f:exec_cf7f251ec694, analysis_f20a9f60553ce57f:exec_25ee09cebebb, analysis_f20a9f60553ce57f:exec_a02b71c30924, analysis_f20a9f60553ce57f:exec_bfffaa01eacb, analysis_f20a9f60553ce57f:exec_6e97406cf140
c23 By static degree, llm/__init__.py is the package's aggregation point (754 incoming calls) and llm/cli.py is a heavy consumer (105 in, 245 out). inferred supported analysis_f20a9f60553ce57f:role_2, analysis_f20a9f60553ce57f:role_4
c24 Within the package, llm/parts.py and llm/models.py carry much of the local call mass, and llm/plugins.py is a leaf: 41 incoming, 0 outgoing. inferred supported analysis_f20a9f60553ce57f:role_12, analysis_f20a9f60553ce57f:role_11, analysis_f20a9f60553ce57f:role_13
c25 The seven dependency records are labeled scope 'runtime' yet all come from docs/requirements.txt (sphinx and documentation tooling), so they describe the docs build toolchain. observed supported analysis_f20a9f60553ce57f:dep_1, analysis_f20a9f60553ce57f:dep_2, analysis_f20a9f60553ce57f:dep_3, analysis_f20a9f60553ce57f:dep_4, analysis_f20a9f60553ce57f:dep_5, analysis_f20a9f60553ce57f:dep_6, analysis_f20a9f60553ce57f:dep_7
c26 lim_3 records that dependency parsing covers only requirements-style manifests and skips pyproject.toml dependency tables, so the package's own runtime dependencies are not established here. observed supported analysis_f20a9f60553ce57f:lim_3, analysis_f20a9f60553ce57f:important_3
c27 Unresolved edges dominate: 7,374 external_or_unresolved versus 2,324 local, and dynamic imports are explicitly not resolved. inferred supported analysis_f20a9f60553ce57f:relation_counts, analysis_f20a9f60553ce57f:lim_1
c28 lim_1 records that reflection, runtime dependency injection, dynamic imports, monkey-patching, generated code, framework runtime wiring, and dynamic dispatch are not resolved by this static analysis. observed supported analysis_f20a9f60553ce57f:lim_1
c29 How plugin loading, model resolution, and logging interact at runtime is not established by this packet. unresolved supported analysis_f20a9f60553ce57f:lim_1, analysis_f20a9f60553ce57f:claim_7c9925f9c8f4
c30 lim_2 records that install/run/build inference is partial and installation commands are not verified. observed supported analysis_f20a9f60553ce57f:lim_2
c31 The packet shows 44 test-like files, but it cannot show whether tests pass or how the code behaves when executed. inferred supported analysis_f20a9f60553ce57f:summary_repository
c32 lim_4 records that README claim extraction is line-based and may capture code lines, so README-derived statements stand as author_claimed at most. observed supported analysis_f20a9f60553ce57f:lim_4
c33 A grounded order: README.md and pyproject.toml for framing; llm/__main__.py, llm/cli.py:cli, and llm/plugins.py [load_plugins] for entry and boundary; llm/__init__.py, llm/parts.py, and llm/models.py for the core. inferred supported analysis_f20a9f60553ce57f:important_1, analysis_f20a9f60553ce57f:important_3, analysis_f20a9f60553ce57f:py_entry_8d052da6b4aa, analysis_f20a9f60553ce57f:entry_1, analysis_f20a9f60553ce57f:exec_c714034a13f9, analysis_f20a9f60553ce57f:role_2, analysis_f20a9f60553ce57f:role_12, analysis_f20a9f60553ce57f:role_11
c34 tests/test_parts.py, with 422 outgoing calls and the orchestration label, is a candidate stop for seeing how parts are exercised. inferred supported analysis_f20a9f60553ce57f:role_35
c35 The teaching record recommends starting from manifests and important symbols, then tracing the bounded execution path and inspecting unresolved boundaries before changing code. inferred supported analysis_f20a9f60553ce57f:claim_e56db45165bf

來源、權利與說明 · attribution-license-templates/v0.1

權利聲明。原始 repository 託管於 GitHub。其原始碼、文件、名稱、媒體與相關素材的權利,仍屬各自的作者、貢獻者與其他權利人所有,並受該 repository 的授權條款約束。

Original repository hosted on GitHub. Repository source code, documentation, names, media, and related project materials remain subject to the rights of their respective authors, contributors, and other rights holders and to applicable repository license terms.

平台聲明。GitHub 是所連結 repository 的來源託管平台。GitHub 與相關標誌為 GitHub, Inc. 的商標。除非另有明確說明,EVEMISS Technology 與 GitHub 之間沒有隸屬或背書關係。

GitHub is the source hosting platform for the linked repository. GitHub and related marks are trademarks of GitHub, Inc. EVEMISS Technology is not affiliated with or endorsed by GitHub unless explicitly stated otherwise.

這一頁怎麼來的。本頁由對應版本的 repository 分析與 AI 輔助的編輯工具產生。技術陳述綁定所分析的版本;原始 repository 更新後,可能重新驗證。

This page was produced using revision-aware repository analysis and AI-assisted editorial tooling. Technical claims are tied to the analyzed repository revision and may be revalidated when the source repository changes.

本頁包含 AI 輔助分析,並經 EVEMISS Technology 人工與 AI 協力審閱。 · 回報權利疑慮 · 回到概覽