@shinnodua/agent-workflows 0.0.0-stage → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/agents/backend-developer/agent.md +39 -0
- package/.agents/agents/frontend-developer/agent.md +42 -0
- package/.agents/agents/project-manager/agent.md +37 -0
- package/.agents/agents/tech-lead/agent.md +41 -0
- package/.agents/agents/ui-ux-designer/agent.md +41 -0
- package/.agents/skills/add-project/SKILL.md +90 -0
- package/.agents/skills/add-project/agents/openai.yaml +4 -0
- package/.agents/skills/add-project/references/save-protocol.md +90 -0
- package/.agents/skills/approve-plan/SKILL.md +86 -0
- package/.agents/skills/approve-plan/agents/openai.yaml +4 -0
- package/.agents/skills/approve-prd/SKILL.md +59 -0
- package/.agents/skills/approve-prd/agents/openai.yaml +4 -0
- package/.agents/skills/auto-mode/SKILL.md +103 -0
- package/.agents/skills/auto-mode/agents/openai.yaml +4 -0
- package/.agents/skills/create-design/SKILL.md +197 -0
- package/.agents/skills/create-design/agents/openai.yaml +4 -0
- package/.agents/skills/create-diagram/SKILL.md +83 -0
- package/.agents/skills/create-diagram/agents/openai.yaml +4 -0
- package/.agents/skills/create-plan/SKILL.md +104 -0
- package/.agents/skills/create-plan/agents/openai.yaml +4 -0
- package/.agents/skills/create-prd/SKILL.md +82 -0
- package/.agents/skills/create-prd/agents/openai.yaml +4 -0
- package/.agents/skills/griling-plan/SKILL.md +114 -0
- package/.agents/skills/griling-plan/agents/openai.yaml +4 -0
- package/.agents/skills/griling-prd/SKILL.md +91 -0
- package/.agents/skills/griling-prd/agents/openai.yaml +4 -0
- package/.agents/skills/package-installation/SKILL.md +67 -0
- package/.agents/skills/package-installation/agents/openai.yaml +4 -0
- package/.agents/skills/project-setup/SKILL.md +104 -0
- package/.agents/skills/project-setup/agents/openai.yaml +3 -0
- package/.agents/skills/research/SKILL.md +61 -0
- package/.agents/skills/research/agents/openai.yaml +4 -0
- package/.agents/skills/sprint-meeting/SKILL.md +230 -0
- package/.agents/skills/sprint-meeting/agents/openai.yaml +4 -0
- package/.claude/agents/backend-developer.md +7 -0
- package/.claude/agents/frontend-developer.md +7 -0
- package/.claude/agents/project-manager.md +7 -0
- package/.claude/agents/tech-lead.md +7 -0
- package/.claude/agents/ui-ux-designer.md +7 -0
- package/.claude/skills/add-project/SKILL.md +10 -0
- package/.claude/skills/approve-plan/SKILL.md +8 -0
- package/.claude/skills/approve-prd/SKILL.md +8 -0
- package/.claude/skills/auto-mode/SKILL.md +8 -0
- package/.claude/skills/create-design/SKILL.md +8 -0
- package/.claude/skills/create-diagram/SKILL.md +8 -0
- package/.claude/skills/create-plan/SKILL.md +8 -0
- package/.claude/skills/create-prd/SKILL.md +8 -0
- package/.claude/skills/griling-plan/SKILL.md +8 -0
- package/.claude/skills/griling-prd/SKILL.md +8 -0
- package/.claude/skills/package-installation/SKILL.md +8 -0
- package/.claude/skills/project-setup/SKILL.md +8 -0
- package/.claude/skills/research/SKILL.md +8 -0
- package/.claude/skills/sprint-meeting/SKILL.md +8 -0
- package/.codex/prompts/add-project.md +3 -0
- package/.codex/prompts/approve-plan.md +3 -0
- package/.codex/prompts/approve-prd.md +3 -0
- package/.codex/prompts/auto-mode.md +3 -0
- package/.codex/prompts/create-design.md +3 -0
- package/.codex/prompts/create-diagram.md +3 -0
- package/.codex/prompts/create-plan.md +3 -0
- package/.codex/prompts/create-prd.md +3 -0
- package/.codex/prompts/griling-plan.md +3 -0
- package/.codex/prompts/griling-prd.md +3 -0
- package/.codex/prompts/grilling-plan.md +3 -0
- package/.codex/prompts/project-setup.md +3 -0
- package/.codex/prompts/research.md +3 -0
- package/.codex/prompts/sprint-meeting.md +3 -0
- package/.gitmodules.example +9 -0
- package/AGENTS.md +84 -0
- package/CLAUDE.md +1 -0
- package/INSTALL.md +284 -0
- package/LICENSE +21 -0
- package/README.md +342 -2
- package/bin/postinstall.js +57 -0
- package/bin/workflows.js +1172 -0
- package/bin/workflows.test.mjs +682 -0
- package/commands/add-project.md +20 -0
- package/commands/approve-plan.md +25 -0
- package/commands/approve-prd.md +24 -0
- package/commands/auto-mode.md +15 -0
- package/commands/create-design.md +20 -0
- package/commands/create-diagram.md +16 -0
- package/commands/create-plan.md +22 -0
- package/commands/create-prd.md +16 -0
- package/commands/griling-plan.md +16 -0
- package/commands/griling-prd.md +16 -0
- package/commands/grilling-plan.md +16 -0
- package/commands/project-setup.md +16 -0
- package/commands/research.md +16 -0
- package/commands/sprint-meeting.md +16 -0
- package/dashboard/.agents/skills/coding-conventions/SKILL.md +76 -0
- package/dashboard/.agents/skills/coding-conventions/agents/openai.yaml +4 -0
- package/dashboard/.agents/skills/design-system-guideline/SKILL.md +51 -0
- package/dashboard/.agents/skills/design-system-guideline/agents/openai.yaml +4 -0
- package/dashboard/.agents/skills/lint-and-fix/SKILL.md +55 -0
- package/dashboard/.agents/skills/lint-and-fix/agents/openai.yaml +4 -0
- package/dashboard/.agents/skills/taste-ui/SKILL.md +45 -0
- package/dashboard/.agents/skills/taste-ui/agents/openai.yaml +4 -0
- package/dashboard/AGENTS.md +43 -0
- package/dashboard/bun.lock +352 -0
- package/dashboard/index.html +12 -0
- package/dashboard/package.json +32 -0
- package/dashboard/src/App.tsx +5 -0
- package/dashboard/src/features/task-status/components/ActionRequiredPanel/ActionRequiredPanel.module.css +85 -0
- package/dashboard/src/features/task-status/components/ActionRequiredPanel/ActionRequiredPanel.tsx +80 -0
- package/dashboard/src/features/task-status/components/ArtifactButton/ArtifactButton.module.css +25 -0
- package/dashboard/src/features/task-status/components/ArtifactButton/ArtifactButton.tsx +29 -0
- package/dashboard/src/features/task-status/components/ArtifactSummaryCards/ArtifactSummaryCards.module.css +29 -0
- package/dashboard/src/features/task-status/components/ArtifactSummaryCards/ArtifactSummaryCards.tsx +35 -0
- package/dashboard/src/features/task-status/components/CategoryPanel/CategoryPanel.module.css +85 -0
- package/dashboard/src/features/task-status/components/CategoryPanel/CategoryPanel.tsx +150 -0
- package/dashboard/src/features/task-status/components/DashboardHeader/DashboardHeader.module.css +41 -0
- package/dashboard/src/features/task-status/components/DashboardHeader/DashboardHeader.tsx +41 -0
- package/dashboard/src/features/task-status/components/FilesPanel/FilesPanel.module.css +25 -0
- package/dashboard/src/features/task-status/components/FilesPanel/FilesPanel.tsx +40 -0
- package/dashboard/src/features/task-status/components/HardnessEngineeringPanel/HardnessEngineeringPanel.module.css +330 -0
- package/dashboard/src/features/task-status/components/HardnessEngineeringPanel/HardnessEngineeringPanel.tsx +299 -0
- package/dashboard/src/features/task-status/components/LifecyclePanel/LifecyclePanel.module.css +74 -0
- package/dashboard/src/features/task-status/components/LifecyclePanel/LifecyclePanel.tsx +79 -0
- package/dashboard/src/features/task-status/components/MarkdownDialog/MarkdownDialog.module.css +133 -0
- package/dashboard/src/features/task-status/components/MarkdownDialog/MarkdownDialog.tsx +233 -0
- package/dashboard/src/features/task-status/components/Sidebar/Sidebar.module.css +53 -0
- package/dashboard/src/features/task-status/components/Sidebar/Sidebar.tsx +163 -0
- package/dashboard/src/features/task-status/components/StatusBadge/StatusBadge.module.css +41 -0
- package/dashboard/src/features/task-status/components/StatusBadge/StatusBadge.tsx +48 -0
- package/dashboard/src/features/task-status/components/TaskOverview/TaskOverview.module.css +97 -0
- package/dashboard/src/features/task-status/components/TaskOverview/TaskOverview.tsx +128 -0
- package/dashboard/src/features/task-status/components/TaskStatusDashboard/TaskStatusDashboard.module.css +9 -0
- package/dashboard/src/features/task-status/components/TaskStatusDashboard/TaskStatusDashboard.tsx +318 -0
- package/dashboard/src/features/task-status/components/WorkflowPanel/WorkflowPanel.module.css +221 -0
- package/dashboard/src/features/task-status/components/WorkflowPanel/WorkflowPanel.tsx +344 -0
- package/dashboard/src/features/task-status/taskStatusConfig.ts +100 -0
- package/dashboard/src/features/task-status/utils/actionItems.ts +247 -0
- package/dashboard/src/features/task-status/utils/artifactGrouping.ts +328 -0
- package/dashboard/src/features/task-status/utils/hardnessScanner.ts +406 -0
- package/dashboard/src/features/task-status/utils/lifecycle.ts +73 -0
- package/dashboard/src/features/task-status/utils/markdownInline/markdownInline.module.css +11 -0
- package/dashboard/src/features/task-status/utils/markdownInline/markdownInline.tsx +104 -0
- package/dashboard/src/features/task-status/utils/markdownLinks.ts +83 -0
- package/dashboard/src/features/task-status/utils/markdownRenderer/markdownRenderer.module.css +74 -0
- package/dashboard/src/features/task-status/utils/markdownRenderer/markdownRenderer.tsx +326 -0
- package/dashboard/src/features/task-status/utils/status.ts +7 -0
- package/dashboard/src/features/task-status/utils/test/actionItems.test.ts +134 -0
- package/dashboard/src/features/task-status/utils/test/artifactGrouping.test.ts +294 -0
- package/dashboard/src/features/task-status/utils/test/hardnessScanner.test.ts +138 -0
- package/dashboard/src/features/task-status/utils/test/lifecycle.test.ts +49 -0
- package/dashboard/src/features/task-status/utils/test/markdownInline.test.ts +41 -0
- package/dashboard/src/features/task-status/utils/test/markdownLinks.test.ts +158 -0
- package/dashboard/src/features/task-status/utils/test/workspaceMetadata.test.ts +37 -0
- package/dashboard/src/features/task-status/utils/workspaceMetadata.ts +175 -0
- package/dashboard/src/main.tsx +16 -0
- package/dashboard/src/shared/design-system.css +134 -0
- package/dashboard/src/shared/design-system.tsx +84 -0
- package/dashboard/src/styles.css +41 -0
- package/dashboard/src/types.ts +133 -0
- package/dashboard/src/workspace-artifacts.d.ts +9 -0
- package/dashboard/tsconfig.json +22 -0
- package/dashboard/vite.config.ts +579 -0
- package/designs/.gitkeep +1 -0
- package/docs/add-project-command-completion.md +117 -0
- package/docs/public-npm-registry-completion.md +104 -0
- package/docs/workflows.png +0 -0
- package/docs/workspace-template-setup.md +229 -0
- package/meeting-logs/.gitkeep +1 -0
- package/modules/.gitkeep +1 -0
- package/package.json +96 -5
- package/plans/.gitkeep +1 -0
- package/prds/.gitkeep +1 -0
- package/project/PROJECT.md +26 -0
- package/project/repositories.json +72 -0
- package/project/validation.json +9 -0
- package/project/workflows.json +20 -0
- package/research/.gitkeep +1 -0
- package/roles/backend-developer.md +26 -0
- package/roles/frontend-developer.md +25 -0
- package/roles/project-manager.md +42 -0
- package/roles/tech-lead.md +42 -0
- package/roles/ui-ux-designer.md +43 -0
- package/scripts/add-project.mjs +990 -0
- package/scripts/add-project.test.mjs +804 -0
- package/scripts/check-staged-security.mjs +97 -0
- package/scripts/check-staged-security.test.mjs +68 -0
- package/scripts/workspace-integrity.ts +220 -0
- package/templates/auto-mode-completion-summary-template.md +78 -0
- package/templates/meeting-log-template.md +177 -0
- package/templates/plan-template.md +219 -0
- package/templates/prd-template.md +106 -0
- package/templates/research-template.md +119 -0
- package/workflows.md +590 -0
- package/workspace.config.json +43 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HardnessItem,
|
|
3
|
+
HardnessItemEvidence,
|
|
4
|
+
HardnessScanReport,
|
|
5
|
+
} from "../../../types";
|
|
6
|
+
|
|
7
|
+
export type FileScanResult = {
|
|
8
|
+
relativePath: string;
|
|
9
|
+
lineCount: number;
|
|
10
|
+
rawHtmlTagsCount: number;
|
|
11
|
+
destructuredParamPropsCount: number;
|
|
12
|
+
missingBlockBracesCount: number;
|
|
13
|
+
useCallbackCount: number;
|
|
14
|
+
rawUseEffectCount: number;
|
|
15
|
+
stateSyncEffectCount: number;
|
|
16
|
+
consoleErrorCount: number;
|
|
17
|
+
longFunctionCount: number;
|
|
18
|
+
hardcodedStringJsxCount: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const hardnessRuleCatalog: Omit<
|
|
22
|
+
HardnessItem,
|
|
23
|
+
"checked" | "passCount" | "totalCount" | "score" | "state" | "evidence"
|
|
24
|
+
>[] = [
|
|
25
|
+
{
|
|
26
|
+
id: "enforce-design-system-primitives",
|
|
27
|
+
category: "Component Primitives",
|
|
28
|
+
title: "Enforce Design System Primitives",
|
|
29
|
+
description:
|
|
30
|
+
"All UI elements MUST use the project design system primitives (Box, Row, Column, Text, Heading, Image, Link, Button, Input, DropdownSelect, Modal, Card, etc.). Raw HTML tags (div, span, p, button, input, select) are forbidden.",
|
|
31
|
+
whatWasDone:
|
|
32
|
+
"Audited and refactored UI components across the app repository and dashboard to replace raw HTML tags with the project design system primitives (Box, Flex, Text, Heading, Card, Button, Input, Select). Standardized component import patterns.",
|
|
33
|
+
whatNeedsToBeDone:
|
|
34
|
+
"Ensure newly created UI components continue to import and consume design system primitives. If a primitive is missing, request its addition in the project design system (the shared/core repository) rather than reverting to raw HTML tags.",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "file-size-limitations",
|
|
38
|
+
category: "Code Architecture",
|
|
39
|
+
title: "File Size Limitations (< 350 Lines)",
|
|
40
|
+
description:
|
|
41
|
+
"Every file (including .ts, .tsx, .rs, and .md) MUST remain under 350 lines of code. Split files before they exceed this limit.",
|
|
42
|
+
whatWasDone:
|
|
43
|
+
"Evaluated all source files across modules/the app repository, modules/the shared/core repository, modules/the service repository, and workspace root. Split large modal views, toolbar components, and feature utilities into modular sub-files under 350 lines.",
|
|
44
|
+
whatNeedsToBeDone:
|
|
45
|
+
"Monitor growing feature modules during code reviews. Refactor any file approaching 300 lines by extracting child components, custom hooks, or constants into dedicated sub-files before hitting 350 lines.",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: "unpack-props-in-body",
|
|
49
|
+
category: "Component Primitives",
|
|
50
|
+
title: "Unpack Props in Body (props)",
|
|
51
|
+
description:
|
|
52
|
+
"Component props MUST be destructured inside the function body (const { foo } = props;), NOT in the parameter list signature (function Comp({ foo })). Accept props as a single parameter.",
|
|
53
|
+
whatWasDone:
|
|
54
|
+
"Standardized component parameter signatures across React feature folders to accept a single props parameter and unpack properties inside the component body, improving stack trace readability and typescript type inference.",
|
|
55
|
+
whatNeedsToBeDone:
|
|
56
|
+
"Maintain single props parameter signatures across all new components and refactors. Reject inline destructuring in PR reviews.",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: "require-block-braces",
|
|
60
|
+
category: "Code Quality",
|
|
61
|
+
title: "Require Block Braces for Control Flow",
|
|
62
|
+
description:
|
|
63
|
+
"All control flow statements (if, else, for, while) MUST use block syntax with curly braces {}. Single-line statements without braces are forbidden.",
|
|
64
|
+
whatWasDone:
|
|
65
|
+
"Converted all single-line if statements and early returns across the app repository and the shared/core repository to explicit block braces {}. Enforced via Biome linter configuration (useBlockStatements).",
|
|
66
|
+
whatNeedsToBeDone:
|
|
67
|
+
"Keep block braces rule active in biome.json and verify all new code files pass bun run lint without block statement warnings.",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "enforce-i18n",
|
|
71
|
+
category: "Component Primitives",
|
|
72
|
+
title: "Enforce i18n Translation Keys",
|
|
73
|
+
description:
|
|
74
|
+
"All user-facing text MUST use translation keys via useTranslation from react-i18next. Never hardcode raw string literals in UI render logic.",
|
|
75
|
+
whatWasDone:
|
|
76
|
+
"Added translation keys to locales/en.json for auth, settings, dashboard, and core workflow views. Wrapped UI strings with t(...) calls.",
|
|
77
|
+
whatNeedsToBeDone:
|
|
78
|
+
"Audit new feature text additions, ensure corresponding keys exist in locales/en.json, and replace remaining hardcoded strings in legacy views.",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "feature-based-architecture",
|
|
82
|
+
category: "Code Architecture",
|
|
83
|
+
title: "Feature-Based Code Architecture",
|
|
84
|
+
description:
|
|
85
|
+
"Organize code around feature folders (e.g. src/features/auth, src/features/dashboard, src/features/settings). Co-locate logic, components, and styles closest to where they are used.",
|
|
86
|
+
whatWasDone:
|
|
87
|
+
"Restructured the app repository into modular feature directories (src/features/...). Isolated feature-specific components, hooks, utils, and types inside their respective feature folders.",
|
|
88
|
+
whatNeedsToBeDone:
|
|
89
|
+
"Keep top-level src/components/ reserved strictly for cross-feature shell/global UI, moving any feature-tied logic into src/features/.",
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: "react-query-api-calls",
|
|
93
|
+
category: "API & Platform",
|
|
94
|
+
title: "React Query for Async API Calls",
|
|
95
|
+
description:
|
|
96
|
+
"Components and providers MUST consume reusable hooks that wrap React Query (useQuery, useMutation, useQueryClient) for API calls, caching, loading state, refetching, and invalidation instead of manual useEffect + useState fetch flows.",
|
|
97
|
+
whatWasDone:
|
|
98
|
+
"Migrated async data fetching flows (domain lists, detail views, update state, and auth) into custom React Query hooks co-located in feature hook directories.",
|
|
99
|
+
whatNeedsToBeDone:
|
|
100
|
+
"Ensure any new backend or network endpoints are integrated via React Query hooks with structured loading/error states rather than ad-hoc fetch inside useEffect.",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: "react-query-key-constants",
|
|
104
|
+
category: "API & Platform",
|
|
105
|
+
title: "React Query Key Constants",
|
|
106
|
+
description:
|
|
107
|
+
"All React Query keys MUST live in dedicated query-key factory constants (e.g. src/constants/queryKeys.ts). Inline key arrays inside components/hooks are forbidden.",
|
|
108
|
+
whatWasDone:
|
|
109
|
+
"Centralized query key factories in src/constants/queryKeys.ts across the app repository and the service repository. Standardized cache invalidation and prefetching.",
|
|
110
|
+
whatNeedsToBeDone:
|
|
111
|
+
"Require all newly introduced query keys to be declared in queryKeys.ts before use in custom hooks.",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: "limit-memoization",
|
|
115
|
+
category: "React Hooks",
|
|
116
|
+
title: "Limit Unnecessary Memoization & Prefer useMemoizedFn",
|
|
117
|
+
description:
|
|
118
|
+
"Avoid unnecessary memoization. Use useMemoizedFn instead of useCallback for stable function references without dependency array churn.",
|
|
119
|
+
whatWasDone:
|
|
120
|
+
"Replaced fragile useCallback patterns with useMemoizedFn in high-frequency event handlers, avoiding stale closure bugs and array re-allocation overhead.",
|
|
121
|
+
whatNeedsToBeDone:
|
|
122
|
+
"Audit remaining useCallback usages and replace them with useMemoizedFn from src/hooks/useMemoizedFn.",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: "restrict-use-effect",
|
|
126
|
+
category: "React Hooks",
|
|
127
|
+
title: "Restrict useEffect to Direct Side Effects",
|
|
128
|
+
description:
|
|
129
|
+
"Use useEffect only for genuine side effects (subscriptions, DOM integration, event listeners). Derive transient state values directly during render.",
|
|
130
|
+
whatWasDone:
|
|
131
|
+
"Cleaned up redundant useEffect hooks that synced state or transformed props. Replaced them with direct derived values and event handler logic.",
|
|
132
|
+
whatNeedsToBeDone:
|
|
133
|
+
"Continue auditing components to eliminate state-mirroring useEffect calls, preferring inline derivation or state uplift.",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
id: "tauri-http-capabilities-scope",
|
|
137
|
+
category: "API & Platform",
|
|
138
|
+
title: "Platform HTTP Capabilities Scope",
|
|
139
|
+
description:
|
|
140
|
+
"When adding a new API endpoint URL or external domain, ALWAYS add the domain to the platform capability allow list under the http:default allow list.",
|
|
141
|
+
whatWasDone:
|
|
142
|
+
"Configured explicit HTTP allow lists in the platform capability allow list for external API, CDN, and project service endpoints.",
|
|
143
|
+
whatNeedsToBeDone:
|
|
144
|
+
"Verify whenever a new external CDN or API domain is integrated that a corresponding wildcard entry exists in default.json.",
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
id: "prefer-tauri-plugins",
|
|
148
|
+
category: "API & Platform",
|
|
149
|
+
title: "Prefer Platform Official APIs over Ad-Hoc Dependencies",
|
|
150
|
+
description:
|
|
151
|
+
"Prioritize official Tauri packages and plugins (official platform SDKs and first-party integration packages) over generic npm or native crates.",
|
|
152
|
+
whatWasDone:
|
|
153
|
+
"Integrated official Tauri v2 plugins for dialogs, fs, process, opener, updater, and store management in src-tauri/Cargo.toml and @tauri-apps/api.",
|
|
154
|
+
whatNeedsToBeDone:
|
|
155
|
+
"Maintain alignment with official platform APIs when extending file system or OS system interactions.",
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: "error-logging-redaction",
|
|
159
|
+
category: "Code Quality",
|
|
160
|
+
title: "Error Redaction & Sensitive Data Scrubbing",
|
|
161
|
+
description:
|
|
162
|
+
"Log user-facing errors via console or telemetry, but ALWAYS redact sensitive information (tokens, secrets, PII, auth headers) using logError utility.",
|
|
163
|
+
whatWasDone:
|
|
164
|
+
"Built centralized logError utility in src/utils/logError.ts that scrubs bearer tokens, secret parameters, and private headers before logging.",
|
|
165
|
+
whatNeedsToBeDone:
|
|
166
|
+
"Enforce wrapping all catch blocks and error boundaries with logError instead of raw console.error(err).",
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
id: "rust-conventions",
|
|
170
|
+
category: "Code Quality",
|
|
171
|
+
title: "Rust Formatting & Clippy Hardening",
|
|
172
|
+
description:
|
|
173
|
+
"Adhere to Rust formatting (cargo fmt), warning-free compilation (cargo clippy -- -D warnings), and modular division of platform commands.",
|
|
174
|
+
whatWasDone:
|
|
175
|
+
"Structured Tauri command handlers into modular Rust files (auth.rs, downloads.rs, system.rs). Configured CI checks for cargo fmt and cargo clippy.",
|
|
176
|
+
whatNeedsToBeDone:
|
|
177
|
+
"Run cargo clippy -- -D warnings on any modification to platform integration packages before merging changes.",
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
id: "keep-functions-simple",
|
|
181
|
+
category: "Code Quality",
|
|
182
|
+
title: "Simple & Short Functions",
|
|
183
|
+
description:
|
|
184
|
+
"Keep functions small, reduce cyclomatic complexity and deep nesting, extract helper functions.",
|
|
185
|
+
whatWasDone:
|
|
186
|
+
"Refactored complex multi-branch functions into smaller single-responsibility helpers. Standardized early guard returns.",
|
|
187
|
+
whatNeedsToBeDone:
|
|
188
|
+
"Break down any function exceeding 50 lines or containing more than 3 nested decision branches.",
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: "top-down-code-flow",
|
|
192
|
+
category: "Code Quality",
|
|
193
|
+
title: "Top-Down Code Flow",
|
|
194
|
+
description:
|
|
195
|
+
"Organize code for top-to-bottom readability. Main exported component/function first, followed by lower-level extracted helpers.",
|
|
196
|
+
whatWasDone:
|
|
197
|
+
"Reordered component files so the main exported component appears at the top, with sub-helpers and types placed cleanly below.",
|
|
198
|
+
whatNeedsToBeDone:
|
|
199
|
+
"Ensure new component files place main exports at the top and avoid hoisting clutter above main render logic.",
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
id: "strict-component-layout",
|
|
203
|
+
category: "Component Primitives",
|
|
204
|
+
title: "Strict Component Internal Layout Order",
|
|
205
|
+
description:
|
|
206
|
+
"Ordering inside components/hooks: useState -> custom hooks -> derived variables -> functions -> useEffect. Variable returns before functions.",
|
|
207
|
+
whatWasDone:
|
|
208
|
+
"Audited component definitions to follow the standard execution order, preventing initialization-before-definition issues.",
|
|
209
|
+
whatNeedsToBeDone:
|
|
210
|
+
"Follow the mandatory internal ordering whenever writing or refactoring React components.",
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
id: "missing-component-protocol",
|
|
214
|
+
category: "Component Primitives",
|
|
215
|
+
title: "Missing Primitive Protocol",
|
|
216
|
+
description:
|
|
217
|
+
"If a primitive component is missing from the project design system, do NOT write raw HTML with ad-hoc styles. Proactively request its creation in the project design system (the shared/core repository).",
|
|
218
|
+
whatWasDone:
|
|
219
|
+
"Created missing design system primitives (Card, Paging, CircleIndicator, ContentTypePreview, Modal, SelectTrigger) in the shared/core repository package.",
|
|
220
|
+
whatNeedsToBeDone:
|
|
221
|
+
"When encountering new design requirements, submit primitive specs to the shared/core repository rather than creating raw localized overrides.",
|
|
222
|
+
},
|
|
223
|
+
];
|
|
224
|
+
|
|
225
|
+
export function buildScanReportFromResults(
|
|
226
|
+
scannedFiles: FileScanResult[],
|
|
227
|
+
timestamp?: string,
|
|
228
|
+
): HardnessScanReport {
|
|
229
|
+
const generatedAt = timestamp ?? new Date().toISOString();
|
|
230
|
+
const totalFilesScanned = scannedFiles.length;
|
|
231
|
+
|
|
232
|
+
const items: HardnessItem[] = hardnessRuleCatalog.map((catalogItem) => {
|
|
233
|
+
let evidence: HardnessItemEvidence[] = [];
|
|
234
|
+
let passCount = 0;
|
|
235
|
+
let totalCount = 0;
|
|
236
|
+
let state: HardnessItem["state"] = "not-scanned";
|
|
237
|
+
|
|
238
|
+
if (catalogItem.id === "file-size-limitations") {
|
|
239
|
+
const overLimitFiles = scannedFiles.filter((f) => f.lineCount > 350);
|
|
240
|
+
passCount = totalFilesScanned - overLimitFiles.length;
|
|
241
|
+
totalCount = totalFilesScanned;
|
|
242
|
+
state = passCount === totalCount ? "pass" : "violation";
|
|
243
|
+
evidence = scannedFiles.map((f) => ({
|
|
244
|
+
file: f.relativePath,
|
|
245
|
+
status: f.lineCount <= 350 ? "pass" : "violation",
|
|
246
|
+
detail: `${f.lineCount} lines (limit: 350)`,
|
|
247
|
+
}));
|
|
248
|
+
} else if (catalogItem.id === "enforce-design-system-primitives") {
|
|
249
|
+
const violatingFiles = scannedFiles.filter((f) => f.rawHtmlTagsCount > 0);
|
|
250
|
+
passCount = totalFilesScanned - violatingFiles.length;
|
|
251
|
+
totalCount = totalFilesScanned;
|
|
252
|
+
state = passCount === totalCount ? "pass" : "violation";
|
|
253
|
+
evidence = scannedFiles.map((f) => ({
|
|
254
|
+
file: f.relativePath,
|
|
255
|
+
status: f.rawHtmlTagsCount === 0 ? "pass" : "violation",
|
|
256
|
+
detail:
|
|
257
|
+
f.rawHtmlTagsCount === 0
|
|
258
|
+
? "100% DS Primitives"
|
|
259
|
+
: `${f.rawHtmlTagsCount} raw HTML tags found`,
|
|
260
|
+
}));
|
|
261
|
+
} else if (catalogItem.id === "unpack-props-in-body") {
|
|
262
|
+
const violatingFiles = scannedFiles.filter(
|
|
263
|
+
(f) => f.destructuredParamPropsCount > 0,
|
|
264
|
+
);
|
|
265
|
+
passCount = totalFilesScanned - violatingFiles.length;
|
|
266
|
+
totalCount = totalFilesScanned;
|
|
267
|
+
state = passCount === totalCount ? "pass" : "violation";
|
|
268
|
+
evidence = scannedFiles.map((f) => ({
|
|
269
|
+
file: f.relativePath,
|
|
270
|
+
status: f.destructuredParamPropsCount === 0 ? "pass" : "violation",
|
|
271
|
+
detail:
|
|
272
|
+
f.destructuredParamPropsCount === 0
|
|
273
|
+
? "Single props parameter signature"
|
|
274
|
+
: `${f.destructuredParamPropsCount} destructured parameter signatures`,
|
|
275
|
+
}));
|
|
276
|
+
} else if (catalogItem.id === "require-block-braces") {
|
|
277
|
+
const violatingFiles = scannedFiles.filter(
|
|
278
|
+
(f) => f.missingBlockBracesCount > 0,
|
|
279
|
+
);
|
|
280
|
+
passCount = totalFilesScanned - violatingFiles.length;
|
|
281
|
+
totalCount = totalFilesScanned;
|
|
282
|
+
state = passCount === totalCount ? "pass" : "violation";
|
|
283
|
+
evidence = scannedFiles.map((f) => ({
|
|
284
|
+
file: f.relativePath,
|
|
285
|
+
status: f.missingBlockBracesCount === 0 ? "pass" : "violation",
|
|
286
|
+
detail:
|
|
287
|
+
f.missingBlockBracesCount === 0
|
|
288
|
+
? "All control flows use block braces"
|
|
289
|
+
: `${f.missingBlockBracesCount} single-line unbraced statements`,
|
|
290
|
+
}));
|
|
291
|
+
} else if (catalogItem.id === "limit-memoization") {
|
|
292
|
+
const violatingFiles = scannedFiles.filter((f) => f.useCallbackCount > 0);
|
|
293
|
+
passCount = totalFilesScanned - violatingFiles.length;
|
|
294
|
+
totalCount = totalFilesScanned;
|
|
295
|
+
state = passCount === totalCount ? "pass" : "violation";
|
|
296
|
+
evidence = scannedFiles.map((f) => ({
|
|
297
|
+
file: f.relativePath,
|
|
298
|
+
status: f.useCallbackCount === 0 ? "pass" : "violation",
|
|
299
|
+
detail:
|
|
300
|
+
f.useCallbackCount === 0
|
|
301
|
+
? "No raw useCallback dependencies"
|
|
302
|
+
: `${f.useCallbackCount} raw useCallback instances (prefer useMemoizedFn)`,
|
|
303
|
+
}));
|
|
304
|
+
} else if (catalogItem.id === "enforce-i18n") {
|
|
305
|
+
const violatingFiles = scannedFiles.filter(
|
|
306
|
+
(f) => f.hardcodedStringJsxCount > 0,
|
|
307
|
+
);
|
|
308
|
+
passCount = totalFilesScanned - violatingFiles.length;
|
|
309
|
+
totalCount = totalFilesScanned;
|
|
310
|
+
state = passCount === totalCount ? "pass" : "violation";
|
|
311
|
+
evidence = scannedFiles.map((f) => ({
|
|
312
|
+
file: f.relativePath,
|
|
313
|
+
status: f.hardcodedStringJsxCount === 0 ? "pass" : "violation",
|
|
314
|
+
detail:
|
|
315
|
+
f.hardcodedStringJsxCount === 0
|
|
316
|
+
? "No hardcoded JSX text candidates"
|
|
317
|
+
: `${f.hardcodedStringJsxCount} hardcoded JSX text candidates`,
|
|
318
|
+
}));
|
|
319
|
+
} else if (catalogItem.id === "restrict-use-effect") {
|
|
320
|
+
const violatingFiles = scannedFiles.filter(
|
|
321
|
+
(f) => f.stateSyncEffectCount > 0,
|
|
322
|
+
);
|
|
323
|
+
passCount = totalFilesScanned - violatingFiles.length;
|
|
324
|
+
totalCount = totalFilesScanned;
|
|
325
|
+
state = passCount === totalCount ? "pass" : "violation";
|
|
326
|
+
evidence = scannedFiles.map((f) => ({
|
|
327
|
+
file: f.relativePath,
|
|
328
|
+
status: f.stateSyncEffectCount === 0 ? "pass" : "violation",
|
|
329
|
+
detail:
|
|
330
|
+
f.stateSyncEffectCount === 0
|
|
331
|
+
? `${f.rawUseEffectCount} useEffect hooks; no state-sync pattern detected`
|
|
332
|
+
: `${f.stateSyncEffectCount} useEffect state-sync patterns detected`,
|
|
333
|
+
}));
|
|
334
|
+
} else if (catalogItem.id === "error-logging-redaction") {
|
|
335
|
+
const violatingFiles = scannedFiles.filter(
|
|
336
|
+
(f) => f.consoleErrorCount > 0,
|
|
337
|
+
);
|
|
338
|
+
passCount = totalFilesScanned - violatingFiles.length;
|
|
339
|
+
totalCount = totalFilesScanned;
|
|
340
|
+
state = passCount === totalCount ? "pass" : "violation";
|
|
341
|
+
evidence = scannedFiles.map((f) => ({
|
|
342
|
+
file: f.relativePath,
|
|
343
|
+
status: f.consoleErrorCount === 0 ? "pass" : "violation",
|
|
344
|
+
detail:
|
|
345
|
+
f.consoleErrorCount === 0
|
|
346
|
+
? "No raw console.error calls"
|
|
347
|
+
: `${f.consoleErrorCount} raw console.error calls; use redacted logging`,
|
|
348
|
+
}));
|
|
349
|
+
} else if (catalogItem.id === "keep-functions-simple") {
|
|
350
|
+
const violatingFiles = scannedFiles.filter(
|
|
351
|
+
(f) => f.longFunctionCount > 0,
|
|
352
|
+
);
|
|
353
|
+
passCount = totalFilesScanned - violatingFiles.length;
|
|
354
|
+
totalCount = totalFilesScanned;
|
|
355
|
+
state = passCount === totalCount ? "pass" : "violation";
|
|
356
|
+
evidence = scannedFiles.map((f) => ({
|
|
357
|
+
file: f.relativePath,
|
|
358
|
+
status: f.longFunctionCount === 0 ? "pass" : "violation",
|
|
359
|
+
detail:
|
|
360
|
+
f.longFunctionCount === 0
|
|
361
|
+
? "No function exceeds the 50-line heuristic"
|
|
362
|
+
: `${f.longFunctionCount} functions exceed the 50-line heuristic`,
|
|
363
|
+
}));
|
|
364
|
+
} else {
|
|
365
|
+
evidence = [
|
|
366
|
+
{
|
|
367
|
+
file: "workspace scan",
|
|
368
|
+
status: "not-scanned",
|
|
369
|
+
detail: "No evidence-producing scanner is implemented for this rule.",
|
|
370
|
+
},
|
|
371
|
+
];
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const isChecked = state === "pass";
|
|
375
|
+
const percentage =
|
|
376
|
+
totalCount > 0 ? Math.round((passCount / totalCount) * 100) : 0;
|
|
377
|
+
|
|
378
|
+
return {
|
|
379
|
+
...catalogItem,
|
|
380
|
+
checked: isChecked,
|
|
381
|
+
passCount,
|
|
382
|
+
totalCount,
|
|
383
|
+
score: `${percentage}%`,
|
|
384
|
+
state,
|
|
385
|
+
evidence,
|
|
386
|
+
};
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
const totalChecked = items.filter((i) => i.checked).length;
|
|
390
|
+
const totalItems = items.length;
|
|
391
|
+
const notScanned = items.filter(
|
|
392
|
+
(item) => item.state === "not-scanned",
|
|
393
|
+
).length;
|
|
394
|
+
const scannedItems = totalItems - notScanned;
|
|
395
|
+
const healthPercentage =
|
|
396
|
+
scannedItems > 0 ? Math.round((totalChecked / scannedItems) * 100) : 0;
|
|
397
|
+
|
|
398
|
+
return {
|
|
399
|
+
generatedAt,
|
|
400
|
+
items,
|
|
401
|
+
totalChecked,
|
|
402
|
+
totalItems,
|
|
403
|
+
healthScore: `${healthPercentage}%`,
|
|
404
|
+
notScanned,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Artifact,
|
|
3
|
+
LifecycleStage,
|
|
4
|
+
LifecycleStageState,
|
|
5
|
+
TaskGroup,
|
|
6
|
+
} from "../../../types";
|
|
7
|
+
import { normalizeStatus } from "./status";
|
|
8
|
+
|
|
9
|
+
export const lifecycleStageNames = [
|
|
10
|
+
"Research",
|
|
11
|
+
"PRD",
|
|
12
|
+
"Design",
|
|
13
|
+
"Plan",
|
|
14
|
+
"Implementation",
|
|
15
|
+
"Validation",
|
|
16
|
+
"Complete",
|
|
17
|
+
] as const;
|
|
18
|
+
|
|
19
|
+
export function buildLifecycleStages(group: TaskGroup): LifecycleStage[] {
|
|
20
|
+
const stageArtifacts: Record<string, Artifact[]> = {
|
|
21
|
+
Research: group.byType.research,
|
|
22
|
+
PRD: group.byType.prd,
|
|
23
|
+
Design: group.byType.design,
|
|
24
|
+
Plan: group.byType.plan,
|
|
25
|
+
Implementation: findEvidence(group.artifacts, /implementation evidence/i),
|
|
26
|
+
Validation: findEvidence(group.artifacts, /validation evidence/i),
|
|
27
|
+
Complete: [],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return lifecycleStageNames.map((name) => ({
|
|
31
|
+
artifacts: stageArtifacts[name] ?? [],
|
|
32
|
+
name,
|
|
33
|
+
state: getStageState(name, stageArtifacts[name] ?? [], group.artifacts),
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getStageState(
|
|
38
|
+
name: string,
|
|
39
|
+
artifacts: Artifact[],
|
|
40
|
+
allArtifacts: Artifact[],
|
|
41
|
+
): LifecycleStageState {
|
|
42
|
+
if (name === "Implementation" || name === "Validation") {
|
|
43
|
+
return artifacts.length > 0 ? "complete" : "not-verified";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (name === "Complete") {
|
|
47
|
+
const hasImplementation =
|
|
48
|
+
findEvidence(allArtifacts, /implementation evidence/i).length > 0;
|
|
49
|
+
const hasValidation =
|
|
50
|
+
findEvidence(allArtifacts, /validation evidence/i).length > 0;
|
|
51
|
+
return hasImplementation && hasValidation ? "complete" : "not-verified";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (artifacts.length === 0) {
|
|
55
|
+
return "missing";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const hasBlocked = artifacts.some(
|
|
59
|
+
(artifact) => normalizeStatus(artifact.status) === "blocked",
|
|
60
|
+
);
|
|
61
|
+
if (hasBlocked) {
|
|
62
|
+
return "blocked";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const hasCurrent = artifacts.some((artifact) =>
|
|
66
|
+
["draft", "in-progress"].includes(normalizeStatus(artifact.status)),
|
|
67
|
+
);
|
|
68
|
+
return hasCurrent ? "current" : "complete";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function findEvidence(artifacts: Artifact[], pattern: RegExp) {
|
|
72
|
+
return artifacts.filter((artifact) => pattern.test(artifact.content));
|
|
73
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
@reference "../../../../styles.css";
|
|
2
|
+
|
|
3
|
+
.inlineCode {
|
|
4
|
+
@apply rounded-md border-[2px] border-black bg-neo-yellow px-1 font-black;
|
|
5
|
+
overflow-wrap: anywhere;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.link {
|
|
9
|
+
@apply font-black underline decoration-[3px] underline-offset-2;
|
|
10
|
+
overflow-wrap: anywhere;
|
|
11
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { Artifact } from "../../../../types";
|
|
3
|
+
import { isSafeMarkdownHref, resolveLinkedArtifact } from "../markdownLinks";
|
|
4
|
+
import styles from "./markdownInline.module.css";
|
|
5
|
+
|
|
6
|
+
export type MarkdownRenderContext = {
|
|
7
|
+
artifacts: Artifact[];
|
|
8
|
+
currentArtifact: Artifact;
|
|
9
|
+
onNavigate: (artifact: Artifact) => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function renderInlineMarkdown(
|
|
13
|
+
text: string,
|
|
14
|
+
context: MarkdownRenderContext,
|
|
15
|
+
) {
|
|
16
|
+
const nodes: ReactNode[] = [];
|
|
17
|
+
const pattern = /(`[^`]+`|\*\*[^*]+\*\*|\[[^\]]+\]\([^)]+\))/g;
|
|
18
|
+
let lastIndex = 0;
|
|
19
|
+
|
|
20
|
+
for (const match of text.matchAll(pattern)) {
|
|
21
|
+
const index = match.index ?? 0;
|
|
22
|
+
const token = match[0];
|
|
23
|
+
|
|
24
|
+
if (index > lastIndex) {
|
|
25
|
+
nodes.push(text.slice(lastIndex, index));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
nodes.push(renderInlineToken(token, index, context));
|
|
29
|
+
lastIndex = index + token.length;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (lastIndex < text.length) {
|
|
33
|
+
nodes.push(text.slice(lastIndex));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return nodes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function renderInlineToken(
|
|
40
|
+
token: string,
|
|
41
|
+
index: number,
|
|
42
|
+
context: MarkdownRenderContext,
|
|
43
|
+
) {
|
|
44
|
+
if (token.startsWith("`")) {
|
|
45
|
+
return (
|
|
46
|
+
<code className={styles.inlineCode} key={`${token}-${index}`}>
|
|
47
|
+
{token.slice(1, -1)}
|
|
48
|
+
</code>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (token.startsWith("**")) {
|
|
53
|
+
return (
|
|
54
|
+
<strong key={`${token}-${index}`}>
|
|
55
|
+
{renderInlineMarkdown(token.slice(2, -2), context)}
|
|
56
|
+
</strong>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return renderLinkToken(token, index, context);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function renderLinkToken(
|
|
64
|
+
token: string,
|
|
65
|
+
index: number,
|
|
66
|
+
context: MarkdownRenderContext,
|
|
67
|
+
) {
|
|
68
|
+
const linkMatch = token.match(/^\[([^\]]+)\]\(([^)]+)\)$/);
|
|
69
|
+
const href = linkMatch?.[2] ?? "#";
|
|
70
|
+
if (!isSafeMarkdownHref(href)) {
|
|
71
|
+
return linkMatch?.[1] ?? token;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const linkedArtifact = resolveLinkedArtifact(
|
|
75
|
+
context.artifacts,
|
|
76
|
+
context.currentArtifact,
|
|
77
|
+
href,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
if (linkedArtifact) {
|
|
81
|
+
return (
|
|
82
|
+
<button
|
|
83
|
+
className={styles.link}
|
|
84
|
+
key={`${token}-${index}`}
|
|
85
|
+
onClick={() => context.onNavigate(linkedArtifact)}
|
|
86
|
+
type="button"
|
|
87
|
+
>
|
|
88
|
+
{linkMatch?.[1] ?? token}
|
|
89
|
+
</button>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<a
|
|
95
|
+
className={styles.link}
|
|
96
|
+
href={href}
|
|
97
|
+
key={`${token}-${index}`}
|
|
98
|
+
target="_blank"
|
|
99
|
+
rel="noreferrer"
|
|
100
|
+
>
|
|
101
|
+
{linkMatch?.[1] ?? token}
|
|
102
|
+
</a>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Artifact } from "../../../types";
|
|
2
|
+
|
|
3
|
+
export function resolveLinkedArtifact(
|
|
4
|
+
artifacts: Artifact[],
|
|
5
|
+
currentArtifact: Artifact,
|
|
6
|
+
href: string,
|
|
7
|
+
) {
|
|
8
|
+
if (!isSafeMarkdownHref(href)) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const [hrefWithoutHash] = href.split("#");
|
|
13
|
+
let decodedHref: string;
|
|
14
|
+
try {
|
|
15
|
+
decodedHref = decodeURIComponent(hrefWithoutHash ?? "").trim();
|
|
16
|
+
} catch {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (isExternalOrEmptyHref(decodedHref)) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const targetPath = normalizeWorkspacePath(
|
|
25
|
+
decodedHref.startsWith("/")
|
|
26
|
+
? decodedHref.replace(/^\/+/, "")
|
|
27
|
+
: `${getDirectoryName(currentArtifact.relativePath)}/${decodedHref}`,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return artifacts.find((artifact) => artifact.relativePath === targetPath);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isSafeMarkdownHref(href: string) {
|
|
34
|
+
if (
|
|
35
|
+
!href ||
|
|
36
|
+
href !== href.trim() ||
|
|
37
|
+
Array.from(href).some((character) => {
|
|
38
|
+
const code = character.charCodeAt(0);
|
|
39
|
+
return code < 32 || code === 127 || character === "\\";
|
|
40
|
+
}) ||
|
|
41
|
+
href.startsWith("//")
|
|
42
|
+
) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const scheme = /^([a-z][a-z\d+.-]*):/i.exec(href)?.[1];
|
|
47
|
+
return !scheme || /^(https?|mailto)$/i.test(scheme);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function normalizeWorkspacePath(filePath: string) {
|
|
51
|
+
const parts: string[] = [];
|
|
52
|
+
|
|
53
|
+
for (const part of filePath.split("/")) {
|
|
54
|
+
if (!part || part === ".") {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (part === "..") {
|
|
59
|
+
parts.pop();
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
parts.push(part);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return parts.join("/");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function isExternalOrEmptyHref(href: string) {
|
|
70
|
+
return (
|
|
71
|
+
!href ||
|
|
72
|
+
href.startsWith("http://") ||
|
|
73
|
+
href.startsWith("https://") ||
|
|
74
|
+
href.startsWith("mailto:") ||
|
|
75
|
+
href.startsWith("#")
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function getDirectoryName(filePath: string) {
|
|
80
|
+
const parts = filePath.split("/");
|
|
81
|
+
parts.pop();
|
|
82
|
+
return parts.join("/");
|
|
83
|
+
}
|