Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/agentics-maintenance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ jobs:

validate_workflows:
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.operation == 'validate' && !github.event.repository.fork }}
runs-on: ubuntu-slim
runs-on: ubuntu-latest
permissions:
Comment on lines 282 to 285
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

This workflow job changes runs-on from ubuntu-slim to ubuntu-latest, but the PR description is focused on comment footers/effective token suffixes and doesn't mention a runner change. If this is intentional (e.g., ubuntu-slim is deprecated/unsupported for this job), please document the rationale in the PR description; otherwise consider reverting to keep runner usage consistent with the rest of the workflow.

Copilot uses AI. Check for mistakes.
contents: read
issues: write
Expand Down
16 changes: 16 additions & 0 deletions actions/setup/js/effective_tokens.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,28 @@ function _resetCache() {
_parsedMultipliers = undefined;
}

/**
* Read effective tokens from the GH_AW_EFFECTIVE_TOKENS environment variable and return
* a pre-formatted suffix string suitable for appending to footer text.
* Returns "" when the variable is absent or the parsed value is not a positive integer.
* @returns {string} Suffix string, e.g. " · ● 12.5K" or ""
*/
function getEffectiveTokensSuffix() {
const raw = process.env.GH_AW_EFFECTIVE_TOKENS;
const parsed = raw ? parseInt(raw, 10) : NaN;
if (!isNaN(parsed) && parsed > 0) {
return ` · ● ${formatET(parsed)}`;
}
return "";
Comment on lines +217 to +223
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

getEffectiveTokensSuffix() duplicates the env-parsing/suffix-formatting logic that already exists in actions/setup/js/messages_footer.cjs (getEffectiveTokensFromEnv() returns effectiveTokensSuffix). To avoid two implementations drifting (e.g., formatting or validation changes), consider extracting a single shared helper (or exporting/reusing getEffectiveTokensFromEnv/suffix logic) and using it from both places.

Copilot uses AI. Check for mistakes.
}

module.exports = {
defaultTokenClassWeights,
getTokenClassWeights,
getModelMultiplier,
computeBaseWeightedTokens,
computeEffectiveTokens,
formatET,
getEffectiveTokensSuffix,
_resetCache,
};
6 changes: 6 additions & 0 deletions actions/setup/js/handle_detection_runs.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { ERR_API } = require("./error_codes.cjs");
const { sanitizeContent } = require("./sanitize_content.cjs");
const { generateFooterWithExpiration } = require("./ephemerals.cjs");
const { renderTemplateFromFile } = require("./messages_core.cjs");
const { getEffectiveTokensSuffix } = require("./effective_tokens.cjs");

