@hmharness/domain-ops 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/channel.d.ts +7 -0
- package/dist/channel.js +104 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +238 -0
- package/dist/issues.d.ts +7 -0
- package/dist/issues.js +184 -0
- package/package.json +31 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Tool } from '@hmharness/kernel';
|
|
2
|
+
export declare function sendNotification(home: string, channelName: string, text: string): Promise<{
|
|
3
|
+
ok: boolean;
|
|
4
|
+
detail: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const opsNotify: Tool;
|
|
7
|
+
export declare const channelTools: Tool[];
|
package/dist/channel.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/domain-ops - channel (message notifications, the codelin channel gap)
|
|
3
|
+
* Minimal honest version: a webhook notifier. Feishu (飞书) and DingTalk
|
|
4
|
+
* (钉钉) custom-bot webhooks plus any generic JSON POST URL. The agent can
|
|
5
|
+
* report task completion / build failures / device-test results to a chat
|
|
6
|
+
* from inside the loop - "tell me when the emulator install finishes".
|
|
7
|
+
* Config lives in HMH_HOME (webhook URLs are secrets-adjacent):
|
|
8
|
+
* config.json -> channels: { name: { type: 'feishu'|'dingtalk'|'json', url, secret? } }
|
|
9
|
+
* Feishu sign: HMAC-SHA256(timestamp + "\n" + secret) base64 - their spec.
|
|
10
|
+
*/
|
|
11
|
+
import { createHmac } from 'node:crypto';
|
|
12
|
+
import { readFile } from 'node:fs/promises';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
function feishuSign(secret, timestamp) {
|
|
15
|
+
const hmac = createHmac('sha256', Buffer.from(timestamp + '\n' + secret, 'utf8'));
|
|
16
|
+
return hmac.update('').digest('base64');
|
|
17
|
+
}
|
|
18
|
+
function dingtalkSignedUrl(url, secret) {
|
|
19
|
+
const ts = Date.now();
|
|
20
|
+
const mac = createHmac('sha256', secret).update(`${ts}\n${secret}`).digest('base64');
|
|
21
|
+
const u = new URL(url);
|
|
22
|
+
u.searchParams.set('timestamp', String(ts));
|
|
23
|
+
u.searchParams.set('sign', encodeURIComponent(mac));
|
|
24
|
+
return u.toString();
|
|
25
|
+
}
|
|
26
|
+
async function sendOne(ch, text) {
|
|
27
|
+
try {
|
|
28
|
+
let url = ch.url;
|
|
29
|
+
const body = {};
|
|
30
|
+
if (ch.type === 'feishu') {
|
|
31
|
+
const timestamp = Date.now();
|
|
32
|
+
if (ch.secret) {
|
|
33
|
+
body.timestamp = String(timestamp);
|
|
34
|
+
body.sign = feishuSign(ch.secret, timestamp);
|
|
35
|
+
}
|
|
36
|
+
body.msg_type = 'text';
|
|
37
|
+
body.content = { text };
|
|
38
|
+
}
|
|
39
|
+
else if (ch.type === 'dingtalk') {
|
|
40
|
+
if (ch.secret)
|
|
41
|
+
url = dingtalkSignedUrl(url, ch.secret);
|
|
42
|
+
body.msgtype = 'text';
|
|
43
|
+
body.text = { content: text };
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
body.text = text;
|
|
47
|
+
body.time = new Date().toISOString();
|
|
48
|
+
}
|
|
49
|
+
const res = await fetch(url, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: { 'Content-Type': 'application/json' },
|
|
52
|
+
body: JSON.stringify(body),
|
|
53
|
+
signal: AbortSignal.timeout(10_000),
|
|
54
|
+
});
|
|
55
|
+
const out = await res.text();
|
|
56
|
+
const ok = res.ok && !/"errcode":\s*[1-9]/.test(out); // feishu/dingtalk use errcode in 200s
|
|
57
|
+
return { ok, detail: out.slice(0, 200) };
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
return { ok: false, detail: String(err).slice(0, 200) };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export async function sendNotification(home, channelName, text) {
|
|
64
|
+
let cfg;
|
|
65
|
+
try {
|
|
66
|
+
cfg = JSON.parse(await readFile(join(home, 'config.json'), 'utf8'));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// no config at all = nothing configured (same hint; file-absent is the
|
|
70
|
+
// common first-run case, not an error state)
|
|
71
|
+
cfg = {};
|
|
72
|
+
}
|
|
73
|
+
const ch = cfg.channels?.[channelName];
|
|
74
|
+
if (!ch) {
|
|
75
|
+
return { ok: false, detail: `channel "${channelName}" not configured. Add to config.json: channels: { ${JSON.stringify(channelName)}: { type: 'feishu'|'dingtalk'|'json', url, secret? } }` };
|
|
76
|
+
}
|
|
77
|
+
return sendOne(ch, text);
|
|
78
|
+
}
|
|
79
|
+
export const opsNotify = {
|
|
80
|
+
name: 'ops_notify',
|
|
81
|
+
description: 'Send a notification to a configured chat channel (Feishu/DingTalk custom bot or generic JSON webhook). Configure once in HMH_HOME config.json: channels: { name: { type, url, secret? } }. Use to report task completion, build results, device-test verdicts - "tell me when it finishes".',
|
|
82
|
+
parameters: {
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: {
|
|
85
|
+
channel: { type: 'string', description: 'configured channel name from config.json channels' },
|
|
86
|
+
text: { type: 'string', description: 'the message text to deliver' },
|
|
87
|
+
},
|
|
88
|
+
required: ['channel', 'text'],
|
|
89
|
+
},
|
|
90
|
+
needsApproval: () => true, // outbound message = visible side effect
|
|
91
|
+
async execute(args) {
|
|
92
|
+
const name = String(args.channel ?? '').trim();
|
|
93
|
+
const text = String(args.text ?? '').trim();
|
|
94
|
+
if (!name || !text)
|
|
95
|
+
return { output: 'channel and text required', isError: true };
|
|
96
|
+
const { homeDir } = await import('@hmharness/kernel');
|
|
97
|
+
const r = await sendNotification(homeDir(), name, text);
|
|
98
|
+
return {
|
|
99
|
+
output: r.ok ? `notified ${name}: ${text.slice(0, 80)}` : `notify ${name} failed: ${r.detail}`,
|
|
100
|
+
isError: !r.ok,
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
export const channelTools = [opsNotify];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type ProviderConfig, type Tool } from '@hmharness/kernel';
|
|
2
|
+
export interface RadarSource {
|
|
3
|
+
key: string;
|
|
4
|
+
kind: 'gitee-releases' | 'github-tags';
|
|
5
|
+
repo: string;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
export interface RadarItem {
|
|
9
|
+
id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
url: string;
|
|
12
|
+
date: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ScanReport {
|
|
15
|
+
time: string;
|
|
16
|
+
baseline: boolean;
|
|
17
|
+
sources: Array<{
|
|
18
|
+
key: string;
|
|
19
|
+
ok: boolean;
|
|
20
|
+
count: number;
|
|
21
|
+
error?: string;
|
|
22
|
+
}>;
|
|
23
|
+
newItems: Array<{
|
|
24
|
+
source: string;
|
|
25
|
+
item: RadarItem;
|
|
26
|
+
}>;
|
|
27
|
+
brief: string;
|
|
28
|
+
briefMode: 'model' | 'template' | 'none';
|
|
29
|
+
}
|
|
30
|
+
declare const DEFAULT_SOURCES: RadarSource[];
|
|
31
|
+
export declare function scanRadar(opts: {
|
|
32
|
+
home: string;
|
|
33
|
+
provider: ProviderConfig;
|
|
34
|
+
sources?: RadarSource[];
|
|
35
|
+
}): Promise<ScanReport>;
|
|
36
|
+
export declare function latestBrief(home: string): Promise<{
|
|
37
|
+
date: string;
|
|
38
|
+
text: string;
|
|
39
|
+
} | null>;
|
|
40
|
+
export declare function opsStatus(home: string): Promise<{
|
|
41
|
+
scans: number;
|
|
42
|
+
lastScan?: string;
|
|
43
|
+
sources: string[];
|
|
44
|
+
}>;
|
|
45
|
+
export declare const harmonyOpsRadarScan: Tool;
|
|
46
|
+
export declare const harmonyOpsRadarBrief: Tool;
|
|
47
|
+
export declare const harmonyOpsStatus: Tool;
|
|
48
|
+
export declare const opsTools: Tool[];
|
|
49
|
+
export { DEFAULT_SOURCES };
|
|
50
|
+
export { harmonyOpsIssueList, harmonyOpsIssueView, harmonyOpsIssueCreate, harmonyOpsIssueComment, harmonyOpsPrDraft } from './issues.ts';
|
|
51
|
+
export { opsNotify, sendNotification, channelTools } from './channel.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/domain-ops
|
|
3
|
+
* The ops keeper (hm-keeper successor, rewritten per the behavior spec
|
|
4
|
+
* captured in docs/MIGRATION-ASSESSMENT.md):
|
|
5
|
+
* - ecosystem radar: pull OpenHarmony release sources -> diff against the
|
|
6
|
+
* last snapshot -> Chinese brief via the model, DEGRADING to a template
|
|
7
|
+
* brief when the model is unreachable
|
|
8
|
+
* - one failing source never kills the scan
|
|
9
|
+
* - everything lands under HMH_HOME/ops/ (snapshots, briefs, scan log)
|
|
10
|
+
* All network fetches are zero-dependency native fetch with per-source
|
|
11
|
+
* timeouts. The issue-flow half of the old keeper is deliberately deferred
|
|
12
|
+
* until a GitHub MCP server is configured - borrow the ecosystem, don't
|
|
13
|
+
* rebuild API clients.
|
|
14
|
+
*/
|
|
15
|
+
import { mkdir, readFile, readdir, writeFile, appendFile } from 'node:fs/promises';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import { chat } from '@hmharness/kernel';
|
|
18
|
+
import { issueTools } from "./issues.js";
|
|
19
|
+
import { channelTools } from "./channel.js";
|
|
20
|
+
const DEFAULT_SOURCES = [
|
|
21
|
+
{ key: 'oh-docs', kind: 'gitee-releases', repo: 'openharmony/docs', label: 'OpenHarmony 文档/版本发布' },
|
|
22
|
+
{ key: 'oh-ace', kind: 'github-tags', repo: 'openharmony/arkui_ace_engine', label: 'ArkUI 框架' },
|
|
23
|
+
{ key: 'oh-ets', kind: 'github-tags', repo: 'openharmony/arkcompiler_ets_frontend', label: 'ArkTS/方舟编译器' },
|
|
24
|
+
{ key: 'oh-ability', kind: 'github-tags', repo: 'openharmony/ability_ability_runtime', label: 'Ability 运行时' },
|
|
25
|
+
];
|
|
26
|
+
function opsDir(home) {
|
|
27
|
+
return join(home, 'ops');
|
|
28
|
+
}
|
|
29
|
+
async function fetchJson(url, timeoutMs = 15_000) {
|
|
30
|
+
const ctrl = new AbortController();
|
|
31
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
32
|
+
try {
|
|
33
|
+
const res = await fetch(url, {
|
|
34
|
+
signal: ctrl.signal,
|
|
35
|
+
headers: { 'User-Agent': 'hmharness-radar/0.1', Accept: 'application/json' },
|
|
36
|
+
});
|
|
37
|
+
if (!res.ok)
|
|
38
|
+
throw new Error(`HTTP ${res.status}`);
|
|
39
|
+
return await res.json();
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function fetchSource(src) {
|
|
46
|
+
if (src.kind === 'gitee-releases') {
|
|
47
|
+
const data = (await fetchJson(`https://gitee.com/api/v5/repos/${src.repo}/releases?per_page=5`));
|
|
48
|
+
return data.map((r) => ({
|
|
49
|
+
id: r.tag_name ?? String(r.name),
|
|
50
|
+
title: `${src.label}: ${r.name || r.tag_name}`,
|
|
51
|
+
url: r.html_url ?? `https://gitee.com/${src.repo}/releases`,
|
|
52
|
+
date: (r.created_at ?? '').slice(0, 10),
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
const data = (await fetchJson(`https://api.github.com/repos/${src.repo}/tags?per_page=5`));
|
|
56
|
+
return data.map((t) => ({
|
|
57
|
+
id: t.name,
|
|
58
|
+
title: `${src.label}: ${t.name}`,
|
|
59
|
+
url: `https://github.com/${src.repo}/tags`,
|
|
60
|
+
date: '',
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
async function loadSnapshot(home) {
|
|
64
|
+
try {
|
|
65
|
+
return JSON.parse(await readFile(join(opsDir(home), 'radar-snapshot.json'), 'utf8'));
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** Template fallback brief - the old keeper's degradation spec, verbatim in spirit. */
|
|
72
|
+
function templateBrief(report) {
|
|
73
|
+
const lines = [`# 生态雷达简报(模板拼接·模型不可达)`, '', `时间:${report.time}`];
|
|
74
|
+
if (report.baseline) {
|
|
75
|
+
lines.push('', '本次为初次基线扫描,记录当前各源最新条目,不做变更分析。');
|
|
76
|
+
}
|
|
77
|
+
lines.push('', '## 变更条目');
|
|
78
|
+
if (report.newItems.length === 0)
|
|
79
|
+
lines.push('(无新增)');
|
|
80
|
+
for (const n of report.newItems.slice(0, 20))
|
|
81
|
+
lines.push(`- ${n.item.title}${n.item.url ? ` (${n.item.url})` : ''}`);
|
|
82
|
+
lines.push('', '## 源健康');
|
|
83
|
+
for (const s of report.sources)
|
|
84
|
+
lines.push(`- ${s.key}: ${s.ok ? `ok (${s.count} 条)` : `FAIL ${s.error ?? ''}`}`);
|
|
85
|
+
lines.push('', '## 影响面建议(模板)', '- 有 OpenHarmony 大版本发布时:检查 compatibleSdkVersion 是否需要跟进;ArkUI/ArkTS 源有发布时:关注 API 变更公告。');
|
|
86
|
+
return lines.join('\n');
|
|
87
|
+
}
|
|
88
|
+
async function modelBrief(provider, partial) {
|
|
89
|
+
const system = [
|
|
90
|
+
'你是 hmharness 的生态雷达编辑。根据 OpenHarmony 生态各源的变更条目写一份简明的中文简报(markdown)。',
|
|
91
|
+
'结构:## 摘要(2-3 句)、## 值得关注(逐条:变更是什么+对鸿蒙应用开发者可能的影响)、## 建议(是否需要行动)。',
|
|
92
|
+
'只依据给到的条目,不编造;条目为空就写"本期无变更";保持简短(300 字内)。',
|
|
93
|
+
].join('\n');
|
|
94
|
+
const user = JSON.stringify({ baseline: partial.baseline, newItems: partial.newItems.slice(0, 20), sources: partial.sources }, null, 2);
|
|
95
|
+
try {
|
|
96
|
+
const r = await chat(provider, [
|
|
97
|
+
{ role: 'system', content: system },
|
|
98
|
+
{ role: 'user', content: user },
|
|
99
|
+
], undefined, { timeoutMs: 90_000 });
|
|
100
|
+
const text = (r.message.content ?? '').trim();
|
|
101
|
+
return text.length > 40 ? text : null;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export async function scanRadar(opts) {
|
|
108
|
+
const home = opts.home;
|
|
109
|
+
const sources = opts.sources && opts.sources.length > 0 ? opts.sources : DEFAULT_SOURCES;
|
|
110
|
+
await mkdir(join(opsDir(home), 'briefs'), { recursive: true });
|
|
111
|
+
const prev = await loadSnapshot(home);
|
|
112
|
+
const baseline = prev === null;
|
|
113
|
+
const sourceStates = [];
|
|
114
|
+
const newItems = [];
|
|
115
|
+
const seen = {};
|
|
116
|
+
await Promise.all(sources.map(async (src) => {
|
|
117
|
+
try {
|
|
118
|
+
const items = await fetchSource(src);
|
|
119
|
+
seen[src.key] = items.map((i) => i.id);
|
|
120
|
+
if (!baseline) {
|
|
121
|
+
const prevIds = new Set(prev.seen[src.key] ?? []);
|
|
122
|
+
for (const item of items)
|
|
123
|
+
if (!prevIds.has(item.id))
|
|
124
|
+
newItems.push({ source: src.label, item });
|
|
125
|
+
}
|
|
126
|
+
sourceStates.push({ key: src.key, ok: true, count: items.length });
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
// single-source failure never kills the scan
|
|
130
|
+
sourceStates.push({ key: src.key, ok: false, count: 0, error: String(err).slice(0, 120) });
|
|
131
|
+
seen[src.key] = prev?.seen[src.key] ?? [];
|
|
132
|
+
}
|
|
133
|
+
}));
|
|
134
|
+
const partial = {
|
|
135
|
+
time: new Date().toISOString().slice(0, 19).replace('T', ' '),
|
|
136
|
+
baseline,
|
|
137
|
+
sources: sourceStates.sort((a, b) => a.key.localeCompare(b.key)),
|
|
138
|
+
newItems: newItems.slice(0, 30),
|
|
139
|
+
};
|
|
140
|
+
let brief;
|
|
141
|
+
let briefMode;
|
|
142
|
+
if (baseline) {
|
|
143
|
+
brief = templateBrief(partial);
|
|
144
|
+
briefMode = 'none';
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
const mb = await modelBrief(opts.provider, partial);
|
|
148
|
+
if (mb) {
|
|
149
|
+
brief = mb;
|
|
150
|
+
briefMode = 'model';
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
brief = templateBrief(partial);
|
|
154
|
+
briefMode = 'template';
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const report = { ...partial, brief, briefMode };
|
|
158
|
+
await writeFile(join(opsDir(home), 'radar-snapshot.json'), JSON.stringify({ time: partial.time, seen }, null, 2), 'utf8');
|
|
159
|
+
await writeFile(join(opsDir(home), 'briefs', `${partial.time.slice(0, 10)}.md`), brief + '\n', 'utf8');
|
|
160
|
+
await appendFile(join(opsDir(home), 'ops-log.jsonl'), JSON.stringify({
|
|
161
|
+
time: partial.time, baseline, briefMode,
|
|
162
|
+
sources: partial.sources.map((s) => ({ key: s.key, ok: s.ok })),
|
|
163
|
+
newCount: partial.newItems.length,
|
|
164
|
+
}) + '\n', 'utf8');
|
|
165
|
+
return report;
|
|
166
|
+
}
|
|
167
|
+
export async function latestBrief(home) {
|
|
168
|
+
try {
|
|
169
|
+
const files = (await readdir(join(opsDir(home), 'briefs'))).filter((f) => f.endsWith('.md')).sort();
|
|
170
|
+
const last = files[files.length - 1];
|
|
171
|
+
if (!last)
|
|
172
|
+
return null;
|
|
173
|
+
return { date: last.replace(/\.md$/, ''), text: await readFile(join(opsDir(home), 'briefs', last), 'utf8') };
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
export async function opsStatus(home) {
|
|
180
|
+
const lines = (await readFile(join(opsDir(home), 'ops-log.jsonl'), 'utf8').catch(() => '')).trim().split('\n').filter(Boolean);
|
|
181
|
+
const last = lines[lines.length - 1];
|
|
182
|
+
return {
|
|
183
|
+
scans: lines.length,
|
|
184
|
+
lastScan: last ? JSON.parse(last).time : undefined,
|
|
185
|
+
sources: DEFAULT_SOURCES.map((s) => s.key),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/* ------------------------------------------------------------------ */
|
|
189
|
+
/* Agent tools */
|
|
190
|
+
/* ------------------------------------------------------------------ */
|
|
191
|
+
async function resolveProvider() {
|
|
192
|
+
const { loadConfig } = await import('@hmharness/kernel');
|
|
193
|
+
return (await loadConfig()).provider;
|
|
194
|
+
}
|
|
195
|
+
export const harmonyOpsRadarScan = {
|
|
196
|
+
name: 'harmony_ops_radar_scan',
|
|
197
|
+
description: 'Scan the OpenHarmony/HarmonyOS ecosystem radar: pull release feeds (OpenHarmony docs/ArkUI/ArkTS/Ability runtime), diff against the last snapshot, and produce a Chinese brief (model-written, template fallback when the model is down). Read-only for the outside world; results land under HMH_HOME/ops/.',
|
|
198
|
+
parameters: { type: 'object', properties: {}, required: [] },
|
|
199
|
+
async execute(_args, ctx) {
|
|
200
|
+
const provider = await resolveProvider();
|
|
201
|
+
const r = await scanRadar({ home: ctx.home, provider });
|
|
202
|
+
const head = [
|
|
203
|
+
`scan ${r.time} · ${r.baseline ? 'BASELINE (first scan)' : `${r.newItems.length} new items`}`,
|
|
204
|
+
`sources: ${r.sources.map((s) => `${s.key}:${s.ok ? 'ok' : 'FAIL'}`).join(' ')}`,
|
|
205
|
+
`brief mode: ${r.briefMode}`,
|
|
206
|
+
'',
|
|
207
|
+
].join('\n');
|
|
208
|
+
return { output: (head + r.brief).slice(0, 20_000) };
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
export const harmonyOpsRadarBrief = {
|
|
212
|
+
name: 'harmony_ops_radar_brief',
|
|
213
|
+
description: 'Read the latest saved ecosystem radar brief (markdown).',
|
|
214
|
+
parameters: { type: 'object', properties: {}, required: [] },
|
|
215
|
+
async execute(_args, ctx) {
|
|
216
|
+
const b = await latestBrief(ctx.home);
|
|
217
|
+
return b ? { output: `(${b.date})\n${b.text}`.slice(0, 20_000) } : { output: 'No brief yet - run harmony_ops_radar_scan first.', isError: true };
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
export const harmonyOpsStatus = {
|
|
221
|
+
name: 'harmony_ops_status',
|
|
222
|
+
description: 'Ops keeper status: scan count, last scan time, watched sources.',
|
|
223
|
+
parameters: { type: 'object', properties: {}, required: [] },
|
|
224
|
+
async execute(_args, ctx) {
|
|
225
|
+
const s = await opsStatus(ctx.home);
|
|
226
|
+
return { output: `scans: ${s.scans}${s.lastScan ? ` · last: ${s.lastScan}` : ''}\nsources: ${s.sources.join(', ')}` };
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
export const opsTools = [
|
|
230
|
+
harmonyOpsRadarScan,
|
|
231
|
+
harmonyOpsRadarBrief,
|
|
232
|
+
harmonyOpsStatus,
|
|
233
|
+
...issueTools,
|
|
234
|
+
...channelTools,
|
|
235
|
+
];
|
|
236
|
+
export { DEFAULT_SOURCES };
|
|
237
|
+
export { harmonyOpsIssueList, harmonyOpsIssueView, harmonyOpsIssueCreate, harmonyOpsIssueComment, harmonyOpsPrDraft } from "./issues.js";
|
|
238
|
+
export { opsNotify, sendNotification, channelTools } from "./channel.js";
|
package/dist/issues.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Tool } from '@hmharness/kernel';
|
|
2
|
+
export declare const harmonyOpsIssueList: Tool;
|
|
3
|
+
export declare const harmonyOpsIssueView: Tool;
|
|
4
|
+
export declare const harmonyOpsIssueCreate: Tool;
|
|
5
|
+
export declare const harmonyOpsIssueComment: Tool;
|
|
6
|
+
export declare const harmonyOpsPrDraft: Tool;
|
|
7
|
+
export declare const issueTools: Tool[];
|
package/dist/issues.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/domain-ops - issues (keeper v2)
|
|
3
|
+
* The issue half of the old hm-keeper, on the gh CLI instead of hand-rolled
|
|
4
|
+
* API clients. Behavior spec preserved from the old line (see
|
|
5
|
+
* docs/MIGRATION-ASSESSMENT.md):
|
|
6
|
+
* - AI only DRAFTS; every publication (comment / new issue / PR) goes
|
|
7
|
+
* through the kernel approval gate - the y/N prompt IS the old
|
|
8
|
+
* "user approved issue <n>" exact-phrase gate, mechanically stricter.
|
|
9
|
+
* - published content always carries the keeper identity footer.
|
|
10
|
+
* - PRs open in draft mode with a plan card body.
|
|
11
|
+
*/
|
|
12
|
+
import { execFile } from 'node:child_process';
|
|
13
|
+
import { promisify } from 'node:util';
|
|
14
|
+
const exec = promisify(execFile);
|
|
15
|
+
const KEEPER_FOOTER = '\n\n---\n_via hmh-keeper (hmharness · draft by AI, published with human approval)_';
|
|
16
|
+
async function gh(args, timeoutMs = 60_000) {
|
|
17
|
+
try {
|
|
18
|
+
const { stdout, stderr } = await exec('gh', args, { timeout: timeoutMs, windowsHide: true, maxBuffer: 8 * 1024 * 1024 });
|
|
19
|
+
return { ok: true, out: (stdout || stderr || '(no output)').trim() };
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
const e = err;
|
|
23
|
+
return { ok: false, out: [e.stderr, e.stdout, e.message].filter(Boolean).join('\n').slice(0, 2000) };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function parseRepo(repo) {
|
|
27
|
+
const r = repo.trim();
|
|
28
|
+
if (!/^[\w.-]+\/[\w.-]+$/.test(r)) {
|
|
29
|
+
throw new Error(`repo must look like owner/name, got "${r}"`);
|
|
30
|
+
}
|
|
31
|
+
return r;
|
|
32
|
+
}
|
|
33
|
+
export const harmonyOpsIssueList = {
|
|
34
|
+
name: 'harmony_ops_issue_list',
|
|
35
|
+
description: 'List GitHub issues for a repo (owner/name) via gh. Read-only. Returns number, title, author, updated time as JSON lines. Draft input for issue triage - pair with harmony_ops_issue_view before proposing replies.',
|
|
36
|
+
parameters: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
repo: { type: 'string', description: 'GitHub repo as owner/name' },
|
|
40
|
+
state: { type: 'string', description: 'open | closed | all (default open)' },
|
|
41
|
+
limit: { type: 'number', description: 'max issues (default 10, max 50)' },
|
|
42
|
+
},
|
|
43
|
+
required: ['repo'],
|
|
44
|
+
},
|
|
45
|
+
async execute(args) {
|
|
46
|
+
let repo;
|
|
47
|
+
try {
|
|
48
|
+
repo = parseRepo(String(args.repo));
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
return { output: String(err), isError: true };
|
|
52
|
+
}
|
|
53
|
+
const state = ['open', 'closed', 'all'].includes(String(args.state)) ? String(args.state) : 'open';
|
|
54
|
+
const limit = Math.min(Math.max(Number(args.limit ?? 10), 1), 50);
|
|
55
|
+
const r = await gh([
|
|
56
|
+
'issue', 'list', '-R', repo,
|
|
57
|
+
'--state', state, '--limit', String(limit),
|
|
58
|
+
'--json', 'number,title,state,author,updatedAt',
|
|
59
|
+
]);
|
|
60
|
+
if (!r.ok)
|
|
61
|
+
return { output: `gh failed (is gh authenticated?):\n${r.out}`, isError: true };
|
|
62
|
+
const items = JSON.parse(r.out);
|
|
63
|
+
if (items.length === 0)
|
|
64
|
+
return { output: `No ${state} issues in ${repo}.` };
|
|
65
|
+
return { output: items.map((i) => `#${i.number} [${i.state}] ${i.title} — @${i.author?.login ?? '?'} · ${i.updatedAt?.slice(0, 10) ?? ''}`).join('\n') };
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
export const harmonyOpsIssueView = {
|
|
69
|
+
name: 'harmony_ops_issue_view',
|
|
70
|
+
description: 'Read one GitHub issue with its comments (gh issue view). Read-only.',
|
|
71
|
+
parameters: {
|
|
72
|
+
type: 'object',
|
|
73
|
+
properties: {
|
|
74
|
+
repo: { type: 'string', description: 'GitHub repo as owner/name' },
|
|
75
|
+
number: { type: 'number', description: 'issue number' },
|
|
76
|
+
},
|
|
77
|
+
required: ['repo', 'number'],
|
|
78
|
+
},
|
|
79
|
+
async execute(args) {
|
|
80
|
+
let repo;
|
|
81
|
+
try {
|
|
82
|
+
repo = parseRepo(String(args.repo));
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
return { output: String(err), isError: true };
|
|
86
|
+
}
|
|
87
|
+
const r = await gh(['issue', 'view', String(Number(args.number)), '-R', repo, '--json', 'number,title,state,body,comments,author']);
|
|
88
|
+
if (!r.ok)
|
|
89
|
+
return { output: r.out, isError: true };
|
|
90
|
+
const i = JSON.parse(r.out);
|
|
91
|
+
const comments = (i.comments ?? []).map((c, idx) => `--- comment ${idx + 1} @${c.author?.login ?? '?'} ---\n${c.body}`).join('\n\n');
|
|
92
|
+
return { output: `#${i.number} [${i.state}] ${i.title} (by @${i.author?.login ?? '?'})\n\n${i.body ?? '(empty body)'}\n\n${comments || '(no comments)'}`.slice(0, 20_000) };
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
export const harmonyOpsIssueCreate = {
|
|
96
|
+
name: 'harmony_ops_issue_create',
|
|
97
|
+
description: 'Create a GitHub issue (PUBLICATION - requires human approval via the gate). AI drafts the title/body; the approval prompt is the publication decision. A keeper identity footer is appended automatically.',
|
|
98
|
+
parameters: {
|
|
99
|
+
type: 'object',
|
|
100
|
+
properties: {
|
|
101
|
+
repo: { type: 'string', description: 'GitHub repo as owner/name' },
|
|
102
|
+
title: { type: 'string', description: 'issue title' },
|
|
103
|
+
body: { type: 'string', description: 'issue body markdown (the draft)' },
|
|
104
|
+
},
|
|
105
|
+
required: ['repo', 'title', 'body'],
|
|
106
|
+
},
|
|
107
|
+
needsApproval: () => true,
|
|
108
|
+
async execute(args) {
|
|
109
|
+
let repo;
|
|
110
|
+
try {
|
|
111
|
+
repo = parseRepo(String(args.repo));
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
return { output: String(err), isError: true };
|
|
115
|
+
}
|
|
116
|
+
const r = await gh(['issue', 'create', '-R', repo, '--title', String(args.title), '--body', String(args.body) + KEEPER_FOOTER]);
|
|
117
|
+
if (!r.ok)
|
|
118
|
+
return { output: r.out, isError: true };
|
|
119
|
+
return { output: `created: ${r.out}` };
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
export const harmonyOpsIssueComment = {
|
|
123
|
+
name: 'harmony_ops_issue_comment',
|
|
124
|
+
description: 'Comment on a GitHub issue (PUBLICATION - requires human approval via the gate). Never closes, never edits others\' comments; keeper identity footer appended automatically.',
|
|
125
|
+
parameters: {
|
|
126
|
+
type: 'object',
|
|
127
|
+
properties: {
|
|
128
|
+
repo: { type: 'string', description: 'GitHub repo as owner/name' },
|
|
129
|
+
number: { type: 'number', description: 'issue number' },
|
|
130
|
+
body: { type: 'string', description: 'comment markdown (the AI draft)' },
|
|
131
|
+
},
|
|
132
|
+
required: ['repo', 'number', 'body'],
|
|
133
|
+
},
|
|
134
|
+
needsApproval: () => true,
|
|
135
|
+
async execute(args) {
|
|
136
|
+
let repo;
|
|
137
|
+
try {
|
|
138
|
+
repo = parseRepo(String(args.repo));
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
return { output: String(err), isError: true };
|
|
142
|
+
}
|
|
143
|
+
const r = await gh(['issue', 'comment', String(Number(args.number)), '-R', repo, '--body', String(args.body) + KEEPER_FOOTER]);
|
|
144
|
+
if (!r.ok)
|
|
145
|
+
return { output: r.out, isError: true };
|
|
146
|
+
return { output: `commented: ${r.out}` };
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
export const harmonyOpsPrDraft = {
|
|
150
|
+
name: 'harmony_ops_pr_draft',
|
|
151
|
+
description: 'Open a DRAFT pull request (PUBLICATION - requires human approval). Always --draft; the body becomes the plan card (what/why/how to test). Keeper identity footer appended.',
|
|
152
|
+
parameters: {
|
|
153
|
+
type: 'object',
|
|
154
|
+
properties: {
|
|
155
|
+
repo: { type: 'string', description: 'GitHub repo as owner/name' },
|
|
156
|
+
title: { type: 'string', description: 'PR title' },
|
|
157
|
+
body: { type: 'string', description: 'plan card: what / why / how to test' },
|
|
158
|
+
head: { type: 'string', description: 'head branch with the changes' },
|
|
159
|
+
base: { type: 'string', description: 'base branch (default main)' },
|
|
160
|
+
},
|
|
161
|
+
required: ['repo', 'title', 'body', 'head'],
|
|
162
|
+
},
|
|
163
|
+
needsApproval: () => true,
|
|
164
|
+
async execute(args) {
|
|
165
|
+
let repo;
|
|
166
|
+
try {
|
|
167
|
+
repo = parseRepo(String(args.repo));
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
return { output: String(err), isError: true };
|
|
171
|
+
}
|
|
172
|
+
const r = await gh([
|
|
173
|
+
'pr', 'create', '-R', repo, '--draft',
|
|
174
|
+
'--title', String(args.title),
|
|
175
|
+
'--body', String(args.body) + KEEPER_FOOTER,
|
|
176
|
+
'--head', String(args.head),
|
|
177
|
+
'--base', String(args.base ?? 'main'),
|
|
178
|
+
]);
|
|
179
|
+
if (!r.ok)
|
|
180
|
+
return { output: r.out, isError: true };
|
|
181
|
+
return { output: `draft PR opened: ${r.out}` };
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
export const issueTools = [harmonyOpsIssueList, harmonyOpsIssueView, harmonyOpsIssueCreate, harmonyOpsIssueComment, harmonyOpsPrDraft];
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hmharness/domain-ops",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "hmharness ops keeper: ecosystem radar (OpenHarmony release tracking, snapshot diff, model brief with template fallback). Rewrite of the old line's hm-keeper per its captured behavior spec.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.build.json"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@hmharness/kernel": "0.1.0"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/swsgbl/hmharness.git"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22"
|
|
30
|
+
}
|
|
31
|
+
}
|