Skip to content

Commit 46bf439

Browse files
committed
feat(logging): add logging for pull and push operations; create LOGS.md for log file documentation
1 parent 58f68fc commit 46bf439

5 files changed

Lines changed: 136 additions & 1 deletion

File tree

docs/LOGS.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Log File Locations
2+
3+
## Path
4+
5+
All platforms use XDG-style paths.
6+
7+
| Platform | Path |
8+
|----------|------|
9+
| Linux | `~/.local/share/opencode/log/opencode-sync.log` |
10+
| macOS | `~/.local/share/opencode/log/opencode-sync.log` |
11+
| Windows | `%USERPROFILE%\.local\share\opencode\log\opencode-sync.log` |
12+
13+
## View Logs
14+
15+
Linux/macOS:
16+
```
17+
cat ~/.local/share/opencode/log/opencode-sync.log
18+
tail -f ~/.local/share/opencode/log/opencode-sync.log
19+
```
20+
21+
Windows PowerShell:
22+
```
23+
Get-Content $HOME\.local\share\opencode\log\opencode-sync.log
24+
Get-Content $HOME\.local\share\opencode\log\opencode-sync.log -Wait
25+
```
26+
27+
Windows Command Prompt:
28+
```
29+
type %USERPROFILE%\.local\share\opencode\log\opencode-sync.log
30+
```
31+
32+
## Format
33+
34+
```
35+
[ISO_TIMESTAMP] [opencode-sync] [CATEGORY] [LEVEL] message
36+
```
37+
38+
Categories: `SYNC`, `REPO`, `PLUGIN`, `DEBUG`, `WRITE`
39+
40+
## Implementation
41+
42+
Source: `src/logging/file-logger.ts`
43+
44+
```typescript
45+
const LOG_DIR = join(homedir(), '.local/share/opencode/log');
46+
const LOG_FILE = join(LOG_DIR, 'opencode-sync.log');
47+
```
48+
49+
## Notes
50+
51+
- No log rotation
52+
- Falls back to console.error if file write fails
53+
- Directory must exist

docs/TODO.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,81 @@
5555
- [x] **Dead code: unused `removeItemsWithTombstones`** - Function in `tombstone.ts` was never imported
5656
- Removed unused function
5757

