Prechádzať zdrojové kódy

fix(paas): fold code scripts as technical files

Python, shell and other source files now collapse with JSON/YAML/logs in
generated files, and the artifact library gains a separate code category
instead of listing scripts as documents.
241880436@seecoder.cn 3 dní pred
rodič
commit
eb1443a54e

+ 6 - 2
packages/app/e2e/paas/artifacts.spec.ts

@@ -16,7 +16,7 @@ test("project artifact library aggregates ended runs and previews files", async
   await expect(group.getByText("研究计划.pdf", { exact: true })).toBeVisible()
   await expect(group.getByText("研究计划.md", { exact: true })).toBeVisible()
   await expect(group.getByText("config.yml", { exact: true })).toBeVisible()
-  await expect(page.getByText("6 个文件", { exact: true })).toBeVisible()
+  await expect(page.getByText("7 个文件", { exact: true })).toBeVisible()
 
   // Duplicate artifact names collapse into one row.
   await expect(group.getByText("manifest.json", { exact: true })).toHaveCount(1)
@@ -45,7 +45,11 @@ test("artifact library filters by type and search", async ({ page }) => {
   await expect(library.getByText("config.yml", { exact: true })).toBeVisible()
   await expect(library.getByText("研究计划.md", { exact: true })).toHaveCount(0)
 
-  await page.getByRole("button", { name: "全部 · 6", exact: true }).click()
+  await page.getByRole("button", { name: "代码 · 1", exact: true }).click()
+  await expect(library.getByText("analysis.py", { exact: true })).toBeVisible()
+  await expect(library.getByText("config.yml", { exact: true })).toHaveCount(0)
+
+  await page.getByRole("button", { name: "全部 · 7", exact: true }).click()
   await page.getByLabel("搜索成果", { exact: true }).fill("不存在")
   await expect(library.getByText("没有匹配的成果", { exact: true })).toBeVisible()
   await page.getByRole("button", { name: "清除筛选", exact: true }).click()

+ 1 - 0
packages/app/e2e/paas/fixture.tsx

@@ -299,6 +299,7 @@ const api: PaasPlatform = {
             ? [
                 { name: "config.yml", path: "work/config.yml" },
                 { name: "trace.json", path: "work/trace.json" },
+                { name: "analysis.py", path: "work/analysis.py" },
               ]
             : []),
         ],

+ 5 - 3
packages/app/e2e/paas/qa-fixes.spec.ts

@@ -45,7 +45,7 @@ test("generated files separate preview cards from collapsed technical files", as
     .first()
     .click()
   const section = page.getByRole("region", { name: "生成文件" })
-  await expect(section.locator("header span")).toHaveText("6")
+  await expect(section.locator("header span")).toHaveText("7")
   const card = section.getByRole("button", { name: "预览 研究计划.md", exact: true })
   await expect(card).toBeVisible()
   const alignment = await card.evaluate((element) => {
@@ -54,11 +54,13 @@ test("generated files separate preview cards from collapsed technical files", as
     return Math.abs(label.top + label.height / 2 - (box.top + box.height / 2))
   })
   expect(alignment).toBeLessThanOrEqual(1)
-  await expect(section.getByText("技术文件 · 3", { exact: true })).toBeVisible()
+  await expect(section.getByText("技术文件 · 4", { exact: true })).toBeVisible()
   await expect(section.locator('button[aria-label="预览 manifest.json"]')).toHaveCount(1)
   await expect(section.locator('button[aria-label="预览 trace.json"]')).toBeHidden()
-  await section.getByText("技术文件 · 3", { exact: true }).click()
+  await expect(section.locator('button[aria-label="预览 analysis.py"]')).toBeHidden()
+  await section.getByText("技术文件 · 4", { exact: true }).click()
   await expect(section.getByRole("button", { name: "预览 trace.json", exact: true })).toBeVisible()
+  await expect(section.getByRole("button", { name: "预览 analysis.py", exact: true })).toBeVisible()
   await expect(section.locator('button[aria-label="预览 manifest.json"]')).toHaveCount(1)
 })
 

+ 2 - 1
packages/app/src/pages/paas/README.md

@@ -55,7 +55,8 @@
 
 ## P1 成果资产库(2026-12-01)
 
-- 侧栏新增“成果”页,按当前项目聚合**已结束任务**生成的成果与工作文件,支持全文搜索与文档/图片/数据/文件筛选。
+- 侧栏新增“成果”页,按当前项目聚合**已结束任务**生成的成果与工作文件,支持全文搜索与文档/图片/数据/代码/文件筛选。
+- Python、Shell 等脚本与配置、日志、中间产物按技术文件处理:会话“生成文件”中折叠,成果页归入“代码/数据”分类并排在同分组的末尾。
 - 来源任务来自平台任务索引与本机会话记录,按 `thread_id` 归属当前项目;归档项目与归档会话不纳入。
 - 同名文件去重,优先保留带平台身份的平台成果;工作文件补齐路径、大小等缺失信息。
 - 按来源会话分组;同一会话的多次运行合并,同名文件保留最新一版;每个分组只展开前 8 个文件,其余折叠(最多展开 200 个)。

+ 3 - 0
packages/app/src/pages/paas/artifact-library.test.ts

@@ -122,9 +122,12 @@ test("hides virtualenv and dependency internals from workspace listings", () =>
 
 test("classifies and filters artifacts by type and search text", () => {
   expect(artifactCategory({ name: "report.md" })).toBe("document")
+  expect(artifactCategory({ name: "report.html" })).toBe("document")
   expect(artifactCategory({ name: "figure.png" })).toBe("image")
   expect(artifactCategory({ name: "trace.json" })).toBe("data")
   expect(artifactCategory({ name: "dataset.csv" })).toBe("data")
+  expect(artifactCategory({ name: "analyze.py" })).toBe("code")
+  expect(artifactCategory({ name: "run.sh" })).toBe("code")
   expect(artifactCategory({ name: "archive.zip" })).toBe("other")
 
   const run = { agentID: "research", runID: "run-1", chatID: "chat-a", chatTitle: "已有研究", at: 10 }

+ 4 - 22
packages/app/src/pages/paas/artifact-library.ts

@@ -1,4 +1,5 @@
-import { paasPreviewKind, paasRecord, paasStatus, paasText } from "@/paas"
+import { paasRecord, paasStatus, paasText } from "@/paas"
+import { paasFileCategory, type PaasFileCategory } from "./file-groups"
 
 export type ArtifactChat = {
   id: string
@@ -40,25 +41,11 @@ export type ArtifactEntry = {
   source: "artifact" | "file"
 }
 
-export type ArtifactCategory = "document" | "image" | "data" | "other"
+export type ArtifactCategory = PaasFileCategory
 
 // Only runs that ended can be archived; active runs keep changing their workspace.
 const archivedStatuses = new Set(["completed", "partial", "failed", "cancelled"])
 
-const dataExtensions = new Set([
-  "json",
-  "jsonl",
-  "yaml",
-  "yml",
-  "toml",
-  "ini",
-  "cfg",
-  "csv",
-  "tsv",
-  "log",
-  "lock",
-])
-
 export function artifactRuns(input: {
   chats: ArtifactChat[]
   tasks: Record<string, unknown>[]
@@ -205,12 +192,7 @@ function dependencyFile(path: string, name: string) {
 }
 
 export function artifactCategory(file: { name: string; mime?: string }): ArtifactCategory {
-  const kind = paasPreviewKind(file.name, file.mime || "")
-  if (kind === "image") return "image"
-  const extension = file.name.split(".").pop()?.toLocaleLowerCase() || ""
-  if (dataExtensions.has(extension)) return "data"
-  if (kind === "markdown" || kind === "pdf" || kind === "text") return "document"
-  return "other"
+  return paasFileCategory(file)
 }
 
 export function filterArtifacts(

+ 3 - 1
packages/app/src/pages/paas/artifacts.tsx

@@ -19,6 +19,7 @@ const categories: { id: ArtifactCategory | "all"; label: string }[] = [
   { id: "document", label: "文档" },
   { id: "image", label: "图片" },
   { id: "data", label: "数据" },
+  { id: "code", label: "代码" },
   { id: "other", label: "其他" },
 ]
 
@@ -26,6 +27,7 @@ const categoryLabels: Record<ArtifactCategory, string> = {
   document: "文档",
   image: "图片",
   data: "数据",
+  code: "代码",
   other: "文件",
 }
 
@@ -398,7 +400,7 @@ async function pool<T>(items: T[], limit: number, task: (item: T) => Promise<voi
   await Promise.all(workers)
 }
 
-const categoryRank: Record<ArtifactCategory, number> = { document: 0, image: 1, data: 2, other: 3 }
+const categoryRank: Record<ArtifactCategory, number> = { document: 0, image: 1, data: 2, code: 3, other: 4 }
 
 function byRelevance(a: ArtifactEntry, b: ArtifactEntry) {
   return (

+ 41 - 0
packages/app/src/pages/paas/file-groups.test.ts

@@ -0,0 +1,41 @@
+import { expect, test } from "bun:test"
+import { groupPaasFiles, paasFileCategory } from "./file-groups"
+
+test("folds scripts, configs and logs but keeps research documents visible", () => {
+  const groups = groupPaasFiles([
+    { name: "report.md" },
+    { name: "figure.png" },
+    { name: "dataset.csv" },
+    { name: "analyze.py" },
+    { name: "run.sh" },
+    { name: "train.ipynb" },
+    { name: "config.yml" },
+    { name: "trace.json" },
+    { name: "trace.json" },
+  ])
+  expect(groups.files.map((file) => file.name)).toEqual([
+    "report.md",
+    "figure.png",
+    "dataset.csv",
+    "analyze.py",
+    "run.sh",
+    "train.ipynb",
+    "config.yml",
+    "trace.json",
+  ])
+  expect(groups.previewable.map((file) => file.name)).toEqual(["report.md", "figure.png", "dataset.csv"])
+  expect(groups.technical.map((file) => file.name)).toEqual([
+    "analyze.py",
+    "run.sh",
+    "train.ipynb",
+    "config.yml",
+    "trace.json",
+  ])
+})
+
+test("exposes code as its own artifact category", () => {
+  expect(paasFileCategory({ name: "analyze.py" })).toBe("code")
+  expect(paasFileCategory({ name: "run.sh" })).toBe("code")
+  expect(paasFileCategory({ name: "dataset.csv" })).toBe("data")
+  expect(paasFileCategory({ name: "report.md" })).toBe("document")
+})

+ 56 - 2
packages/app/src/pages/paas/file-groups.ts

@@ -8,8 +8,51 @@ export type PaasGeneratedFile = {
   size?: number
 }
 
+export type PaasFileCategory = "document" | "image" | "data" | "code" | "other"
+
 const technicalExtensions = new Set(["json", "jsonl", "yaml", "yml", "toml", "ini", "cfg", "log", "lock"])
 
+const codeExtensions = new Set([
+  "py",
+  "pyw",
+  "ipynb",
+  "sh",
+  "bash",
+  "zsh",
+  "ps1",
+  "bat",
+  "cmd",
+  "js",
+  "jsx",
+  "mjs",
+  "cjs",
+  "ts",
+  "tsx",
+  "r",
+  "rb",
+  "go",
+  "rs",
+  "c",
+  "h",
+  "cc",
+  "cpp",
+  "cxx",
+  "hpp",
+  "java",
+  "kt",
+  "swift",
+  "php",
+  "lua",
+  "pl",
+  "sql",
+  "css",
+  "scss",
+])
+
+const dataCategoryExtensions = new Set([...technicalExtensions, "csv", "tsv"])
+
+const extension = (name: string) => name.split(".").pop()?.toLocaleLowerCase()
+
 export function groupPaasFiles<T extends { name: string; mime?: string }>(files: T[]) {
   const unique = Array.from(new Map(files.map((file) => [file.name.trim().toLocaleLowerCase(), file])).values())
   const technical = unique.filter((file) => isTechnicalFile(file))
@@ -20,10 +63,21 @@ export function groupPaasFiles<T extends { name: string; mime?: string }>(files:
   }
 }
 
+export function paasFileCategory(file: { name: string; mime?: string }): PaasFileCategory {
+  const kind = paasPreviewKind(file.name, file.mime || "")
+  if (kind === "image") return "image"
+  const value = extension(file.name)
+  if (value && codeExtensions.has(value)) return "code"
+  if (value && dataCategoryExtensions.has(value)) return "data"
+  if (kind === "markdown" || kind === "pdf" || kind === "text") return "document"
+  return "other"
+}
+
 function isTechnicalFile(file: { name: string; mime?: string }) {
-  const extension = file.name.split(".").pop()?.toLocaleLowerCase()
+  const value = extension(file.name)
   return (
-    (!!extension && technicalExtensions.has(extension)) ||
+    (!!value && technicalExtensions.has(value)) ||
+    (!!value && codeExtensions.has(value)) ||
     paasPreviewKind(file.name, file.mime || "") === "unsupported"
   )
 }

+ 1 - 1
packages/app/src/pages/paas/generated-files.tsx

@@ -119,7 +119,7 @@ export function PaasGeneratedFiles(props: {
         <Show when={groups().technical.length}>
           <details class="paas-file-technical">
             <summary>技术文件 · {groups().technical.length}</summary>
-            <p class="paas-muted">JSON、YAML、日志与中间产物;展开后仍可预览或保存。</p>
+            <p class="paas-muted">JSON、YAML、日志、代码脚本与中间产物;展开后仍可预览或保存。</p>
             <For each={groups().technical}>{card}</For>
           </details>
         </Show>

+ 2 - 2
packages/app/src/pages/paas/run-panel.tsx

@@ -427,7 +427,7 @@ export function PaasRunPanel(props: {
           <Show when={artifactGroups().technical.length}>
             <details class="paas-run-technical">
               <summary>技术文件 · {artifactGroups().technical.length}</summary>
-              <p class="paas-muted">JSON、YAML、日志与中间产物;展开后仍可预览或保存。</p>
+              <p class="paas-muted">JSON、YAML、日志、代码脚本与中间产物;展开后仍可预览或保存。</p>
               <For each={artifactGroups().technical}>{artifactRow}</For>
             </details>
           </Show>
@@ -462,7 +462,7 @@ export function PaasRunPanel(props: {
         <Show when={workFileGroups().technical.length}>
           <details class="paas-run-technical">
             <summary>技术文件 · {workFileGroups().technical.length}</summary>
-            <p class="paas-muted">JSON、YAML、日志与中间产物;展开后仍可预览或保存。</p>
+            <p class="paas-muted">JSON、YAML、日志、代码脚本与中间产物;展开后仍可预览或保存。</p>
             <For each={workFileGroups().technical}>{workFileRow}</For>
           </details>
         </Show>

+ 4 - 0
packages/app/src/pages/paas/studio.css

@@ -493,6 +493,10 @@
   background: color-mix(in srgb, #ffd06c 28%, transparent);
   color: light-dark(#8a6212, #f2cf86);
 }
+.paas-artifact-kind[data-category="code"] {
+  background: color-mix(in srgb, #b9a7f2 26%, transparent);
+  color: light-dark(#5b3f9b, #cdbdf5);
+}
 .paas-artifact-name {
   display: flex;
   flex-direction: column;