Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
213 commits
Select commit Hold shift + click to select a range
b19c33c
Initial plan
Copilot Dec 3, 2025
b36af8e
Fix useProject bug and create global projectStore for consistent proj…
Copilot Dec 3, 2025
51b758a
Apply code review feedback: use getCurrentProjectId utility consistently
Copilot Dec 3, 2025
f87a39d
Add PROJECT-ID-BEST-PRACTICES.md documentation
Copilot Dec 3, 2025
d8ca7ee
Merge pull request #131 from Stasshe/copilot/investigate-project-ts-i…
Stasshe Dec 3, 2025
81566ea
Initial plan
Copilot Dec 3, 2025
898f595
fix(i18n): Cache initial locale to prevent repeated warnings on page …
Copilot Dec 3, 2025
abda062
Merge pull request #133 from Stasshe/copilot/improve-try-handling-on-…
Stasshe Dec 3, 2025
e8af199
Initial plan
Copilot Dec 3, 2025
8541a4e
Fix shell string tokenization to handle $() and nested quotes correctly
Copilot Dec 3, 2025
4b333b4
Improve backtick and quote handling in shell tokenizer
Copilot Dec 3, 2025
31f6c27
Add JS/TS template literal tokenizer with nested ${} support
Copilot Dec 3, 2025
da11f35
Fix edge cases in string parsing (bounds check and unclosed backticks)
Copilot Dec 3, 2025
698fa68
Merge pull request #134 from Stasshe/copilot/fix-inline-highlighter-q…
Stasshe Dec 3, 2025
ac2a28e
Initial plan
Copilot Dec 3, 2025
67a39c1
Fix DiffTab and AIReviewTab theme handling - use defineAndSetMonacoTh…
Copilot Dec 3, 2025
34aa4fb
Fix DiffTab height for single file view and remove 'as any' type casts
Copilot Dec 3, 2025
0f2a8e1
Increase DiffTab height: single file uses 100% height, multiple files…
Copilot Dec 3, 2025
5fb651f
Fix DiffTab reuse logic and add real-time content sync across panes
Copilot Dec 3, 2025
75a5cb0
Improve DiffTab file change listener: use ref for diffs, fix type nar…
Copilot Dec 3, 2025
041a62e
Fix DiffTab real-time sync: use memory-based updateDiffTabContent ins…
Copilot Dec 3, 2025
e6deb9e
Optimize updateDiffTabContent to avoid unnecessary re-renders
Copilot Dec 3, 2025
bb7ca19
Fix theme re-setting issue and add real-time sync between DiffTab and…
Copilot Dec 3, 2025
3141796
Simplify: remove updateDiffTabContent and extend updateTabContent to …
Copilot Dec 3, 2025
2f851cc
Fix theme not being applied after tab switch - always call setTheme
Copilot Dec 3, 2025
6856de9
Merge pull request #135 from Stasshe/copilot/add-theme-setting-difftab
Stasshe Dec 3, 2025
80437f0
Initial plan
Copilot Dec 3, 2025
e3db988
Fix Monaco theme handling for DiffTab and CodeEditor consistency
Copilot Dec 3, 2025
b00bb32
Simplify Monaco theme logic using themeName instead of color detection
Copilot Dec 3, 2025
6878859
Merge pull request #136 from Stasshe/copilot/fix-diff-theme-reset-issue
Stasshe Dec 3, 2025
0d1a7ea
Initial plan
Copilot Dec 3, 2025
0a5dc33
Fix DiffTab wordWrap to use user settings instead of hardcoded value
Copilot Dec 3, 2025
ea71d17
Merge pull request #137 from Stasshe/copilot/fix-difftab-line-wrapping
Stasshe Dec 3, 2025
6417458
Initial plan
Copilot Dec 3, 2025
f8b3c58
Add viewport configuration for 60% initial scale on mobile devices
Copilot Dec 3, 2025
9ae13b3
0.7
Stasshe Dec 3, 2025
b87e6f0
Merge pull request #138 from Stasshe/copilot/add-viewport-settings
Stasshe Dec 3, 2025
10a45f1
0.9
Stasshe Dec 3, 2025
a36a751
Initial plan
Copilot Dec 3, 2025
7c68643
Initial plan
Copilot Dec 3, 2025
ed9dc32
Refactor MarkdownPreviewTab with lazy-loaded Mermaid components
Copilot Dec 3, 2025
7cdaa8f
Add real-time terminal logging for git push and npm install operations
Copilot Dec 3, 2025
8c2aaa9
Fix code review feedback: improve progress output accuracy and use AN…
Copilot Dec 3, 2025
a794fde
Final improvements: use descriptive progress messages and remove redu…
Copilot Dec 3, 2025
d578be9
Address code review feedback: improve types and fix dependencies
Copilot Dec 3, 2025
7ddf5da
Add newline after warning message for consistent formatting
Copilot Dec 3, 2025
854fa84
Fix loading spinner conflict with progress output - use inline spinne…
Copilot Dec 3, 2025
034de35
Fix Mermaid performance and use proper types
Copilot Dec 3, 2025
a05e792
Refactor: use emitSpinnerProgress consistently throughout npm.ts
Copilot Dec 3, 2025
a50fa8e
Add mermaid zoom state persistence and real-time markdown preview
Copilot Dec 3, 2025
d4defdc
Add TerminalUI API for advanced terminal display and integrate with n…
Copilot Dec 3, 2025
e72557e
Fix double scroll structure in Mermaid diagram display
Copilot Dec 3, 2025
ba43d99
Fix spinner newline issue - don't add newlines to in-place terminal u…
Copilot Dec 3, 2025
a61cdf2
Merge pull request #139 from Stasshe/copilot/improve-md-preview-perfo…
Stasshe Dec 3, 2025
c0667e9
Initial plan
Copilot Dec 3, 2025
eb5f00c
Add react-dnd drag and drop support to FileTree for internal file/fol…
Copilot Dec 3, 2025
2db0a3f
Refactor resize handling with unified useResize and usePaneResize hooks
Copilot Dec 3, 2025
eb048c7
Fix spinner by combining ANSI sequences into single writes to prevent…
Copilot Dec 3, 2025
f098dbd
Address code review feedback: improve readability and add safety limits
Copilot Dec 3, 2025
99128b0
Merge pull request #140 from Stasshe/copilot/add-logging-to-terminal
Stasshe Dec 3, 2025
6bc357f
Initial plan
Copilot Dec 3, 2025
6cfb69a
Add progress callback to display all packages (direct + transitive) d…
Copilot Dec 3, 2025
03018d9
Fix unused parameters in progress callback
Copilot Dec 3, 2025
16846cd
Fix FileTree drag-drop: use mv instead of rename, add file drop to pane
Copilot Dec 3, 2025
bbcee03
Fix spinner newline issue by adding write lock to prevent concurrent …
Copilot Dec 3, 2025
3d1919f
Fix terminal newline issue by adding write queue to serialize xterm w…
Copilot Dec 3, 2025
516d921
Refactor: remove redundant safeWrite from terminalUI, delegate to Ter…
Copilot Dec 3, 2025
3b96928
Update src/engine/cmd/global/npm.ts
Stasshe Dec 3, 2025
0c7f976
Merge pull request #142 from Stasshe/copilot/log-all-node-installations
Stasshe Dec 3, 2025
26fbae2
Initial plan
Copilot Dec 3, 2025
171e2bd
Changes before error encountered
Copilot Dec 3, 2025
e2c651f
Initial plan
Copilot Dec 3, 2025
addb6b9
Add ANSI color support for chalk and similar libraries in NodeRuntime
Copilot Dec 3, 2025
d9dc2c7
Add Chromium-spoofed navigator for color support on iOS
Copilot Dec 3, 2025
6f404f4
refactor: migrate ChatSpace operations to chatStorageAdapter and fix …
Copilot Dec 3, 2025
fad04c4
Move Chromium-spoofed navigator from ModuleLoader to NodeRuntime
Copilot Dec 3, 2025
5bcaae6
Fix code review issues: remove dynamic imports and any type
Copilot Dec 3, 2025
9a378e9
Fix FileTree DnD: use shared constants and improve drop logic
Copilot Dec 3, 2025
51d378e
Use getters instead of private fields, remove any types
Copilot Dec 3, 2025
dc413d7
Spoof globalThis.navigator for supports-color detection
Copilot Dec 4, 2025
8cb31a2
Add detailed logging to debug FileTree DnD mv operation
Copilot Dec 4, 2025
659c4bd
fix: improve revert file restoration and optimize prompt management
Copilot Dec 4, 2025
875953e
Merge pull request #143 from Stasshe/copilot/fix-chalk-module-display…
Stasshe Dec 4, 2025
c5adb17
Fix FileTree DnD ref binding - remove native event handlers that conf…
Copilot Dec 4, 2025
a576e3e
Fix FileTree DnD - use callback ref to properly attach both drag and …
Copilot Dec 4, 2025
dcd63b1
Merge pull request #141 from Stasshe/copilot/refactor-drag-and-drop-i…
Stasshe Dec 4, 2025
65b8181
fix: use aiStorageAdapter originalSnapshot for file restoration and f…
Copilot Dec 4, 2025
5732a42
Merge pull request #144 from Stasshe/copilot/fix-revert-processing-is…
Stasshe Dec 4, 2025
317ade7
Initial plan
Copilot Dec 4, 2025
50a71a7
Changes before error encountered
Copilot Dec 4, 2025
b11d626
Fix D&D issues: add grab handle for mobile, fix tab context menu
Copilot Dec 4, 2025
b3d0fef
Fix TabBar: click shows context menu, remove MoreVertical button
Copilot Dec 4, 2025
3ad0396
Fix code review issues: move refs, fix ts-ignore
Copilot Dec 4, 2025
5110665
Fix TabBar close button conflict and FileTree D&D with callback refs
Copilot Dec 4, 2025
9163086
Wrap debug logs in development condition
Copilot Dec 4, 2025
231b507
Fix drag preview, use NEXT_PUBLIC_IS_DEV_SERVER, fix tab close button
Copilot Dec 4, 2025
7c85db1
Use data attribute for close button detection instead of hardcoded el…
Copilot Dec 4, 2025
bc5c8d1
Fix FileTree D&D: prevent native events from blocking react-dnd, fix …
Copilot Dec 4, 2025
13c29f3
Merge pull request #148 from Stasshe/copilot/fix-filetree-dnd-issues-…
Stasshe Dec 4, 2025
1509d98
Initial plan
Copilot Dec 4, 2025
6d13dc1
Fix tab bar button and context menu conflicts
Copilot Dec 4, 2025
b170cb8
Address code review: add null checks for ref.current
Copilot Dec 4, 2025
730fd2c
Change touch behavior: tap shows context menu (instead of long-press)
Copilot Dec 4, 2025
4dc3eee
Merge pull request #149 from Stasshe/copilot/fix-tab-bar-issues
Stasshe Dec 4, 2025
15f177c
Initial plan
Copilot Dec 4, 2025
feef65c
Fix duplicate diff tab opening and add file deletion handling for tabs
Copilot Dec 4, 2025
0bfeb26
Refactor: centralize file deletion handling in tabStore
Copilot Dec 4, 2025
dbaafa9
Fix type casting in handleFileDeleted to use DiffTab instead of any
Copilot Dec 4, 2025
0e1c3ee
Fix multi-file diff tab handling by checking individual diff entry paths
Copilot Dec 4, 2025
00de7a6
Fix diff tab handling: only update editable diffs (working directory)…
Copilot Dec 4, 2025
637862c
Merge pull request #150 from Stasshe/copilot/fix-tabstore-preview-clo…
Stasshe Dec 4, 2025
5bea640
Initial plan
Copilot Dec 4, 2025
0bd6663
Fix TabBar context menu (PC right-click only) and Markdown KaTeX deli…
Copilot Dec 4, 2025
1cd689a
Address code review: use safer placeholders for dollar sign escaping
Copilot Dec 4, 2025
1143a3e
Fix DnD issues: fix moveTab stale state bug and allow DnD in scroll lock
Copilot Dec 4, 2025
be80dfe
Fix TabBar to accept FILE_TREE_ITEM drops from FileTree
Copilot Dec 4, 2025
74f7658
Fix iPad DnD: add TouchBackend support for touch devices
Copilot Dec 4, 2025
86faa70
Fix iPad DnD: remove preventDefault in handleTouchEnd that blocked dr…
Copilot Dec 4, 2025
6fd27f8
Fix TabBar DnD: use ref for dragOverSide to prevent hook recreation d…
Copilot Dec 4, 2025
3fdc24f
Add long-press DnD for tabs and shared drag preview layer
Copilot Dec 4, 2025
d9f577c
Merge pull request #151 from Stasshe/copilot/fix-markdown-katex-settings
Stasshe Dec 4, 2025
e0ccdb8
Initial plan
Copilot Dec 5, 2025
be0494c
Add pane navigation shortcuts and PaneNavigator modal
Copilot Dec 5, 2025
dba62b6
Fix code review issues - remove unused 'm' key and add i18n for tab/tabs
Copilot Dec 5, 2025
423e504
Ultra-compact PaneNavigator with recursive layout and number key sele…
Copilot Dec 5, 2025
b303e14
Fix PaneNavigator: size adjustment (1.3x), active pane selection fix …
Copilot Dec 5, 2025
f084edd
Revert active pane selection change - original code was correct
Copilot Dec 5, 2025
646f63a
Fix OperationWindow to use activePane from tabStore for Ctrl+P
Copilot Dec 5, 2025
69c0be9
Fix tab reuse to search only in target pane, add active pane border, …
Copilot Dec 5, 2025
8c962c9
Use foreground color for active pane border (adapts to dark/light theme)
Copilot Dec 5, 2025
23c308c
Fix PaneNavigator dynamic sizing to prevent pane items from overflowing
Copilot Dec 5, 2025
bcfe346
Simplify PaneNavigator: remove background box, use foreground blur ov…
Copilot Dec 5, 2025
2fffa06
Improve PaneNavigator size/layout and active pane visibility with pri…
Copilot Dec 5, 2025
fb952ed
Use green color for active pane and fix layout calculation
Copilot Dec 5, 2025
3a05995
Fix closeTab to only affect active pane, add Lucide icons to PaneNavi…
Copilot Dec 5, 2025
c73483e
Merge pull request #152 from Stasshe/copilot/add-shortcut-keys-utility
Stasshe Dec 5, 2025
7109391
Initial plan
Copilot Dec 5, 2025
be1710b
Improve tab focus, scroll, and highlight visibility
Copilot Dec 5, 2025
4de8323
Address code review feedback for editor focus logic
Copilot Dec 5, 2025
a884679
Merge pull request #153 from Stasshe/copilot/improve-tab-focus-and-sc…
Stasshe Dec 5, 2025
5e5516a
Initial plan
Copilot Dec 5, 2025
749eff9
Implement Monaco models limit and searchAllPanesForReuse for shouldRe…
Copilot Dec 5, 2025
280dde7
Refactor: extract flattenLeafPanes to module scope
Copilot Dec 5, 2025
a0c66eb
Fix ProblemsPanel to show all models and enable scroll beyond last line
Copilot Dec 5, 2025
a878a0d
ProblemsPanel: exclude .txt/.md files, add collapsible sections, comp…
Copilot Dec 5, 2025
5f92458
Fix ProblemsPanel: get ALL markers from Monaco, refresh when panel is…
Copilot Dec 5, 2025
6e7b3af
Remove 2s polling, use debounced onDidChangeMarkers instead
Copilot Dec 5, 2025
fc56eaf
Fix ProblemsPanel: add isActive dependency and delayed initial collec…
Copilot Dec 5, 2025
df8eec5
ProblemsPanel: restore working implementation, add refresh button ins…
Copilot Dec 5, 2025
dc73d14
Fix ProblemsPanel: use refs to prevent state loss on re-render, separ…
Copilot Dec 5, 2025
3c145a0
Fix ProblemsPanel: simplify Monaco access, avoid dynamic import to pr…
Copilot Dec 5, 2025
8bbdf6d
Fix ProblemsPanel: use @monaco-editor/react loader.init() for proper …
Copilot Dec 5, 2025
dd2636f
Add Monaco language defaults for CSS/JSON/HTML diagnostics in separat…
Copilot Dec 5, 2025
1e8cda0
Fix ProblemsPanel: filter markers by owner to match file type (e.g., …
Copilot Dec 5, 2025
3614e5b
Merge pull request #154 from Stasshe/copilot/update-model-configuration
Stasshe Dec 5, 2025
760f0a5
Initial plan
Copilot Dec 5, 2025
d94642d
Update keybindings for Git and pane management
Stasshe Dec 5, 2025
e19f4be
Soften green border highlighting for panes and tabs, hide border when…
Copilot Dec 5, 2025
9b37818
Memoize leafPaneCount calculation for performance improvement
Copilot Dec 5, 2025
29cab68
Merge pull request #155 from Stasshe/copilot/adjust-green-border-opacity
Stasshe Dec 5, 2025
c5c63fa
Comment out togglePreview keybinding
Stasshe Dec 5, 2025
7193ae7
Initial plan
Copilot Dec 5, 2025
b9d2892
Fix focus issue when opening tabs from OperationWindow by making stat…
Copilot Dec 5, 2025
479baed
Fix editor focus by adding key prop to TabComponent for proper re-mou…
Copilot Dec 5, 2025
9852778
Merge pull request #156 from Stasshe/copilot/fix-focus-functionality-…
Stasshe Dec 5, 2025
73263e1
Initial plan
Copilot Dec 5, 2025
9572ecc
Fix AI assistant revert bug - restore files from originalContent, add…
Copilot Dec 5, 2025
c0dcc7d
Improve AI panel UI - more compact Copilot-like design, remove unused…
Copilot Dec 5, 2025
68959d5
Address code review feedback - extract filter results, add JSDoc, fix…
Copilot Dec 5, 2025
d1cba59
Fix revert applying empty content for existing files and handle new f…
Copilot Dec 5, 2025
49f0e85
Fix type casting for isNewFile property
Copilot Dec 5, 2025
23b8325
Merge pull request #158 from Stasshe/copilot/fix-ai-assistant-revert-bug
Stasshe Dec 5, 2025
9ef51b1
Initial plan
Copilot Dec 5, 2025
7b95517
fix: include user message when reverting AI assistant response
Copilot Dec 5, 2025
4bc3789
Merge pull request #159 from Stasshe/copilot/revert-with-user-message
Stasshe Dec 5, 2025
1a0897a
Initial plan
Copilot Dec 5, 2025
e20b834
Implement multi-patch editing system with SEARCH/REPLACE blocks
Copilot Dec 5, 2025
8d54a7a
Address code review feedback and improve error messages
Copilot Dec 5, 2025
cf93934
Merge pull request #161 from Stasshe/copilot/add-multi-patch-function…
Stasshe Dec 6, 2025
576b8e0
v0.16.0
Stasshe Dec 6, 2025
8add629
chore: update
Stasshe Dec 6, 2025
3b483d6
Initial plan
Copilot Dec 7, 2025
51f2171
Implement RuntimeProvider architecture and RuntimeRegistry
Copilot Dec 7, 2025
56d7f99
Fix import order and update tests for runtime refactoring
Copilot Dec 7, 2025
53a4611
Add comprehensive documentation for Runtime Provider architecture
Copilot Dec 7, 2025
2cf62bb
Fix build error and remove JSX/TSX support per feedback
Copilot Dec 7, 2025
f5aac53
Remove "no output" message and create Python runtime extension
Copilot Dec 7, 2025
8bea8dc
Fix python-runtime extension build error - remove @/ imports
Copilot Dec 7, 2025
e643cb0
Update pnpm-lock.yaml after removing pyodide from root
Copilot Dec 7, 2025
4612484
Add auto-loading of Python packages in python-runtime extension
Copilot Dec 7, 2025
27b8ef9
Fix fileRepository API usage and add pathUtils system module
Copilot Dec 7, 2025
f23b722
Fix python-runtime: add pathUtils to extension types and improve file…
Copilot Dec 7, 2025
32c3010
Add .gitignore support to python-runtime file sync
Copilot Dec 7, 2025
1a5c3e3
Fix Python runtime path resolution to match main branch
Copilot Dec 7, 2025
4c7f8cf
Merge pull request #162 from Stasshe/copilot/refactor-runtime-design
Stasshe Dec 7, 2025
8450bb7
Initial plan
Copilot Dec 7, 2025
5ab6cca
docs: Add TWO-LAYER-ARCHITECTURE.md and gitignore integration tests
Copilot Dec 7, 2025
c7c76b3
docs: Add investigation summary and address code review feedback
Copilot Dec 7, 2025
6fa5039
docs: Add Japanese summary for architecture investigation
Copilot Dec 7, 2025
f8b577b
analysis: Re-evaluate single-layer architecture feasibility
Copilot Dec 7, 2025
9ee7e40
fix: Apply .gitignore filtering in bulk sync (syncFromIndexedDBToFS)
Copilot Dec 7, 2025
e75c420
docs: Update investigation docs to reflect gitignore bug fix
Copilot Dec 7, 2025
a274999
refactor: Add documentation to gitignore filtering methods
Copilot Dec 7, 2025
0205242
docs: Add comprehensive gitignore bug fix report
Copilot Dec 7, 2025
fc180c9
Merge pull request #163 from Stasshe/copilot/refactor-filerepository-…
Stasshe Dec 7, 2025
080bc8a
Delete docs/TWO-LAYER-INVESTIGATION-SUMMARY.md
Stasshe Dec 7, 2025
f45dbf8
v16.0.1
Stasshe Dec 7, 2025
a31026c
Update Gemini API URL to version 2.5
Stasshe Dec 8, 2025
d9c648c
Initial plan
Copilot Dec 8, 2025
e615754
Implement streaming AI assistant support
Copilot Dec 8, 2025
467541e
Address code review feedback
Copilot Dec 8, 2025
b8f4c4d
Fix 400 error: Remove &alt=sse parameter from streaming API calls
Copilot Dec 8, 2025
5c936e8
Update Gemini API URL to version 2.0
Stasshe Dec 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
227 changes: 227 additions & 0 deletions Development/PROJECT-ID-BEST-PRACTICES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
# Project ID ベストプラクティス

このドキュメントでは、Pyxis CodeCanvasにおけるProject IDの取得・使用に関するベストプラクティスを説明します。

---

## 背景と問題

### useProject()フックの問題

`useProject()`フックはReactの`useState`を使用しているため、**各コンポーネントで独立したステートを持ちます**。これにより以下の問題が発生していました:

```typescript
// 問題のあるコード
const EditorTabComponent = () => {
const { saveFile, currentProject } = useProject();
// currentProjectは独立したステートのため、nullになる可能性がある

const handleSave = async (content: string) => {
// currentProjectがnullの場合、サイレントに失敗
if (saveFile && currentProject) {
await saveFile(path, content);
}
};
};
```

---

## アーキテクチャ

### Project ID の流れ

```mermaid
graph TB
subgraph page.tsx
A[useProject - 唯一の権威ソース]
end

subgraph projectStore
B[グローバルZustandストア]
end

subgraph Components
C[useProjectStore - Reactコンポーネント内]
D[getCurrentProjectId - コールバック内]
E[props経由 - 明示的な受け渡し]
end

subgraph Extensions
F[context.projectId]
end

A -->|useEffect sync| B
B --> C
B --> D
A -->|props| E
E -->|Terminal| F
```

---

## ベストプラクティス

### 1. Reactコンポーネント内でProject IDを取得

**推奨: `useProjectStore`を使用**

```typescript
import { useProjectStore } from '@/stores/projectStore';

const MyComponent = () => {
// グローバルストアからリアクティブに取得
const currentProject = useProjectStore(state => state.currentProject);
const projectId = currentProject?.id;

// projectIdを使用
};
```

### 2. コールバック関数内でProject IDを取得

**推奨: `getCurrentProjectId()`ユーティリティを使用**

```typescript
import { getCurrentProjectId } from '@/stores/projectStore';

const MyComponent = () => {
const handleContentChange = useCallback(async (content: string) => {
// コールバック実行時点の最新のprojectIdを取得
const projectId = getCurrentProjectId();

if (projectId && path) {
await fileRepository.saveFileByPath(projectId, path, content);
}
}, [path]);
};
```

### 3. propsで受け取る場合

**親コンポーネントからpropsで渡される場合は、そのまま使用**

```typescript
interface TerminalProps {
currentProjectId: string;
}

const Terminal = ({ currentProjectId }: TerminalProps) => {
// propsで受け取ったprojectIdを使用
await fileRepository.createFile(currentProjectId, path, content, 'file');
};
```

### 4. Extension内でProject IDを取得

**`context.projectId`を使用**

```typescript
// Extension command handler
export const handler = async (args: string[], context: CommandContext) => {
const { projectId } = context;

const fileRepository = context.getSystemModule('fileRepository');
const file = await fileRepository.getFileByPath(projectId, '/src/index.ts');
};
```

---

## 非推奨パターン

### ❌ page.tsx以外でuseProject()を使用

```typescript
// 非推奨: 独立したステートが作成される
const MyTabComponent = () => {
const { currentProject, saveFile } = useProject(); // NG
};
```

### ❌ LocalStorageから直接取得

```typescript
// 非推奨: 同期の問題がある
const projectId = JSON.parse(localStorage.getItem('recent-projects'))?.[0]?.id;
```

---

## API リファレンス

### projectStore.ts

| API | 用途 | 使用場所 |
|-----|------|----------|
| `useProjectStore(state => state.currentProject)` | リアクティブにプロジェクト取得 | Reactコンポーネント内 |
| `useProjectStore(state => state.currentProjectId)` | リアクティブにID取得 | Reactコンポーネント内 |
| `getCurrentProjectId()` | 即時にID取得 | コールバック、非同期関数内 |
| `getCurrentProject()` | 即時にプロジェクト取得 | コールバック、非同期関数内 |

### page.tsxでの同期

```typescript
// page.tsx
const { currentProject } = useProject();
const setCurrentProjectToStore = useProjectStore(state => state.setCurrentProject);

useEffect(() => {
setCurrentProjectToStore(currentProject);
}, [currentProject, setCurrentProjectToStore]);
```

---

## ファイル操作時のProject ID使用例

### ファイル保存

```typescript
import { fileRepository } from '@/engine/core/fileRepository';
import { getCurrentProjectId } from '@/stores/projectStore';

const saveFile = async (path: string, content: string) => {
const projectId = getCurrentProjectId();
if (!projectId) {
console.error('No project selected');
return;
}

await fileRepository.saveFileByPath(projectId, path, content);
};
```

### ファイル取得

```typescript
const getFile = async (path: string) => {
const projectId = getCurrentProjectId();
if (!projectId) return null;

return await fileRepository.getFileByPath(projectId, path);
};
```

---

## チェックリスト

新しいコンポーネントでProject IDを使用する際:

- [ ] `useProject()`を直接使用していないか確認
- [ ] Reactコンポーネント内では`useProjectStore`を使用
- [ ] コールバック内では`getCurrentProjectId()`を使用
- [ ] propsで渡される場合はそのまま使用
- [ ] Extension内では`context.projectId`を使用

---

## 関連ドキュメント

- [FILE_REPOSITORY_BEST_PRACTICES.md](./FILE_REPOSITORY_BEST_PRACTICES.md) - FileRepositoryの最適化とキャッシュ
- [CORE-ENGINE.md](../docs/CORE-ENGINE.md) - コアエンジンアーキテクチャ

---

ドキュメント作成日: 2025-12-03
Loading