@compilr-dev/sdk 0.12.0 → 0.14.0
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/dist/host/index.d.ts +2 -0
- package/dist/host/index.js +2 -0
- package/dist/host/project-context.d.ts +43 -0
- package/dist/host/project-context.js +76 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/host/index.d.ts
CHANGED
|
@@ -11,3 +11,5 @@ export { ensureFreshToken } from './token.js';
|
|
|
11
11
|
export type { EnsureFreshTokenOptions, FreshToken } from './token.js';
|
|
12
12
|
export { runDeviceFlow, nextPollInterval } from './device-flow.js';
|
|
13
13
|
export type { DeviceFlowStatus, DeviceFlowCallbacks, LoginResult, RunDeviceFlowOptions, } from './device-flow.js';
|
|
14
|
+
export { loadProjectContextFiles, hasProjectContextFile, PROJECT_CONTEXT_FILES, } from './project-context.js';
|
|
15
|
+
export type { ProjectContextResult, LoadProjectContextOptions } from './project-context.js';
|
package/dist/host/index.js
CHANGED
|
@@ -8,3 +8,5 @@ export { refreshToken, sendHeartbeat, getProfile, updateProfile, requestDeviceCo
|
|
|
8
8
|
export { loadAuthData, saveAuthData, clearAuthData, updateSession, hasAuthData, checkAuthFilePermissions, readAuthFile, writeAuthFile, } from './auth-store.js';
|
|
9
9
|
export { ensureFreshToken } from './token.js';
|
|
10
10
|
export { runDeviceFlow, nextPollInterval } from './device-flow.js';
|
|
11
|
+
// ── Project context files (COMPILR.md / CLAUDE.md → system prompt) ────────────
|
|
12
|
+
export { loadProjectContextFiles, hasProjectContextFile, PROJECT_CONTEXT_FILES, } from './project-context.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* loadProjectContextFiles — read a project's instruction file (COMPILR.md etc.)
|
|
3
|
+
* for injection into the system prompt.
|
|
4
|
+
*
|
|
5
|
+
* Shared by CLI and Desktop: the CLI had this logic in utils/project-memory.ts
|
|
6
|
+
* and Desktop hand-rolled a thinner inline 2-file version. This is the single
|
|
7
|
+
* implementation — searches a priority-ordered list, size-guards/truncates large
|
|
8
|
+
* files, and reports metadata.
|
|
9
|
+
*
|
|
10
|
+
* Pure file read; no fs writes, no electron. `estimatedTokens` is a cheap
|
|
11
|
+
* chars/4 heuristic (callers that need a real count tokenize themselves).
|
|
12
|
+
*/
|
|
13
|
+
/** Instruction files searched, in priority order. */
|
|
14
|
+
export declare const PROJECT_CONTEXT_FILES: readonly ["COMPILR.md", ".compilr/instructions.md", "CLAUDE.md", ".claude/instructions.md"];
|
|
15
|
+
export interface ProjectContextResult {
|
|
16
|
+
/** Whether an instruction file was found. */
|
|
17
|
+
found: boolean;
|
|
18
|
+
/** Loaded content (possibly truncated); '' when not found. */
|
|
19
|
+
content: string;
|
|
20
|
+
/** Path of the file that was loaded, or null. */
|
|
21
|
+
filePath: string | null;
|
|
22
|
+
/** Original file size in bytes. */
|
|
23
|
+
originalSize: number;
|
|
24
|
+
/** Whether the content was truncated due to size. */
|
|
25
|
+
truncated: boolean;
|
|
26
|
+
/** Rough token estimate (chars / 4). */
|
|
27
|
+
estimatedTokens: number;
|
|
28
|
+
}
|
|
29
|
+
export interface LoadProjectContextOptions {
|
|
30
|
+
/** Directory to search (default: process.cwd()). */
|
|
31
|
+
cwd?: string;
|
|
32
|
+
/** Max content bytes before truncation (default: 100KB). */
|
|
33
|
+
maxSize?: number;
|
|
34
|
+
/** Override the filenames searched, in priority order. */
|
|
35
|
+
files?: readonly string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Load the first matching project instruction file from `cwd`. Returns a
|
|
39
|
+
* not-found result (never throws) if none exists or all are unreadable.
|
|
40
|
+
*/
|
|
41
|
+
export declare function loadProjectContextFiles(options?: LoadProjectContextOptions): ProjectContextResult;
|
|
42
|
+
/** Quick existence check (no read) for any project instruction file. */
|
|
43
|
+
export declare function hasProjectContextFile(cwd?: string): boolean;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* loadProjectContextFiles — read a project's instruction file (COMPILR.md etc.)
|
|
3
|
+
* for injection into the system prompt.
|
|
4
|
+
*
|
|
5
|
+
* Shared by CLI and Desktop: the CLI had this logic in utils/project-memory.ts
|
|
6
|
+
* and Desktop hand-rolled a thinner inline 2-file version. This is the single
|
|
7
|
+
* implementation — searches a priority-ordered list, size-guards/truncates large
|
|
8
|
+
* files, and reports metadata.
|
|
9
|
+
*
|
|
10
|
+
* Pure file read; no fs writes, no electron. `estimatedTokens` is a cheap
|
|
11
|
+
* chars/4 heuristic (callers that need a real count tokenize themselves).
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
/** Instruction files searched, in priority order. */
|
|
16
|
+
export const PROJECT_CONTEXT_FILES = [
|
|
17
|
+
'COMPILR.md',
|
|
18
|
+
'.compilr/instructions.md',
|
|
19
|
+
'CLAUDE.md',
|
|
20
|
+
'.claude/instructions.md',
|
|
21
|
+
];
|
|
22
|
+
/** Default max content size before truncation: 100KB. */
|
|
23
|
+
const DEFAULT_MAX_SIZE = 100 * 1024;
|
|
24
|
+
/**
|
|
25
|
+
* Load the first matching project instruction file from `cwd`. Returns a
|
|
26
|
+
* not-found result (never throws) if none exists or all are unreadable.
|
|
27
|
+
*/
|
|
28
|
+
export function loadProjectContextFiles(options = {}) {
|
|
29
|
+
const cwd = options.cwd ?? process.cwd();
|
|
30
|
+
const maxSize = options.maxSize ?? DEFAULT_MAX_SIZE;
|
|
31
|
+
const files = options.files ?? PROJECT_CONTEXT_FILES;
|
|
32
|
+
for (const filename of files) {
|
|
33
|
+
const filePath = join(cwd, filename);
|
|
34
|
+
if (!existsSync(filePath))
|
|
35
|
+
continue;
|
|
36
|
+
try {
|
|
37
|
+
const originalSize = statSync(filePath).size;
|
|
38
|
+
let content = readFileSync(filePath, 'utf-8');
|
|
39
|
+
let truncated = false;
|
|
40
|
+
if (content.length > maxSize) {
|
|
41
|
+
content = content.slice(0, maxSize);
|
|
42
|
+
// Prefer a line boundary if one is reasonably close to the cut.
|
|
43
|
+
const lastNewline = content.lastIndexOf('\n');
|
|
44
|
+
if (lastNewline > maxSize * 0.8) {
|
|
45
|
+
content = content.slice(0, lastNewline);
|
|
46
|
+
}
|
|
47
|
+
content += '\n\n[... truncated due to size ...]';
|
|
48
|
+
truncated = true;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
found: true,
|
|
52
|
+
content,
|
|
53
|
+
filePath,
|
|
54
|
+
originalSize,
|
|
55
|
+
truncated,
|
|
56
|
+
estimatedTokens: Math.ceil(content.length / 4),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Exists but unreadable — try the next candidate.
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
found: false,
|
|
66
|
+
content: '',
|
|
67
|
+
filePath: null,
|
|
68
|
+
originalSize: 0,
|
|
69
|
+
truncated: false,
|
|
70
|
+
estimatedTokens: 0,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Quick existence check (no read) for any project instruction file. */
|
|
74
|
+
export function hasProjectContextFile(cwd = process.cwd()) {
|
|
75
|
+
return PROJECT_CONTEXT_FILES.some((f) => existsSync(join(cwd, f)));
|
|
76
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -83,8 +83,8 @@ export { DEFAULT_PERMISSION_RULES, WRITE_TOOLS, findMatchingRule, permissionMode
|
|
|
83
83
|
export type { PermissionRule, PermissionMode, PermissionLevel } from './permissions.js';
|
|
84
84
|
export { SHARED_DEFAULTS, migrateRawSettings } from './host/index.js';
|
|
85
85
|
export type { HostSettings, SettingsProviderType, TextSize, NotificationMode, Verbosity, CompactMode, ProjectSessionMode, MascotSetting, StartupMode, ProjectStartupMode, StartupBehavior, DefaultLeftPanel, TipsProficiency, } from './host/index.js';
|
|
86
|
-
export { refreshToken, sendHeartbeat, getProfile, updateProfile, requestDeviceCode, pollDeviceToken, getAuthorizationUrl, loadAuthData, saveAuthData, clearAuthData, updateSession, hasAuthData, checkAuthFilePermissions, readAuthFile, writeAuthFile, ensureFreshToken, runDeviceFlow, nextPollInterval, } from './host/index.js';
|
|
87
|
-
export type { AccountType, AuthUser, AuthSession, AuthData, RefreshTokenResponse, ProfileData, HeartbeatData, DeviceCodeResponse, DeviceTokenResponse, DeviceTokenError, AuthEndpoints, EnsureFreshTokenOptions, FreshToken, DeviceFlowStatus, DeviceFlowCallbacks, LoginResult, RunDeviceFlowOptions, } from './host/index.js';
|
|
86
|
+
export { refreshToken, sendHeartbeat, getProfile, updateProfile, requestDeviceCode, pollDeviceToken, getAuthorizationUrl, loadAuthData, saveAuthData, clearAuthData, updateSession, hasAuthData, checkAuthFilePermissions, readAuthFile, writeAuthFile, ensureFreshToken, runDeviceFlow, nextPollInterval, loadProjectContextFiles, hasProjectContextFile, PROJECT_CONTEXT_FILES, } from './host/index.js';
|
|
87
|
+
export type { AccountType, AuthUser, AuthSession, AuthData, RefreshTokenResponse, ProfileData, HeartbeatData, DeviceCodeResponse, DeviceTokenResponse, DeviceTokenError, AuthEndpoints, EnsureFreshTokenOptions, FreshToken, DeviceFlowStatus, DeviceFlowCallbacks, LoginResult, RunDeviceFlowOptions, ProjectContextResult, LoadProjectContextOptions, } from './host/index.js';
|
|
88
88
|
export { DEFAULT_DELEGATION_CONFIG } from './delegation.js';
|
|
89
89
|
export { FileEpisodeStore, EpisodeRecorder, isSignificantWork, extractAffectedFiles, extractLinesChanged, queryWorkAtRisk, buildWorkSummaryContent, updateWorkSummaryAnchor, } from './episodes/index.js';
|
|
90
90
|
export type { FileEpisodeStoreOptions, EpisodeRecorderConfig, WorkSummaryAnchorConfig, PendingToolSignal, EpisodeFile, } from './episodes/index.js';
|
package/dist/index.js
CHANGED
|
@@ -202,7 +202,7 @@ export { DEFAULT_PERMISSION_RULES, WRITE_TOOLS, findMatchingRule, permissionMode
|
|
|
202
202
|
// =============================================================================
|
|
203
203
|
export { SHARED_DEFAULTS, migrateRawSettings } from './host/index.js';
|
|
204
204
|
// Auth: shared backend client, credential store, token refresh, device flow.
|
|
205
|
-
export { refreshToken, sendHeartbeat, getProfile, updateProfile, requestDeviceCode, pollDeviceToken, getAuthorizationUrl, loadAuthData, saveAuthData, clearAuthData, updateSession, hasAuthData, checkAuthFilePermissions, readAuthFile, writeAuthFile, ensureFreshToken, runDeviceFlow, nextPollInterval, } from './host/index.js';
|
|
205
|
+
export { refreshToken, sendHeartbeat, getProfile, updateProfile, requestDeviceCode, pollDeviceToken, getAuthorizationUrl, loadAuthData, saveAuthData, clearAuthData, updateSession, hasAuthData, checkAuthFilePermissions, readAuthFile, writeAuthFile, ensureFreshToken, runDeviceFlow, nextPollInterval, loadProjectContextFiles, hasProjectContextFile, PROJECT_CONTEXT_FILES, } from './host/index.js';
|
|
206
206
|
// =============================================================================
|
|
207
207
|
// Shared Delegation Config Defaults
|
|
208
208
|
// =============================================================================
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compilr-dev/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Universal agent runtime for building AI-powered applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"node": ">=20.0.0"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@compilr-dev/agents": "^0.
|
|
67
|
+
"@compilr-dev/agents": "^0.6.0",
|
|
68
68
|
"@compilr-dev/logger": "^0.1.0",
|
|
69
69
|
"ajv": "^6.14.0",
|
|
70
70
|
"yaml": "^2.8.4"
|