58+
## Dead Code Cleanup (knip analysis)
59+
60+
### Unused Files (11)
61+
- [ ] `src/crypto/index.ts` - barrel export, check if needed for external API
62+
- [ ] `src/data/directory-loader.ts`
63+
- [ ] `src/data/parsers.ts`
64+
- [ ] `src/sync/index.ts` - barrel export, check if needed for external API
65+
- [ ] `src/sync/merge/` - entire directory (index.ts, json-merge.ts, jsonl-merge.ts, types.ts, utils.ts)
66+
- [ ] `src/sync/operations/index.ts` - barrel export, check if needed for external API
67+
- [ ] `src/sync/packer.ts`
68+
69+
### Unused Dependencies
70+
- [ ] `@opencode-ai/plugin` - verify if peer/runtime dependency
71+
- [ ] `eslint-plugin-import` - remove if not used
72+
73+
### Unused Exports - Crypto (4)
74+
- [ ] `deriveKey` in `src/crypto/encrypt.ts`
75+
- [ ] `generateSalt` in `src/crypto/encrypt.ts`
76+
- [ ] `hashPassphrase` in `src/crypto/encrypt.ts`
77+
- [ ] `verifyPassphrase` in `src/crypto/encrypt.ts`
78+
79+
### Unused Exports - Data (2)
80+
- [ ] `ensureDir` in `src/data/file-io.ts`
81+
- [ ] `createInitialConfig` in `src/data/state.ts`
82+
83+
### Unused Exports - Logging (3)
84+
- [ ] `fileLogger` in `src/logging/file-logger.ts`
85+
- [ ] `syncDebug` in `src/logging/file-logger.ts`
86+
- [ ] `startOperation` in `src/logging/file-logger.ts`
87+
88+
### Unused Exports - Sync Engine (15+)
89+
- [ ] `buildLocalChecksums` in `src/sync/engine/helpers.ts`
90+
- [ ] `MAX_CONFLICT_RETRIES` in `src/sync/engine/retry.ts`
91+
- [ ] Multiple re-exports in `src/sync/engine/index.ts`
92+
93+
### Unused Exports - Tombstones (6)
94+
- [ ] `isTombstoneExpired` in `src/sync/tombstone.ts`
95+
- [ ] `isItemTombstoned` in `src/sync/tombstone.ts`
96+
- [ ] `getItemsToDelete` in `src/sync/tombstone.ts`
97+
- [ ] `addTombstone` re-export in `src/sync/tombstone.ts`
98+
- [ ] `mergeTombstonesFiles` re-export in `src/sync/tombstone.ts`
99+
- [ ] `filterExpiredTombstonesFile` re-export in `src/sync/tombstone.ts`
100+
101+
### Unused Exports - Operations (6)
102+
- [ ] `maybeEncrypt` in `src/sync/operations/crypto-helpers.ts`
103+
- [ ] `maybeDecrypt` in `src/sync/operations/crypto-helpers.ts`
104+
- [ ] `parseEncryptedData` in `src/sync/operations/crypto-helpers.ts`
105+
- [ ] `createManifest` in `src/sync/operations/helpers.ts`
106+
- [ ] `getLockFilePath` in `src/sync/local-lock.ts`
107+
- [ ] `readLock` in `src/sync/local-lock.ts`
108+
- [ ] `withLocalLock` in `src/sync/local-lock.ts`
109+
110+
### Unused Exports - Shared (7)
111+
- [ ] `isError` in `src/shared/error-utils.ts`
112+
- [ ] `processSyncResult` in `src/shared/sync-result-handler.ts`
113+
- [ ] `AppError`, `PackerError`, `SyncError`, `MergeError`, `RepoNotFoundError` classes
114+
115+
### Unused Exports - Types (10+)
116+
- [ ] `SYNC_CATEGORIES` in `src/types/categories.ts`
117+
- [ ] `isSyncCategory` in `src/types/categories.ts`
118+
- [ ] `DEFAULT_TOMBSTONE_GRACE_DAYS`, `CURRENT_SCHEMA_VERSION`, `createEmptyTombstonesFile` in `src/types/index.ts`
119+
- [ ] `getCategoryForPath` in `src/types/paths.ts`
120+
121+
### Unused Exported Types (22)
122+
- [ ] `LoadedData`, `LoadError` in `src/data/index.ts`
123+
- [ ] `PluginState` in `src/plugin/index.ts`
124+
- [ ] `MergeConflict`, `StateProvider` in `src/shared/`
125+
- [ ] `SyncAction` in `src/sync/engine/routing.ts`
126+
- [ ] `ItemDiff` in `src/sync/item-packer.ts`
127+
- [ ] `CryptoOptions` duplicate exports
128+
- [ ] `StorageFiles`, `OperationContext`, `ChunkDownloadResult`, `SyncResult` in `src/sync/operations/types.ts`
129+
- [ ] `CategoryInfo`, `AdvisoryLock`, `TombstonesFile`, `PackedCategory`, `LogLevel` in `src/types/`
130+
131+
**Note:** Many "unused" exports may be intentional public API for package consumers. Review before removing.
132+
58133
## In Progress: Safety & Observability
59134

60135
- [ ] Log when local files are overwritten by remote

src/sync/operations/pull.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ function processDownloadedFiles(
118118
const unpacked = unpackItem(filename, content);
119119
items[itemId] = unpacked.content;
120120
checksums[itemId] = unpacked.checksum;
121+
syncLog(`[PULL] ${filename}`);
121122
} catch (error) {
122123
syncLog(`[PULL] Failed to unpack ${itemId}: ${String(error)}`);
123124
}

src/sync/operations/push.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
markOrphanedFiles,
99
buildPushContext,
1010
} from './helpers.js';
11+
import { syncLog } from '../../logging/index.js';
1112
import {
1213
type ItemInfo,
1314
type TreeIndexedCategoryInfo,
@@ -90,6 +91,7 @@ function processItemsForUpload(
9091
ctx.files[packed.filename] = { content: packed.content };
9192
newItems[itemId] = buildItemInfo(packed, ctx.machineId);
9293
filenames.push(packed.filename);
94+
syncLog(`[PUSH] ${category}/${itemId}`);
9395
}
9496

9597
// Keep unchanged items' filenames

src/types/paths.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ export function getCategoryPaths(pathConfig: PathConfig): Record<SyncCategory, s
3636
`${pathConfig.configDir}/commands`,
3737
`${pathConfig.configDir}/plugins`,
3838
],
39-
state: [`${pathConfig.stateDir}/model.json`, `${pathConfig.stateDir}/prompt-history.jsonl`],
39+
state: [
40+
`${pathConfig.stateDir}/model.json`,
41+
`${pathConfig.stateDir}/prompt-history.jsonl`,
42+
`${pathConfig.stateDir}/kv.json`,
43+
],
4044
credentials: [`${pathConfig.dataDir}/auth.json`, `${pathConfig.dataDir}/mcp-auth.json`],
4145
sessions: [`${pathConfig.dataDir}/storage/session`],
4246
messages: [`${pathConfig.dataDir}/storage/message`, `${pathConfig.dataDir}/storage/part`],

0 commit comments

Comments
 (0)