Perhaps something like the script below ?
In Keyboard Maestro you could paste the code into an Execute JavaScript for Automation action.
(You should be able to find descriptions of the properties and methods in http://guide.taskpaper.com/scripting_api.html, and more general material on scripts in http://guide.taskpaper.com/creating_scripts.html and these threads:
(function () {
'use strict';
function fn(editor, options) {
var outline = editor.outline,
sln = editor.selection.startItem,
strTag = options.tagName,
strAttr = 'data-' + strTag;
if (sln && !sln.hasAttribute(strAttr)) {
outline.groupUndoAndChanges(
function () {
sln.setAttribute(
strAttr, outline
// list the items with that tag,
.evaluateItemPath('//@' + strTag)
// and trawl for their highest value.
.reduce(
function (a, x) {
var v = x.getAttribute(strAttr),
n = parseInt(v, 10) || 0;
return n > a ? n : a;
},
0 // start at zero,
) + 1 // add one to the final max.
);
}
);
}
}
var ds = Application("TaskPaper")
.documents,
varResult = ds.length ? ds[0].evaluate({
script: fn.toString(),
withOptions: {
tagName: 'issue'
}
}) : false;
return varResult
})();