pi-anchor 0.2.2 → 0.2.4

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.
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Anchor Data Contracts & Type Definitions
3
+ * Single Global Source of Truth with Zero Workspace Contamination.
4
+ */
5
+ type AnchorStatus = 'active' | 'sleeping' | 'settled' | 'graveyard';
6
+ type AnchorPriority = 'p0' | 'p1' | 'p2';
7
+ type AnchorDurability = 'ephemeral' | 'durable';
8
+ interface AnchorDecayPolicy {
9
+ /** Days before an untouched active anchor transitions to sleeping */
10
+ activeDays: number;
11
+ /** Days an anchor remains sleeping before dropping to graveyard */
12
+ sleepDays: number;
13
+ /** Total maximum days before permanent graveyard sweep (9999 = never) */
14
+ graveyardDays: number;
15
+ }
16
+ interface AnchorEvidence {
17
+ settledAt?: number;
18
+ settledBy?: 'one-tap-settlement' | 'manual-command' | 'verification-test';
19
+ commitHash?: string;
20
+ summary?: string;
21
+ touchedFiles?: string[];
22
+ }
23
+ interface Anchor {
24
+ /** Unique sequential identifier, e.g., 'anc-1' */
25
+ id: string;
26
+ /** Short imperative title of the task */
27
+ title: string;
28
+ /** Optional detailed context or notes */
29
+ description?: string;
30
+ /** Task priority */
31
+ priority: AnchorPriority;
32
+ /** Current lifecycle status */
33
+ status: AnchorStatus;
34
+ /** Durability tier: ephemeral (short-lived reminder, 48h TTL) or durable (long-term architecture vision) */
35
+ durability: AnchorDurability;
36
+ /** Canonical project name (e.g. 'PPT', 'X', or 'global') */
37
+ project: string;
38
+ /** Canonical root directory where the task was anchored (empty string for global tasks) */
39
+ cwd: string;
40
+ /** Creation timestamp in ms */
41
+ createdAt: number;
42
+ /** Last update timestamp in ms */
43
+ updatedAt: number;
44
+ /** Last touched timestamp in ms (resets on file touch) */
45
+ lastTouchedAt: number;
46
+ /** Associated file paths or globs, e.g. ['src/auth/*.ts'] */
47
+ files: string[];
48
+ /** Expected completion date in format 'YYYY-MM-DD' (e.g. '2026-09-24') */
49
+ targetDate?: string;
50
+ /** Optional shell command for automated physical verification (e.g. 'npm test') */
51
+ verifyCommand?: string;
52
+ /** Topic or domain tags, e.g. ['auth', 'security'] */
53
+ tags: string[];
54
+ /** Optional recurrence pattern: 'daily' for recurring daily habits */
55
+ recurrence?: 'daily';
56
+ /** Last completed date string 'YYYY-MM-DD' for recurring tasks */
57
+ lastCompletedDate?: string;
58
+ /** Decay policy overrides */
59
+ decay: AnchorDecayPolicy;
60
+ /** Settlement evidence metadata upon closure */
61
+ evidence?: AnchorEvidence;
62
+ }
63
+ interface AnchorStoreState {
64
+ version: number;
65
+ anchors: Anchor[];
66
+ lastSweepAt: number;
67
+ nextId?: number;
68
+ }
69
+ interface TouchMatchResult {
70
+ anchor: Anchor;
71
+ score: number;
72
+ matchedFiles: string[];
73
+ reason: 'exact-file' | 'dir-prefix' | 'tag-keyword';
74
+ }
75
+ interface SettlementProposal {
76
+ anchor: Anchor;
77
+ matchedFiles: string[];
78
+ reason: string;
79
+ recommendedAction: 'settle' | 'defer';
80
+ }
81
+ declare const EPHEMERAL_DECAY_POLICY: AnchorDecayPolicy;
82
+ declare const DURABLE_DECAY_POLICY: AnchorDecayPolicy;
83
+ declare const DEFAULT_DECAY_POLICY: AnchorDecayPolicy;
84
+
85
+ /**
86
+ * Detect whether a task is a short-term ephemeral reminder or a long-term architectural vision
87
+ */
88
+ declare function detectDurability(title: string): AnchorDurability;
89
+ /**
90
+ * Get custom ephemeral decay policy based on temporal span (e.g. 后天, 大后天)
91
+ */
92
+ declare function getEphemeralDecayPolicy(title: string): AnchorDecayPolicy;
93
+ /**
94
+ * Detect expected completion date from title keywords or explicit date string, returning 'YYYY-MM-DD'
95
+ */
96
+ declare function detectTargetDate(titleOrDate: string, now?: number): string | undefined;
97
+ /**
98
+ * Detect recurring patterns, e.g. daily habits
99
+ */
100
+ declare function detectRecurrence(title: string): 'daily' | undefined;
101
+ /**
102
+ * Get current date string 'YYYY-MM-DD' in local timezone
103
+ */
104
+ declare function getTodayDateString(timestamp?: number): string;
105
+ /**
106
+ * Resolve the default storage directory for Anchor (~/.anchor).
107
+ * Hierarchy:
108
+ * 1. Process environment: ANCHOR_DIR
109
+ * 2. Canonical user-global store: ~/.anchor/
110
+ * 3. Legacy Pi harness fallback: ~/.pi/agent/anchors/ (migrates automatically if present)
111
+ */
112
+ declare function getDefaultStorageDir(): string;
113
+ /**
114
+ * Acquire exclusive lockfile using atomic 'wx' file creation (zero external dependencies).
115
+ * Features:
116
+ * - 0 async infection (100% synchronous)
117
+ * - Automatic stale lock eviction (>5000ms or dead PID)
118
+ * - Exponential backoff with jitter
119
+ */
120
+ declare function acquireSyncLock(lockPath: string, maxWaitMs?: number, staleTimeoutMs?: number): () => void;
121
+ /**
122
+ * Windows-tolerant atomic rename with exponential spin-retry to combat NTFS EBUSY/EPERM file locks
123
+ */
124
+ declare function atomicRenameWithRetry(tempPath: string, targetPath: string, maxAttempts?: number): void;
125
+ declare class AnchorStore {
126
+ readonly storageDir: string;
127
+ readonly statePath: string;
128
+ readonly archivePath: string;
129
+ readonly graveyardPath: string;
130
+ constructor(customStorageDir?: string);
131
+ get lockPath(): string;
132
+ /**
133
+ * Execute mutation within a cross-process exclusive lock
134
+ */
135
+ withLock<T>(fn: () => T): T;
136
+ private ensureDirs;
137
+ /**
138
+ * Load store state. If corrupt or missing, returns safe default.
139
+ */
140
+ loadState(): AnchorStoreState;
141
+ /**
142
+ * Atomically save store state via temp file + atomic rename with Windows NTFS spin-retry
143
+ */
144
+ saveState(state: AnchorStoreState): void;
145
+ private generateId;
146
+ /**
147
+ * Create a new Anchor with automatic project and cwd tagging
148
+ */
149
+ create(input: {
150
+ title: string;
151
+ description?: string;
152
+ priority?: AnchorPriority;
153
+ durability?: AnchorDurability;
154
+ recurrence?: 'daily';
155
+ cwd?: string;
156
+ project?: string;
157
+ targetDate?: string;
158
+ files?: string[];
159
+ tags?: string[];
160
+ verifyCommand?: string;
161
+ decay?: AnchorDecayPolicy;
162
+ }): Anchor;
163
+ private findAnchorIndex;
164
+ /**
165
+ * Get an anchor by ID (supports 'anc-1', '#anc-1', '1', '01')
166
+ */
167
+ get(id: string): Anchor | undefined;
168
+ /**
169
+ * List anchors. By default, if cwd is provided, only returns anchors
170
+ * belonging to this cwd or marked as global (''). Pass all: true for global view.
171
+ */
172
+ list(filter?: {
173
+ status?: AnchorStatus;
174
+ priority?: AnchorPriority;
175
+ cwd?: string;
176
+ all?: boolean;
177
+ now?: number;
178
+ }): Anchor[];
179
+ /**
180
+ * Update an existing anchor
181
+ */
182
+ update(id: string, patch: Partial<Omit<Anchor, 'id' | 'createdAt'>>): Anchor;
183
+ /**
184
+ * Touch an anchor to refresh its decay window and reactivate sleeping state
185
+ */
186
+ touch(id: string, timestamp?: number): Anchor;
187
+ /**
188
+ * Settle an anchor (recurring daily habits complete for today and wake up tomorrow)
189
+ */
190
+ settle(id: string, evidence?: AnchorEvidence, now?: number): Anchor;
191
+ /**
192
+ * Reverse/undo the last settled anchor, popping it from archive.jsonl back into state.json
193
+ */
194
+ undoSettle(): Anchor;
195
+ /**
196
+ * Evict anchor to graveyard.jsonl upon total decay expiry
197
+ */
198
+ dropToGraveyard(id: string, reason: string): Anchor;
199
+ getArchive(filter?: {
200
+ cwd?: string;
201
+ all?: boolean;
202
+ }): Anchor[];
203
+ getGraveyard(filter?: {
204
+ cwd?: string;
205
+ all?: boolean;
206
+ }): Anchor[];
207
+ }
208
+
209
+ export { AnchorStore as A, DEFAULT_DECAY_POLICY as D, EPHEMERAL_DECAY_POLICY as E, type SettlementProposal as S, type TouchMatchResult as T, type AnchorStatus as a, type Anchor as b, type AnchorDecayPolicy as c, type AnchorDurability as d, type AnchorEvidence as e, type AnchorPriority as f, type AnchorStoreState as g, DURABLE_DECAY_POLICY as h, acquireSyncLock as i, atomicRenameWithRetry as j, detectDurability as k, detectRecurrence as l, detectTargetDate as m, getDefaultStorageDir as n, getEphemeralDecayPolicy as o, getTodayDateString as p };
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Anchor Data Contracts & Type Definitions
3
+ * Single Global Source of Truth with Zero Workspace Contamination.
4
+ */
5
+ type AnchorStatus = 'active' | 'sleeping' | 'settled' | 'graveyard';
6
+ type AnchorPriority = 'p0' | 'p1' | 'p2';
7
+ type AnchorDurability = 'ephemeral' | 'durable';
8
+ interface AnchorDecayPolicy {
9
+ /** Days before an untouched active anchor transitions to sleeping */
10
+ activeDays: number;
11
+ /** Days an anchor remains sleeping before dropping to graveyard */
12
+ sleepDays: number;
13
+ /** Total maximum days before permanent graveyard sweep (9999 = never) */
14
+ graveyardDays: number;
15
+ }
16
+ interface AnchorEvidence {
17
+ settledAt?: number;
18
+ settledBy?: 'one-tap-settlement' | 'manual-command' | 'verification-test';
19
+ commitHash?: string;
20
+ summary?: string;
21
+ touchedFiles?: string[];
22
+ }
23
+ interface Anchor {
24
+ /** Unique sequential identifier, e.g., 'anc-1' */
25
+ id: string;
26
+ /** Short imperative title of the task */
27
+ title: string;
28
+ /** Optional detailed context or notes */
29
+ description?: string;
30
+ /** Task priority */
31
+ priority: AnchorPriority;
32
+ /** Current lifecycle status */
33
+ status: AnchorStatus;
34
+ /** Durability tier: ephemeral (short-lived reminder, 48h TTL) or durable (long-term architecture vision) */
35
+ durability: AnchorDurability;
36
+ /** Canonical project name (e.g. 'PPT', 'X', or 'global') */
37
+ project: string;
38
+ /** Canonical root directory where the task was anchored (empty string for global tasks) */
39
+ cwd: string;
40
+ /** Creation timestamp in ms */
41
+ createdAt: number;
42
+ /** Last update timestamp in ms */
43
+ updatedAt: number;
44
+ /** Last touched timestamp in ms (resets on file touch) */
45
+ lastTouchedAt: number;
46
+ /** Associated file paths or globs, e.g. ['src/auth/*.ts'] */
47
+ files: string[];
48
+ /** Expected completion date in format 'YYYY-MM-DD' (e.g. '2026-09-24') */
49
+ targetDate?: string;
50
+ /** Optional shell command for automated physical verification (e.g. 'npm test') */
51
+ verifyCommand?: string;
52
+ /** Topic or domain tags, e.g. ['auth', 'security'] */
53
+ tags: string[];
54
+ /** Optional recurrence pattern: 'daily' for recurring daily habits */
55
+ recurrence?: 'daily';
56
+ /** Last completed date string 'YYYY-MM-DD' for recurring tasks */
57
+ lastCompletedDate?: string;
58
+ /** Decay policy overrides */
59
+ decay: AnchorDecayPolicy;
60
+ /** Settlement evidence metadata upon closure */
61
+ evidence?: AnchorEvidence;
62
+ }
63
+ interface AnchorStoreState {
64
+ version: number;
65
+ anchors: Anchor[];
66
+ lastSweepAt: number;
67
+ nextId?: number;
68
+ }
69
+ interface TouchMatchResult {
70
+ anchor: Anchor;
71
+ score: number;
72
+ matchedFiles: string[];
73
+ reason: 'exact-file' | 'dir-prefix' | 'tag-keyword';
74
+ }
75
+ interface SettlementProposal {
76
+ anchor: Anchor;
77
+ matchedFiles: string[];
78
+ reason: string;
79
+ recommendedAction: 'settle' | 'defer';
80
+ }
81
+ declare const EPHEMERAL_DECAY_POLICY: AnchorDecayPolicy;
82
+ declare const DURABLE_DECAY_POLICY: AnchorDecayPolicy;
83
+ declare const DEFAULT_DECAY_POLICY: AnchorDecayPolicy;
84
+
85
+ /**
86
+ * Detect whether a task is a short-term ephemeral reminder or a long-term architectural vision
87
+ */
88
+ declare function detectDurability(title: string): AnchorDurability;
89
+ /**
90
+ * Get custom ephemeral decay policy based on temporal span (e.g. 后天, 大后天)
91
+ */
92
+ declare function getEphemeralDecayPolicy(title: string): AnchorDecayPolicy;
93
+ /**
94
+ * Detect expected completion date from title keywords or explicit date string, returning 'YYYY-MM-DD'
95
+ */
96
+ declare function detectTargetDate(titleOrDate: string, now?: number): string | undefined;
97
+ /**
98
+ * Detect recurring patterns, e.g. daily habits
99
+ */
100
+ declare function detectRecurrence(title: string): 'daily' | undefined;
101
+ /**
102
+ * Get current date string 'YYYY-MM-DD' in local timezone
103
+ */
104
+ declare function getTodayDateString(timestamp?: number): string;
105
+ /**
106
+ * Resolve the default storage directory for Anchor (~/.anchor).
107
+ * Hierarchy:
108
+ * 1. Process environment: ANCHOR_DIR
109
+ * 2. Canonical user-global store: ~/.anchor/
110
+ * 3. Legacy Pi harness fallback: ~/.pi/agent/anchors/ (migrates automatically if present)
111
+ */
112
+ declare function getDefaultStorageDir(): string;
113
+ /**
114
+ * Acquire exclusive lockfile using atomic 'wx' file creation (zero external dependencies).
115
+ * Features:
116
+ * - 0 async infection (100% synchronous)
117
+ * - Automatic stale lock eviction (>5000ms or dead PID)
118
+ * - Exponential backoff with jitter
119
+ */
120
+ declare function acquireSyncLock(lockPath: string, maxWaitMs?: number, staleTimeoutMs?: number): () => void;
121
+ /**
122
+ * Windows-tolerant atomic rename with exponential spin-retry to combat NTFS EBUSY/EPERM file locks
123
+ */
124
+ declare function atomicRenameWithRetry(tempPath: string, targetPath: string, maxAttempts?: number): void;
125
+ declare class AnchorStore {
126
+ readonly storageDir: string;
127
+ readonly statePath: string;
128
+ readonly archivePath: string;
129
+ readonly graveyardPath: string;
130
+ constructor(customStorageDir?: string);
131
+ get lockPath(): string;
132
+ /**
133
+ * Execute mutation within a cross-process exclusive lock
134
+ */
135
+ withLock<T>(fn: () => T): T;
136
+ private ensureDirs;
137
+ /**
138
+ * Load store state. If corrupt or missing, returns safe default.
139
+ */
140
+ loadState(): AnchorStoreState;
141
+ /**
142
+ * Atomically save store state via temp file + atomic rename with Windows NTFS spin-retry
143
+ */
144
+ saveState(state: AnchorStoreState): void;
145
+ private generateId;
146
+ /**
147
+ * Create a new Anchor with automatic project and cwd tagging
148
+ */
149
+ create(input: {
150
+ title: string;
151
+ description?: string;
152
+ priority?: AnchorPriority;
153
+ durability?: AnchorDurability;
154
+ recurrence?: 'daily';
155
+ cwd?: string;
156
+ project?: string;
157
+ targetDate?: string;
158
+ files?: string[];
159
+ tags?: string[];
160
+ verifyCommand?: string;
161
+ decay?: AnchorDecayPolicy;
162
+ }): Anchor;
163
+ private findAnchorIndex;
164
+ /**
165
+ * Get an anchor by ID (supports 'anc-1', '#anc-1', '1', '01')
166
+ */
167
+ get(id: string): Anchor | undefined;
168
+ /**
169
+ * List anchors. By default, if cwd is provided, only returns anchors
170
+ * belonging to this cwd or marked as global (''). Pass all: true for global view.
171
+ */
172
+ list(filter?: {
173
+ status?: AnchorStatus;
174
+ priority?: AnchorPriority;
175
+ cwd?: string;
176
+ all?: boolean;
177
+ now?: number;
178
+ }): Anchor[];
179
+ /**
180
+ * Update an existing anchor
181
+ */
182
+ update(id: string, patch: Partial<Omit<Anchor, 'id' | 'createdAt'>>): Anchor;
183
+ /**
184
+ * Touch an anchor to refresh its decay window and reactivate sleeping state
185
+ */
186
+ touch(id: string, timestamp?: number): Anchor;
187
+ /**
188
+ * Settle an anchor (recurring daily habits complete for today and wake up tomorrow)
189
+ */
190
+ settle(id: string, evidence?: AnchorEvidence, now?: number): Anchor;
191
+ /**
192
+ * Reverse/undo the last settled anchor, popping it from archive.jsonl back into state.json
193
+ */
194
+ undoSettle(): Anchor;
195
+ /**
196
+ * Evict anchor to graveyard.jsonl upon total decay expiry
197
+ */
198
+ dropToGraveyard(id: string, reason: string): Anchor;
199
+ getArchive(filter?: {
200
+ cwd?: string;
201
+ all?: boolean;
202
+ }): Anchor[];
203
+ getGraveyard(filter?: {
204
+ cwd?: string;
205
+ all?: boolean;
206
+ }): Anchor[];
207
+ }
208
+
209
+ export { AnchorStore as A, DEFAULT_DECAY_POLICY as D, EPHEMERAL_DECAY_POLICY as E, type SettlementProposal as S, type TouchMatchResult as T, type AnchorStatus as a, type Anchor as b, type AnchorDecayPolicy as c, type AnchorDurability as d, type AnchorEvidence as e, type AnchorPriority as f, type AnchorStoreState as g, DURABLE_DECAY_POLICY as h, acquireSyncLock as i, atomicRenameWithRetry as j, detectDurability as k, detectRecurrence as l, detectTargetDate as m, getDefaultStorageDir as n, getEphemeralDecayPolicy as o, getTodayDateString as p };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-anchor",
3
- "version": "0.2.2",
4
- "description": "Zero-pollution, 0-idle-token task memory for AI coding agents",
3
+ "version": "0.2.4",
4
+ "description": "Never lose unfinished tasks when closing Pi — pin reminders across sessions (/pin), auto-remind when touching matching files, and auto-complete on git commit with 0 TODO.md clutter.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -10,6 +10,7 @@
10
10
  "dist",