/**
* Search for or create the parent issue for all agentic workflow detection runs.
Expand Down Expand Up @@ -107,11 +108,16 @@ async function main() {

// Load and render comment template from file
const commentTemplatePath = `${process.env.RUNNER_TEMP}/gh-aw/prompts/detection_runs_comment.md`;

// Compute effective tokens suffix from environment variable (set by parse_token_usage.cjs / parse_mcp_gateway_log.cjs)
const effectiveTokensSuffix = getEffectiveTokensSuffix();

const commentBody = renderTemplateFromFile(commentTemplatePath, {
workflow_name: workflowName,
conclusion: detectionConclusion,
reason: detectionReason || "unknown",
run_url: runUrl,
effective_tokens_suffix: effectiveTokensSuffix,
});

// Sanitize the full comment body
Expand Down
6 changes: 6 additions & 0 deletions actions/setup/js/handle_noop_message.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { generateFooterWithExpiration } = require("./ephemerals.cjs");
const { renderTemplateFromFile } = require("./messages_core.cjs");
const { loadAgentOutput } = require("./load_agent_output.cjs");
const { isStagedMode } = require("./safe_output_helpers.cjs");
const { getEffectiveTokensSuffix } = require("./effective_tokens.cjs");

/**
* Search for or create the parent issue for all agentic workflow no-op runs
Expand Down Expand Up @@ -184,10 +185,15 @@ async function main() {

// Load and render comment template from file
const commentTemplatePath = `${process.env.RUNNER_TEMP}/gh-aw/prompts/noop_comment.md`;

// Compute effective tokens suffix from environment variable (set by parse_token_usage.cjs / parse_mcp_gateway_log.cjs)
const effectiveTokensSuffix = getEffectiveTokensSuffix();

const commentBody = renderTemplateFromFile(commentTemplatePath, {
workflow_name: workflowName,
message: noopMessage,
run_url: runUrl,
effective_tokens_suffix: effectiveTokensSuffix,
});

// Sanitize the full comment body
Expand Down
61 changes: 60 additions & 1 deletion actions/setup/js/handle_noop_message.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ This issue helps you:

{message}

> Generated from [{workflow_name}]({run_url})`;
> Generated from [{workflow_name}]({run_url}){effective_tokens_suffix}`;
}
return originalReadFileSync.call(fs, filePath, encoding);
});
Expand Down Expand Up @@ -669,4 +669,63 @@ This issue helps you:
// Verify XSS attempt was sanitized (specific behavior depends on sanitizeContent implementation)
expect(commentCall.body).not.toContain("<script>");
});

it("should include effective token count in footer when GH_AW_EFFECTIVE_TOKENS is set", async () => {
process.env.GH_AW_WORKFLOW_NAME = "Token Test Workflow";
process.env.GH_AW_RUN_URL = "https://github.com/test/test/actions/runs/123";
process.env.GH_AW_AGENT_CONCLUSION = "success";
process.env.GH_AW_EFFECTIVE_TOKENS = "12500";

// Create agent output file with only noop outputs
const outputFile = path.join(tempDir, "agent_output.json");
fs.writeFileSync(
outputFile,
JSON.stringify({
items: [{ type: "noop", message: "No action needed" }],
})
);
process.env.GH_AW_AGENT_OUTPUT = outputFile;

mockGithub.rest.search.issuesAndPullRequests.mockResolvedValue({
data: { total_count: 1, items: [{ number: 1, node_id: "ID", html_url: "url" }] },
});

mockGithub.rest.issues.createComment.mockResolvedValue({ data: {} });

const { main } = await import("./handle_noop_message.cjs?t=" + Date.now());
await main();

const commentCall = mockGithub.rest.issues.createComment.mock.calls[0][0];
expect(commentCall.body).toContain("· ● 12.5K");
});

it("should not include effective token count in footer when GH_AW_EFFECTIVE_TOKENS is not set", async () => {
process.env.GH_AW_WORKFLOW_NAME = "No Token Workflow";
process.env.GH_AW_RUN_URL = "https://github.com/test/test/actions/runs/456";
process.env.GH_AW_AGENT_CONCLUSION = "success";
delete process.env.GH_AW_EFFECTIVE_TOKENS;

// Create agent output file with only noop outputs
const outputFile = path.join(tempDir, "agent_output.json");
fs.writeFileSync(
outputFile,
JSON.stringify({
items: [{ type: "noop", message: "Nothing to do" }],
})
);
process.env.GH_AW_AGENT_OUTPUT = outputFile;

mockGithub.rest.search.issuesAndPullRequests.mockResolvedValue({
data: { total_count: 1, items: [{ number: 1, node_id: "ID", html_url: "url" }] },
});

mockGithub.rest.issues.createComment.mockResolvedValue({ data: {} });

const { main } = await import("./handle_noop_message.cjs?t=" + Date.now());
await main();

const commentCall = mockGithub.rest.issues.createComment.mock.calls[0][0];
expect(commentCall.body).not.toContain("●");
expect(commentCall.body).toContain("> Generated from [No Token Workflow](https://github.com/test/test/actions/runs/456)");
});
});
2 changes: 1 addition & 1 deletion actions/setup/md/detection_runs_comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

**Conclusion:** {conclusion} | **Reason:** {reason}

> Generated from [{workflow_name}]({run_url})
> Generated from [{workflow_name}]({run_url}){effective_tokens_suffix}
2 changes: 1 addition & 1 deletion actions/setup/md/noop_comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

{message}

> Generated from [{workflow_name}]({run_url})
> Generated from [{workflow_name}]({run_url}){effective_tokens_suffix}
Loading