@vkenliu/adit-cloud 0.2.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/LICENSE +21 -0
- package/dist/auth/credentials.d.ts +62 -0
- package/dist/auth/credentials.d.ts.map +1 -0
- package/dist/auth/credentials.js +151 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/device-auth.d.ts +40 -0
- package/dist/auth/device-auth.d.ts.map +1 -0
- package/dist/auth/device-auth.js +84 -0
- package/dist/auth/device-auth.js.map +1 -0
- package/dist/config.d.ts +48 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +80 -0
- package/dist/config.js.map +1 -0
- package/dist/http/client.d.ts +28 -0
- package/dist/http/client.d.ts.map +1 -0
- package/dist/http/client.js +229 -0
- package/dist/http/client.js.map +1 -0
- package/dist/http/errors.d.ts +19 -0
- package/dist/http/errors.d.ts.map +1 -0
- package/dist/http/errors.js +31 -0
- package/dist/http/errors.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/project-link/auto-link.d.ts +30 -0
- package/dist/project-link/auto-link.d.ts.map +1 -0
- package/dist/project-link/auto-link.js +91 -0
- package/dist/project-link/auto-link.js.map +1 -0
- package/dist/project-link/bulk-task.d.ts +15 -0
- package/dist/project-link/bulk-task.d.ts.map +1 -0
- package/dist/project-link/bulk-task.js +107 -0
- package/dist/project-link/bulk-task.js.map +1 -0
- package/dist/project-link/cache.d.ts +22 -0
- package/dist/project-link/cache.d.ts.map +1 -0
- package/dist/project-link/cache.js +82 -0
- package/dist/project-link/cache.js.map +1 -0
- package/dist/project-link/doc-discovery.d.ts +35 -0
- package/dist/project-link/doc-discovery.d.ts.map +1 -0
- package/dist/project-link/doc-discovery.js +260 -0
- package/dist/project-link/doc-discovery.js.map +1 -0
- package/dist/project-link/git-collector.d.ts +88 -0
- package/dist/project-link/git-collector.d.ts.map +1 -0
- package/dist/project-link/git-collector.js +250 -0
- package/dist/project-link/git-collector.js.map +1 -0
- package/dist/project-link/index.d.ts +15 -0
- package/dist/project-link/index.d.ts.map +1 -0
- package/dist/project-link/index.js +20 -0
- package/dist/project-link/index.js.map +1 -0
- package/dist/project-link/intent-command.d.ts +23 -0
- package/dist/project-link/intent-command.d.ts.map +1 -0
- package/dist/project-link/intent-command.js +104 -0
- package/dist/project-link/intent-command.js.map +1 -0
- package/dist/project-link/link-command.d.ts +26 -0
- package/dist/project-link/link-command.d.ts.map +1 -0
- package/dist/project-link/link-command.js +350 -0
- package/dist/project-link/link-command.js.map +1 -0
- package/dist/project-link/qualify.d.ts +25 -0
- package/dist/project-link/qualify.d.ts.map +1 -0
- package/dist/project-link/qualify.js +45 -0
- package/dist/project-link/qualify.js.map +1 -0
- package/dist/project-link/types.d.ts +254 -0
- package/dist/project-link/types.d.ts.map +1 -0
- package/dist/project-link/types.js +8 -0
- package/dist/project-link/types.js.map +1 -0
- package/dist/sync/auto-sync.d.ts +42 -0
- package/dist/sync/auto-sync.d.ts.map +1 -0
- package/dist/sync/auto-sync.js +136 -0
- package/dist/sync/auto-sync.js.map +1 -0
- package/dist/sync/conflicts.d.ts +27 -0
- package/dist/sync/conflicts.d.ts.map +1 -0
- package/dist/sync/conflicts.js +28 -0
- package/dist/sync/conflicts.js.map +1 -0
- package/dist/sync/engine.d.ts +76 -0
- package/dist/sync/engine.d.ts.map +1 -0
- package/dist/sync/engine.js +152 -0
- package/dist/sync/engine.js.map +1 -0
- package/dist/sync/serializer.d.ts +123 -0
- package/dist/sync/serializer.d.ts.map +1 -0
- package/dist/sync/serializer.js +280 -0
- package/dist/sync/serializer.js.map +1 -0
- package/dist/transcript/auto-upload.d.ts +25 -0
- package/dist/transcript/auto-upload.d.ts.map +1 -0
- package/dist/transcript/auto-upload.js +75 -0
- package/dist/transcript/auto-upload.js.map +1 -0
- package/dist/transcript/index.d.ts +4 -0
- package/dist/transcript/index.d.ts.map +1 -0
- package/dist/transcript/index.js +4 -0
- package/dist/transcript/index.js.map +1 -0
- package/dist/transcript/manager.d.ts +63 -0
- package/dist/transcript/manager.d.ts.map +1 -0
- package/dist/transcript/manager.js +143 -0
- package/dist/transcript/manager.js.map +1 -0
- package/dist/transcript/uploader.d.ts +135 -0
- package/dist/transcript/uploader.d.ts.map +1 -0
- package/dist/transcript/uploader.js +235 -0
- package/dist/transcript/uploader.js.map +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local SQLite cache for project link state.
|
|
3
|
+
*
|
|
4
|
+
* Tracks the server-confirmed project ID, last-synced commit SHA,
|
|
5
|
+
* document content hashes, and qualification status. Stored in the
|
|
6
|
+
* existing adit database ($projectRoot/.adit/adit.sqlite).
|
|
7
|
+
*/
|
|
8
|
+
import type Database from "better-sqlite3";
|
|
9
|
+
import type { ProjectLinkCache } from "./types.js";
|
|
10
|
+
/** Get cached state for a project link */
|
|
11
|
+
export declare function getProjectLinkCache(db: Database.Database, projectId: string, serverUrl: string): ProjectLinkCache | null;
|
|
12
|
+
/** Create or update project link cache */
|
|
13
|
+
export declare function upsertProjectLinkCache(db: Database.Database, cache: ProjectLinkCache): void;
|
|
14
|
+
/** Clear cache for a project link (used by --force) */
|
|
15
|
+
export declare function clearProjectLinkCache(db: Database.Database, projectId: string, serverUrl: string): void;
|
|
16
|
+
/** Update the last-synced commit SHA after upload */
|
|
17
|
+
export declare function updateCachedCommitSha(db: Database.Database, projectId: string, serverUrl: string, sha: string): void;
|
|
18
|
+
/** Update cached document hashes after upload */
|
|
19
|
+
export declare function updateCachedDocHashes(db: Database.Database, projectId: string, serverUrl: string, hashes: Record<string, string>): void;
|
|
20
|
+
/** Mark as qualified or not */
|
|
21
|
+
export declare function updateCachedQualified(db: Database.Database, projectId: string, serverUrl: string, qualified: boolean): void;
|
|
22
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/project-link/cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAgBnD,0CAA0C;AAC1C,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,gBAAgB,GAAG,IAAI,CA0BzB;AAED,0CAA0C;AAC1C,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,KAAK,EAAE,gBAAgB,GACtB,IAAI,CA2BN;AAED,uDAAuD;AACvD,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,IAAI,CAGN;AAED,qDAAqD;AACrD,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,GACV,IAAI,CAMN;AAED,iDAAiD;AACjD,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,IAAI,CAYN;AAED,+BAA+B;AAC/B,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,OAAO,GACjB,IAAI,CAMN"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local SQLite cache for project link state.
|
|
3
|
+
*
|
|
4
|
+
* Tracks the server-confirmed project ID, last-synced commit SHA,
|
|
5
|
+
* document content hashes, and qualification status. Stored in the
|
|
6
|
+
* existing adit database ($projectRoot/.adit/adit.sqlite).
|
|
7
|
+
*/
|
|
8
|
+
/** Get cached state for a project link */
|
|
9
|
+
export function getProjectLinkCache(db, projectId, serverUrl) {
|
|
10
|
+
const row = db
|
|
11
|
+
.prepare("SELECT * FROM project_link_cache WHERE project_id = ? AND server_url = ?")
|
|
12
|
+
.get(projectId, serverUrl);
|
|
13
|
+
if (!row)
|
|
14
|
+
return null;
|
|
15
|
+
let docHashes = {};
|
|
16
|
+
try {
|
|
17
|
+
docHashes = JSON.parse(row.doc_hashes_json);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Corrupted JSON — treat as empty (documents will be re-uploaded)
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
projectId: row.project_id,
|
|
24
|
+
serverUrl: row.server_url,
|
|
25
|
+
confirmedProjectId: row.confirmed_project_id,
|
|
26
|
+
lastCommitSha: row.last_commit_sha,
|
|
27
|
+
lastBranchSyncAt: row.last_branch_sync_at,
|
|
28
|
+
lastDocSyncAt: row.last_doc_sync_at,
|
|
29
|
+
docHashes,
|
|
30
|
+
qualified: row.qualified === 1,
|
|
31
|
+
initializedAt: row.initialized_at,
|
|
32
|
+
updatedAt: row.updated_at,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Create or update project link cache */
|
|
36
|
+
export function upsertProjectLinkCache(db, cache) {
|
|
37
|
+
db.prepare(`
|
|
38
|
+
INSERT INTO project_link_cache (
|
|
39
|
+
project_id, server_url, confirmed_project_id,
|
|
40
|
+
last_commit_sha, last_branch_sync_at, last_doc_sync_at,
|
|
41
|
+
doc_hashes_json, qualified, initialized_at, updated_at
|
|
42
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
43
|
+
ON CONFLICT (project_id, server_url) DO UPDATE SET
|
|
44
|
+
confirmed_project_id = excluded.confirmed_project_id,
|
|
45
|
+
last_commit_sha = excluded.last_commit_sha,
|
|
46
|
+
last_branch_sync_at = excluded.last_branch_sync_at,
|
|
47
|
+
last_doc_sync_at = excluded.last_doc_sync_at,
|
|
48
|
+
doc_hashes_json = excluded.doc_hashes_json,
|
|
49
|
+
qualified = excluded.qualified,
|
|
50
|
+
updated_at = excluded.updated_at
|
|
51
|
+
`).run(cache.projectId, cache.serverUrl, cache.confirmedProjectId, cache.lastCommitSha, cache.lastBranchSyncAt, cache.lastDocSyncAt, JSON.stringify(cache.docHashes), cache.qualified ? 1 : 0, cache.initializedAt, cache.updatedAt);
|
|
52
|
+
}
|
|
53
|
+
/** Clear cache for a project link (used by --force) */
|
|
54
|
+
export function clearProjectLinkCache(db, projectId, serverUrl) {
|
|
55
|
+
db.prepare("DELETE FROM project_link_cache WHERE project_id = ? AND server_url = ?")
|
|
56
|
+
.run(projectId, serverUrl);
|
|
57
|
+
}
|
|
58
|
+
/** Update the last-synced commit SHA after upload */
|
|
59
|
+
export function updateCachedCommitSha(db, projectId, serverUrl, sha) {
|
|
60
|
+
db.prepare(`
|
|
61
|
+
UPDATE project_link_cache
|
|
62
|
+
SET last_commit_sha = ?, updated_at = ?
|
|
63
|
+
WHERE project_id = ? AND server_url = ?
|
|
64
|
+
`).run(sha, new Date().toISOString(), projectId, serverUrl);
|
|
65
|
+
}
|
|
66
|
+
/** Update cached document hashes after upload */
|
|
67
|
+
export function updateCachedDocHashes(db, projectId, serverUrl, hashes) {
|
|
68
|
+
db.prepare(`
|
|
69
|
+
UPDATE project_link_cache
|
|
70
|
+
SET doc_hashes_json = ?, last_doc_sync_at = ?, updated_at = ?
|
|
71
|
+
WHERE project_id = ? AND server_url = ?
|
|
72
|
+
`).run(JSON.stringify(hashes), new Date().toISOString(), new Date().toISOString(), projectId, serverUrl);
|
|
73
|
+
}
|
|
74
|
+
/** Mark as qualified or not */
|
|
75
|
+
export function updateCachedQualified(db, projectId, serverUrl, qualified) {
|
|
76
|
+
db.prepare(`
|
|
77
|
+
UPDATE project_link_cache
|
|
78
|
+
SET qualified = ?, updated_at = ?
|
|
79
|
+
WHERE project_id = ? AND server_url = ?
|
|
80
|
+
`).run(qualified ? 1 : 0, new Date().toISOString(), projectId, serverUrl);
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/project-link/cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAmBH,0CAA0C;AAC1C,MAAM,UAAU,mBAAmB,CACjC,EAAqB,EACrB,SAAiB,EACjB,SAAiB;IAEjB,MAAM,GAAG,GAAG,EAAE;SACX,OAAO,CAAC,0EAA0E,CAAC;SACnF,GAAG,CAAC,SAAS,EAAE,SAAS,CAAyB,CAAC;IAErD,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IAEtB,IAAI,SAAS,GAA2B,EAAE,CAAC;IAC3C,IAAI,CAAC;QACH,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,CAA2B,CAAC;IACxE,CAAC;IAAC,MAAM,CAAC;QACP,kEAAkE;IACpE,CAAC;IAED,OAAO;QACL,SAAS,EAAE,GAAG,CAAC,UAAU;QACzB,SAAS,EAAE,GAAG,CAAC,UAAU;QACzB,kBAAkB,EAAE,GAAG,CAAC,oBAAoB;QAC5C,aAAa,EAAE,GAAG,CAAC,eAAe;QAClC,gBAAgB,EAAE,GAAG,CAAC,mBAAmB;QACzC,aAAa,EAAE,GAAG,CAAC,gBAAgB;QACnC,SAAS;QACT,SAAS,EAAE,GAAG,CAAC,SAAS,KAAK,CAAC;QAC9B,aAAa,EAAE,GAAG,CAAC,cAAc;QACjC,SAAS,EAAE,GAAG,CAAC,UAAU;KAC1B,CAAC;AACJ,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,sBAAsB,CACpC,EAAqB,EACrB,KA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EAAqB,EACrB,SAAiB,EACjB,SAAiB,EACjB,SAAkB;IAElB,EAAE,CAAC,OAAO,CAAC;;;;GAIV,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project document discovery for project link.
|
|
3
|
+
*
|
|
4
|
+
* Scans the project root for markdown documents matching configurable
|
|
5
|
+
* glob patterns, computes content hashes, and classifies each document
|
|
6
|
+
* as new, changed, or unchanged relative to cached hashes.
|
|
7
|
+
*/
|
|
8
|
+
import type { DiscoveredDocument } from "./types.js";
|
|
9
|
+
/** Options for document discovery */
|
|
10
|
+
export interface DocDiscoveryOptions {
|
|
11
|
+
/** Override default include patterns (replaces, does not merge) */
|
|
12
|
+
patterns?: string[];
|
|
13
|
+
/** Override default exclude patterns (replaces, does not merge) */
|
|
14
|
+
excludePatterns?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Discover project documents by scanning the project root.
|
|
18
|
+
*
|
|
19
|
+
* Returns documents sorted: new first, then changed, then unchanged.
|
|
20
|
+
* Files > 500KB or containing null bytes (binary) are skipped with
|
|
21
|
+
* a warning to stderr.
|
|
22
|
+
*/
|
|
23
|
+
export declare function discoverDocuments(projectRoot: string, cachedHashes: Record<string, string>, options?: DocDiscoveryOptions): DiscoveredDocument[];
|
|
24
|
+
/**
|
|
25
|
+
* Load custom document discovery settings from the project's settings.json.
|
|
26
|
+
*
|
|
27
|
+
* The settings file is at `{projectRoot}/settings.json` and may contain:
|
|
28
|
+
* ```json
|
|
29
|
+
* { "projectLink": { "docPatterns": [...], "excludePatterns": [...] } }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* Returns undefined if no custom settings are found.
|
|
33
|
+
*/
|
|
34
|
+
export declare function loadDocSettings(projectRoot: string): DocDiscoveryOptions | undefined;
|
|
35
|
+
//# sourceMappingURL=doc-discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-discovery.d.ts","sourceRoot":"","sources":["../../src/project-link/doc-discovery.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAmJrD,qCAAqC;AACrC,MAAM,WAAW,mBAAmB;IAClC,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,mEAAmE;IACnE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,kBAAkB,EAAE,CA8EtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,MAAM,GAClB,mBAAmB,GAAG,SAAS,CAqBjC"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project document discovery for project link.
|
|
3
|
+
*
|
|
4
|
+
* Scans the project root for markdown documents matching configurable
|
|
5
|
+
* glob patterns, computes content hashes, and classifies each document
|
|
6
|
+
* as new, changed, or unchanged relative to cached hashes.
|
|
7
|
+
*/
|
|
8
|
+
import { readdirSync, readFileSync, existsSync } from "node:fs";
|
|
9
|
+
import { join, basename, relative } from "node:path";
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
/** Maximum file size for document upload (500 KB) */
|
|
12
|
+
const MAX_DOC_SIZE = 500 * 1024;
|
|
13
|
+
/** Default glob patterns for project documents */
|
|
14
|
+
const DEFAULT_DOC_PATTERNS = [
|
|
15
|
+
// Root-level documentation files (case-insensitive matching handled by glob)
|
|
16
|
+
"*.md",
|
|
17
|
+
// Common documentation directories
|
|
18
|
+
"docs/**/*.md",
|
|
19
|
+
"doc/**/*.md",
|
|
20
|
+
"documentation/**/*.md",
|
|
21
|
+
"specs/**/*.md",
|
|
22
|
+
"design/**/*.md",
|
|
23
|
+
"wiki/**/*.md",
|
|
24
|
+
"guides/**/*.md",
|
|
25
|
+
"rfcs/**/*.md",
|
|
26
|
+
"adrs/**/*.md",
|
|
27
|
+
];
|
|
28
|
+
/** Default patterns to exclude from document discovery */
|
|
29
|
+
const DEFAULT_EXCLUDE_PATTERNS = [
|
|
30
|
+
"node_modules/**",
|
|
31
|
+
".git/**",
|
|
32
|
+
"vendor/**",
|
|
33
|
+
"dist/**",
|
|
34
|
+
"build/**",
|
|
35
|
+
"out/**",
|
|
36
|
+
"coverage/**",
|
|
37
|
+
".adit/**",
|
|
38
|
+
"**/CHANGELOG.md",
|
|
39
|
+
"**/changelog.md",
|
|
40
|
+
];
|
|
41
|
+
/** Check if a relative path contains any hidden (dot-prefixed) directory or file */
|
|
42
|
+
function isInHiddenPath(relativePath) {
|
|
43
|
+
return relativePath.split("/").some((segment) => segment.startsWith("."));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Convert a simple glob pattern to a RegExp.
|
|
47
|
+
*
|
|
48
|
+
* Supports:
|
|
49
|
+
* - `*` matches any non-separator characters
|
|
50
|
+
* - `**` matches any path segment(s), including nested directories
|
|
51
|
+
* - `?` matches a single non-separator character
|
|
52
|
+
* - `{a,b}` alternation (one level, no nesting)
|
|
53
|
+
*/
|
|
54
|
+
function globToRegex(pattern) {
|
|
55
|
+
let re = "";
|
|
56
|
+
let i = 0;
|
|
57
|
+
while (i < pattern.length) {
|
|
58
|
+
const ch = pattern[i];
|
|
59
|
+
if (ch === "*") {
|
|
60
|
+
if (pattern[i + 1] === "*") {
|
|
61
|
+
// ** matches everything including path separators
|
|
62
|
+
if (pattern[i + 2] === "/") {
|
|
63
|
+
re += "(?:.+/)?"; // **/ matches zero or more directories
|
|
64
|
+
i += 3;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
re += ".*";
|
|
68
|
+
i += 2;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
re += "[^/]*"; // * matches within a single segment
|
|
73
|
+
i += 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (ch === "?") {
|
|
77
|
+
re += "[^/]";
|
|
78
|
+
i += 1;
|
|
79
|
+
}
|
|
80
|
+
else if (ch === "{") {
|
|
81
|
+
const close = pattern.indexOf("}", i);
|
|
82
|
+
if (close !== -1) {
|
|
83
|
+
const alternatives = pattern.slice(i + 1, close).split(",");
|
|
84
|
+
re += "(?:" + alternatives.map(escapeRegex).join("|") + ")";
|
|
85
|
+
i = close + 1;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
re += escapeRegex(ch);
|
|
89
|
+
i += 1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
re += escapeRegex(ch);
|
|
94
|
+
i += 1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return new RegExp("^" + re + "$");
|
|
98
|
+
}
|
|
99
|
+
/** Escape a character for use in a RegExp */
|
|
100
|
+
function escapeRegex(s) {
|
|
101
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* List all files under projectRoot recursively, returning POSIX-style
|
|
105
|
+
* relative paths. Uses `readdirSync({ recursive: true })` which is
|
|
106
|
+
* stable since Node 18.17.
|
|
107
|
+
*/
|
|
108
|
+
function listAllFiles(projectRoot) {
|
|
109
|
+
try {
|
|
110
|
+
const entries = readdirSync(projectRoot, { recursive: true, withFileTypes: true });
|
|
111
|
+
const files = [];
|
|
112
|
+
for (const entry of entries) {
|
|
113
|
+
if (!entry.isFile())
|
|
114
|
+
continue;
|
|
115
|
+
// Build relative path from the dirent. parentPath is stable since Node 20.12.
|
|
116
|
+
const fullPath = join(entry.parentPath, entry.name);
|
|
117
|
+
const rel = relative(projectRoot, fullPath).split("\\").join("/");
|
|
118
|
+
files.push(rel);
|
|
119
|
+
}
|
|
120
|
+
return files;
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Match files against include/exclude glob patterns.
|
|
128
|
+
*
|
|
129
|
+
* Replaces `node:fs` experimental `globSync` with stable
|
|
130
|
+
* `readdirSync({ recursive: true })` + pattern matching, ensuring
|
|
131
|
+
* compatibility with Node >= 20.
|
|
132
|
+
*/
|
|
133
|
+
function matchFiles(projectRoot, includePatterns, excludePatterns) {
|
|
134
|
+
const allFiles = listAllFiles(projectRoot);
|
|
135
|
+
const includeRegexes = includePatterns.map(globToRegex);
|
|
136
|
+
const excludeRegexes = excludePatterns.map(globToRegex);
|
|
137
|
+
const matched = new Set();
|
|
138
|
+
for (const file of allFiles) {
|
|
139
|
+
// Check if file matches any include pattern
|
|
140
|
+
const included = includeRegexes.some((re) => re.test(file));
|
|
141
|
+
if (!included)
|
|
142
|
+
continue;
|
|
143
|
+
// Check if file matches any exclude pattern
|
|
144
|
+
const excluded = excludeRegexes.some((re) => re.test(file));
|
|
145
|
+
if (excluded)
|
|
146
|
+
continue;
|
|
147
|
+
matched.add(file);
|
|
148
|
+
}
|
|
149
|
+
return matched;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Discover project documents by scanning the project root.
|
|
153
|
+
*
|
|
154
|
+
* Returns documents sorted: new first, then changed, then unchanged.
|
|
155
|
+
* Files > 500KB or containing null bytes (binary) are skipped with
|
|
156
|
+
* a warning to stderr.
|
|
157
|
+
*/
|
|
158
|
+
export function discoverDocuments(projectRoot, cachedHashes, options) {
|
|
159
|
+
const patterns = options?.patterns ?? DEFAULT_DOC_PATTERNS;
|
|
160
|
+
const excludePatterns = options?.excludePatterns ?? DEFAULT_EXCLUDE_PATTERNS;
|
|
161
|
+
// Collect matching files via recursive directory listing + pattern matching.
|
|
162
|
+
// Uses readdirSync({ recursive: true }) which is stable since Node 18.17,
|
|
163
|
+
// avoiding the experimental node:fs globSync (Node 22+).
|
|
164
|
+
const matchedPaths = matchFiles(projectRoot, patterns, excludePatterns);
|
|
165
|
+
const documents = [];
|
|
166
|
+
const skipped = [];
|
|
167
|
+
for (const sourcePath of matchedPaths) {
|
|
168
|
+
// Skip files in hidden (dot-prefixed) directories or hidden files
|
|
169
|
+
if (isInHiddenPath(sourcePath))
|
|
170
|
+
continue;
|
|
171
|
+
const fullPath = join(projectRoot, sourcePath);
|
|
172
|
+
if (!existsSync(fullPath))
|
|
173
|
+
continue;
|
|
174
|
+
// Read file and check constraints
|
|
175
|
+
let content;
|
|
176
|
+
let sizeBytes;
|
|
177
|
+
try {
|
|
178
|
+
const buffer = readFileSync(fullPath);
|
|
179
|
+
sizeBytes = buffer.length;
|
|
180
|
+
// Skip files exceeding size limit
|
|
181
|
+
if (sizeBytes > MAX_DOC_SIZE) {
|
|
182
|
+
const sizeMB = (sizeBytes / (1024 * 1024)).toFixed(1);
|
|
183
|
+
skipped.push(`Skipping ${sourcePath} (${sizeMB} MB) — exceeds 500KB limit`);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
// Skip binary files (null byte check)
|
|
187
|
+
if (buffer.includes(0)) {
|
|
188
|
+
skipped.push(`Skipping ${sourcePath} — binary file`);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
content = buffer.toString("utf-8");
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
continue; // Unreadable file — skip silently
|
|
195
|
+
}
|
|
196
|
+
// Compute content hash
|
|
197
|
+
const contentHash = createHash("sha256").update(content).digest("hex");
|
|
198
|
+
// Classify relative to cache
|
|
199
|
+
const cachedHash = cachedHashes[sourcePath];
|
|
200
|
+
let status;
|
|
201
|
+
if (!cachedHash) {
|
|
202
|
+
status = "new";
|
|
203
|
+
}
|
|
204
|
+
else if (cachedHash !== contentHash) {
|
|
205
|
+
status = "changed";
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
status = "unchanged";
|
|
209
|
+
}
|
|
210
|
+
documents.push({
|
|
211
|
+
fileName: basename(sourcePath),
|
|
212
|
+
sourcePath,
|
|
213
|
+
content,
|
|
214
|
+
contentHash,
|
|
215
|
+
sizeBytes,
|
|
216
|
+
status,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
// Report skipped files
|
|
220
|
+
for (const msg of skipped) {
|
|
221
|
+
process.stderr.write(`[adit] ${msg}\n`);
|
|
222
|
+
}
|
|
223
|
+
// Sort: new first, then changed, then unchanged
|
|
224
|
+
const order = { new: 0, changed: 1, unchanged: 2 };
|
|
225
|
+
documents.sort((a, b) => order[a.status] - order[b.status]);
|
|
226
|
+
return documents;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Load custom document discovery settings from the project's settings.json.
|
|
230
|
+
*
|
|
231
|
+
* The settings file is at `{projectRoot}/settings.json` and may contain:
|
|
232
|
+
* ```json
|
|
233
|
+
* { "projectLink": { "docPatterns": [...], "excludePatterns": [...] } }
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* Returns undefined if no custom settings are found.
|
|
237
|
+
*/
|
|
238
|
+
export function loadDocSettings(projectRoot) {
|
|
239
|
+
const settingsPath = join(projectRoot, "settings.json");
|
|
240
|
+
if (!existsSync(settingsPath))
|
|
241
|
+
return undefined;
|
|
242
|
+
try {
|
|
243
|
+
const raw = JSON.parse(readFileSync(settingsPath, "utf-8"));
|
|
244
|
+
const projectLink = raw.projectLink;
|
|
245
|
+
if (!projectLink)
|
|
246
|
+
return undefined;
|
|
247
|
+
const opts = {};
|
|
248
|
+
if (Array.isArray(projectLink.docPatterns)) {
|
|
249
|
+
opts.patterns = projectLink.docPatterns;
|
|
250
|
+
}
|
|
251
|
+
if (Array.isArray(projectLink.excludePatterns)) {
|
|
252
|
+
opts.excludePatterns = projectLink.excludePatterns;
|
|
253
|
+
}
|
|
254
|
+
return Object.keys(opts).length > 0 ? opts : undefined;
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
//# sourceMappingURL=doc-discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-discovery.js","sourceRoot":"","sources":["../../src/project-link/doc-discovery.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,qDAAqD;AACrD,MAAM,YAAY,GAAG,GAAG,GAAG,IAAI,CAAC;AAEhC,kDAAkD;AAClD,MAAM,oBAAoB,GAAG;IAC3B,6EAA6E;IAC7E,MAAM;IACN,mCAAmC;IACnC,cAAc;IACd,aAAa;IACb,uBAAuB;IACvB,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,gBAAgB;IAChB,cAAc;IACd,cAAc;CACf,CAAC;AAEF,0DAA0D;AAC1D,MAAM,wBAAwB,GAAG;IAC/B,iBAAiB;IACjB,SAAS;IACT,WAAW;IACX,SAAS;IACT,UAAU;IACV,QAAQ;IACR,aAAa;IACb,UAAU;IACV,iBAAiB;IACjB,iBAAiB;CAClB,CAAC;AAEF,oFAAoF;AACpF,SAAS,cAAc,CAAC,YAAoB;IAC1C,OAAO,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;;GAQG;AACH,S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AI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;YAC3C,IAAI,CAAC,QAAQ,GAAG,WAAW,CAAC,WAAuB,CAAC;QACtD,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,CAAC;YAC/C,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,eAA2B,CAAC;QACjE,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git metadata collection for project link.
|
|
3
|
+
*
|
|
4
|
+
* Collects remote URL, branches, commit logs, and default branch
|
|
5
|
+
* using the existing @vkenliu/adit-engine git runner. All functions are
|
|
6
|
+
* fail-safe — they throw on critical errors (no git repo, no remote)
|
|
7
|
+
* but return empty arrays for non-critical failures.
|
|
8
|
+
*/
|
|
9
|
+
import type { GitBranch, GitCommit } from "./types.js";
|
|
10
|
+
/** Collect the remote origin URL. Throws if no remote is configured. */
|
|
11
|
+
export declare function collectRemoteUrl(cwd: string): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Detect the default branch name.
|
|
14
|
+
*
|
|
15
|
+
* Tries `git symbolic-ref refs/remotes/origin/HEAD` first (reliable
|
|
16
|
+
* if the remote HEAD is set). Falls back to checking for `main` then
|
|
17
|
+
* `master` branch existence.
|
|
18
|
+
*/
|
|
19
|
+
export declare function collectDefaultBranch(cwd: string): Promise<string | null>;
|
|
20
|
+
/**
|
|
21
|
+
* Get the currently checked-out branch name.
|
|
22
|
+
*
|
|
23
|
+
* Uses `git branch --show-current` which returns an empty string
|
|
24
|
+
* in detached HEAD state. Returns null if not on a branch or if
|
|
25
|
+
* the command fails.
|
|
26
|
+
*/
|
|
27
|
+
export declare function collectCurrentBranch(cwd: string): Promise<string | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Collect all branches (local + remote) with their HEAD SHAs.
|
|
30
|
+
*
|
|
31
|
+
* Remote branches are included and deduplicated — if a local branch
|
|
32
|
+
* name matches a remote tracking branch, the local version is kept.
|
|
33
|
+
*/
|
|
34
|
+
export declare function collectBranches(cwd: string): Promise<GitBranch[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Options for collecting commit logs.
|
|
37
|
+
*/
|
|
38
|
+
export interface CollectCommitOptions {
|
|
39
|
+
/** Only return commits after this SHA (incremental sync). */
|
|
40
|
+
sinceCommitSha?: string | null;
|
|
41
|
+
/** Branch name to tag on each returned commit (legacy — prefer resolveCommitBranches). */
|
|
42
|
+
branch?: string | null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Collect commit logs, optionally since a specific commit SHA.
|
|
46
|
+
*
|
|
47
|
+
* When `sinceCommitSha` is provided, only commits after that SHA
|
|
48
|
+
* are returned (incremental sync). Otherwise, all commits are returned.
|
|
49
|
+
* Commits are ordered newest-first (git log default).
|
|
50
|
+
*
|
|
51
|
+
* When `branch` is provided, each returned commit will have its
|
|
52
|
+
* `branch` field set to that value. For accurate per-commit branch
|
|
53
|
+
* assignment, use `resolveCommitBranches()` after collecting commits
|
|
54
|
+
* instead of this option.
|
|
55
|
+
*
|
|
56
|
+
* Format uses NUL (\x00) as record delimiter and SOH (\x01) as field
|
|
57
|
+
* delimiter so that pipe characters and newlines inside commit messages
|
|
58
|
+
* (%B = subject + body, multi-line) are preserved without ambiguity.
|
|
59
|
+
*/
|
|
60
|
+
export declare function collectCommitLogs(cwd: string, sinceCommitShaOrOptions?: string | null | CollectCommitOptions): Promise<GitCommit[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Resolve per-commit branch assignments for a set of commits.
|
|
63
|
+
*
|
|
64
|
+
* For each known branch, runs `git log <branch> --format=%H` to collect
|
|
65
|
+
* the SHAs reachable from that branch. Commits are assigned to the most
|
|
66
|
+
* specific branch (non-default branches take priority over the default
|
|
67
|
+
* branch, so a commit on `feature/x` that was later merged into `main`
|
|
68
|
+
* is attributed to `feature/x`).
|
|
69
|
+
*
|
|
70
|
+
* Only SHAs present in `commitShas` are assigned — this avoids building
|
|
71
|
+
* a map for the entire repository history when doing incremental sync.
|
|
72
|
+
*
|
|
73
|
+
* Mutates the `branch` field of each commit in `commits` in-place and
|
|
74
|
+
* also returns the same array for chaining convenience.
|
|
75
|
+
*/
|
|
76
|
+
export declare function resolveCommitBranches(cwd: string, commits: GitCommit[], branches: GitBranch[], defaultBranch: string | null): Promise<GitCommit[]>;
|
|
77
|
+
/** Count total commits reachable from HEAD. */
|
|
78
|
+
export declare function collectCommitCount(cwd: string): Promise<number>;
|
|
79
|
+
/**
|
|
80
|
+
* Extract a project name from a git remote URL.
|
|
81
|
+
*
|
|
82
|
+
* Examples:
|
|
83
|
+
* "https://github.com/user/my-repo.git" → "my-repo"
|
|
84
|
+
* "git@github.com:user/my-repo.git" → "my-repo"
|
|
85
|
+
* "https://github.com/user/my-repo" → "my-repo"
|
|
86
|
+
*/
|
|
87
|
+
export declare function projectNameFromRemoteUrl(url: string): string;
|
|
88
|
+
//# sourceMappingURL=git-collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-collector.d.ts","sourceRoot":"","sources":["../../src/project-link/git-collector.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvD,wEAAwE;AACxE,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMnE;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA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