@sanqianx/project-knowledge 4.6.1 → 4.8.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/.agents/plugins/marketplace.json +17 -17
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +817 -780
- package/README.md +48 -36
- package/_modules/knowledge-engine/README.md +88 -0
- package/_modules/knowledge-engine/package.json +38 -0
- package/_modules/knowledge-engine/src/analysis-contract.js +25 -0
- package/_modules/knowledge-engine/src/analysis-worker.js +54 -0
- package/_modules/knowledge-engine/src/bin.js +52 -0
- package/_modules/knowledge-engine/src/bridge-client.js +24 -0
- package/_modules/knowledge-engine/src/coordinator.js +255 -0
- package/_modules/knowledge-engine/src/headless-analyzer.js +75 -0
- package/_modules/knowledge-engine/src/memories.js +85 -0
- package/_modules/knowledge-engine/src/migration.js +88 -0
- package/_modules/knowledge-engine/src/retrieval.js +116 -0
- package/_modules/knowledge-engine/src/runtime/README.md +7 -0
- package/_modules/knowledge-engine/src/runtime/atomic-file.js +204 -0
- package/_modules/knowledge-engine/src/runtime/automation-config.js +140 -0
- package/_modules/knowledge-engine/src/runtime/commit-conversation-binder.js +249 -0
- package/_modules/knowledge-engine/src/runtime/commit-processing-ledger.js +26 -0
- package/_modules/knowledge-engine/src/runtime/commit-prompt.js +202 -0
- package/_modules/knowledge-engine/src/runtime/commit-reconciler.js +432 -0
- package/_modules/knowledge-engine/src/runtime/content-hash.js +4 -0
- package/_modules/knowledge-engine/src/runtime/contracts.js +279 -0
- package/_modules/knowledge-engine/src/runtime/conversation-exclusions.js +204 -0
- package/_modules/knowledge-engine/src/runtime/conversation-store.js +387 -0
- package/_modules/knowledge-engine/src/runtime/evidence-bundle.js +228 -0
- package/_modules/knowledge-engine/src/runtime/git-runner.js +62 -0
- package/_modules/knowledge-engine/src/runtime/knowledge-promotion.js +444 -0
- package/_modules/knowledge-engine/src/runtime/knowledge-retrieval-service.js +402 -0
- package/_modules/knowledge-engine/src/runtime/layout.js +44 -0
- package/_modules/knowledge-engine/src/runtime/markdown-knowledge-indexer.js +230 -0
- package/_modules/knowledge-engine/src/runtime/scanner.js +298 -0
- package/_modules/knowledge-engine/src/server.js +155 -0
- package/_modules/knowledge-engine/src/store.js +239 -0
- package/_modules/knowledge-engine/ui/app.css +172 -0
- package/_modules/knowledge-engine/ui/app.js +297 -0
- package/_modules/knowledge-engine/ui/index.html +95 -0
- package/_site/README.md +30 -30
- package/_site/_test/ai-profile-resolver-test.js +137 -137
- package/_site/_test/automation-queue-test.js +14 -14
- package/_site/_test/automation-ui-test.js +40 -40
- package/_site/_test/background-task-registry-test.js +43 -43
- package/_site/_test/baseline-schema-test.js +91 -91
- package/_site/_test/bridge-adapter-test.js +1 -1
- package/_site/_test/bridge-consumer-service-test.js +1 -1
- package/_site/_test/chat-claudecodeui-match-test.js +92 -92
- package/_site/_test/claude-executable-discovery-test.js +62 -62
- package/_site/_test/claude-workbench-test.js +170 -170
- package/_site/_test/client-capture-restart-e2e-test.js +4 -4
- package/_site/_test/codex-conversation-projection-test.js +2 -1
- package/_site/_test/commit-boundary-freeze-test.js +1 -1
- package/_site/_test/commit-conversation-binding-test.js +95 -95
- package/_site/_test/commit-evidence-test.js +110 -110
- package/_site/_test/conversation-api-test.js +109 -109
- package/_site/_test/conversation-store-test.js +136 -136
- package/_site/_test/cross-repo-isolation-e2e-test.js +2 -2
- package/_site/_test/data-dir-migration-test.js +57 -57
- package/_site/_test/desktop-browser-compat-test.js +28 -28
- package/_site/_test/desktop-hook-runtime-regression-test.js +204 -204
- package/_site/_test/explicit-commit-processor-test.js +37 -37
- package/_site/_test/fixtures/make-git-repos.js +12 -1
- package/_site/_test/folder-picker-output-test.js +19 -19
- package/_site/_test/full-integration-e2e-test.js +165 -165
- package/_site/_test/git-validation-test.js +2 -2
- package/_site/_test/hook-runtime-endpoint-test.js +88 -88
- package/_site/_test/hook-status-repair-api-test.js +152 -152
- package/_site/_test/hook-trigger-test.js +85 -85
- package/_site/_test/import-preflight-api-test.js +234 -233
- package/_site/_test/index-writer-concurrency-test.js +135 -135
- package/_site/_test/integration-adapters-test.js +171 -171
- package/_site/_test/integration-capture-setup-test.js +1 -1
- package/_site/_test/integration-surface-coverage-test.js +164 -164
- package/_site/_test/knowledge-language-control-test.js +170 -170
- package/_site/_test/knowledge-promotion-recovery-test.js +260 -260
- package/_site/_test/knowledge-query-test.js +54 -54
- package/_site/_test/knowledge-retrieval-service-test.js +77 -77
- package/_site/_test/knowledge-storage-startup-test.js +52 -52
- package/_site/_test/knowledge-store-logs-supervision-test.js +89 -89
- package/_site/_test/legacy-forward-compat-test.js +257 -257
- package/_site/_test/legacy-project-upgrade-e2e-test.js +363 -363
- package/_site/_test/logging-api-test.js +89 -89
- package/_site/_test/logging-sse-no-gap-test.js +88 -88
- package/_site/_test/logging-ui-test.js +106 -104
- package/_site/_test/markdown-delta-overlay-test.js +85 -85
- package/_site/_test/markdown-maintenance-api-test.js +75 -75
- package/_site/_test/mcp-server-test.js +149 -149
- package/_site/_test/module-artifact-integrity-test.js +27 -0
- package/_site/_test/module-boundary-test.js +30 -0
- package/_site/_test/module-bridge-eventbridge-test.js +7 -0
- package/_site/_test/module-model-configuration-test.js +43 -0
- package/_site/_test/module-process-lifecycle-test.js +24 -0
- package/_site/_test/module-stream-proxy-test.js +34 -0
- package/_site/_test/non-release-ci-test.js +34 -34
- package/_site/_test/offline-boundary-isolation-test.js +32 -32
- package/_site/_test/p0-data-migration-characterization-test.js +37 -37
- package/_site/_test/p0-e2e-gate-test.js +347 -347
- package/_site/_test/packaged-ui-smoke-test.js +19 -10
- package/_site/_test/path-consistency-test.js +151 -151
- package/_site/_test/pending-sweep-test.js +9 -9
- package/_site/_test/post-commit-automation-test.js +87 -87
- package/_site/_test/product-diagnostics-ui-test.js +75 -0
- package/_site/_test/product-import-ui-test.js +92 -0
- package/_site/_test/project-delete-recovery-test.js +64 -64
- package/_site/_test/project-goal-editor-test.js +144 -144
- package/_site/_test/project-layout-v2-migration-test.js +127 -127
- package/_site/_test/project-lifecycle-transaction-test.js +106 -106
- package/_site/_test/prompt-settings-test.js +115 -115
- package/_site/_test/protected-architecture-gate-test.js +122 -122
- package/_site/_test/refactor-characterization-test.js +36 -36
- package/_site/_test/release-version-sync-test.js +1 -1
- package/_site/_test/requirement-recorder-test.js +173 -173
- package/_site/_test/run-all-tests.js +159 -156
- package/_site/_test/server-runtime-migration-safety-test.js +27 -27
- package/_site/_test/shared-contracts-test.js +58 -58
- package/_site/_test/startup-analysis-disabled-test.js +10 -10
- package/_site/_test/storage-foundation-test.js +78 -78
- package/_site/_test/structured-logger-test.js +101 -101
- package/_site/_test/tracking-start-test.js +108 -108
- package/_site/_test/v4122-upgrade-data-contract-test.js +56 -56
- package/_site/_test/workbench-permission-test.js +117 -117
- package/_site/_test/workspace-ui-contract-test.js +28 -43
- package/_site/lib/ai-profile-resolver.js +78 -78
- package/_site/lib/ai-workspace.js +101 -101
- package/_site/lib/automation-config.js +140 -140
- package/_site/lib/bridge-adapter.js +5 -1
- package/_site/lib/bridge-consumer-service.js +402 -402
- package/_site/lib/claude-cli-runner.js +1510 -1510
- package/_site/lib/commit-conversation-binder.js +234 -234
- package/_site/lib/commit-processing-ledger.js +27 -27
- package/_site/lib/commit-prompt.js +202 -202
- package/_site/lib/commit-reconciler.js +406 -406
- package/_site/lib/contracts.js +284 -279
- package/_site/lib/conversation-query-service.js +144 -144
- package/_site/lib/conversation-store.js +385 -385
- package/_site/lib/data-dir.js +74 -74
- package/_site/lib/data-state-classifier.js +40 -40
- package/_site/lib/engine-cutover.js +97 -0
- package/_site/lib/evidence-bundle.js +228 -228
- package/_site/lib/folder-picker-output.js +21 -21
- package/_site/lib/git-runner.js +62 -62
- package/_site/lib/github-team-store.js +1172 -1172
- package/_site/lib/hook-manager.js +203 -202
- package/_site/lib/index-service.js +173 -173
- package/_site/lib/integration-installer.js +907 -907
- package/_site/lib/kb-framework.js +176 -176
- package/_site/lib/kb-validator.js +124 -124
- package/_site/lib/knowledge-promotion.js +435 -435
- package/_site/lib/knowledge-retrieval-service.js +401 -401
- package/_site/lib/knowledge-tool-runtime.js +359 -359
- package/_site/lib/legacy-data-manifest.js +26 -26
- package/_site/lib/llm-client.js +161 -161
- package/_site/lib/markdown-knowledge-indexer.js +230 -230
- package/_site/lib/migration-service.js +442 -442
- package/_site/lib/module-bridge.js +198 -33
- package/_site/lib/post-commit-automation.js +87 -87
- package/_site/lib/project-lifecycle-service.js +519 -497
- package/_site/lib/project-store.js +268 -262
- package/_site/lib/requirement-recorder.js +278 -278
- package/_site/lib/runtime-endpoint.js +155 -155
- package/_site/lib/scanner.js +298 -298
- package/_site/lib/server-app.js +1590 -1520
- package/_site/lib/settings-store.js +133 -113
- package/_site/lib/storage-layout.js +162 -162
- package/_site/lib/structured-logger.js +574 -574
- package/_site/scripts/folder-picker.ps1 +156 -156
- package/_site/scripts/hook-trigger.js +157 -156
- package/_site/scripts/install-module-candidates.js +69 -0
- package/_site/scripts/pack-module-candidates.js +72 -0
- package/_site/scripts/sync-release-version.js +2 -2
- package/_site/scripts/vendor-modules.js +47 -0
- package/_site/scripts/verify-module-runtime.js +45 -0
- package/_site/scripts/verify-product-runtime.js +34 -0
- package/bin/project-knowledge-mcp.js +194 -194
- package/docs/README.zh-CN.md +34 -25
- package/docs/project-registry-schema.md +22 -22
- package/docs/testing-strategy.md +33 -33
- package/module-runtime-manifest.json +220 -0
- package/package.json +13 -10
- package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.mcp.json +1 -1
- package/plugins/project-knowledge/opencode/project-knowledge.md +3 -3
- package/plugins/project-knowledge/skills/project-knowledge/SKILL.md +28 -28
- package/templates/project-readme.md +34 -34
- package/ui/favicon.svg +38 -38
- package/ui/index.html +51 -149
- package/ui/product.css +9 -0
- package/ui/product.js +386 -0
- package/vendor-manifest.json +46 -0
- package/_site/_test/import-ui-flow-test.js +0 -171
- package/_site/_test/project-control-panel-task14-test.js +0 -63
- package/_site/_test/task15-20-ui-flow-test.js +0 -148
- package/_site/_test/ui-i18n-toggle-test.js +0 -114
- package/_site/_test/ui-smoke-test.js +0 -73
- package/ui/app.css +0 -58
- package/ui/app.js +0 -607
- package/ui/i18n.js +0 -146
|
@@ -1,156 +1,156 @@
|
|
|
1
|
-
# folder-picker.ps1 — modern folder picker for project-knowledge import dialog.
|
|
2
|
-
# Uses the Vista+ IFileOpenDialog COM API (the same dialog VS Code / modern
|
|
3
|
-
# Windows apps show) with the default initial folder set to "This PC".
|
|
4
|
-
#
|
|
5
|
-
# Reads title from $args[0]. Prints the selected absolute path to stdout, or
|
|
6
|
-
# prints nothing if the user cancelled. Exits 0 in both cases.
|
|
7
|
-
#
|
|
8
|
-
# STA apartment + -WindowStyle Hidden is required by the caller; this script
|
|
9
|
-
# assumes the host process has set those flags.
|
|
10
|
-
|
|
11
|
-
param([string]$Title = 'Select folder')
|
|
12
|
-
|
|
13
|
-
$ErrorActionPreference = 'Stop'
|
|
14
|
-
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
|
|
15
|
-
|
|
16
|
-
$src = @'
|
|
17
|
-
using System;
|
|
18
|
-
using System.ComponentModel;
|
|
19
|
-
using System.Linq;
|
|
20
|
-
using System.Runtime.InteropServices;
|
|
21
|
-
|
|
22
|
-
[Flags]
|
|
23
|
-
public enum FOS : uint {
|
|
24
|
-
PICKFOLDERS = 0x00000020,
|
|
25
|
-
FORCEFILESYSTEM = 0x00000040,
|
|
26
|
-
NOCHANGEDIR = 0x00000008
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
[ComImport, Guid("d57c7288-d4ad-4768-be02-9d969532d960"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
30
|
-
public interface IFileOpenDialog {
|
|
31
|
-
[PreserveSig] int Show(IntPtr hwndOwner);
|
|
32
|
-
[PreserveSig] int SetFileTypes(uint cFileTypes, IntPtr rgFilterSpec);
|
|
33
|
-
[PreserveSig] int SetFileTypeIndex(uint iFileType);
|
|
34
|
-
[PreserveSig] int GetFileTypeIndex(out uint piFileType);
|
|
35
|
-
[PreserveSig] int Advise(IntPtr pfde, out uint pdwCookie);
|
|
36
|
-
[PreserveSig] int Unadvise(uint dwCookie);
|
|
37
|
-
[PreserveSig] int SetOptions(FOS fos);
|
|
38
|
-
[PreserveSig] int GetOptions(out FOS pfos);
|
|
39
|
-
[PreserveSig] int SetDefaultFolder(IntPtr psi);
|
|
40
|
-
[PreserveSig] int SetFolder(IntPtr psi);
|
|
41
|
-
[PreserveSig] int GetFolder(out IntPtr ppsi);
|
|
42
|
-
[PreserveSig] int GetCurrentSelection(out IntPtr ppsi);
|
|
43
|
-
[PreserveSig] int SetFileName([MarshalAs(UnmanagedType.LPWStr)] string pszName);
|
|
44
|
-
[PreserveSig] int GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);
|
|
45
|
-
[PreserveSig] int SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
|
|
46
|
-
[PreserveSig] int SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string pszText);
|
|
47
|
-
[PreserveSig] int SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr)] string pszLabel);
|
|
48
|
-
[PreserveSig] int GetResult(out IntPtr ppsi);
|
|
49
|
-
[PreserveSig] int AddPlace(IntPtr psi, int fdap);
|
|
50
|
-
[PreserveSig] int SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension);
|
|
51
|
-
[PreserveSig] int Close(int hr);
|
|
52
|
-
[PreserveSig] int SetClientGuid(ref Guid guid);
|
|
53
|
-
[PreserveSig] int ClearClientData();
|
|
54
|
-
[PreserveSig] int SetFilter(IntPtr pFilter);
|
|
55
|
-
[PreserveSig] int GetResults(out IntPtr ppenum);
|
|
56
|
-
[PreserveSig] int GetSelectedItems(out IntPtr ppsai);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public static class Shell32 {
|
|
60
|
-
[DllImport("shell32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = true)]
|
|
61
|
-
public static extern int SHCreateItemFromParsingName(
|
|
62
|
-
[MarshalAs(UnmanagedType.LPWStr)] string pszPath,
|
|
63
|
-
IntPtr pbc,
|
|
64
|
-
[MarshalAs(UnmanagedType.LPStruct)] Guid riid,
|
|
65
|
-
out IntPtr ppv);
|
|
66
|
-
|
|
67
|
-
[DllImport("ole32.dll", PreserveSig = true)]
|
|
68
|
-
public static extern int CoCreateInstance(
|
|
69
|
-
ref Guid rclsid, IntPtr pUnkOuter, uint dwClsContext, ref Guid riid, out IntPtr ppv);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public static class User32 {
|
|
73
|
-
[DllImport("user32.dll")]
|
|
74
|
-
public static extern IntPtr GetForegroundWindow();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public static class FolderPicker {
|
|
78
|
-
public static string Pick(string title) {
|
|
79
|
-
Guid clsid = new Guid("DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7");
|
|
80
|
-
Guid iid = new Guid("d57c7288-d4ad-4768-be02-9d969532d960");
|
|
81
|
-
IntPtr pIfod = IntPtr.Zero;
|
|
82
|
-
IntPtr pItem = IntPtr.Zero;
|
|
83
|
-
IntPtr pResult = IntPtr.Zero;
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
int hr = Shell32.CoCreateInstance(ref clsid, IntPtr.Zero, 0x1, ref iid, out pIfod);
|
|
87
|
-
if (hr != 0) throw new Win32Exception(hr);
|
|
88
|
-
|
|
89
|
-
IFileOpenDialog dialog = (IFileOpenDialog)Marshal.GetTypedObjectForIUnknown(pIfod, typeof(IFileOpenDialog));
|
|
90
|
-
|
|
91
|
-
FOS opts = FOS.PICKFOLDERS | FOS.FORCEFILESYSTEM | FOS.NOCHANGEDIR;
|
|
92
|
-
hr = dialog.SetOptions(opts);
|
|
93
|
-
if (hr != 0) throw new Win32Exception(hr);
|
|
94
|
-
|
|
95
|
-
// On Win11 with system ANSI codepage set (e.g. 936 GBK) the Fluent
|
|
96
|
-
// title-bar chrome can garble CJK even though the dialog stores the title
|
|
97
|
-
// correctly in Unicode (taskbar preview is correct via the Unicode path).
|
|
98
|
-
// Use an ASCII title to keep the chrome legible; the import button's
|
|
99
|
-
// surrounding UI (Chinese) tells the user what the picker is for.
|
|
100
|
-
string safeTitle = title.All(c => c < 128) ? title : "Select Project Folder";
|
|
101
|
-
hr = dialog.SetTitle(safeTitle);
|
|
102
|
-
if (hr != 0) throw new Win32Exception(hr);
|
|
103
|
-
|
|
104
|
-
// Initial folder = This PC (FOLDERID_ComputerFolder)
|
|
105
|
-
Guid iidShellItem = new Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe");
|
|
106
|
-
hr = Shell32.SHCreateItemFromParsingName(
|
|
107
|
-
"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
|
|
108
|
-
IntPtr.Zero, iidShellItem, out pItem);
|
|
109
|
-
if (hr != 0) throw new Win32Exception(hr);
|
|
110
|
-
hr = dialog.SetFolder(pItem);
|
|
111
|
-
if (hr != 0) throw new Win32Exception(hr);
|
|
112
|
-
|
|
113
|
-
// Pass the current foreground window as owner so the dialog is parented
|
|
114
|
-
// to it (positioned on top, modal to it). Without an owner, the dialog
|
|
115
|
-
// has no z-order anchor and on Windows 11 ends up hidden behind the
|
|
116
|
-
// browser window that initiated the call.
|
|
117
|
-
IntPtr owner = User32.GetForegroundWindow();
|
|
118
|
-
hr = dialog.Show(owner);
|
|
119
|
-
// 0 = OK, 0x800704C7 = ERROR_CANCELLED, others = error
|
|
120
|
-
if (hr != 0) return null;
|
|
121
|
-
|
|
122
|
-
hr = dialog.GetResult(out pResult);
|
|
123
|
-
if (hr != 0 || pResult == IntPtr.Zero) return null;
|
|
124
|
-
|
|
125
|
-
// IShellItem vtable index 5 = GetDisplayName(SIGDN, LPWSTR*)
|
|
126
|
-
IntPtr vtable = Marshal.ReadIntPtr(pResult);
|
|
127
|
-
IntPtr getDisplayNameFn = Marshal.ReadIntPtr(vtable, 5 * IntPtr.Size);
|
|
128
|
-
GetDisplayNameDelegate del = (GetDisplayNameDelegate)Marshal.GetDelegateForFunctionPointer(
|
|
129
|
-
getDisplayNameFn, typeof(GetDisplayNameDelegate));
|
|
130
|
-
|
|
131
|
-
IntPtr strPtr = IntPtr.Zero;
|
|
132
|
-
int ghr = del(pResult, 0x80058000u, out strPtr); // SIGDN_FILESYSPATH
|
|
133
|
-
if (ghr != 0 || strPtr == IntPtr.Zero) return null;
|
|
134
|
-
|
|
135
|
-
string path = Marshal.PtrToStringUni(strPtr);
|
|
136
|
-
Marshal.FreeCoTaskMem(strPtr);
|
|
137
|
-
return path;
|
|
138
|
-
} finally {
|
|
139
|
-
if (pResult != IntPtr.Zero) Marshal.Release(pResult);
|
|
140
|
-
if (pItem != IntPtr.Zero) Marshal.Release(pItem);
|
|
141
|
-
if (pIfod != IntPtr.Zero) Marshal.Release(pIfod);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
|
146
|
-
private delegate int GetDisplayNameDelegate(IntPtr pThis, uint sigdn, out IntPtr ppszName);
|
|
147
|
-
}
|
|
148
|
-
'@
|
|
149
|
-
|
|
150
|
-
Add-Type -TypeDefinition $src -Language CSharp | Out-Null
|
|
151
|
-
|
|
152
|
-
$path = [FolderPicker]::Pick($Title)
|
|
153
|
-
if ($null -ne $path -and $path.Length -gt 0) {
|
|
154
|
-
Write-Output $path
|
|
155
|
-
}
|
|
156
|
-
exit 0
|
|
1
|
+
# folder-picker.ps1 — modern folder picker for project-knowledge import dialog.
|
|
2
|
+
# Uses the Vista+ IFileOpenDialog COM API (the same dialog VS Code / modern
|
|
3
|
+
# Windows apps show) with the default initial folder set to "This PC".
|
|
4
|
+
#
|
|
5
|
+
# Reads title from $args[0]. Prints the selected absolute path to stdout, or
|
|
6
|
+
# prints nothing if the user cancelled. Exits 0 in both cases.
|
|
7
|
+
#
|
|
8
|
+
# STA apartment + -WindowStyle Hidden is required by the caller; this script
|
|
9
|
+
# assumes the host process has set those flags.
|
|
10
|
+
|
|
11
|
+
param([string]$Title = 'Select folder')
|
|
12
|
+
|
|
13
|
+
$ErrorActionPreference = 'Stop'
|
|
14
|
+
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
|
|
15
|
+
|
|
16
|
+
$src = @'
|
|
17
|
+
using System;
|
|
18
|
+
using System.ComponentModel;
|
|
19
|
+
using System.Linq;
|
|
20
|
+
using System.Runtime.InteropServices;
|
|
21
|
+
|
|
22
|
+
[Flags]
|
|
23
|
+
public enum FOS : uint {
|
|
24
|
+
PICKFOLDERS = 0x00000020,
|
|
25
|
+
FORCEFILESYSTEM = 0x00000040,
|
|
26
|
+
NOCHANGEDIR = 0x00000008
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[ComImport, Guid("d57c7288-d4ad-4768-be02-9d969532d960"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
30
|
+
public interface IFileOpenDialog {
|
|
31
|
+
[PreserveSig] int Show(IntPtr hwndOwner);
|
|
32
|
+
[PreserveSig] int SetFileTypes(uint cFileTypes, IntPtr rgFilterSpec);
|
|
33
|
+
[PreserveSig] int SetFileTypeIndex(uint iFileType);
|
|
34
|
+
[PreserveSig] int GetFileTypeIndex(out uint piFileType);
|
|
35
|
+
[PreserveSig] int Advise(IntPtr pfde, out uint pdwCookie);
|
|
36
|
+
[PreserveSig] int Unadvise(uint dwCookie);
|
|
37
|
+
[PreserveSig] int SetOptions(FOS fos);
|
|
38
|
+
[PreserveSig] int GetOptions(out FOS pfos);
|
|
39
|
+
[PreserveSig] int SetDefaultFolder(IntPtr psi);
|
|
40
|
+
[PreserveSig] int SetFolder(IntPtr psi);
|
|
41
|
+
[PreserveSig] int GetFolder(out IntPtr ppsi);
|
|
42
|
+
[PreserveSig] int GetCurrentSelection(out IntPtr ppsi);
|
|
43
|
+
[PreserveSig] int SetFileName([MarshalAs(UnmanagedType.LPWStr)] string pszName);
|
|
44
|
+
[PreserveSig] int GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);
|
|
45
|
+
[PreserveSig] int SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
|
|
46
|
+
[PreserveSig] int SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string pszText);
|
|
47
|
+
[PreserveSig] int SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr)] string pszLabel);
|
|
48
|
+
[PreserveSig] int GetResult(out IntPtr ppsi);
|
|
49
|
+
[PreserveSig] int AddPlace(IntPtr psi, int fdap);
|
|
50
|
+
[PreserveSig] int SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension);
|
|
51
|
+
[PreserveSig] int Close(int hr);
|
|
52
|
+
[PreserveSig] int SetClientGuid(ref Guid guid);
|
|
53
|
+
[PreserveSig] int ClearClientData();
|
|
54
|
+
[PreserveSig] int SetFilter(IntPtr pFilter);
|
|
55
|
+
[PreserveSig] int GetResults(out IntPtr ppenum);
|
|
56
|
+
[PreserveSig] int GetSelectedItems(out IntPtr ppsai);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public static class Shell32 {
|
|
60
|
+
[DllImport("shell32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = true)]
|
|
61
|
+
public static extern int SHCreateItemFromParsingName(
|
|
62
|
+
[MarshalAs(UnmanagedType.LPWStr)] string pszPath,
|
|
63
|
+
IntPtr pbc,
|
|
64
|
+
[MarshalAs(UnmanagedType.LPStruct)] Guid riid,
|
|
65
|
+
out IntPtr ppv);
|
|
66
|
+
|
|
67
|
+
[DllImport("ole32.dll", PreserveSig = true)]
|
|
68
|
+
public static extern int CoCreateInstance(
|
|
69
|
+
ref Guid rclsid, IntPtr pUnkOuter, uint dwClsContext, ref Guid riid, out IntPtr ppv);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public static class User32 {
|
|
73
|
+
[DllImport("user32.dll")]
|
|
74
|
+
public static extern IntPtr GetForegroundWindow();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public static class FolderPicker {
|
|
78
|
+
public static string Pick(string title) {
|
|
79
|
+
Guid clsid = new Guid("DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7");
|
|
80
|
+
Guid iid = new Guid("d57c7288-d4ad-4768-be02-9d969532d960");
|
|
81
|
+
IntPtr pIfod = IntPtr.Zero;
|
|
82
|
+
IntPtr pItem = IntPtr.Zero;
|
|
83
|
+
IntPtr pResult = IntPtr.Zero;
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
int hr = Shell32.CoCreateInstance(ref clsid, IntPtr.Zero, 0x1, ref iid, out pIfod);
|
|
87
|
+
if (hr != 0) throw new Win32Exception(hr);
|
|
88
|
+
|
|
89
|
+
IFileOpenDialog dialog = (IFileOpenDialog)Marshal.GetTypedObjectForIUnknown(pIfod, typeof(IFileOpenDialog));
|
|
90
|
+
|
|
91
|
+
FOS opts = FOS.PICKFOLDERS | FOS.FORCEFILESYSTEM | FOS.NOCHANGEDIR;
|
|
92
|
+
hr = dialog.SetOptions(opts);
|
|
93
|
+
if (hr != 0) throw new Win32Exception(hr);
|
|
94
|
+
|
|
95
|
+
// On Win11 with system ANSI codepage set (e.g. 936 GBK) the Fluent
|
|
96
|
+
// title-bar chrome can garble CJK even though the dialog stores the title
|
|
97
|
+
// correctly in Unicode (taskbar preview is correct via the Unicode path).
|
|
98
|
+
// Use an ASCII title to keep the chrome legible; the import button's
|
|
99
|
+
// surrounding UI (Chinese) tells the user what the picker is for.
|
|
100
|
+
string safeTitle = title.All(c => c < 128) ? title : "Select Project Folder";
|
|
101
|
+
hr = dialog.SetTitle(safeTitle);
|
|
102
|
+
if (hr != 0) throw new Win32Exception(hr);
|
|
103
|
+
|
|
104
|
+
// Initial folder = This PC (FOLDERID_ComputerFolder)
|
|
105
|
+
Guid iidShellItem = new Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe");
|
|
106
|
+
hr = Shell32.SHCreateItemFromParsingName(
|
|
107
|
+
"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
|
|
108
|
+
IntPtr.Zero, iidShellItem, out pItem);
|
|
109
|
+
if (hr != 0) throw new Win32Exception(hr);
|
|
110
|
+
hr = dialog.SetFolder(pItem);
|
|
111
|
+
if (hr != 0) throw new Win32Exception(hr);
|
|
112
|
+
|
|
113
|
+
// Pass the current foreground window as owner so the dialog is parented
|
|
114
|
+
// to it (positioned on top, modal to it). Without an owner, the dialog
|
|
115
|
+
// has no z-order anchor and on Windows 11 ends up hidden behind the
|
|
116
|
+
// browser window that initiated the call.
|
|
117
|
+
IntPtr owner = User32.GetForegroundWindow();
|
|
118
|
+
hr = dialog.Show(owner);
|
|
119
|
+
// 0 = OK, 0x800704C7 = ERROR_CANCELLED, others = error
|
|
120
|
+
if (hr != 0) return null;
|
|
121
|
+
|
|
122
|
+
hr = dialog.GetResult(out pResult);
|
|
123
|
+
if (hr != 0 || pResult == IntPtr.Zero) return null;
|
|
124
|
+
|
|
125
|
+
// IShellItem vtable index 5 = GetDisplayName(SIGDN, LPWSTR*)
|
|
126
|
+
IntPtr vtable = Marshal.ReadIntPtr(pResult);
|
|
127
|
+
IntPtr getDisplayNameFn = Marshal.ReadIntPtr(vtable, 5 * IntPtr.Size);
|
|
128
|
+
GetDisplayNameDelegate del = (GetDisplayNameDelegate)Marshal.GetDelegateForFunctionPointer(
|
|
129
|
+
getDisplayNameFn, typeof(GetDisplayNameDelegate));
|
|
130
|
+
|
|
131
|
+
IntPtr strPtr = IntPtr.Zero;
|
|
132
|
+
int ghr = del(pResult, 0x80058000u, out strPtr); // SIGDN_FILESYSPATH
|
|
133
|
+
if (ghr != 0 || strPtr == IntPtr.Zero) return null;
|
|
134
|
+
|
|
135
|
+
string path = Marshal.PtrToStringUni(strPtr);
|
|
136
|
+
Marshal.FreeCoTaskMem(strPtr);
|
|
137
|
+
return path;
|
|
138
|
+
} finally {
|
|
139
|
+
if (pResult != IntPtr.Zero) Marshal.Release(pResult);
|
|
140
|
+
if (pItem != IntPtr.Zero) Marshal.Release(pItem);
|
|
141
|
+
if (pIfod != IntPtr.Zero) Marshal.Release(pIfod);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
|
146
|
+
private delegate int GetDisplayNameDelegate(IntPtr pThis, uint sigdn, out IntPtr ppszName);
|
|
147
|
+
}
|
|
148
|
+
'@
|
|
149
|
+
|
|
150
|
+
Add-Type -TypeDefinition $src -Language CSharp | Out-Null
|
|
151
|
+
|
|
152
|
+
$path = [FolderPicker]::Pick($Title)
|
|
153
|
+
if ($null -ne $path -and $path.Length -gt 0) {
|
|
154
|
+
Write-Output $path
|
|
155
|
+
}
|
|
156
|
+
exit 0
|
|
@@ -1,156 +1,157 @@
|
|
|
1
|
-
const http = require('http');
|
|
2
|
-
const crypto = require('crypto');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { execFileSync } = require('child_process');
|
|
6
|
-
const { getDataDir } = require('../lib/data-dir');
|
|
7
|
-
const { readLiveEndpoint } = require('../lib/runtime-endpoint');
|
|
8
|
-
const { StorageLayout } = require('../lib/storage-layout');
|
|
9
|
-
const { Logger } = require('../lib/structured-logger');
|
|
10
|
-
const { BridgeAdapter } = require('../lib/bridge-adapter');
|
|
11
|
-
|
|
12
|
-
let bridgeIdentityModule = null;
|
|
13
|
-
try {
|
|
14
|
-
const bridgePackage = require('@sanqianx/ai-coding-event-bridge');
|
|
15
|
-
if (bridgePackage && typeof bridgePackage.buildRepoIdentityV1 === 'function') bridgeIdentityModule = bridgePackage;
|
|
16
|
-
} catch (_) {
|
|
17
|
-
bridgeIdentityModule = null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const args = process.argv.slice(2);
|
|
21
|
-
function arg(name, fallback = '') {
|
|
22
|
-
const index = args.indexOf(name);
|
|
23
|
-
return index >= 0 ? (args[index + 1] || fallback) : fallback;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const projectId = arg('--project-id', '');
|
|
27
|
-
const repoRoot = arg('--repo-root', arg('--repo', ''));
|
|
28
|
-
const fallbackHost = arg('--host', '127.0.0.1');
|
|
29
|
-
const fallbackPort = Number(arg('--port', process.env.KB_SITE_PORT || '5757'));
|
|
30
|
-
const dataDir = getDataDir();
|
|
31
|
-
const layout = new StorageLayout({ dataDir });
|
|
32
|
-
const logger = new Logger({
|
|
33
|
-
layout,
|
|
34
|
-
settingsProvider: () => ({ levels: ['trace', 'debug', 'info', 'warn', 'error', 'fatal'] }),
|
|
35
|
-
context: { component: 'git-hook', projectId },
|
|
36
|
-
});
|
|
37
|
-
const bridge = new BridgeAdapter({ dataDir, modulePath: arg('--bridge-module', '') });
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
response.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
request.on('
|
|
72
|
-
request.
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
payload.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
1
|
+
const http = require('http');
|
|
2
|
+
const crypto = require('crypto');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { execFileSync } = require('child_process');
|
|
6
|
+
const { getDataDir } = require('../lib/data-dir');
|
|
7
|
+
const { readLiveEndpoint } = require('../lib/runtime-endpoint');
|
|
8
|
+
const { StorageLayout } = require('../lib/storage-layout');
|
|
9
|
+
const { Logger } = require('../lib/structured-logger');
|
|
10
|
+
const { BridgeAdapter } = require('../lib/bridge-adapter');
|
|
11
|
+
|
|
12
|
+
let bridgeIdentityModule = null;
|
|
13
|
+
try {
|
|
14
|
+
const bridgePackage = require('@sanqianx/ai-coding-event-bridge-console/src/bridge');
|
|
15
|
+
if (bridgePackage && typeof bridgePackage.buildRepoIdentityV1 === 'function') bridgeIdentityModule = bridgePackage;
|
|
16
|
+
} catch (_) {
|
|
17
|
+
bridgeIdentityModule = null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const args = process.argv.slice(2);
|
|
21
|
+
function arg(name, fallback = '') {
|
|
22
|
+
const index = args.indexOf(name);
|
|
23
|
+
return index >= 0 ? (args[index + 1] || fallback) : fallback;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const projectId = arg('--project-id', '');
|
|
27
|
+
const repoRoot = arg('--repo-root', arg('--repo', ''));
|
|
28
|
+
const fallbackHost = arg('--host', '127.0.0.1');
|
|
29
|
+
const fallbackPort = Number(arg('--port', process.env.KB_SITE_PORT || '5757'));
|
|
30
|
+
const dataDir = path.resolve(arg('--data-dir', getDataDir()));
|
|
31
|
+
const layout = new StorageLayout({ dataDir });
|
|
32
|
+
const logger = new Logger({
|
|
33
|
+
layout,
|
|
34
|
+
settingsProvider: () => ({ levels: ['trace', 'debug', 'info', 'warn', 'error', 'fatal'] }),
|
|
35
|
+
context: { component: 'git-hook', projectId },
|
|
36
|
+
});
|
|
37
|
+
const bridge = new BridgeAdapter({ dataDir, modulePath: arg('--bridge-module', ''), bridgeHomeDir: arg('--bridge-home', '') });
|
|
38
|
+
if (bridge.module && typeof bridge.module.buildRepoIdentityV1 === 'function') bridgeIdentityModule = bridge.module;
|
|
39
|
+
const timeoutMs = 2000;
|
|
40
|
+
|
|
41
|
+
function git(gitArgs, fallback = '') {
|
|
42
|
+
if (!repoRoot) return fallback;
|
|
43
|
+
try {
|
|
44
|
+
return execFileSync('git', ['-C', repoRoot, ...gitArgs], {
|
|
45
|
+
encoding: 'utf8', windowsHide: true, timeout: timeoutMs,
|
|
46
|
+
stdio: ['ignore', 'pipe', 'ignore'], env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
47
|
+
}).trim();
|
|
48
|
+
} catch { return fallback; }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function target() {
|
|
52
|
+
const endpoint = readLiveEndpoint(dataDir);
|
|
53
|
+
return endpoint ? { host: endpoint.host, port: endpoint.port } : { host: fallbackHost, port: fallbackPort };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function post(body) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const payload = JSON.stringify(body);
|
|
59
|
+
const endpoint = target();
|
|
60
|
+
const request = http.request({
|
|
61
|
+
host: endpoint.host,
|
|
62
|
+
port: endpoint.port,
|
|
63
|
+
method: 'POST',
|
|
64
|
+
path: '/api/hooks/post-commit',
|
|
65
|
+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) },
|
|
66
|
+
timeout: timeoutMs,
|
|
67
|
+
}, response => {
|
|
68
|
+
response.resume();
|
|
69
|
+
response.on('end', () => resolve(response.statusCode || 0));
|
|
70
|
+
});
|
|
71
|
+
request.on('error', reject);
|
|
72
|
+
request.on('timeout', () => request.destroy(new Error('hook notification timeout')));
|
|
73
|
+
request.end(payload);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
(async () => {
|
|
78
|
+
try {
|
|
79
|
+
if (!projectId || !repoRoot) {
|
|
80
|
+
await logger.warn('hook.notification.skipped', 'Hook payload is missing project identity or repository root.', { phase: 'validate' });
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const payload = {
|
|
84
|
+
schema: 'hook-event/v2',
|
|
85
|
+
projectId,
|
|
86
|
+
repoRoot,
|
|
87
|
+
head: git(['rev-parse', 'HEAD']),
|
|
88
|
+
branch: git(['branch', '--show-current']),
|
|
89
|
+
};
|
|
90
|
+
const operationId = arg('--operation-id', `op-${crypto.randomUUID()}`);
|
|
91
|
+
// Canonical repo-identity/v1 from the authoritative Git working tree.
|
|
92
|
+
// The old { commonDir }-only shape must never reach the Bridge again.
|
|
93
|
+
let repoIdentity = null;
|
|
94
|
+
if (bridgeIdentityModule) {
|
|
95
|
+
const toplevel = git(['rev-parse', '--show-toplevel']);
|
|
96
|
+
if (toplevel) {
|
|
97
|
+
let workspaceRoot = path.resolve(toplevel);
|
|
98
|
+
try { workspaceRoot = fs.realpathSync.native(workspaceRoot) || workspaceRoot; } catch { workspaceRoot = path.resolve(toplevel); }
|
|
99
|
+
const commonDir = git(['rev-parse', '--path-format=absolute', '--git-common-dir']);
|
|
100
|
+
const remoteRaw = git(['config', '--get', 'remote.origin.url']);
|
|
101
|
+
repoIdentity = bridgeIdentityModule.buildRepoIdentityV1({
|
|
102
|
+
workspaceRoot,
|
|
103
|
+
commonDir: commonDir ? path.resolve(commonDir) : null,
|
|
104
|
+
remote: remoteRaw ? bridgeIdentityModule.normalizeGitUrl(remoteRaw) : null,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const boundaryResult = await bridge.appendCommitBoundary({
|
|
109
|
+
projectId,
|
|
110
|
+
repoIdentity,
|
|
111
|
+
commitSha: payload.head,
|
|
112
|
+
parentShas: git(['show', '-s', '--format=%P', 'HEAD']).split(/\s+/).filter(Boolean),
|
|
113
|
+
branch: payload.branch || null,
|
|
114
|
+
committedAt: git(['show', '-s', '--format=%cI', 'HEAD']) || new Date().toISOString(),
|
|
115
|
+
operationId,
|
|
116
|
+
});
|
|
117
|
+
payload.operationId = operationId;
|
|
118
|
+
payload.boundary = boundaryResult;
|
|
119
|
+
if (boundaryResult.status === 'captured') {
|
|
120
|
+
await logger.debug('hook.boundary.captured', 'Commit conversation boundary was durably captured.', {
|
|
121
|
+
operationId,
|
|
122
|
+
phase: 'boundary',
|
|
123
|
+
commitSha: payload.head,
|
|
124
|
+
context: {
|
|
125
|
+
bridgeCursorAtCommit: boundaryResult.boundary.bridgeCursorAtCommit,
|
|
126
|
+
openTurnCount: boundaryResult.boundary.openTurnIdsAtCommit.length,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
} else {
|
|
130
|
+
await logger.warn('hook.boundary.unavailable', 'Commit conversation boundary could not be captured.', {
|
|
131
|
+
operationId,
|
|
132
|
+
phase: 'boundary',
|
|
133
|
+
commitSha: payload.head,
|
|
134
|
+
context: { gapId: boundaryResult.gap && boundaryResult.gap.gapId, reason: boundaryResult.gap && boundaryResult.gap.reason },
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const status = await post(payload);
|
|
139
|
+
if (status < 200 || status >= 300) {
|
|
140
|
+
await logger.warn('hook.notification.failed', 'Knowledge service rejected the Hook notification.', { phase: 'notify', context: { status } });
|
|
141
|
+
} else {
|
|
142
|
+
await logger.debug('hook.notification.completed', 'Hook notification delivered.', { phase: 'notify' });
|
|
143
|
+
}
|
|
144
|
+
} catch (error) {
|
|
145
|
+
await logger.warn('hook.notification.degraded', 'Knowledge service is unavailable; this commit was not submitted for knowledge analysis.', { phase: 'notify', error });
|
|
146
|
+
}
|
|
147
|
+
} catch (error) {
|
|
148
|
+
await logger.error('hook.script.failed', 'Hook trigger failed.', { phase: 'runtime', error });
|
|
149
|
+
} finally {
|
|
150
|
+
await logger.close();
|
|
151
|
+
}
|
|
152
|
+
})().then(() => process.exit(0), async error => {
|
|
153
|
+
try { await logger.error('hook.script.failed', 'Hook trigger failed unexpectedly.', { error }); await logger.close(); } catch {
|
|
154
|
+
// Hook execution must always exit zero even when logging is unavailable.
|
|
155
|
+
}
|
|
156
|
+
process.exit(0);
|
|
157
|
+
});
|