srcpack 0.1.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/README.md +165 -0
- package/dist/bundle.d.ts +37 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +189620 -0
- package/dist/config.d.ts +45 -0
- package/dist/gdrive.d.ts +33 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +187079 -0
- package/dist/init.d.ts +1 -0
- package/dist/src/bundle.d.ts +37 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/config.d.ts +45 -0
- package/dist/src/gdrive.d.ts +33 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/init.d.ts +1 -0
- package/dist/tests/bundle.test.d.ts +1 -0
- package/dist/tests/cli.test.d.ts +1 -0
- package/dist/tests/config.test.d.ts +1 -0
- package/package.json +74 -0
- package/src/bundle.ts +237 -0
- package/src/cli.ts +266 -0
- package/src/config.ts +107 -0
- package/src/gdrive.ts +200 -0
- package/src/index.ts +4 -0
- package/src/init.ts +144 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Konstantin Tarkus <koistya@kriasoft.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Srcpack
|
|
2
|
+
|
|
3
|
+
Zero-config CLI for bundling code into LLM-optimized context files.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx srcpack --init # Create config interactively
|
|
9
|
+
npx srcpack # Bundle all
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Why
|
|
13
|
+
|
|
14
|
+
LLM context fails when codebases are large, noisy, or poorly organized. Srcpack lets you split code into semantic bundles (e.g., `web`, `api`, `docs`) with clear file boundaries and an index header—optimized for ChatGPT, Claude, Gemini, etc.
|
|
15
|
+
|
|
16
|
+
## Configuration
|
|
17
|
+
|
|
18
|
+
Create `srcpack.config.ts` in your project root:
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { defineConfig } from "srcpack";
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
bundles: {
|
|
25
|
+
web: "apps/web/**/*",
|
|
26
|
+
api: ["apps/api/**/*", "!apps/api/**/*.test.ts"],
|
|
27
|
+
docs: {
|
|
28
|
+
include: "docs/**/*",
|
|
29
|
+
index: false, // disable index header
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Or add to `package.json`:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"srcpack": {
|
|
40
|
+
"bundles": {
|
|
41
|
+
"web": "apps/web/**/*"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Options
|
|
48
|
+
|
|
49
|
+
| Option | Default | Description |
|
|
50
|
+
| --------- | ---------- | -------------------------------- |
|
|
51
|
+
| `outDir` | `.srcpack` | Output directory for bundles |
|
|
52
|
+
| `bundles` | — | Named bundles with glob patterns |
|
|
53
|
+
| `upload` | — | Upload destination(s) |
|
|
54
|
+
|
|
55
|
+
### Bundle Config
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// Simple glob
|
|
59
|
+
"src/**/*"
|
|
60
|
+
|
|
61
|
+
// Array with exclusions
|
|
62
|
+
["src/**/*", "!src/**/*.test.ts"]
|
|
63
|
+
|
|
64
|
+
// Full options
|
|
65
|
+
{
|
|
66
|
+
include: "src/**/*",
|
|
67
|
+
outfile: "~/Downloads/bundle.txt", // custom output path
|
|
68
|
+
index: true // include index header (default)
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Patterns follow glob syntax. Prefix with `!` to exclude. `.gitignore` patterns are respected automatically.
|
|
73
|
+
|
|
74
|
+
### Google Drive Upload
|
|
75
|
+
|
|
76
|
+
To upload bundles to Google Drive, add OAuth credentials to your config:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
export default defineConfig({
|
|
80
|
+
bundles: {
|
|
81
|
+
/* ... */
|
|
82
|
+
},
|
|
83
|
+
upload: {
|
|
84
|
+
provider: "gdrive",
|
|
85
|
+
folder: "srcpack/outputs", // target folder path
|
|
86
|
+
clientId: "...", // OAuth 2.0 client ID
|
|
87
|
+
clientSecret: "...", // OAuth 2.0 client secret
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Setup:**
|
|
93
|
+
|
|
94
|
+
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
|
|
95
|
+
2. Create a project (or select existing)
|
|
96
|
+
3. Enable the Google Drive API
|
|
97
|
+
4. Go to **Credentials** → **Create Credentials** → **OAuth client ID**
|
|
98
|
+
5. Select **Desktop app**, then copy the client ID and secret
|
|
99
|
+
|
|
100
|
+
Multiple destinations are supported via array:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
upload: [
|
|
104
|
+
{
|
|
105
|
+
provider: "gdrive",
|
|
106
|
+
folder: "backup1",
|
|
107
|
+
clientId: "...",
|
|
108
|
+
clientSecret: "...",
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
provider: "gdrive",
|
|
112
|
+
folder: "backup2",
|
|
113
|
+
clientId: "...",
|
|
114
|
+
clientSecret: "...",
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Output Format
|
|
120
|
+
|
|
121
|
+
```text
|
|
122
|
+
# Index (3 files)
|
|
123
|
+
# [1] src/index.ts L1-L42 (42 lines)
|
|
124
|
+
# [2] src/utils.ts L43-L89 (47 lines)
|
|
125
|
+
# [3] src/api.ts L90-L150 (61 lines)
|
|
126
|
+
|
|
127
|
+
#==> [1] src/index.ts <==
|
|
128
|
+
import { utils } from "./utils";
|
|
129
|
+
...
|
|
130
|
+
|
|
131
|
+
#==> [2] src/utils.ts <==
|
|
132
|
+
export function utils() {
|
|
133
|
+
...
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
- Numbered entries for easy cross-reference in conversations
|
|
137
|
+
- Line ranges point to actual content lines
|
|
138
|
+
- `#` prefix keeps format safe inside code blocks
|
|
139
|
+
|
|
140
|
+
## CLI
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
npx srcpack # Bundle all, upload if gdrive configured
|
|
144
|
+
npx srcpack web api # Bundle specific bundles only
|
|
145
|
+
npx srcpack --dry-run # Preview without writing files
|
|
146
|
+
npx srcpack --init # Interactive config setup
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## API
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { defineConfig, loadConfig } from "srcpack";
|
|
153
|
+
|
|
154
|
+
// In config files
|
|
155
|
+
export default defineConfig({
|
|
156
|
+
bundles: { web: "apps/web/**/*" },
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Programmatic
|
|
160
|
+
const config = await loadConfig();
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT
|
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { BundleConfigInput } from "./config.ts";
|
|
2
|
+
export interface FileEntry {
|
|
3
|
+
path: string;
|
|
4
|
+
lines: number;
|
|
5
|
+
startLine: number;
|
|
6
|
+
endLine: number;
|
|
7
|
+
}
|
|
8
|
+
export interface BundleResult {
|
|
9
|
+
content: string;
|
|
10
|
+
index: FileEntry[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolve bundle config to a list of file paths.
|
|
14
|
+
* Respects .gitignore patterns in the working directory.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolvePatterns(config: BundleConfigInput, cwd: string): Promise<string[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Format the index header block.
|
|
19
|
+
* Format designed for LLM context files (ChatGPT, Grok, Gemini):
|
|
20
|
+
* - Numbered entries for cross-reference with file separators
|
|
21
|
+
* - ASCII-only characters for broad compatibility
|
|
22
|
+
* - Line locations that point to actual file content
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatIndex(index: FileEntry[]): string;
|
|
25
|
+
export interface BundleOptions {
|
|
26
|
+
includeIndex?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a bundle from a list of files.
|
|
30
|
+
* Line numbers in the index point to the first line of actual file content,
|
|
31
|
+
* not to the separator line.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createBundle(files: string[], cwd: string, options?: BundleOptions): Promise<BundleResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Bundle a single named bundle from config
|
|
36
|
+
*/
|
|
37
|
+
export declare function bundleOne(name: string, config: BundleConfigInput, cwd: string): Promise<BundleResult>;
|
package/dist/cli.d.ts
ADDED