From 8c781e824c032ef487f540157a5213ad4415f937 Mon Sep 17 00:00:00 2001 From: Da Shen Date: Tue, 24 Nov 2026 23:56:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[1404]=20=E9=A1=B5=E7=9C=89=E4=B8=8E=20--he?= =?UTF-8?q?lp=20=E6=98=BE=E7=A4=BA=E7=89=88=E6=9C=AC=E5=8F=B7=E5=8F=8A?= =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=80=85=E6=A8=A1=E5=BC=8F=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通过 (liii sys) 的 library-file 在库体顶层捕获源码绝对路径: - 路径位于 ~/.gf/site-lisp 之下 → 正式安装,不显示标记 - 否则 → 开发者模式,显示源码仓库根(home 前缀缩写成 ~) 效果: - 交互页眉:gfcode v2026.11.24 (~/git/gfcode2) - gf pi --help 首行:gf pi v2026.11.24 (~/git/gfcode2) 依赖 goldfish 侧修复:local 层显式注册的工具整体覆盖低层条目, 避免 user 层 package 字段残留导致 gf pi 误走缓存包。 --- tui/liii/pi/tui/cli/help.scm | 93 ++++++++++++++++++- tui/liii/pi/tui/interactive/header.scm | 75 ++++++++++++++- .../header/make-pi-header-test.scm | 3 + 3 files changed, 164 insertions(+), 7 deletions(-) diff --git a/tui/liii/pi/tui/cli/help.scm b/tui/liii/pi/tui/cli/help.scm index da4ee6c0..1f768cf8 100644 --- a/tui/liii/pi/tui/cli/help.scm +++ b/tui/liii/pi/tui/cli/help.scm @@ -5,11 +5,95 @@ ;; (define-library (liii pi tui cli help) - (import (scheme base) (scheme write) (liii raw-string)) + (import (scheme base) (scheme write) (liii raw-string) + (liii json) (liii path) (liii string) (liii sys) (srfi srfi-13) + (liii gfproject tools)) (export PI_HELP_TEXT display-pi-help) (begin - (define PI_HELP_TEXT - (string-append (&- #"" + ;; 库体顶层缓存本源码文件的绝对路径,用于判定正式安装 / 开发者模式。 + (define %self-source-file (library-file)) + + ;; 正式安装布局:库位于 ~/.gf/site-lisp 之下;否则为开发者模式。 + (define (%dev-mode?) + (and %self-source-file + (catch #t + (lambda () + (not (path-starts-with? (path %self-source-file) + (path-join (path-home) ".gf" "site-lisp"))) + ) ;lambda + (lambda args #f) + ) ;catch + ) ;and + ) ;define + + ;; 把绝对路径中的 home 前缀缩写成 ~,分隔符统一为 /。 + (define (%abbreviate-home dir) + (let* ((posix (path-as-posix (path dir))) + (home (catch #t + (lambda () (path-as-posix (path-home))) + (lambda args #f))) + ) ;let* + (if (and home (string-prefix? home posix)) + (let ((rest (substring posix (string-length home)))) + (if (or (string-null? rest) + (and (> (string-length rest) 0) (char=? (string-ref rest 0) #\/))) + (string-append "~" rest) + posix + ) ;if + ) ;let + posix + ) ;if + ) ;let* + ) ;define + + ;; 源码仓库根:...//tui/liii/pi/tui/cli/help.scm 上溯 5 级。 + (define (%source-repo-root) + (and %self-source-file + (catch #t + (lambda () + (let loop ((p (path-parent (path %self-source-file))) (n 0)) + (if (= n 5) (path->string p) (loop (path-parent p) (+ n 1))) + ) ;let + ) ;lambda + (lambda args #f) + ) ;catch + ) ;and + ) ;define + + ;; 开发者模式标记:" (~/git/gfcode2)";正式安装为空串。 + (define (%dev-suffix) + (if (%dev-mode?) + (let ((root (%source-repo-root))) + (if root (string-append " (" (%abbreviate-home root) ")") "") + ) ;let + "" + ) ;if + ) ;define + + ;; 读取 gfcode 自身 gfproject.json 的 package.version;失败回退 Goldfish 的 (version)。 + (define (%pi-version) + (catch #t + (lambda () + (let* ((bundle (gfproject-resolve-tool-bundle "pi")) + (base (bundle-ref bundle "tool_base_dir")) + ) ; + (if (not (string? base)) + (version) + (let* ((file (path->string (path-join (path base) "gfproject.json"))) + (pkg (json-ref (string->json (path-read-text file)) "package")) + ) ; + (or (json-ref-string pkg "version" #f) (version)) + ) ;let* + ) ;if + ) ;let* + ) ;lambda + (lambda args (version)) + ) ;catch + ) ;define + + (define (%pi-help-text) + (string-append "gf pi v" (%pi-version) (%dev-suffix) "\n" + (&- #"" gf pi - AI coding assistant script mode Usage: @@ -66,6 +150,9 @@ ) ;string-append ) ;define + ;; 完整帮助文本:首行含版本号与开发者模式标记。 + (define PI_HELP_TEXT (%pi-help-text)) + (define (display-pi-help) (display PI_HELP_TEXT) ) ;define diff --git a/tui/liii/pi/tui/interactive/header.scm b/tui/liii/pi/tui/interactive/header.scm index d97c69da..dc7ad931 100644 --- a/tui/liii/pi/tui/interactive/header.scm +++ b/tui/liii/pi/tui/interactive/header.scm @@ -12,12 +12,66 @@ (liii json) (liii path) (liii string) + (liii sys) + (srfi srfi-13) (liii tui component) (liii gfproject tools) (liii pi tui interactive common) ) ;import (begin + ;; 库体顶层缓存本源码文件的绝对路径(运行期调用 library-file 会返回 + ;; 调用方文件,必须在此捕获)。用于判定正式安装 / 开发者模式。 + (define %self-source-file (library-file)) + + ;; 正式安装布局:库位于 ~/.gf/site-lisp 之下;其余(如直接在本仓库 + ;; ~/git/gfcode2 运行)视为开发者模式。 + (define (%dev-mode?) + (and %self-source-file + (catch #t + (lambda () + (not (path-starts-with? (path %self-source-file) + (path-join (path-home) ".gf" "site-lisp"))) + ) ;lambda + (lambda args #f) + ) ;catch + ) ;and + ) ;define + + ;; 把绝对路径中的 home 前缀缩写成 ~,分隔符统一为 /。 + (define (%abbreviate-home dir) + (let* ((posix (path-as-posix (path dir))) + (home (catch #t + (lambda () (path-as-posix (path-home))) + (lambda args #f))) + ) ;let* + (if (and home (string-prefix? home posix)) + (let ((rest (substring posix (string-length home)))) + (if (or (string-null? rest) + (and (> (string-length rest) 0) (char=? (string-ref rest 0) #\/))) + (string-append "~" rest) + posix + ) ;if + ) ;let + posix + ) ;if + ) ;let* + ) ;define + + ;; 源码仓库根:...//tui/liii/pi/tui/interactive/header.scm 上溯 5 级。 + (define (%source-repo-root) + (and %self-source-file + (catch #t + (lambda () + (let loop ((p (path-parent (path %self-source-file))) (n 0)) + (if (= n 5) (path->string p) (loop (path-parent p) (+ n 1))) + ) ;let + ) ;lambda + (lambda args #f) + ) ;catch + ) ;and + ) ;define + (define (pi-header? obj) (and (component? obj) (let ((d (component-data obj))) @@ -41,10 +95,13 @@ (show #f (as-bold (apply as-true-color (cons c parts)))) ) ;define - ;; 页眉内容只随 version 变化,与宽度无关,故一次构造后复用 - (define (%header-lines version) + ;; 页眉内容只随 version 与开发者标记变化,与宽度无关,故一次构造后复用。 + ;; dev-suffix 为 #f(正式安装)或形如 " (~/git/gfcode2)" 的标记。 + (define (%header-lines version dev-suffix) (let* ((dot (%fg %c-mid " · ")) - (line1 (string-append " " (%fg-bold %c-brand "gfcode") (%fg %c-dim " v" version)) + (line1 (string-append " " (%fg-bold %c-brand "gfcode") (%fg %c-dim " v" version) + (or dev-suffix "") + ) ;string-append ) ;line1 (line2 (string-append " " (%fg %c-dim "escape") @@ -94,9 +151,19 @@ ) ;catch ) ;define + ;; 开发者模式标记:显示源码仓库根(home 前缀缩写成 ~);正式安装不显示。 + (define (%dev-suffix) + (if (%dev-mode?) + (let ((root (%source-repo-root))) + (and root (%fg %c-dim " (" (%abbreviate-home root) ")")) + ) ;let + #f + ) ;if + ) ;define + (define (make-pi-header . args) (let* ((version (%keyword-value :version args (%pi-tool-version))) - (lines (%header-lines version)) + (lines (%header-lines version (%dev-suffix))) (comp (make-component :render (lambda (self width) lines))) ) ; (component-data-set! comp (list 'pi-header version)) diff --git a/tui/tests/liii/pi/tui/interactive/header/make-pi-header-test.scm b/tui/tests/liii/pi/tui/interactive/header/make-pi-header-test.scm index 737616f1..ed4b673a 100644 --- a/tui/tests/liii/pi/tui/interactive/header/make-pi-header-test.scm +++ b/tui/tests/liii/pi/tui/interactive/header/make-pi-header-test.scm @@ -33,6 +33,9 @@ (check (list-ref plain-lines 0) => "") (check-true (string-contains? (list-ref plain-lines 1) " gfcode v")) (check-true (string-contains? (list-ref plain-lines 1) (version))) + ;; 本测试从源码仓库加载 header.scm,属开发者模式,应显示仓库根标记 ( ... gfcode2)。 + (check-true (string-contains? (list-ref plain-lines 1) "(")) + (check-true (string-contains? (list-ref plain-lines 1) "gfcode2)")) (check-true (string-contains? (list-ref plain-lines 2) "escape interrupt")) (check-true (string-contains? (list-ref plain-lines 2) "ctrl+c/ctrl+d clear/exit") ) ;check-true From 855a3ab3b7de6a8a939840990f39c59525ff39d8 Mon Sep 17 00:00:00 2001 From: Da Shen Date: Wed, 25 Nov 2026 00:02:44 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[1404]=20gf=20fmt=20=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=20header.scm=20=E4=B8=8E=20help.scm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tui/liii/pi/tui/cli/help.scm | 41 ++++++++++++++++++-------- tui/liii/pi/tui/interactive/header.scm | 25 ++++++++++------ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/tui/liii/pi/tui/cli/help.scm b/tui/liii/pi/tui/cli/help.scm index 1f768cf8..28f5b3fa 100644 --- a/tui/liii/pi/tui/cli/help.scm +++ b/tui/liii/pi/tui/cli/help.scm @@ -5,9 +5,16 @@ ;; (define-library (liii pi tui cli help) - (import (scheme base) (scheme write) (liii raw-string) - (liii json) (liii path) (liii string) (liii sys) (srfi srfi-13) - (liii gfproject tools)) + (import (scheme base) + (scheme write) + (liii raw-string) + (liii json) + (liii path) + (liii string) + (liii sys) + (srfi srfi-13) + (liii gfproject tools) + ) ;import (export PI_HELP_TEXT display-pi-help) (begin ;; 库体顶层缓存本源码文件的绝对路径,用于判定正式安装 / 开发者模式。 @@ -19,7 +26,9 @@ (catch #t (lambda () (not (path-starts-with? (path %self-source-file) - (path-join (path-home) ".gf" "site-lisp"))) + (path-join (path-home) ".gf" "site-lisp") + ) ;path-starts-with? + ) ;not ) ;lambda (lambda args #f) ) ;catch @@ -29,14 +38,16 @@ ;; 把绝对路径中的 home 前缀缩写成 ~,分隔符统一为 /。 (define (%abbreviate-home dir) (let* ((posix (path-as-posix (path dir))) - (home (catch #t - (lambda () (path-as-posix (path-home))) - (lambda args #f))) - ) ;let* + (home + (catch #t (lambda () (path-as-posix (path-home))) (lambda args #f)) + ) ;home + ) ; (if (and home (string-prefix? home posix)) (let ((rest (substring posix (string-length home)))) - (if (or (string-null? rest) - (and (> (string-length rest) 0) (char=? (string-ref rest 0) #\/))) + (if + (or (string-null? rest) + (and (> (string-length rest) 0) (char=? (string-ref rest 0) #\/)) + ) ;or (string-append "~" rest) posix ) ;if @@ -51,7 +62,8 @@ (and %self-source-file (catch #t (lambda () - (let loop ((p (path-parent (path %self-source-file))) (n 0)) + (let loop + ((p (path-parent (path %self-source-file))) (n 0)) (if (= n 5) (path->string p) (loop (path-parent p) (+ n 1))) ) ;let ) ;lambda @@ -92,7 +104,10 @@ ) ;define (define (%pi-help-text) - (string-append "gf pi v" (%pi-version) (%dev-suffix) "\n" + (string-append "gf pi v" + (%pi-version) + (%dev-suffix) + "\n" (&- #"" gf pi - AI coding assistant script mode @@ -145,7 +160,7 @@ (~/.gf/agent/settings.json), falling back to retry.maxRetries when the nested section is absent. "" - ) ;&- + ) ;&- "\n" ) ;string-append ) ;define diff --git a/tui/liii/pi/tui/interactive/header.scm b/tui/liii/pi/tui/interactive/header.scm index dc7ad931..9c03550e 100644 --- a/tui/liii/pi/tui/interactive/header.scm +++ b/tui/liii/pi/tui/interactive/header.scm @@ -31,7 +31,9 @@ (catch #t (lambda () (not (path-starts-with? (path %self-source-file) - (path-join (path-home) ".gf" "site-lisp"))) + (path-join (path-home) ".gf" "site-lisp") + ) ;path-starts-with? + ) ;not ) ;lambda (lambda args #f) ) ;catch @@ -41,14 +43,16 @@ ;; 把绝对路径中的 home 前缀缩写成 ~,分隔符统一为 /。 (define (%abbreviate-home dir) (let* ((posix (path-as-posix (path dir))) - (home (catch #t - (lambda () (path-as-posix (path-home))) - (lambda args #f))) - ) ;let* + (home + (catch #t (lambda () (path-as-posix (path-home))) (lambda args #f)) + ) ;home + ) ; (if (and home (string-prefix? home posix)) (let ((rest (substring posix (string-length home)))) - (if (or (string-null? rest) - (and (> (string-length rest) 0) (char=? (string-ref rest 0) #\/))) + (if + (or (string-null? rest) + (and (> (string-length rest) 0) (char=? (string-ref rest 0) #\/)) + ) ;or (string-append "~" rest) posix ) ;if @@ -63,7 +67,8 @@ (and %self-source-file (catch #t (lambda () - (let loop ((p (path-parent (path %self-source-file))) (n 0)) + (let loop + ((p (path-parent (path %self-source-file))) (n 0)) (if (= n 5) (path->string p) (loop (path-parent p) (+ n 1))) ) ;let ) ;lambda @@ -99,7 +104,9 @@ ;; dev-suffix 为 #f(正式安装)或形如 " (~/git/gfcode2)" 的标记。 (define (%header-lines version dev-suffix) (let* ((dot (%fg %c-mid " · ")) - (line1 (string-append " " (%fg-bold %c-brand "gfcode") (%fg %c-dim " v" version) + (line1 (string-append " " + (%fg-bold %c-brand "gfcode") + (%fg %c-dim " v" version) (or dev-suffix "") ) ;string-append ) ;line1 From f2869310b4b1e987474c91593a92749c0adb1943 Mon Sep 17 00:00:00 2001 From: Da Shen Date: Wed, 25 Nov 2026 00:07:32 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[1404]=20=E5=BC=80=E5=8F=91=E8=80=85?= =?UTF-8?q?=E6=A0=87=E8=AE=B0=E6=96=AD=E8=A8=80=E4=B8=8D=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E5=85=B7=E4=BD=93=E4=BB=93=E5=BA=93=E5=90=8D=EF=BC=88=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20CI=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liii/pi/tui/interactive/header/make-pi-header-test.scm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tui/tests/liii/pi/tui/interactive/header/make-pi-header-test.scm b/tui/tests/liii/pi/tui/interactive/header/make-pi-header-test.scm index ed4b673a..53155d21 100644 --- a/tui/tests/liii/pi/tui/interactive/header/make-pi-header-test.scm +++ b/tui/tests/liii/pi/tui/interactive/header/make-pi-header-test.scm @@ -33,9 +33,10 @@ (check (list-ref plain-lines 0) => "") (check-true (string-contains? (list-ref plain-lines 1) " gfcode v")) (check-true (string-contains? (list-ref plain-lines 1) (version))) - ;; 本测试从源码仓库加载 header.scm,属开发者模式,应显示仓库根标记 ( ... gfcode2)。 - (check-true (string-contains? (list-ref plain-lines 1) "(")) - (check-true (string-contains? (list-ref plain-lines 1) "gfcode2)")) + ;; 本测试从源码仓库加载 header.scm,属开发者模式,版本号后应有仓库根标记 ( ... )。 + ;; 不断言具体仓库名(CI 上 checkout 目录名与本地可能不同)。 + (check-true (string-contains? (list-ref plain-lines 1) " (")) + (check-true (string-contains? (list-ref plain-lines 1) ")")) (check-true (string-contains? (list-ref plain-lines 2) "escape interrupt")) (check-true (string-contains? (list-ref plain-lines 2) "ctrl+c/ctrl+d clear/exit") ) ;check-true