11
11
  "src",
12
12
  "bin",
13
+ "assets",
13
14
  "README.md",
14
15
  "README_zh.md",
15
16
  "LICENSE"
@@ -21,7 +22,7 @@
21
22
  "extensions": [
22
23
  "dist/extension.js"
23
24
  ],
24
- "image": "https://raw.githubusercontent.com/3ZEROS12/anchor/main/assets/hero.svg"
25
+ "image": "https://raw.githubusercontent.com/3ZEROS12/anchor/main/assets/hero-en.svg"
25
26
  },
26
27
  "scripts": {
27
28
  "build": "tsup src/index.ts src/extension.ts --format esm,cjs --dts --clean",
@@ -31,13 +32,28 @@
31
32
  },
32
33
  "keywords": [
33
34
  "pi-package",
34
- "ai-agent",
35
- "coding-agent",
35
+ "pi-extension",
36
+ "anchor",
37
+ "pi-anchor",
38
+ "todo",
39
+ "todos",
40
+ "tasks",
36
41
  "task-management",
42
+ "reminder",
43
+ "reminders",
37
44
  "memory",
45
+ "session",
46
+ "session-memory",
47
+ "handoff",
48
+ "persistence",
49
+ "checkpoint",
50
+ "resume",
51
+ "plan",
52
+ "roadmap",
38
53
  "context-window",
39
54
  "zero-pollution",
40
- "pi-extension"
55
+ "ai-agent",
56
+ "coding-agent"
41
57
  ],
42
58
  "author": "Jason Song <jiaxinsong312@gmail.com>",
43
59
  "license": "MIT",