Skip to content

[WIP] Add doc-analyst GitHub Copilot extension to repository - #2

Merged
HarrisConsulting merged 6 commits into
mainfrom
copilot/add-doc-analyst-extension
May 11, 2026
Merged

HarrisConsulting merged 6 commits into
mainfrom
copilot/add-doc-analyst-extension

Conversation

Copilot AI commented May 11, 2026 •

Copy link
Copy Markdown
Contributor
  • Inspect the repository structure, existing tooling, and recent GitHub Actions runs
  • Confirm there is no existing root TypeScript/test infrastructure to reuse
  • Add the project-agnostic copilot-extension/ service files at the repository root, migrated from HarrisConsulting/NewSchoolConnect#618
  • Run npm install inside copilot-extension/ to generate a lockfile and install the scoped dependencies
  • Validate the new extension with targeted build/lint commands inside copilot-extension/
  • Add the dedicated .github/workflows/copilot-extension-ci.yml workflow for the extension
  • Review the final diff for minimal scope and address automated validation feedback
  • Re-run final automated validation after the last code review improvement
Original prompt

Overview

Add the doc-analyst GitHub Copilot Extension to this repository as a reusable, project-agnostic service. This extension was originally built for NewSchoolConnect but belongs here in business-assets-toolkit since it is applicable across all projects.

Place all files under copilot-extension/ at the root of the repository.


File Structure to Create

copilot-extension/
  src/
    index.ts
    handlers/
      agentHandler.ts
    skills/
      ingest.ts
      summarize.ts
      query.ts
      themes.ts
    utils/
      chunker.ts
      openai.ts
      store.ts
      parser.ts
  .env.example
  .gitignore
  package.json
  tsconfig.json
  Dockerfile
  README.md

Also add: .github/workflows/copilot-extension-ci.yml


Exact File Contents

copilot-extension/package.json

{
  "name": "doc-analyst",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "ts-node-dev --respawn src/index.ts",
    "build": "tsc",
    "start": "node dist/index.js",
    "lint": "eslint src"
  },
  "dependencies": {
    "@copilot-extensions/preview-sdk": "^5.0.1",
    "dotenv": "^16.4.5",
    "express": "^4.19.2",
    "openai": "^4.52.0",
    "tiktoken": "^1.0.15",
    "uuid": "^10.0.0"
  },
  "devDependencies": {
    "@types/express": "^4.17.21",
    "@types/node": "^20.0.0",
    "@types/uuid": "^10.0.0",
    "ts-node-dev": "^2.0.0",
    "typescript": "^5.4.0"
  }
}

copilot-extension/tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "lib": ["ES2020"],
    "rootDir": "src",
    "outDir": "dist",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": false,
    "types": ["node"],
    "allowJs": false,
    "allowImportingTsExtensions": false,
    "resolveJsonModule": true
  },
  "include": ["src/**/*"]
}

copilot-extension/.env.example

OPENAI_API_KEY=sk-...
PORT=3000

copilot-extension/.gitignore

node_modules/
dist/
.env

copilot-extension/Dockerfile

FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY dist ./dist
EXPOSE 3000
CMD ["node", "dist/index.js"]

copilot-extension/README.md

# doc-analyst — GitHub Copilot Extension

`doc-analyst` is a reusable GitHub Copilot Extension for long-document understanding. It can be used across any project — not tied to any specific application.

## What It Does

Invoke it in Copilot Chat with `@doc-analyst`:

| Command | What happens |
|---|---|
| `@doc-analyst ingest this: <paste text>` | Chunks & stores the document, returns a `document_id` |
| `@doc-analyst summarize doc <id>` | Multi-level GPT-4o summary (sentence / paragraph / full) |
| `@doc-analyst what does it say about X? doc <id>` | Grounded Q&A with chunk citations |
| `@doc-analyst extract themes from doc <id>` | Themes, entities, main argument, contradictions |

## Register as a GitHub Copilot Extension

Follow GitHub's official guide:
https://docs.github.com/en/copilot/building-copilot-extensions

