Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/m365-skill/offline-overlay.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# Offline changes for the M365 plugin's SKILL.md. `npm run build:m365` builds that SKILL.md from
# skills/microsoft-build/SKILL.md: each key here replaces the same frontmatter key (an empty value
# the repository's skill: each key here replaces the same frontmatter key (an empty value
# removes it), and the body below replaces the "## Session catalog access" section. The build
# script rewrites the rest of the skill for offline use; see SKILL_REWRITES in
# cli/scripts/build-m365-plugin.mjs.
Expand All @@ -11,7 +11,7 @@ compatibility: >-
come from the Microsoft Learn MCP Server or the agent's built-in web tools.
metadata:
author: Microsoft Learn partnerships team
domain: microsoft-build
domain: "{{SKILL_NAME}}"
snapshot: "{{SNAPSHOT_DATE}}"
msevents: "{{CLI_VERSION}}"
allowed-tools:
Expand Down
20 changes: 14 additions & 6 deletions cli/scripts/build-m365-plugin.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Builds the Microsoft 365 Copilot plugin (a Claude-format plugin folder for Cowork) with an offline
// session snapshot: skills/microsoft-build/{SKILL.md, scripts/msevents.mjs, data/<event>-*.json}.
// session snapshot: skills/<skill>/{SKILL.md, scripts/msevents.mjs, data/<event>-*.json}.
// scripts/msevents.mjs is the whole msevents CLI bundled into one file. Its banner turns on
// offline mode (MSEVENTS_OFFLINE) and points the cache at ../data, so data/ is a frozen cache.
// SKILL.md is the repo skill (skills/microsoft-build/SKILL.md) rewritten for offline use with
// SKILL.md is the repo skill rewritten for offline use with
// cli/m365-skill/offline-overlay.md. Run through `npm run build:m365` so dist/ is up to date.
import { execFile } from 'node:child_process';
import { existsSync } from 'node:fs';
import { existsSync, readdirSync } from 'node:fs';
import { mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { delimiter, dirname, isAbsolute, join, relative, resolve } from 'node:path';
Expand All @@ -17,19 +17,26 @@ import { KNOWN_EVENTS } from '../dist/config.js';
const execFileAsync = promisify(execFile);
const cliRoot = fileURLToPath(new URL('..', import.meta.url));
const repoRoot = resolve(cliRoot, '..');
const SKILL_NAME = 'microsoft-build';
const skillRoot = join(repoRoot, 'skills');
const skillNames = readdirSync(skillRoot, { withFileTypes: true })
.filter((entry) => entry.isDirectory() && existsSync(join(skillRoot, entry.name, 'SKILL.md')))
.map((entry) => entry.name);
if (skillNames.length !== 1) {
throw new Error(`Expected exactly one skill folder with SKILL.md under ${skillRoot}; found ${skillNames.length}`);
}
const SKILL_NAME = skillNames[0];
const SCRIPT_FILE = 'msevents.mjs';
const MB = 1024 * 1024;
// Cowork limits for files that ship next to SKILL.md.
const COMPANION_LIMITS = { files: 20, fileBytes: 5 * MB, totalBytes: 10 * MB };
const SKILL_DESCRIPTION_MAX_CHARS = 1024;
const SKILL_SOURCE = join(repoRoot, 'skills', SKILL_NAME, 'SKILL.md');
const SKILL_SOURCE = join(skillRoot, SKILL_NAME, 'SKILL.md');
const SKILL_OVERLAY = join(cliRoot, 'm365-skill', 'offline-overlay.md');
// The repo skill section that the overlay's body replaces.
const SKILL_SECTION = '## Session catalog access';

// Rewrites that turn the repo skill's online steps into offline ones. Each one must match, so a
// wording change in skills/microsoft-build/SKILL.md fails the build until this list is updated.
// wording change in the source SKILL.md fails the build until this list is updated.
const SKILL_REWRITES = [
{
find: /Uses the msevents CLI for fast local search and\s+Learn MCP Server for docs\./,
Expand Down Expand Up @@ -507,6 +514,7 @@ async function main() {
const snapshotDate = collected.map(({ meta }) => meta.fetchedAt).sort()[0].slice(0, 10);

const skill = buildSkill(await readFile(SKILL_SOURCE, 'utf8'), await readFile(SKILL_OVERLAY, 'utf8'), {
SKILL_NAME,
SNAPSHOT_DATE: snapshotDate,
CLI_VERSION: cliVersion,
SNAPSHOT_EVENTS: collected
Expand Down
16 changes: 11 additions & 5 deletions cli/scripts/smoke-m365-plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const commandTimeoutMs = 60_000;
const eventId = 'build-2025';
const isWindows = process.platform === 'win32';
const { values: options } = parseArgs({ options: { package: { type: 'boolean' } } });
const sourceSkillsDir = join(cliRoot, '..', 'skills');

function assert(condition, message) {
if (!condition) throw new Error(message);
Expand Down Expand Up @@ -44,6 +45,11 @@ async function listFiles(dir) {
.sort();
}

const sourceSkillDirs = (await readdir(sourceSkillsDir, { withFileTypes: true }))
.filter((entry) => entry.isDirectory());
assert(sourceSkillDirs.length === 1, `Expected one source skill folder, found ${sourceSkillDirs.length}`);
const skillName = sourceSkillDirs[0].name;

// Windows' built-in tar (bsdtar) reads zip files; a Git Bash tar earlier on PATH may not.
async function unzip(zip, dir) {
await mkdir(dir, { recursive: true });
Expand All @@ -58,9 +64,9 @@ const root = await mkdtemp(join(tmpdir(), 'msevents-m365-smoke-'));
const cacheDir = join(root, 'cache');
const emptyCacheDir = join(root, 'empty-cache');
const pluginDir = join(root, 'plugin');
const builtSkillDir = join(pluginDir, 'skills', 'microsoft-build');
const builtSkillDir = join(pluginDir, 'skills', skillName);
const unzippedDir = join(root, 'unzipped');
const skillDir = options.package ? join(unzippedDir, 'skills', 'microsoft-build') : builtSkillDir;
const skillDir = options.package ? join(unzippedDir, 'skills', skillName) : builtSkillDir;
const dataDir = join(skillDir, 'data');
const workDir = join(root, 'work');
const noNetwork = join(root, 'no-network.mjs');
Expand Down Expand Up @@ -101,8 +107,8 @@ try {
await unzip(join(`${pluginDir}-app`, 'appPackage', 'build', 'appPackage.zip'), unzippedDir);
const appManifest = JSON.parse(await readFile(join(unzippedDir, 'manifest.json'), 'utf8'));
assert(
appManifest.agentSkills?.some((s) => s.folder === './skills/microsoft-build'),
'Expected the app package manifest to register skills/microsoft-build',
appManifest.agentSkills?.some((s) => s.folder === `./skills/${skillName}`),
`Expected the app package manifest to register skills/${skillName}`,
);
const builtFiles = await listFiles(builtSkillDir);
const packedFiles = await listFiles(skillDir);
Expand All @@ -128,7 +134,7 @@ try {
assert(!text.includes('{{'), 'SKILL.md has unfilled placeholders');
assert(text.includes('2026-01-01'), 'Expected SKILL.md to show the snapshot date from the cache meta file');
assert(text.includes(`| \`${eventId}\` | ${sessions.length} |`), 'Expected SKILL.md to list the bundled event');
const repoSkill = (await readFile('../skills/microsoft-build/SKILL.md', 'utf8')).replace(/\r\n?/g, '\n');
const repoSkill = (await readFile(join(sourceSkillsDir, skillName, 'SKILL.md'), 'utf8')).replace(/\r\n?/g, '\n');
for (const heading of repoSkill.match(/^## .+$/gm)) {
assert(text.includes(`\n${heading}\n`), `Expected SKILL.md to keep the repo skill's "${heading}" section`);
}
Expand Down
Loading