hammoc 1.4.0 → 1.5.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/README.md +422 -405
- package/bin/hammoc.js +0 -6
- package/package.json +100 -94
- package/packages/client/dist/assets/agentExampleHighlight-BgwTm15v.js +1 -0
- package/packages/client/dist/assets/commandTokenHighlight-BljHwnrK.js +1 -0
- package/packages/client/dist/assets/index-CjyjnXB8.css +32 -0
- package/packages/client/dist/assets/index-D3LxqW3f.js +2 -0
- package/packages/client/dist/assets/index-NqJdhlek.js +1498 -0
- package/packages/client/dist/assets/snippetTokenHighlight-DWsaQXX0.js +1 -0
- package/packages/client/dist/index.html +2 -2
- package/packages/client/dist/sw.js +1 -1
- package/packages/server/dist/app.d.ts.map +1 -1
- package/packages/server/dist/app.js +13 -21
- package/packages/server/dist/app.js.map +1 -1
- package/packages/server/dist/controllers/claudeMdController.d.ts +26 -0
- package/packages/server/dist/controllers/claudeMdController.d.ts.map +1 -0
- package/packages/server/dist/controllers/claudeMdController.js +158 -0
- package/packages/server/dist/controllers/claudeMdController.js.map +1 -0
- package/packages/server/dist/controllers/harnessAgentController.d.ts +28 -0
- package/packages/server/dist/controllers/harnessAgentController.d.ts.map +1 -0
- package/packages/server/dist/controllers/harnessAgentController.js +339 -0
- package/packages/server/dist/controllers/harnessAgentController.js.map +1 -0
- package/packages/server/dist/controllers/harnessCommandController.d.ts +28 -0
- package/packages/server/dist/controllers/harnessCommandController.d.ts.map +1 -0
- package/packages/server/dist/controllers/harnessCommandController.js +382 -0
- package/packages/server/dist/controllers/harnessCommandController.js.map +1 -0
- package/packages/server/dist/controllers/harnessController.d.ts +21 -0
- package/packages/server/dist/controllers/harnessController.d.ts.map +1 -0
- package/packages/server/dist/controllers/harnessController.js +176 -0
- package/packages/server/dist/controllers/harnessController.js.map +1 -0
- package/packages/server/dist/controllers/harnessHookController.d.ts +32 -0
- package/packages/server/dist/controllers/harnessHookController.d.ts.map +1 -0
- package/packages/server/dist/controllers/harnessHookController.js +363 -0
- package/packages/server/dist/controllers/harnessHookController.js.map +1 -0
- package/packages/server/dist/controllers/harnessLintController.d.ts +18 -0
- package/packages/server/dist/controllers/harnessLintController.d.ts.map +1 -0
- package/packages/server/dist/controllers/harnessLintController.js +72 -0
- package/packages/server/dist/controllers/harnessLintController.js.map +1 -0
- package/packages/server/dist/controllers/harnessMcpController.d.ts +28 -0
- package/packages/server/dist/controllers/harnessMcpController.d.ts.map +1 -0
- package/packages/server/dist/controllers/harnessMcpController.js +310 -0
- package/packages/server/dist/controllers/harnessMcpController.js.map +1 -0
- package/packages/server/dist/controllers/harnessPluginController.d.ts +17 -0
- package/packages/server/dist/controllers/harnessPluginController.d.ts.map +1 -0
- package/packages/server/dist/controllers/harnessPluginController.js +115 -0
- package/packages/server/dist/controllers/harnessPluginController.js.map +1 -0
- package/packages/server/dist/controllers/harnessShareScopeController.d.ts +15 -0
- package/packages/server/dist/controllers/harnessShareScopeController.d.ts.map +1 -0
- package/packages/server/dist/controllers/harnessShareScopeController.js +73 -0
- package/packages/server/dist/controllers/harnessShareScopeController.js.map +1 -0
- package/packages/server/dist/controllers/harnessSkillController.d.ts +32 -0
- package/packages/server/dist/controllers/harnessSkillController.d.ts.map +1 -0
- package/packages/server/dist/controllers/harnessSkillController.js +453 -0
- package/packages/server/dist/controllers/harnessSkillController.js.map +1 -0
- package/packages/server/dist/controllers/projectController.d.ts.map +1 -1
- package/packages/server/dist/controllers/projectController.js +11 -0
- package/packages/server/dist/controllers/projectController.js.map +1 -1
- package/packages/server/dist/controllers/snippetController.d.ts +35 -0
- package/packages/server/dist/controllers/snippetController.d.ts.map +1 -0
- package/packages/server/dist/controllers/snippetController.js +294 -0
- package/packages/server/dist/controllers/snippetController.js.map +1 -0
- package/packages/server/dist/handlers/websocket.d.ts +15 -0
- package/packages/server/dist/handlers/websocket.d.ts.map +1 -1
- package/packages/server/dist/handlers/websocket.js +79 -0
- package/packages/server/dist/handlers/websocket.js.map +1 -1
- package/packages/server/dist/index.js +5 -0
- package/packages/server/dist/index.js.map +1 -1
- package/packages/server/dist/locales/en/server.json +37 -4
- package/packages/server/dist/locales/es/server.json +0 -4
- package/packages/server/dist/locales/ja/server.json +0 -4
- package/packages/server/dist/locales/ko/server.json +0 -4
- package/packages/server/dist/locales/pt/server.json +0 -4
- package/packages/server/dist/locales/zh-CN/server.json +0 -4
- package/packages/server/dist/routes/harness.d.ts +8 -0
- package/packages/server/dist/routes/harness.d.ts.map +1 -0
- package/packages/server/dist/routes/harness.js +92 -0
- package/packages/server/dist/routes/harness.js.map +1 -0
- package/packages/server/dist/routes/projects.d.ts.map +1 -1
- package/packages/server/dist/routes/projects.js +5 -60
- package/packages/server/dist/routes/projects.js.map +1 -1
- package/packages/server/dist/routes/snippets.d.ts +14 -0
- package/packages/server/dist/routes/snippets.d.ts.map +1 -0
- package/packages/server/dist/routes/snippets.js +27 -0
- package/packages/server/dist/routes/snippets.js.map +1 -0
- package/packages/server/dist/services/bmadStatusService.d.ts +6 -2
- package/packages/server/dist/services/bmadStatusService.d.ts.map +1 -1
- package/packages/server/dist/services/bmadStatusService.js +88 -32
- package/packages/server/dist/services/bmadStatusService.js.map +1 -1
- package/packages/server/dist/services/chatService.d.ts +3 -0
- package/packages/server/dist/services/chatService.d.ts.map +1 -1
- package/packages/server/dist/services/chatService.js +27 -6
- package/packages/server/dist/services/chatService.js.map +1 -1
- package/packages/server/dist/services/claudeMdService.d.ts +48 -0
- package/packages/server/dist/services/claudeMdService.d.ts.map +1 -0
- package/packages/server/dist/services/claudeMdService.js +240 -0
- package/packages/server/dist/services/claudeMdService.js.map +1 -0
- package/packages/server/dist/services/commandService.d.ts +10 -0
- package/packages/server/dist/services/commandService.d.ts.map +1 -1
- package/packages/server/dist/services/commandService.js +129 -4
- package/packages/server/dist/services/commandService.js.map +1 -1
- package/packages/server/dist/services/fileWatcherService.d.ts +24 -0
- package/packages/server/dist/services/fileWatcherService.d.ts.map +1 -1
- package/packages/server/dist/services/fileWatcherService.js +192 -1
- package/packages/server/dist/services/fileWatcherService.js.map +1 -1
- package/packages/server/dist/services/harnessAgentService.d.ts +79 -0
- package/packages/server/dist/services/harnessAgentService.d.ts.map +1 -0
- package/packages/server/dist/services/harnessAgentService.js +933 -0
- package/packages/server/dist/services/harnessAgentService.js.map +1 -0
- package/packages/server/dist/services/harnessCommandService.d.ts +60 -0
- package/packages/server/dist/services/harnessCommandService.d.ts.map +1 -0
- package/packages/server/dist/services/harnessCommandService.js +853 -0
- package/packages/server/dist/services/harnessCommandService.js.map +1 -0
- package/packages/server/dist/services/harnessHookService.d.ts +55 -0
- package/packages/server/dist/services/harnessHookService.d.ts.map +1 -0
- package/packages/server/dist/services/harnessHookService.js +1060 -0
- package/packages/server/dist/services/harnessHookService.js.map +1 -0
- package/packages/server/dist/services/harnessLintService.d.ts +49 -0
- package/packages/server/dist/services/harnessLintService.d.ts.map +1 -0
- package/packages/server/dist/services/harnessLintService.js +628 -0
- package/packages/server/dist/services/harnessLintService.js.map +1 -0
- package/packages/server/dist/services/harnessMcpService.d.ts +77 -0
- package/packages/server/dist/services/harnessMcpService.d.ts.map +1 -0
- package/packages/server/dist/services/harnessMcpService.js +814 -0
- package/packages/server/dist/services/harnessMcpService.js.map +1 -0
- package/packages/server/dist/services/harnessPluginService.d.ts +66 -0
- package/packages/server/dist/services/harnessPluginService.d.ts.map +1 -0
- package/packages/server/dist/services/harnessPluginService.js +559 -0
- package/packages/server/dist/services/harnessPluginService.js.map +1 -0
- package/packages/server/dist/services/harnessService.d.ts +40 -0
- package/packages/server/dist/services/harnessService.d.ts.map +1 -0
- package/packages/server/dist/services/harnessService.js +222 -0
- package/packages/server/dist/services/harnessService.js.map +1 -0
- package/packages/server/dist/services/harnessShareScopeService.d.ts +31 -0
- package/packages/server/dist/services/harnessShareScopeService.d.ts.map +1 -0
- package/packages/server/dist/services/harnessShareScopeService.js +93 -0
- package/packages/server/dist/services/harnessShareScopeService.js.map +1 -0
- package/packages/server/dist/services/harnessSkillService.d.ts +70 -0
- package/packages/server/dist/services/harnessSkillService.d.ts.map +1 -0
- package/packages/server/dist/services/harnessSkillService.js +636 -0
- package/packages/server/dist/services/harnessSkillService.js.map +1 -0
- package/packages/server/dist/services/issueService.d.ts.map +1 -1
- package/packages/server/dist/services/issueService.js +2 -1
- package/packages/server/dist/services/issueService.js.map +1 -1
- package/packages/server/dist/services/manualSyncService.d.ts +19 -0
- package/packages/server/dist/services/manualSyncService.d.ts.map +1 -0
- package/packages/server/dist/services/manualSyncService.js +110 -0
- package/packages/server/dist/services/manualSyncService.js.map +1 -0
- package/packages/server/dist/services/queueService.d.ts.map +1 -1
- package/packages/server/dist/services/queueService.js +45 -2
- package/packages/server/dist/services/queueService.js.map +1 -1
- package/packages/server/dist/services/snippetService.d.ts +54 -0
- package/packages/server/dist/services/snippetService.d.ts.map +1 -0
- package/packages/server/dist/services/snippetService.js +371 -0
- package/packages/server/dist/services/snippetService.js.map +1 -0
- package/packages/server/dist/services/utils/applyYamlFrontmatterPatch.d.ts +46 -0
- package/packages/server/dist/services/utils/applyYamlFrontmatterPatch.d.ts.map +1 -0
- package/packages/server/dist/services/utils/applyYamlFrontmatterPatch.js +125 -0
- package/packages/server/dist/services/utils/applyYamlFrontmatterPatch.js.map +1 -0
- package/packages/server/dist/snippets/split-commit +9 -0
- package/packages/server/dist/utils/applySecretsPolicy.d.ts +53 -0
- package/packages/server/dist/utils/applySecretsPolicy.d.ts.map +1 -0
- package/packages/server/dist/utils/applySecretsPolicy.js +204 -0
- package/packages/server/dist/utils/applySecretsPolicy.js.map +1 -0
- package/packages/server/dist/utils/assertNoSecretOnShared.d.ts +40 -0
- package/packages/server/dist/utils/assertNoSecretOnShared.d.ts.map +1 -0
- package/packages/server/dist/utils/assertNoSecretOnShared.js +47 -0
- package/packages/server/dist/utils/assertNoSecretOnShared.js.map +1 -0
- package/packages/server/dist/utils/gitignoreFilter.d.ts +23 -0
- package/packages/server/dist/utils/gitignoreFilter.d.ts.map +1 -0
- package/packages/server/dist/utils/gitignoreFilter.js +42 -0
- package/packages/server/dist/utils/gitignoreFilter.js.map +1 -0
- package/packages/server/dist/utils/harnessBundleSchema.d.ts +105 -0
- package/packages/server/dist/utils/harnessBundleSchema.d.ts.map +1 -0
- package/packages/server/dist/utils/harnessBundleSchema.js +79 -0
- package/packages/server/dist/utils/harnessBundleSchema.js.map +1 -0
- package/packages/server/dist/utils/harnessPaths.d.ts +34 -0
- package/packages/server/dist/utils/harnessPaths.d.ts.map +1 -0
- package/packages/server/dist/utils/harnessPaths.js +124 -0
- package/packages/server/dist/utils/harnessPaths.js.map +1 -0
- package/packages/server/dist/utils/secretHeuristic.d.ts +72 -0
- package/packages/server/dist/utils/secretHeuristic.d.ts.map +1 -0
- package/packages/server/dist/utils/secretHeuristic.js +163 -0
- package/packages/server/dist/utils/secretHeuristic.js.map +1 -0
- package/packages/server/dist/utils/secretPlaceholderNamer.d.ts +41 -0
- package/packages/server/dist/utils/secretPlaceholderNamer.d.ts.map +1 -0
- package/packages/server/dist/utils/secretPlaceholderNamer.js +81 -0
- package/packages/server/dist/utils/secretPlaceholderNamer.js.map +1 -0
- package/packages/server/dist/utils/serverPathResolver.d.ts +29 -0
- package/packages/server/dist/utils/serverPathResolver.d.ts.map +1 -0
- package/packages/server/dist/utils/serverPathResolver.js +59 -0
- package/packages/server/dist/utils/serverPathResolver.js.map +1 -0
- package/packages/server/dist/utils/snippetPaths.d.ts +61 -0
- package/packages/server/dist/utils/snippetPaths.d.ts.map +1 -0
- package/packages/server/dist/utils/snippetPaths.js +123 -0
- package/packages/server/dist/utils/snippetPaths.js.map +1 -0
- package/packages/server/dist/utils/structuredEditor.d.ts +34 -0
- package/packages/server/dist/utils/structuredEditor.d.ts.map +1 -0
- package/packages/server/dist/utils/structuredEditor.js +111 -0
- package/packages/server/dist/utils/structuredEditor.js.map +1 -0
- package/packages/server/package.json +4 -1
- package/packages/server/resources/internals/INDEX.md +23 -0
- package/packages/server/resources/internals/harness-files.md +63 -0
- package/packages/server/resources/internals/image-storage.md +43 -0
- package/packages/server/resources/manual/01-getting-started.md +104 -0
- package/packages/server/resources/manual/02-chat.md +285 -0
- package/packages/server/resources/manual/03-sessions.md +48 -0
- package/packages/server/resources/manual/04-slash-commands-favorites.md +152 -0
- package/packages/server/resources/manual/05-projects.md +74 -0
- package/packages/server/resources/manual/06-file-explorer-editor.md +90 -0
- package/packages/server/resources/manual/07-git.md +94 -0
- package/packages/server/resources/manual/08-terminal.md +59 -0
- package/packages/server/resources/manual/09-queue-runner.md +262 -0
- package/packages/server/resources/manual/10-project-board.md +193 -0
- package/packages/server/resources/manual/11-bmad-method-integration.md +128 -0
- package/packages/server/resources/manual/12-harness-workbench.md +175 -0
- package/packages/server/resources/manual/13-settings.md +241 -0
- package/packages/server/resources/manual/14-keyboard-shortcuts.md +68 -0
- package/packages/server/resources/manual/15-environment-variables.md +28 -0
- package/packages/server/resources/manual/16-troubleshooting.md +110 -0
- package/packages/server/resources/manual/INDEX.md +60 -0
- package/packages/shared/dist/index.d.ts +3 -0
- package/packages/shared/dist/index.d.ts.map +1 -1
- package/packages/shared/dist/index.js +6 -0
- package/packages/shared/dist/index.js.map +1 -1
- package/packages/shared/dist/types/command.d.ts +3 -3
- package/packages/shared/dist/types/command.d.ts.map +1 -1
- package/packages/shared/dist/types/harness.d.ts +1211 -0
- package/packages/shared/dist/types/harness.d.ts.map +1 -0
- package/packages/shared/dist/types/harness.js +107 -0
- package/packages/shared/dist/types/harness.js.map +1 -0
- package/packages/shared/dist/types/harnessBundle.d.ts +170 -0
- package/packages/shared/dist/types/harnessBundle.d.ts.map +1 -0
- package/packages/shared/dist/types/harnessBundle.js +18 -0
- package/packages/shared/dist/types/harnessBundle.js.map +1 -0
- package/packages/shared/dist/types/preferences.d.ts +2 -0
- package/packages/shared/dist/types/preferences.d.ts.map +1 -1
- package/packages/shared/dist/types/preferences.js.map +1 -1
- package/packages/shared/dist/types/queue.d.ts +9 -0
- package/packages/shared/dist/types/queue.d.ts.map +1 -1
- package/packages/shared/dist/types/websocket.d.ts +10 -0
- package/packages/shared/dist/types/websocket.d.ts.map +1 -1
- package/packages/shared/dist/utils/markdownSections.d.ts +50 -0
- package/packages/shared/dist/utils/markdownSections.d.ts.map +1 -0
- package/packages/shared/dist/utils/markdownSections.js +111 -0
- package/packages/shared/dist/utils/markdownSections.js.map +1 -0
- package/packages/shared/dist/utils/queueParser.d.ts.map +1 -1
- package/packages/shared/dist/utils/queueParser.js +104 -0
- package/packages/shared/dist/utils/queueParser.js.map +1 -1
- package/scripts/build-manual-shards.mjs +100 -0
- package/packages/client/dist/assets/index-6jREnVYd.js +0 -2
- package/packages/client/dist/assets/index-BFF0iqyW.css +0 -32
- package/packages/client/dist/assets/index-BcI4y-fU.js +0 -1454
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Story 29.2: Snippet path resolver.
|
|
3
|
+
*
|
|
4
|
+
* The snippet system has three scopes that map to different on-disk roots:
|
|
5
|
+
*
|
|
6
|
+
* - project → `<projectRoot>/.hammoc/snippets/`
|
|
7
|
+
* - user → `~/.hammoc/snippets/`
|
|
8
|
+
* - bundled → server-bundled snippets (read-only, located alongside the
|
|
9
|
+
* server build at `<serverDist>/snippets/`)
|
|
10
|
+
*
|
|
11
|
+
* `resolveSnippetPath` is the only path-shaping entry point used by
|
|
12
|
+
* `snippetService` — it accepts `{ scope, projectSlug?, name }` and never lets
|
|
13
|
+
* a caller-supplied relative path through. NAME_RE rejects anything outside
|
|
14
|
+
* `[A-Za-z0-9._-]+` so directory traversal (`..`, `/`, `\`, `\0`, drive
|
|
15
|
+
* letters, UNC prefixes) is impossible by construction.
|
|
16
|
+
*
|
|
17
|
+
* On-disk filename normalization: writes always land at `<root>/<name>.md`
|
|
18
|
+
* regardless of input form. Reads accept both `<name>.md` and the legacy
|
|
19
|
+
* extension-less `<name>` (snippetResolver supports both for back-compat) so
|
|
20
|
+
* existing bundled and user files continue to load.
|
|
21
|
+
*/
|
|
22
|
+
/** Snippet name regex — same shape as snippetResolver's NAME_RE. */
|
|
23
|
+
export declare const SNIPPET_NAME_RE: RegExp;
|
|
24
|
+
/** Return the absolute path of `~/.hammoc/snippets/`. */
|
|
25
|
+
export declare function getUserSnippetsDir(): string;
|
|
26
|
+
/** Return the absolute path of the server-bundled snippets directory. */
|
|
27
|
+
export declare function getBundledSnippetsDir(): string;
|
|
28
|
+
/** Return the absolute path of `<projectRoot>/.hammoc/snippets/`. */
|
|
29
|
+
export declare function getProjectSnippetsDir(projectSlug: string): Promise<string>;
|
|
30
|
+
export interface ResolvedSnippetPath {
|
|
31
|
+
/** Root directory (the snippets dir itself, not the project root). */
|
|
32
|
+
resolvedRoot: string;
|
|
33
|
+
/** `<resolvedRoot>/<name>.md`. */
|
|
34
|
+
absolutePath: string;
|
|
35
|
+
/** Same path but without `.md` — legacy format used for back-compat reads. */
|
|
36
|
+
legacyAbsolutePath: string;
|
|
37
|
+
/** True when this path is read-only (bundled). */
|
|
38
|
+
readOnly: boolean;
|
|
39
|
+
}
|
|
40
|
+
export type SnippetScope = 'project' | 'user' | 'bundled';
|
|
41
|
+
export interface SnippetPathRef {
|
|
42
|
+
scope: SnippetScope;
|
|
43
|
+
/** Required when scope === 'project'. */
|
|
44
|
+
projectSlug?: string;
|
|
45
|
+
name: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Resolve a snippet path with NAME_RE validation and bundled read-only flagging.
|
|
49
|
+
* Throws an Error with `code: 'HARNESS_PATH_DENIED'` for invalid names.
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveSnippetPath(ref: SnippetPathRef): Promise<ResolvedSnippetPath>;
|
|
52
|
+
/**
|
|
53
|
+
* Throws an HARNESS_PATH_DENIED Error when the name is invalid.
|
|
54
|
+
*
|
|
55
|
+
* Note: SNIPPET_NAME_RE allows `.` so single-dot names (`a.b`) pass through.
|
|
56
|
+
* That also means literal `..` would pass the regex — we reject it
|
|
57
|
+
* separately below, mirroring snippetResolver.resolveSnippet's defensive
|
|
58
|
+
* filter.
|
|
59
|
+
*/
|
|
60
|
+
export declare function validateSnippetName(name: string): void;
|
|
61
|
+
//# sourceMappingURL=snippetPaths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snippetPaths.d.ts","sourceRoot":"","sources":["../../src/utils/snippetPaths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAaH,oEAAoE;AACpE,eAAO,MAAM,eAAe,QAAsB,CAAC;AAOnD,yDAAyD;AACzD,wBAAgB,kBAAkB,IAAI,MAAM,CAM3C;AAED,yEAAyE;AACzE,wBAAgB,qBAAqB,IAAI,MAAM,CAM9C;AAED,qEAAqE;AACrE,wBAAsB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAchF;AAED,MAAM,WAAW,mBAAmB;IAClC,sEAAsE;IACtE,YAAY,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,8EAA8E;IAC9E,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kDAAkD;IAClD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;AAE1D,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,YAAY,CAAC;IACpB,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA4B1F;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAatD"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Story 29.2: Snippet path resolver.
|
|
3
|
+
*
|
|
4
|
+
* The snippet system has three scopes that map to different on-disk roots:
|
|
5
|
+
*
|
|
6
|
+
* - project → `<projectRoot>/.hammoc/snippets/`
|
|
7
|
+
* - user → `~/.hammoc/snippets/`
|
|
8
|
+
* - bundled → server-bundled snippets (read-only, located alongside the
|
|
9
|
+
* server build at `<serverDist>/snippets/`)
|
|
10
|
+
*
|
|
11
|
+
* `resolveSnippetPath` is the only path-shaping entry point used by
|
|
12
|
+
* `snippetService` — it accepts `{ scope, projectSlug?, name }` and never lets
|
|
13
|
+
* a caller-supplied relative path through. NAME_RE rejects anything outside
|
|
14
|
+
* `[A-Za-z0-9._-]+` so directory traversal (`..`, `/`, `\`, `\0`, drive
|
|
15
|
+
* letters, UNC prefixes) is impossible by construction.
|
|
16
|
+
*
|
|
17
|
+
* On-disk filename normalization: writes always land at `<root>/<name>.md`
|
|
18
|
+
* regardless of input form. Reads accept both `<name>.md` and the legacy
|
|
19
|
+
* extension-less `<name>` (snippetResolver supports both for back-compat) so
|
|
20
|
+
* existing bundled and user files continue to load.
|
|
21
|
+
*/
|
|
22
|
+
import os from 'os';
|
|
23
|
+
import path from 'path';
|
|
24
|
+
import { fileURLToPath } from 'node:url';
|
|
25
|
+
import { projectService } from '../services/projectService.js';
|
|
26
|
+
/** Hammoc home root override for tests. Mirrors `HAMMOC_HARNESS_HOME_OVERRIDE`. */
|
|
27
|
+
const HOME_OVERRIDE_ENV = 'HAMMOC_HOME_OVERRIDE';
|
|
28
|
+
/** Bundled snippet directory override for tests (e.g. point at a tmp dir). */
|
|
29
|
+
const BUNDLED_OVERRIDE_ENV = 'HAMMOC_BUNDLED_SNIPPETS_DIR';
|
|
30
|
+
/** Snippet name regex — same shape as snippetResolver's NAME_RE. */
|
|
31
|
+
export const SNIPPET_NAME_RE = /^[a-zA-Z0-9._-]+$/;
|
|
32
|
+
const SNIPPETS_SUBDIR = '.hammoc/snippets';
|
|
33
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
34
|
+
const DEFAULT_BUNDLED_DIR = path.resolve(__dirname, '..', 'snippets');
|
|
35
|
+
/** Return the absolute path of `~/.hammoc/snippets/`. */
|
|
36
|
+
export function getUserSnippetsDir() {
|
|
37
|
+
const override = process.env[HOME_OVERRIDE_ENV];
|
|
38
|
+
if (override && override.length > 0) {
|
|
39
|
+
return path.join(override, '.hammoc', 'snippets');
|
|
40
|
+
}
|
|
41
|
+
return path.join(os.homedir(), '.hammoc', 'snippets');
|
|
42
|
+
}
|
|
43
|
+
/** Return the absolute path of the server-bundled snippets directory. */
|
|
44
|
+
export function getBundledSnippetsDir() {
|
|
45
|
+
const override = process.env[BUNDLED_OVERRIDE_ENV];
|
|
46
|
+
if (override && override.length > 0) {
|
|
47
|
+
return override;
|
|
48
|
+
}
|
|
49
|
+
return DEFAULT_BUNDLED_DIR;
|
|
50
|
+
}
|
|
51
|
+
/** Return the absolute path of `<projectRoot>/.hammoc/snippets/`. */
|
|
52
|
+
export async function getProjectSnippetsDir(projectSlug) {
|
|
53
|
+
if (!projectSlug) {
|
|
54
|
+
throw makePathDeniedError('projectSlug is required for project scope');
|
|
55
|
+
}
|
|
56
|
+
if (projectSlug.includes('\0') ||
|
|
57
|
+
projectSlug.includes('..') ||
|
|
58
|
+
projectSlug.includes('/') ||
|
|
59
|
+
projectSlug.includes('\\')) {
|
|
60
|
+
throw makePathDeniedError('projectSlug must not contain path separators');
|
|
61
|
+
}
|
|
62
|
+
const projectRoot = await projectService.resolveOriginalPath(projectSlug);
|
|
63
|
+
return path.join(projectRoot, SNIPPETS_SUBDIR);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Resolve a snippet path with NAME_RE validation and bundled read-only flagging.
|
|
67
|
+
* Throws an Error with `code: 'HARNESS_PATH_DENIED'` for invalid names.
|
|
68
|
+
*/
|
|
69
|
+
export async function resolveSnippetPath(ref) {
|
|
70
|
+
validateSnippetName(ref.name);
|
|
71
|
+
let resolvedRoot;
|
|
72
|
+
let readOnly = false;
|
|
73
|
+
if (ref.scope === 'project') {
|
|
74
|
+
if (!ref.projectSlug) {
|
|
75
|
+
throw makePathDeniedError('projectSlug is required for project scope');
|
|
76
|
+
}
|
|
77
|
+
resolvedRoot = path.resolve(await getProjectSnippetsDir(ref.projectSlug));
|
|
78
|
+
}
|
|
79
|
+
else if (ref.scope === 'user') {
|
|
80
|
+
resolvedRoot = path.resolve(getUserSnippetsDir());
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
resolvedRoot = path.resolve(getBundledSnippetsDir());
|
|
84
|
+
readOnly = true;
|
|
85
|
+
}
|
|
86
|
+
// Belt + suspenders: even though NAME_RE forbids separators, double-check
|
|
87
|
+
// the resolved file stays inside the root.
|
|
88
|
+
const absolutePath = path.resolve(resolvedRoot, `${ref.name}.md`);
|
|
89
|
+
if (absolutePath !== resolvedRoot &&
|
|
90
|
+
!absolutePath.startsWith(resolvedRoot + path.sep)) {
|
|
91
|
+
throw makePathDeniedError('snippet path escapes root');
|
|
92
|
+
}
|
|
93
|
+
const legacyAbsolutePath = path.resolve(resolvedRoot, ref.name);
|
|
94
|
+
return { resolvedRoot, absolutePath, legacyAbsolutePath, readOnly };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Throws an HARNESS_PATH_DENIED Error when the name is invalid.
|
|
98
|
+
*
|
|
99
|
+
* Note: SNIPPET_NAME_RE allows `.` so single-dot names (`a.b`) pass through.
|
|
100
|
+
* That also means literal `..` would pass the regex — we reject it
|
|
101
|
+
* separately below, mirroring snippetResolver.resolveSnippet's defensive
|
|
102
|
+
* filter.
|
|
103
|
+
*/
|
|
104
|
+
export function validateSnippetName(name) {
|
|
105
|
+
if (!name || typeof name !== 'string') {
|
|
106
|
+
throw makePathDeniedError('snippet name is required');
|
|
107
|
+
}
|
|
108
|
+
if (name.includes('\0')) {
|
|
109
|
+
throw makePathDeniedError('null byte in snippet name');
|
|
110
|
+
}
|
|
111
|
+
if (name === '..' || name === '.' || name.includes('/') || name.includes('\\')) {
|
|
112
|
+
throw makePathDeniedError(`path traversal denied: ${name}`);
|
|
113
|
+
}
|
|
114
|
+
if (!SNIPPET_NAME_RE.test(name)) {
|
|
115
|
+
throw makePathDeniedError(`invalid snippet name: ${name}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function makePathDeniedError(message) {
|
|
119
|
+
const err = new Error(message);
|
|
120
|
+
err.code = 'HARNESS_PATH_DENIED';
|
|
121
|
+
return err;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=snippetPaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snippetPaths.js","sourceRoot":"","sources":["../../src/utils/snippetPaths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,mFAAmF;AACnF,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AAEjD,8EAA8E;AAC9E,MAAM,oBAAoB,GAAG,6BAA6B,CAAC;AAE3D,oEAAoE;AACpE,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAEnD,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAE3C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/D,MAAM,mBAAmB,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;AAEtE,yDAAyD;AACzD,MAAM,UAAU,kBAAkB;IAChC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAChD,IAAI,QAAQ,IAAI,QAAQ,CAAC,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AAI,CAAC,EAAE,CAAC;QACxB,MAAM,mBAAmB,CAAC,2BAA2B,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/E,MAAM,mBAAmB,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,mBAAmB,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAe;IAC1C,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,OAAO,CAA0B,CAAC;IACxD,GAAG,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Story 28.0.5: YAML / JSONC round-trip editor.
|
|
3
|
+
*
|
|
4
|
+
* The goal is to mutate a single key inside a structured config file while
|
|
5
|
+
* preserving the author's comments, blank lines, key order, and quoting style.
|
|
6
|
+
*
|
|
7
|
+
* - YAML → `yaml` (eemeli) `parseDocument` + `doc.setIn/deleteIn` + `doc.toString()`.
|
|
8
|
+
* The Document AST keeps comment & blank-line metadata attached to
|
|
9
|
+
* each node, and `toString()` re-emits them.
|
|
10
|
+
* NOTE: `js-yaml@4` remains a coexisting dependency for session-meta parsing
|
|
11
|
+
* elsewhere in the codebase, but has no comment-preservation path and must
|
|
12
|
+
* not be used for harness edits.
|
|
13
|
+
*
|
|
14
|
+
* - JSONC → `jsonc-parser` `modify` + `applyEdits`. This is the same path VS
|
|
15
|
+
* Code uses when it edits user `settings.json` — comments and
|
|
16
|
+
* formatting are preserved.
|
|
17
|
+
*
|
|
18
|
+
* Both entry points throw `HARNESS_PARSE_ERROR` on unparseable input so the
|
|
19
|
+
* harness controller can surface the envelope and the client can fall back to
|
|
20
|
+
* raw editing.
|
|
21
|
+
*/
|
|
22
|
+
import { type HarnessStructuredPatchOp } from '@hammoc/shared';
|
|
23
|
+
/**
|
|
24
|
+
* Apply structured patches to a YAML source string while preserving comments,
|
|
25
|
+
* blank lines, and key order.
|
|
26
|
+
*/
|
|
27
|
+
export declare function applyYamlPatch(source: string, ops: HarnessStructuredPatchOp[]): string;
|
|
28
|
+
/**
|
|
29
|
+
* Apply structured patches to a JSONC source string while preserving comments
|
|
30
|
+
* and formatting. Inserts missing intermediate objects as needed (matches
|
|
31
|
+
* `jsonc-parser` `modify` default behavior).
|
|
32
|
+
*/
|
|
33
|
+
export declare function applyJsoncPatch(source: string, ops: HarnessStructuredPatchOp[]): string;
|
|
34
|
+
//# sourceMappingURL=structuredEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structuredEditor.d.ts","sourceRoot":"","sources":["../../src/utils/structuredEditor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAaH,OAAO,EAAkB,KAAK,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAQ/E;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,wBAAwB,EAAE,GAAG,MAAM,CAmCtF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,wBAAwB,EAAE,GAAG,MAAM,CAqCvF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Story 28.0.5: YAML / JSONC round-trip editor.
|
|
3
|
+
*
|
|
4
|
+
* The goal is to mutate a single key inside a structured config file while
|
|
5
|
+
* preserving the author's comments, blank lines, key order, and quoting style.
|
|
6
|
+
*
|
|
7
|
+
* - YAML → `yaml` (eemeli) `parseDocument` + `doc.setIn/deleteIn` + `doc.toString()`.
|
|
8
|
+
* The Document AST keeps comment & blank-line metadata attached to
|
|
9
|
+
* each node, and `toString()` re-emits them.
|
|
10
|
+
* NOTE: `js-yaml@4` remains a coexisting dependency for session-meta parsing
|
|
11
|
+
* elsewhere in the codebase, but has no comment-preservation path and must
|
|
12
|
+
* not be used for harness edits.
|
|
13
|
+
*
|
|
14
|
+
* - JSONC → `jsonc-parser` `modify` + `applyEdits`. This is the same path VS
|
|
15
|
+
* Code uses when it edits user `settings.json` — comments and
|
|
16
|
+
* formatting are preserved.
|
|
17
|
+
*
|
|
18
|
+
* Both entry points throw `HARNESS_PARSE_ERROR` on unparseable input so the
|
|
19
|
+
* harness controller can surface the envelope and the client can fall back to
|
|
20
|
+
* raw editing.
|
|
21
|
+
*/
|
|
22
|
+
import { parseDocument } from 'yaml';
|
|
23
|
+
import { modify, applyEdits, parse, parseTree, findNodeAtLocation, printParseErrorCode, } from 'jsonc-parser';
|
|
24
|
+
import { HARNESS_ERRORS } from '@hammoc/shared';
|
|
25
|
+
function parseError(format, cause) {
|
|
26
|
+
const err = new Error(`failed to parse ${format}: ${cause?.message ?? String(cause)}`);
|
|
27
|
+
err.code = HARNESS_ERRORS.HARNESS_PARSE_ERROR.code;
|
|
28
|
+
return err;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Apply structured patches to a YAML source string while preserving comments,
|
|
32
|
+
* blank lines, and key order.
|
|
33
|
+
*/
|
|
34
|
+
export function applyYamlPatch(source, ops) {
|
|
35
|
+
let doc;
|
|
36
|
+
try {
|
|
37
|
+
doc = parseDocument(source, { keepSourceTokens: true });
|
|
38
|
+
if (doc.errors.length > 0) {
|
|
39
|
+
throw doc.errors[0];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (cause) {
|
|
43
|
+
throw parseError('yaml', cause);
|
|
44
|
+
}
|
|
45
|
+
// A freshly-created empty document has `contents: null`; we need a map so
|
|
46
|
+
// setIn can plant new keys at the top level.
|
|
47
|
+
if (doc.contents == null) {
|
|
48
|
+
doc.contents = doc.createNode({});
|
|
49
|
+
}
|
|
50
|
+
for (const op of ops) {
|
|
51
|
+
if (!op.path || op.path.length === 0) {
|
|
52
|
+
throw parseError('yaml', new Error('patch op requires a non-empty path'));
|
|
53
|
+
}
|
|
54
|
+
if (op.value === undefined) {
|
|
55
|
+
// Idempotent delete: if any segment (including intermediates) is already
|
|
56
|
+
// absent, the target is effectively deleted — skip. `doc.deleteIn`
|
|
57
|
+
// itself only no-ops on a missing leaf; a missing intermediate throws.
|
|
58
|
+
if (!doc.hasIn(op.path))
|
|
59
|
+
continue;
|
|
60
|
+
doc.deleteIn(op.path);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
doc.setIn(op.path, op.value);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// toString() preserves original comments/blank lines/quote style for any
|
|
67
|
+
// node that was not explicitly replaced.
|
|
68
|
+
return doc.toString();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Apply structured patches to a JSONC source string while preserving comments
|
|
72
|
+
* and formatting. Inserts missing intermediate objects as needed (matches
|
|
73
|
+
* `jsonc-parser` `modify` default behavior).
|
|
74
|
+
*/
|
|
75
|
+
export function applyJsoncPatch(source, ops) {
|
|
76
|
+
// Validate the source up front — `modify` silently starts from `{}` on
|
|
77
|
+
// garbage input, which would quietly erase the user's file. Feed the
|
|
78
|
+
// official errors array to catch unterminated strings, missing values, etc.
|
|
79
|
+
if (source.trim().length > 0) {
|
|
80
|
+
const errors = [];
|
|
81
|
+
parse(source, errors, { allowTrailingComma: true, disallowComments: false });
|
|
82
|
+
if (errors.length > 0) {
|
|
83
|
+
const first = errors[0];
|
|
84
|
+
throw parseError('jsonc', new Error(`${printParseErrorCode(first.error)} at offset ${first.offset}`));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const formattingOptions = {
|
|
88
|
+
insertSpaces: true,
|
|
89
|
+
tabSize: 2,
|
|
90
|
+
eol: source.includes('\r\n') ? '\r\n' : '\n',
|
|
91
|
+
};
|
|
92
|
+
let current = source;
|
|
93
|
+
for (const op of ops) {
|
|
94
|
+
if (!op.path || op.path.length === 0) {
|
|
95
|
+
throw parseError('jsonc', new Error('patch op requires a non-empty path'));
|
|
96
|
+
}
|
|
97
|
+
// Idempotent delete: `modify(undefined)` throws "Can not delete…" when the
|
|
98
|
+
// target (or any intermediate) does not exist; treat that as a no-op so
|
|
99
|
+
// callers can apply delete patches without first probing state.
|
|
100
|
+
if (op.value === undefined) {
|
|
101
|
+
const tree = parseTree(current, [], { allowTrailingComma: true, disallowComments: false });
|
|
102
|
+
if (!tree || !findNodeAtLocation(tree, op.path))
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
// `modify` takes `undefined` to mean "remove", matching HarnessStructuredPatchOp.value semantics.
|
|
106
|
+
const edits = modify(current, op.path, op.value, { formattingOptions });
|
|
107
|
+
current = applyEdits(current, edits);
|
|
108
|
+
}
|
|
109
|
+
return current;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=structuredEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structuredEditor.js","sourceRoot":"","sources":["../../src/utils/structuredEditor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAiB,MAAM,MAAM,CAAC;AACpD,OAAO,EACL,MAAM,EACN,UAAU,EACV,KAAK,EACL,SAAS,EACT,kBAAkB,EAClB,mBAAmB,GAGpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAiC,MAAM,gBAAgB,CAAC;AAE/E,SAAS,UAAU,CAAC,MAAwB,EAAE,KAAc;IAC1D,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,mBAAmB,MAAM,KAAM,KAAe,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,E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C,CAAC,CAAC;QAC7E,CAAC;QACD,2EAA2E;QAC3E,wEAAwE;QACxE,gEAAgE;QAChE,IAAI,EAAE,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,CAAC;YAC3F,IAAI,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;gBAAE,SAAS;QAC5D,CAAC;QACD,kGAAkG;QAClG,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,iBAAiB,EAAE,CAAC,CAAC;QACxE,OAAO,GAAG,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -22,16 +22,19 @@
|
|
|
22
22
|
"cookie-session": "^2.1.1",
|
|
23
23
|
"cors": "^2.8.5",
|
|
24
24
|
"express": "^4.21.0",
|
|
25
|
-
"express-rate-limit": "^8.3.1",
|
|
26
25
|
"helmet": "^8.1.0",
|
|
27
26
|
"i18next": "^24.2.3",
|
|
27
|
+
"ignore": "^5.3.2",
|
|
28
28
|
"js-yaml": "^4.1.1",
|
|
29
|
+
"jsonc-parser": "^3.3.1",
|
|
30
|
+
"jszip": "^3.10.1",
|
|
29
31
|
"multer": "^2.1.1",
|
|
30
32
|
"node-pty": "^1.0.0",
|
|
31
33
|
"sharp": "^0.34.5",
|
|
32
34
|
"simple-git": "^3.27.0",
|
|
33
35
|
"socket.io": "^4.8.0",
|
|
34
36
|
"web-push": "^3.6.7",
|
|
37
|
+
"yaml": "^2.8.3",
|
|
35
38
|
"zod": "^4.3.6"
|
|
36
39
|
},
|
|
37
40
|
"devDependencies": {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Hammoc Internals (Agent-Only Reference)
|
|
2
|
+
|
|
3
|
+
This folder documents Hammoc's internal mechanisms that an in-IDE agent may need to read or correlate, but that are deliberately omitted from the user-facing manual. The user does not need to know any of this; the agent does.
|
|
4
|
+
|
|
5
|
+
## How to use
|
|
6
|
+
|
|
7
|
+
Read individual entries **on demand** when the user's request involves the underlying mechanism (for example: correlating an attached image with a file on disk, understanding how a session ID maps to a JSONL file). Do not pre-load this folder.
|
|
8
|
+
|
|
9
|
+
## Entries
|
|
10
|
+
|
|
11
|
+
- [Image Storage](./image-storage.md) — On-disk path and filename scheme for chat-attached images
|
|
12
|
+
- [Harness File Layout](./harness-files.md) — Where `.claude/` items (skills, commands, agents, hooks, MCP servers, `CLAUDE.md`) live on disk, when changes take effect, and how the Secret-on-Shared guard relates to direct file writes
|
|
13
|
+
|
|
14
|
+
## Maintenance
|
|
15
|
+
|
|
16
|
+
Add a new file here whenever there is internal behavior the agent needs to act on but the user does not need to see. Likely future entries:
|
|
17
|
+
|
|
18
|
+
- Session ID and project-path slug encoding under `~/.claude/projects/`
|
|
19
|
+
- JSONL message tree structure (parent/child UUIDs, branching)
|
|
20
|
+
- Permission-mode internal effects on the SDK call
|
|
21
|
+
- Snippet resolution order and substitution rules
|
|
22
|
+
|
|
23
|
+
Each new file should describe the on-disk reality (paths, formats, lifecycle), not the user-facing UI behavior — that belongs in the user manual.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Harness File Layout
|
|
2
|
+
|
|
3
|
+
The Harness Workbench (user-facing, see manual §12) edits Claude Code's `.claude/` configuration trees in place. An agent can reach the same files directly with Read / Write / Edit and skip the UI when that's faster.
|
|
4
|
+
|
|
5
|
+
## On-disk roots
|
|
6
|
+
|
|
7
|
+
Two trees, walked in this priority order:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
<projectRoot>/.claude/ # project scope (highest)
|
|
11
|
+
<homeDir>/.claude/ # global scope (user scope)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
When the same name (skill, command, agent, hook, MCP server, snippet) exists in both, the project copy is **active** and the global copy is **shadowed** but kept on disk.
|
|
15
|
+
|
|
16
|
+
`<homeDir>` must be resolved before use — Read / Write / Edit do not expand `~`. On Windows that is `C:\Users\<user>\`.
|
|
17
|
+
|
|
18
|
+
## Per-item layout
|
|
19
|
+
|
|
20
|
+
| Item | Path (under either `.claude/` root) | Format |
|
|
21
|
+
|------|--------------------------------------|--------|
|
|
22
|
+
| Skill | `skills/<name>/SKILL.md` + bundle assets in the same directory | Markdown body + YAML frontmatter (`name`, `description`, `version`) |
|
|
23
|
+
| Slash command | `commands/<name>.md` | Markdown body + YAML frontmatter |
|
|
24
|
+
| Sub-agent | `agents/<name>.md` | Markdown body + YAML frontmatter (`name`, `description`, `tools`) |
|
|
25
|
+
| Hook | `settings.json` → `hooks.<EventName>[]` entries | JSON; one event name per array key (`PreToolUse`, `PostToolUse`, `Stop`, `SubagentStop`, `SessionStart`, `SessionEnd`, `UserPromptSubmit`, `PreCompact`, `Notification`) |
|
|
26
|
+
| MCP server | `.mcp.json` at the project root, or `<homeDir>/.claude/.mcp.json` | JSON; entries under `mcpServers.<name>` |
|
|
27
|
+
| `CLAUDE.md` | `<projectRoot>/.claude/CLAUDE.md`, `<homeDir>/.claude/CLAUDE.md` | Plain Markdown; both files load into every session, project wins on conflict |
|
|
28
|
+
| Plugin | `plugins/<vendor>__<name>/` | Plugin bundle directory; treated read-only by Hammoc — copy items out to project/global to customize |
|
|
29
|
+
|
|
30
|
+
Hammoc-native `%snippets` are a separate layer (see manual §4.6); they live under `<projectRoot>/.hammoc/snippets/` and `<homeDir>/.hammoc/snippets/`, **not** the `.claude/` tree.
|
|
31
|
+
|
|
32
|
+
## Sharing scope
|
|
33
|
+
|
|
34
|
+
Each file's "share" status is computed from the project's `.gitignore`:
|
|
35
|
+
|
|
36
|
+
- **Shared** — File path is tracked by git
|
|
37
|
+
- **Local** — File path is untracked but `.claude/` is not ignored
|
|
38
|
+
- **Ignored** — A `.gitignore` rule excludes `.claude/` (or an ancestor)
|
|
39
|
+
|
|
40
|
+
The workbench shows a badge for each file. When an agent writes a file under `.claude/`, the resulting share scope is whatever the `.gitignore` already says — Hammoc does not rewrite `.gitignore` on the agent's behalf.
|
|
41
|
+
|
|
42
|
+
## Secret-on-Shared guard
|
|
43
|
+
|
|
44
|
+
When the user saves a `Shared`-scope file through the UI, Hammoc scans for plaintext secrets (entropy + pattern heuristic) and blocks the save with a dialog. **An agent writing the file directly via Write / Edit bypasses that dialog.** If the agent is editing a `Shared` file under `.claude/`, it must avoid committing plaintext API keys, bearer tokens, etc. Use a sibling `*.local.<ext>` file (gitignored) and reference it from the shared file, or use `${ENV_VAR}` references that the hook / MCP runtime expands.
|
|
45
|
+
|
|
46
|
+
## When changes take effect
|
|
47
|
+
|
|
48
|
+
- **Skills, commands, agents, CLAUDE.md, snippets** — Picked up on the next message in a chat turn (the system prompt and tool list re-resolve on each turn).
|
|
49
|
+
- **Hooks** — Same: next message in a chat turn.
|
|
50
|
+
- **MCP servers** — Picked up only on a **fresh session spawn**, not mid-session. The workbench UI shows a "Takes effect on your next user message" banner with a "Start new session" button after the user edits an MCP entry; an agent making MCP edits should remind the user to start a new session, or do so on their behalf.
|
|
51
|
+
- **Plugin enable/disable** — Same as MCP: fresh spawn required.
|
|
52
|
+
|
|
53
|
+
## Static lint (informational)
|
|
54
|
+
|
|
55
|
+
The workbench runs seven static-lint rules over the trees (see manual §12.12). Agents writing harness files should keep these rules in mind even though writes are not blocked:
|
|
56
|
+
|
|
57
|
+
- duplicate names across scopes
|
|
58
|
+
- invalid hook matcher regex
|
|
59
|
+
- frontmatter / JSON parse errors
|
|
60
|
+
- MCP `stdio` command not on `PATH`
|
|
61
|
+
- malformed MCP URLs
|
|
62
|
+
- non-standard agent tool names
|
|
63
|
+
- hook bodies referencing undefined env vars
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Image Storage
|
|
2
|
+
|
|
3
|
+
When the user attaches an image to a chat message, Hammoc saves it under **Claude Code's per-project session data**, not inside the project being worked on. The user does not see this — they just attach and send. This document is for an agent that needs to read or correlate the file directly.
|
|
4
|
+
|
|
5
|
+
## On-disk location
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
<homeDir>/.claude/projects/<encoded-project-path>/images/<sessionId>/<filename>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- `<homeDir>` — User home directory (Read/Edit tools do not expand `~`, so resolve to the absolute path first).
|
|
12
|
+
- `<encoded-project-path>` — Claude Code's project slug. Path separators (`/`, `\`) and colons (`:`) in the original project path are replaced with hyphens. Example: `D:\repo\hammoc` → `D--repo-hammoc`.
|
|
13
|
+
- `<sessionId>` — UUID of the chat session containing the message.
|
|
14
|
+
- `<filename>` — `<sha256-prefix-16chars>.<ext>` for the original. Thumbnails use `<sha256-prefix-16chars>_thumb.<ext>`.
|
|
15
|
+
- `<ext>` — One of `.png`, `.jpg`, `.gif`, `.webp`.
|
|
16
|
+
|
|
17
|
+
## Supported MIME types
|
|
18
|
+
|
|
19
|
+
| MIME | Extension |
|
|
20
|
+
|---|---|
|
|
21
|
+
| image/png | .png |
|
|
22
|
+
| image/jpeg | .jpg |
|
|
23
|
+
| image/gif | .gif |
|
|
24
|
+
| image/webp | .webp |
|
|
25
|
+
|
|
26
|
+
Anything else is rejected at attach time.
|
|
27
|
+
|
|
28
|
+
## How an agent reaches these files
|
|
29
|
+
|
|
30
|
+
- The chat message references each image via the API URL `/api/projects/<projectSlug>/sessions/<sessionId>/images/<filename>`. That URL is for the **browser** to render thumbnails — it is not a file-system path and Read tools cannot use it directly.
|
|
31
|
+
- To open the file from disk, build the absolute path under `<homeDir>/.claude/projects/...` using the rules above, then call Read with that path.
|
|
32
|
+
|
|
33
|
+
## Lifecycle
|
|
34
|
+
|
|
35
|
+
- Images are written the moment the user sends a message with attachments.
|
|
36
|
+
- A session's `images/<sessionId>/` directory is removed when the session itself is deleted.
|
|
37
|
+
- Filenames are content-addressed (sha256 prefix), so attaching the same image bytes twice within a session reuses the same filename — automatic deduplication.
|
|
38
|
+
|
|
39
|
+
## Limits
|
|
40
|
+
|
|
41
|
+
- 5 images per message
|
|
42
|
+
- 10 MB per image
|
|
43
|
+
- Total per-session storage is bounded only by disk; there is no automatic eviction other than session deletion.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
## 1. Getting Started
|
|
2
|
+
|
|
3
|
+
### 1.1 Installation
|
|
4
|
+
|
|
5
|
+
**Option A: Run with npx (no install)**
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx hammoc
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**Option B: Global install**
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install -g hammoc
|
|
15
|
+
hammoc
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Option C: From source (development)**
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
git clone https://github.com/starsh2001/hammoc.git
|
|
22
|
+
cd hammoc
|
|
23
|
+
npm install
|
|
24
|
+
npm run dev
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 1.2 System Requirements
|
|
28
|
+
|
|
29
|
+
- **Node.js** >= 18.0.0 (v22 LTS recommended)
|
|
30
|
+
- **Claude Code CLI** installed and authenticated
|
|
31
|
+
- Modern browser (Chrome, Firefox, Safari, Edge)
|
|
32
|
+
|
|
33
|
+
### 1.3 First Launch
|
|
34
|
+
|
|
35
|
+
1. Open http://localhost:3000 in your browser
|
|
36
|
+
2. **Password Setup**: Set an admin password on first visit. This protects your instance from unauthorized access.
|
|
37
|
+
3. **Login**: Enter your password to sign in. **"Stay signed in"** keeps you logged in for 30 days (checked by default). After too many failed attempts, login is temporarily locked with a countdown timer.
|
|
38
|
+
4. **CLI Verification**: The onboarding wizard checks that Claude Code CLI is installed and authenticated. Follow the prompts if any step fails.
|
|
39
|
+
5. **Project Selection**: Choose an existing Claude Code project or create a new one.
|
|
40
|
+
|
|
41
|
+
### 1.4 Mobile Access
|
|
42
|
+
|
|
43
|
+
Hammoc is fully responsive. From any device on the same network:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
http://<your-computer-ip>:3000
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- Desktop: Enter sends message, Shift+Enter for new line
|
|
50
|
+
- Mobile (touch devices): Enter adds new line, tap the send button to send
|
|
51
|
+
- **Pull-to-refresh**: Swipe down on the session list to refresh
|
|
52
|
+
|
|
53
|
+
### 1.5 CLI Options
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
hammoc --port 8080 # Custom port
|
|
57
|
+
hammoc --host localhost # Bind to localhost only
|
|
58
|
+
hammoc --trust-proxy # Enable reverse proxy support
|
|
59
|
+
hammoc --cors-origin <url> # Restrict CORS to specific origin
|
|
60
|
+
hammoc --reset-password # Reset admin password
|
|
61
|
+
hammoc --version # Show version
|
|
62
|
+
hammoc --help # Show help
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
All options are also available as environment variables (see [Environment Variables](#14-environment-variables)).
|
|
66
|
+
|
|
67
|
+
### 1.6 Remote Access (Reverse Proxy)
|
|
68
|
+
|
|
69
|
+
If you need to expose Hammoc through a reverse proxy (Cloudflare Tunnel, nginx, etc.), use `--trust-proxy` and `--cors-origin`:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npx hammoc --trust-proxy --cors-origin https://hammoc.yourdomain.com
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**What `--trust-proxy` enables:**
|
|
76
|
+
- Reads real client IP from proxy headers for access control (e.g. localhost-only endpoints)
|
|
77
|
+
- Sets session cookies with `Secure` flag (HTTPS-only)
|
|
78
|
+
|
|
79
|
+
**What `--cors-origin` does:**
|
|
80
|
+
- Restricts cross-origin requests to the specified URL only
|
|
81
|
+
- Without it, any website can make authenticated requests to your Hammoc instance
|
|
82
|
+
|
|
83
|
+
**Security features (always active, no configuration needed):**
|
|
84
|
+
- Security headers (CSP, X-Frame-Options, HSTS, etc.)
|
|
85
|
+
- Server management APIs (restart, update) restricted to localhost only
|
|
86
|
+
- Terminal access restricted to local network IPs
|
|
87
|
+
- Login brute-force protection (5 failed attempts → 30s lockout per IP)
|
|
88
|
+
|
|
89
|
+
> **Note:** Hammoc does not apply request-level rate limiting itself — traffic shaping is an infrastructure concern. Configure it at your reverse proxy / WAF / API gateway (nginx `limit_req`, Cloudflare WAF rules, etc.).
|
|
90
|
+
|
|
91
|
+
### 1.7 HTTPS / TLS
|
|
92
|
+
|
|
93
|
+
Hammoc automatically enables HTTPS when TLS certificates are found:
|
|
94
|
+
|
|
95
|
+
1. Place your certificate files in the `~/.hammoc/` directory:
|
|
96
|
+
- `~/.hammoc/key.pem` — Private key
|
|
97
|
+
- `~/.hammoc/cert.pem` — Certificate (or full chain)
|
|
98
|
+
2. Restart Hammoc — it will detect the files and start an HTTPS server
|
|
99
|
+
3. The startup log will show `TLS: enabled (certs from ~/.hammoc/)`
|
|
100
|
+
|
|
101
|
+
If no certificates are found, the server runs over HTTP as usual.
|
|
102
|
+
|
|
103
|
+
> **Tip:** For local development, you can generate self-signed certificates with `mkcert` or `openssl`. For production, use certificates from Let's Encrypt or your domain provider.
|
|
104
|
+
|