Set the GitHub App's Copilot Extension type to `agent` and point the callback URL to your deployed service.

## Local Development

```bash
cd copilot-extension
npm install
cp .env.example .env   # add your OPENAI_API_KEY
npm run dev

Health check:

curl http://localhost:3000/
# {"status":"ok","extension":"doc-analyst"}

Build & Run

npm run build
npm run start

Docker

npm run build
docker build -t doc-analyst .
docker run --rm -p 3000:3000 --env-file .env doc-analyst

Environment Variables

Variable Required Description
OPENAI_API_KEY ✅ Your OpenAI API key
PORT ❌ Server port (default: 3000)

Notes

  • The document store is in-memory only and resets on service restart. For persistence, swap src/utils/store.ts with a Redis or database-backed implementation.
  • All dependencies are scoped to copilot-extension/ — this does not affect the root repository.

### `copilot-extension/src/index.ts`
```typescript
import * as copilotSdk from '@copilot-extensions/preview-sdk';
import dotenv from 'dotenv';
import express from 'express';
import { handleAgentMessages } from './handlers/agentHandler';
import type { CopilotMessage } from './utils/parser';

dotenv.config();

const sdk = copilotSdk as {
  createTextEvent?: (text: string) => unknown;
  createDoneEvent?: () => unknown;
};

const app = express();
app.use(express.json({ limit: '10mb' }));

const writeSse = (res: express.Response, payload: unknown): void => {
  res.write(`data: ${JSON.stringify(payload)}\n\n`);
};

const createTextPayload = (text: string): unknown => {
  if (sdk.createTextEvent) {
    return sdk.createTextEvent(text);
  }
  return { type: 'text', text };
};

const createDonePayload = (): unknown => {
  if (sdk.createDoneEvent) {
    return sdk.createDoneEvent();
  }
  retu...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

Copilot AI and others added 3 commits May 11, 2026 12:33
Agent-Logs-Url: https://github.com/HarrisConsulting/business-assets-toolkit/sessions/7983b453-e614-4bdf-86c7-df6c963535ea

Co-authored-by: HarrisConsulting <210942603+HarrisConsulting@users.noreply.github.com>
Agent-Logs-Url: https://github.com/HarrisConsulting/business-assets-toolkit/sessions/7983b453-e614-4bdf-86c7-df6c963535ea

Co-authored-by: HarrisConsulting <210942603+HarrisConsulting@users.noreply.github.com>
@HarrisConsulting
HarrisConsulting marked this pull request as ready for review May 11, 2026 12:36
Copilot AI and others added 2 commits May 11, 2026 12:36
Agent-Logs-Url: https://github.com/HarrisConsulting/business-assets-toolkit/sessions/7983b453-e614-4bdf-86c7-df6c963535ea

Co-authored-by: HarrisConsulting <210942603+HarrisConsulting@users.noreply.github.com>
Agent-Logs-Url: https://github.com/HarrisConsulting/business-assets-toolkit/sessions/7983b453-e614-4bdf-86c7-df6c963535ea

Co-authored-by: HarrisConsulting <210942603+HarrisConsulting@users.noreply.github.com>
@HarrisConsulting
HarrisConsulting merged commit d58f863 into main May 11, 2026
2 checks passed
@HarrisConsulting
HarrisConsulting deleted the copilot/add-doc-analyst-extension branch May 11, 2026 12:39
Copilot stopped work on behalf of HarrisConsulting due to an error May 11, 2026 12:40
Copilot AI requested a review from HarrisConsulting May 11, 2026 12:40

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1fae60e94e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +12 to +14
private readonly documents = new Map<string, DocumentRecord>();

private latestId: string | null = null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Scope documents to the requesting user

Because this store is process-global and records no GitHub user/session/installation ownership, every request shares the same latestId and document map. In a deployed Copilot extension with multiple users, a user who omits document_id after another user's ingest will query/summarize the other user's latest document, and any known UUID can be retrieved with get(id) without an owner check. Store documents under the authenticated identity or enforce owner matching on reads.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants