skillhub/plugins/dsh/scripts/windows-job.ps1
XiaoSeS 3560679793
Some checks failed
Deploy Docs / build (push) Has been cancelled
Security / Dependency Review (push) Has been cancelled
Security / CodeQL (java-kotlin) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Deploy Docs / Deploy (push) Has been cancelled
feat(dsh): add native SkillHub plugin for DeepSeek Harness (#956)
Add the native SkillHub plugin for DeepSeek Harness with a scoped skill center, conversation search/install tools, exact-version installation and protected lifecycle management. Prepare the independently versioned 0.1.0 npm candidate with an empty default Registry and documented compatibility limits.

Keep formal specifications and executable regression tests; remove archived development screenshots and runtime reports from the final tree. Review fixes cover independent scopes, installed references, pre-staging recovery and idempotent discovery.

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-10-16 19:22:26 +08:00

123 lines
6.5 KiB
PowerShell

param([Parameter(Mandatory=$true)][string]$Configuration)
$ErrorActionPreference = 'Stop'
# Keep every command descendant in a Job, even when its immediate parent exits.
# Suspended creation prevents a child from spawning before assignment to the Job.
Add-Type -TypeDefinition @'
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
public static class SkillHubSmokeJob {
[StructLayout(LayoutKind.Sequential)] struct BasicLimit {
public long ProcessTime, JobTime;
public uint Flags;
public UIntPtr MinWorkingSet, MaxWorkingSet;
public uint ActiveLimit;
public UIntPtr Affinity;
public uint Priority, Scheduling;
}
[StructLayout(LayoutKind.Sequential)] struct IoCounters {
public ulong ReadOperations, WriteOperations, OtherOperations, ReadBytes, WriteBytes, OtherBytes;
}
[StructLayout(LayoutKind.Sequential)] struct ExtendedLimit {
public BasicLimit Basic;
public IoCounters Io;
public UIntPtr ProcessMemory, JobMemory, PeakProcessMemory, PeakJobMemory;
}
[StructLayout(LayoutKind.Sequential)] struct Accounting {
public long UserTime, KernelTime, PeriodUserTime, PeriodKernelTime;
public uint PageFaults, TotalProcesses, ActiveProcesses, TerminatedProcesses;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)] struct StartupInfo {
public uint Size;
public string Reserved, Desktop, Title;
public uint X, Y, Width, Height, XChars, YChars, Fill, Flags;
public ushort Show, ReservedSize;
public IntPtr ReservedPointer, Input, Output, Error;
}
[StructLayout(LayoutKind.Sequential)] struct ProcessInfo {
public IntPtr Process, Thread;
public uint ProcessId, ThreadId;
}
[DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
static extern IntPtr CreateJobObject(IntPtr attributes, string name);
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool SetInformationJobObject(IntPtr job, int kind, ref ExtendedLimit info, uint size);
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool QueryInformationJobObject(IntPtr job, int kind, out Accounting info, uint size, IntPtr returned);
[DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
static extern bool CreateProcess(string app, StringBuilder command, IntPtr processAttributes,
IntPtr threadAttributes, bool inherit, uint flags, IntPtr environment, string cwd,
ref StartupInfo startup, out ProcessInfo process);
[DllImport("kernel32.dll", SetLastError=true)] static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
[DllImport("kernel32.dll", SetLastError=true)] static extern uint ResumeThread(IntPtr thread);
[DllImport("kernel32.dll", SetLastError=true)] static extern uint WaitForSingleObject(IntPtr handle, uint milliseconds);
[DllImport("kernel32.dll", SetLastError=true)] static extern bool GetExitCodeProcess(IntPtr process, out uint code);
[DllImport("kernel32.dll", SetLastError=true)] static extern bool TerminateJobObject(IntPtr job, uint code);
[DllImport("kernel32.dll", SetLastError=true)] static extern bool TerminateProcess(IntPtr process, uint code);
[DllImport("kernel32.dll")] static extern bool CloseHandle(IntPtr handle);
[DllImport("kernel32.dll")] static extern IntPtr GetStdHandle(int kind);
static void Check(bool success) { if (!success) throw new Win32Exception(Marshal.GetLastWin32Error()); }
static string Quote(string value) {
var result = new StringBuilder("\"");
int slashes = 0;
foreach (char c in value) {
if (c == '\\') { slashes++; continue; }
if (c == '"') result.Append('\\', slashes * 2 + 1);
else result.Append('\\', slashes);
result.Append(c);
slashes = 0;
}
return result.Append('\\', slashes * 2).Append('"').ToString();
}
public static int Run(string executable, string[] args, string cwd) {
IntPtr job = CreateJobObject(IntPtr.Zero, null);
Check(job != IntPtr.Zero);
ProcessInfo process = new ProcessInfo();
bool assigned = false;
try {
var limits = new ExtendedLimit();
limits.Basic.Flags = 0x2000; // JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
Check(SetInformationJobObject(job, 9, ref limits, (uint)Marshal.SizeOf(limits)));
var command = new StringBuilder(Quote(executable));
foreach (string arg in args) command.Append(' ').Append(Quote(arg));
var startup = new StartupInfo();
startup.Size = (uint)Marshal.SizeOf(startup);
startup.Flags = 0x100; // STARTF_USESTDHANDLES
startup.Input = GetStdHandle(-10);
startup.Output = GetStdHandle(-11);
startup.Error = GetStdHandle(-12);
Check(CreateProcess(executable, command, IntPtr.Zero, IntPtr.Zero, true,
0x08000004, IntPtr.Zero, cwd, ref startup, out process)); // NO_WINDOW | SUSPENDED
Check(AssignProcessToJobObject(job, process.Process));
assigned = true;
Check(ResumeThread(process.Thread) != UInt32.MaxValue);
Check(WaitForSingleObject(process.Process, UInt32.MaxValue) == 0);
uint code;
Check(GetExitCodeProcess(process.Process, out code));
Check(TerminateJobObject(job, 1));
var deadline = Stopwatch.StartNew();
while (true) {
Accounting accounting;
Check(QueryInformationJobObject(job, 1, out accounting, (uint)Marshal.SizeOf(typeof(Accounting)), IntPtr.Zero));
if (accounting.ActiveProcesses == 0) break;
if (deadline.ElapsedMilliseconds >= 10000) throw new Exception("Job cleanup deadline reached.");
Thread.Sleep(20);
}
return unchecked((int)code);
} finally {
// Assignment failure must also terminate the still-suspended command.
if (!assigned && process.Process != IntPtr.Zero) TerminateProcess(process.Process, 1);
CloseHandle(job);
if (process.Thread != IntPtr.Zero) CloseHandle(process.Thread);
if (process.Process != IntPtr.Zero) CloseHandle(process.Process);
}
}
}
'@
$config = Get-Content -LiteralPath $Configuration -Raw -Encoding UTF8 | ConvertFrom-Json
exit [SkillHubSmokeJob]::Run([string]$config.executable, [string[]]$config.arguments, [string]$config.cwd)